Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve plugin preload logic #6576

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions plugin/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import (
opentracing "github.com/opentracing/opentracing-go"
)

var preloadPlugins []plugin.Plugin

// Preload adds one or more plugins to the preload list. This should _only_ be called during init.
func Preload(plugins ...plugin.Plugin) {
preloadPlugins = append(preloadPlugins, plugins...)
}

var log = logging.Logger("plugin/loader")

var loadPluginsFunc = func(string) ([]plugin.Plugin, error) {
Expand Down
11 changes: 5 additions & 6 deletions plugin/loader/preload.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package loader

import (
"github.com/ipfs/go-ipfs/plugin"
pluginbadgerds "github.com/ipfs/go-ipfs/plugin/plugins/badgerds"
pluginflatfs "github.com/ipfs/go-ipfs/plugin/plugins/flatfs"
pluginipldgit "github.com/ipfs/go-ipfs/plugin/plugins/git"
Expand All @@ -12,9 +11,9 @@ import (
// This file is being generated as part of plugin build process
// To change it, modify the plugin/loader/preload.sh

var preloadPlugins = []plugin.Plugin{
pluginipldgit.Plugins[0],
pluginbadgerds.Plugins[0],
pluginflatfs.Plugins[0],
pluginlevelds.Plugins[0],
func init() {
Preload(pluginipldgit.Plugins...)
Preload(pluginbadgerds.Plugins...)
Preload(pluginflatfs.Plugins...)
Preload(pluginlevelds.Plugins...)
}
9 changes: 5 additions & 4 deletions plugin/loader/preload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ cat <<EOL
package loader

import (
"github.com/ipfs/go-ipfs/plugin"
EOL

to_preload | while read -r name path num; do
Expand All @@ -25,12 +24,14 @@ cat <<EOL
// This file is being generated as part of plugin build process
// To change it, modify the plugin/loader/preload.sh

var preloadPlugins = []plugin.Plugin{
func init() {
EOL

to_preload | while read -r name path num; do
echo "plugin$name.Plugins[$num],"
case "$num" in
'*') echo " Preload(plugin$name.Plugins...)" ;; # All plugins
*) echo " Preload(plugin$name.Plugins[$num])" ;; # A specific plugin
esac
done


echo "}"
10 changes: 5 additions & 5 deletions plugin/loader/preload_list
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# this file contains plugins to be preloaded
# empty lines or starting with '#' are ignored
#
# name go-path number of the sub-plugin
# name go-path number of the sub-plugin or *

ipldgit github.com/ipfs/go-ipfs/plugin/plugins/git 0
ipldgit github.com/ipfs/go-ipfs/plugin/plugins/git *

badgerds github.com/ipfs/go-ipfs/plugin/plugins/badgerds 0
flatfs github.com/ipfs/go-ipfs/plugin/plugins/flatfs 0
levelds github.com/ipfs/go-ipfs/plugin/plugins/levelds 0
badgerds github.com/ipfs/go-ipfs/plugin/plugins/badgerds *
flatfs github.com/ipfs/go-ipfs/plugin/plugins/flatfs *
levelds github.com/ipfs/go-ipfs/plugin/plugins/levelds *