Skip to content

Commit

Permalink
Speed up and improve "ipfs-cluster-follow * list"
Browse files Browse the repository at this point in the history
For the online case we were unnecessarily loading the configuration from IPFS, a very
slow operation if IPFS is very busy (when syncing).

For the offline case, we required IPFS to be online (for remote
configurations) slow things down as well and is uncovenient. Instead, simply
open the database with default parameters and list it.
  • Loading branch information
hsanjuan committed May 14, 2020
1 parent 7e9cece commit 7378183
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
28 changes: 10 additions & 18 deletions cmd/ipfs-cluster-follow/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,17 +407,7 @@ func listCmd(c *cli.Context) error {
clusterName := c.String("clusterName")

absPath, configPath, identityPath := buildPaths(c, clusterName)
cfgHelper, err := cmdutils.NewLoadedConfigHelper(configPath, identityPath)
if err != nil {
fmt.Println("error loading configurations.")
if config.IsErrFetchingSource(err) {
fmt.Println("Make sure the source URL is reachable:")
}
return cli.Exit(err, 1)
}
cfgHelper.Manager().Shutdown()

err = printStatusOnline(absPath, clusterName)
err := printStatusOnline(absPath, clusterName)
if err != nil {
apiErr, ok := err.(*api.Error)
if ok && apiErr.Code != 0 {
Expand All @@ -429,6 +419,15 @@ func listCmd(c *cli.Context) error {
), 1)
}

// Generate a default config just for the purpose of having
// a badger configuration that the state manager can use to
// open and read the database.
cfgHelper := cmdutils.NewConfigHelper(configPath, identityPath, "crdt")
cfgHelper.Manager().Shutdown() // not needed
cfgHelper.Manager().Default() // we have a default crdt/Badger config
cfgHelper.Configs().Badger.SetBaseDir(absPath)
cfgHelper.Manager().ApplyEnvVars()

err := printStatusOffline(cfgHelper)
if err != nil {
return cli.Exit(errors.Wrap(err, "error obtaining the pinset"), 1)
Expand Down Expand Up @@ -465,13 +464,6 @@ func printStatusOnline(absPath, clusterName string) error {
}

func printStatusOffline(cfgHelper *cmdutils.ConfigHelper) error {
// The blockstore module loaded from ipfs-lite tends to print
// an error when the datastore is closed before the bloom
// filter cached has finished building. Could not find a way
// to avoid it other than disabling bloom chaching on offline
// ipfs-lite peers which is overkill. So we just hide it.
ipfscluster.SetFacilityLogLevel("blockstore", "critical")

mgr, err := cmdutils.NewStateManagerWithHelper(cfgHelper)
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions cmdutils/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewStateManager(consensus string, ident *config.Identity, cfgs *Configs) (S
case cfgs.Raft.ConfigKey():
return &raftStateManager{ident, cfgs}, nil
case cfgs.Crdt.ConfigKey():
return &crdtStateManager{ident, cfgs}, nil
return &crdtStateManager{cfgs}, nil
case "":
return nil, errors.New("could not determine the consensus component")
default:
Expand Down Expand Up @@ -113,8 +113,7 @@ func (raftsm *raftStateManager) Clean() error {
}

type crdtStateManager struct {
ident *config.Identity
cfgs *Configs
cfgs *Configs
}

func (crdtsm *crdtStateManager) GetStore() (ds.Datastore, error) {
Expand Down

0 comments on commit 7378183

Please sign in to comment.