From 2e77a1da58bbbfd0cce872957fac6e75f88b6b81 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Tue, 15 Feb 2022 14:33:35 -0500 Subject: [PATCH 1/8] feat: fs-repo-11-to-12 special flatfs handling --- fs-repo-11-to-12/go.mod | 1 + fs-repo-11-to-12/migration/setup.go | 58 +++++++++++++++++++++++ fs-repo-11-to-12/migration/swapper.go | 67 +++++++++++++++++++++++++++ fs-repo-11-to-12/vendor/modules.txt | 1 + 4 files changed, 127 insertions(+) diff --git a/fs-repo-11-to-12/go.mod b/fs-repo-11-to-12/go.mod index 0d2769d8..942b39de 100644 --- a/fs-repo-11-to-12/go.mod +++ b/fs-repo-11-to-12/go.mod @@ -8,6 +8,7 @@ require ( github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-datastore v0.4.5 github.com/ipfs/go-ds-badger v0.2.7-0.20220117180822-159330558612 // indirect + github.com/ipfs/go-ds-flatfs v0.4.5 github.com/ipfs/go-filestore v1.0.0 github.com/ipfs/go-ipfs v0.8.0 github.com/ipfs/go-ipfs-ds-help v1.0.0 diff --git a/fs-repo-11-to-12/migration/setup.go b/fs-repo-11-to-12/migration/setup.go index a7b29cf9..738a1bc6 100644 --- a/fs-repo-11-to-12/migration/setup.go +++ b/fs-repo-11-to-12/migration/setup.go @@ -2,10 +2,13 @@ package mg11 import ( "context" + "errors" "fmt" "io" "os" "path/filepath" + "reflect" + "unsafe" ipfslite "github.com/hsanjuan/ipfs-lite" migrate "github.com/ipfs/fs-repo-migrations/tools/go-migrate" @@ -18,6 +21,9 @@ import ( loader "github.com/ipfs/go-ipfs/plugin/loader" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" format "github.com/ipfs/go-ipld-format" + + "github.com/ipfs/go-datastore/mount" + flatfs "github.com/ipfs/go-ds-flatfs" ) // locks the repo @@ -83,6 +89,58 @@ func (m *Migration) open(opts migrate.Options) error { return nil } +func getUnexportedField(field reflect.Value) interface{} { + return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface() +} + +func IsBasicFlatFSBlockstore(dstore ds.Datastore) (dsPath string, v1 *flatfs.ShardIdV1, err error) { + errNotDefault := errors.New("not the default config") + defer func() { + if err := recover(); err != nil { + err = errNotDefault + } + }() + + mds, ok := dstore.(*mount.Datastore) + if !ok { + return "", nil, errNotDefault + } + + mnts, ok := getUnexportedField(reflect.ValueOf(mds).Elem().FieldByName("mounts")).([]mount.Mount) + if !ok { + return "", nil, errNotDefault + } + + if len(mnts) != 2 { + return "", nil, errNotDefault + } + + var blkDs ds.Datastore + if mnts[0].Prefix.Equal(blocksPrefix) { + blkDs = mnts[0].Datastore + } else if mnts[1].Prefix.Equal(blocksPrefix) { + blkDs = mnts[1].Datastore + } else { + return "", nil, errNotDefault + } + + if reflect.TypeOf(blkDs).String() != "*measure.measure" { + return "", nil, errNotDefault + } + + fsds, ok := getUnexportedField(reflect.ValueOf(blkDs).Elem().FieldByName("backend")).(*flatfs.Datastore) + if !ok { + return "", nil, errNotDefault + } + fsdsPath := reflect.ValueOf(fsds).Elem().FieldByName("path").String() + + shard, err := flatfs.ParseShardFunc(fsds.ShardStr()) + if err != nil { + return "", nil, errNotDefault + } + return fsdsPath, shard, nil +} + // Create a file to store the list of migrated CIDs. If it exists, it is // opened for appending only. func createBackupFile(path, name string) (*os.File, error) { diff --git a/fs-repo-11-to-12/migration/swapper.go b/fs-repo-11-to-12/migration/swapper.go index 82da7563..92ec1573 100644 --- a/fs-repo-11-to-12/migration/swapper.go +++ b/fs-repo-11-to-12/migration/swapper.go @@ -2,7 +2,9 @@ package mg11 import ( "errors" + flatfs "github.com/ipfs/go-ds-flatfs" "os" + "path/filepath" "strconv" "sync" "sync/atomic" @@ -10,6 +12,7 @@ import ( log "github.com/ipfs/fs-repo-migrations/tools/stump" cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" + ktds "github.com/ipfs/go-datastore/keytransform" query "github.com/ipfs/go-datastore/query" dshelp "github.com/ipfs/go-ipfs-ds-help" ) @@ -177,10 +180,74 @@ func (cswap *CidSwapper) prepareWorker(resultsCh <-chan query.Result) (uint64, u return sw.swapped, errored } +func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.ShardIdV1, swapCh <-chan Swap, reverting bool) (uint64, uint64) { + var swapped, errored uint64 + + const flatfsExtension = ".data" + prefix := ktds.PrefixTransform{Prefix: blocksPrefix} + + getPath := func(basePath string, key ds.Key) (string, string) { + child := prefix.InvertKey(key) + noslash := child.String()[1:] + dir := filepath.Join(fsdsPath, fsdsShard.Func()(noslash)) + file := filepath.Join(dir, noslash+flatfsExtension) + + return dir, file + } + + // Process keys from the results channel + for sw := range swapCh { + if reverting { + old := sw.Old + sw.Old = sw.New + sw.New = old + } + + _, oldPath := getPath(fsdsPath, sw.Old) + newDir, newPath := getPath(fsdsPath, sw.New) + + _, err := os.Stat(oldPath) + if err != nil { + log.Error("could not swap %s->%s. Could not find %s even though it was in the backup file %s. Skipping.", sw.Old, sw.New, sw.Old, err.Error()) + continue + } + + if err := os.Mkdir(newDir, 0755); err != nil && !os.IsExist(err) { + log.Error("could not swap %s->%s. Skipping.", sw.Old, sw.New, err.Error()) + continue + } + + if err := os.Rename(oldPath, newPath); err != nil { + log.Error("could not swap %s->%s. Skipping.", sw.Old, sw.New, err.Error()) + errored++ + continue + } + swapped++ + + if cswap.SwapCh != nil { + cswap.SwapCh <- Swap{Old: sw.Old, New: sw.New} + } + } + + return swapped, errored +} + // unswap worker takes notifications from unswapCh (as they would be sent by // the swapWorker) and undoes them. It ignores NotFound errors so that reverts // can succeed even if they failed half-way. func (cswap *CidSwapper) swapWorker(swapCh <-chan Swap, reverting bool) (uint64, uint64) { + // Use the more generic datastore swapper if not using a simple FlatFS setup. + // Also use it for reversion since the FlatFS specific code doesn't specifically + // handle some reversion edge cases. + fsdsPath, fsDsShard, err := IsBasicFlatFSBlockstore(cswap.Store) + if err != nil || reverting || !cswap.Prefix.Equal(blocksPrefix) { + return cswap.swapWorkerDS(swapCh, reverting) + } + + return cswap.swapWorkerFlatFS(fsdsPath, fsDsShard, swapCh, reverting) +} + +func (cswap *CidSwapper) swapWorkerDS(swapCh <-chan Swap, reverting bool) (uint64, uint64) { var errored uint64 swker := &swapWorker{ diff --git a/fs-repo-11-to-12/vendor/modules.txt b/fs-repo-11-to-12/vendor/modules.txt index 157a1c19..a43c7274 100644 --- a/fs-repo-11-to-12/vendor/modules.txt +++ b/fs-repo-11-to-12/vendor/modules.txt @@ -127,6 +127,7 @@ github.com/ipfs/go-datastore/sync ## explicit github.com/ipfs/go-ds-badger # github.com/ipfs/go-ds-flatfs v0.4.5 +## explicit github.com/ipfs/go-ds-flatfs # github.com/ipfs/go-ds-leveldb v0.4.2 github.com/ipfs/go-ds-leveldb From 6cf297c220fe7f23acf90db25e9f0ec3cfc786ec Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 16 Feb 2022 06:05:15 -0500 Subject: [PATCH 2/8] fix: run the migration using the flatfs fast-path. Was previously not doing it for the actual migration --- fs-repo-11-to-12/migration/swapper.go | 53 ++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/fs-repo-11-to-12/migration/swapper.go b/fs-repo-11-to-12/migration/swapper.go index 92ec1573..0860b1c4 100644 --- a/fs-repo-11-to-12/migration/swapper.go +++ b/fs-repo-11-to-12/migration/swapper.go @@ -195,6 +195,11 @@ func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.Sha return dir, file } + genericSwker := &swapWorker{ + store: cswap.Store, + syncPrefix: cswap.Prefix, + } + // Process keys from the results channel for sw := range swapCh { if reverting { @@ -203,6 +208,32 @@ func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.Sha sw.New = old } + if !sw.Old.Parent().Equal(sw.New.Parent()) { + log.Error("could not swap %s->%s. The namespaces changed. Skipping.", sw.Old, sw.New) + errored++ + continue + } + + if !sw.Old.Parent().Equal(blocksPrefix) { + err := genericSwker.swap(sw.Old, sw.New, reverting) + + // The datastore does not have the block we are planning to + // migrate. + if err == ds.ErrNotFound { + log.Error("could not swap %s->%s. Could not find %s even though it was in the backup file. Skipping.", sw.Old, sw.New, sw.Old) + continue + } else if err != nil { + log.Error("swapping %s->%s: %s", sw.Old, sw.New, err) + errored++ + continue + } + + if cswap.SwapCh != nil { + cswap.SwapCh <- Swap{Old: sw.Old, New: sw.New} + } + continue + } + _, oldPath := getPath(fsdsPath, sw.Old) newDir, newPath := getPath(fsdsPath, sw.New) @@ -224,12 +255,30 @@ func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.Sha } swapped++ + const swapLogThreshold = 10000 + if swapped%swapLogThreshold == 0 { + log.Log("Migration worker has moved %d flatfs files", swapLogThreshold) + } + if cswap.SwapCh != nil { cswap.SwapCh <- Swap{Old: sw.Old, New: sw.New} } } - return swapped, errored + // handle generic worker sync + // final sync to added things + err := genericSwker.syncAndDelete() + if err != nil { + log.Error("error performing last sync: %s", err) + errored++ + } + err = genericSwker.sync() // final sync for deletes. + if err != nil { + log.Error("error performing last sync for deletions: %s", err) + errored++ + } + + return genericSwker.swapped + swapped, errored } // unswap worker takes notifications from unswapCh (as they would be sent by @@ -240,7 +289,7 @@ func (cswap *CidSwapper) swapWorker(swapCh <-chan Swap, reverting bool) (uint64, // Also use it for reversion since the FlatFS specific code doesn't specifically // handle some reversion edge cases. fsdsPath, fsDsShard, err := IsBasicFlatFSBlockstore(cswap.Store) - if err != nil || reverting || !cswap.Prefix.Equal(blocksPrefix) { + if err != nil || reverting { return cswap.swapWorkerDS(swapCh, reverting) } From 7bdf4b4361dff3ae04887299f560eac6489165f8 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 16 Feb 2022 12:36:28 -0500 Subject: [PATCH 3/8] add time to incremental migration worker logging Also log total swapped in flatfs specific migration --- fs-repo-11-to-12/migration/swapper.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs-repo-11-to-12/migration/swapper.go b/fs-repo-11-to-12/migration/swapper.go index 0860b1c4..8e49570c 100644 --- a/fs-repo-11-to-12/migration/swapper.go +++ b/fs-repo-11-to-12/migration/swapper.go @@ -8,6 +8,7 @@ import ( "strconv" "sync" "sync/atomic" + "time" log "github.com/ipfs/fs-repo-migrations/tools/stump" cid "github.com/ipfs/go-cid" @@ -257,7 +258,7 @@ func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.Sha const swapLogThreshold = 10000 if swapped%swapLogThreshold == 0 { - log.Log("Migration worker has moved %d flatfs files", swapLogThreshold) + log.Log("%v: Migration worker has moved %d flatfs files and %d in total", time.Now(), swapLogThreshold, swapped) } if cswap.SwapCh != nil { @@ -404,7 +405,7 @@ func (sw *swapWorker) syncAndDelete() error { } func (sw *swapWorker) sync() error { - log.Log("Migration worker syncing after %d objects migrated", sw.swapped) + log.Log("%v: Migration worker syncing after %d objects migrated", time.Now(), sw.swapped) err := sw.store.Sync(sw.syncPrefix) if err != nil { return err From 015aa166037877809196b48c975ee5cbc3009c22 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 16 Feb 2022 15:37:38 -0500 Subject: [PATCH 4/8] add env var to control disabling the flatfs fast path. it is enabled by default --- fs-repo-11-to-12/migration/migration_test.go | 20 +++++++++++++++++++- fs-repo-11-to-12/migration/swapper.go | 20 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/fs-repo-11-to-12/migration/migration_test.go b/fs-repo-11-to-12/migration/migration_test.go index bec635d4..d165c1f7 100644 --- a/fs-repo-11-to-12/migration/migration_test.go +++ b/fs-repo-11-to-12/migration/migration_test.go @@ -17,6 +17,24 @@ const ( workingRepo = "repotest_copy" ) +func TestGenericMigration(t *testing.T) { + origSetting := EnableFlatFSFastPath + defer func() { + EnableFlatFSFastPath = origSetting + }() + EnableFlatFSFastPath = false + testMigrationBase(t) +} + +func TestFlatFSMigration(t *testing.T) { + origSetting := EnableFlatFSFastPath + defer func() { + EnableFlatFSFastPath = origSetting + }() + EnableFlatFSFastPath = true + testMigrationBase(t) +} + // TestMigration works on an IPFS repository as created by running steps.sh // with ipfs v0.8.0 on using the $repotest folder: // @@ -28,7 +46,7 @@ const ( // added bafybeie4pduk2uwvr5dq36wnbhxspgox7dtqo3fprri4r2wpa7vrej5jqq b // added Qmesmmf1EEG1orJb6XdK6DabxexsseJnCfw8pqWgonbkoj c/file3 // added QmT3zhz9ZZjEpbzWib95EQ5ESUQs4YasrMQwPScpNGLEXZ c -func TestMigration(t *testing.T) { +func testMigrationBase(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/fs-repo-11-to-12/migration/swapper.go b/fs-repo-11-to-12/migration/swapper.go index 8e49570c..e821d5ff 100644 --- a/fs-repo-11-to-12/migration/swapper.go +++ b/fs-repo-11-to-12/migration/swapper.go @@ -25,9 +25,12 @@ var SyncSize uint64 = 100 * 1024 * 1024 // 100MiB // migration. var NWorkers int = 1 +var EnableFlatFSFastPath bool = true + func init() { workerEnvVar := "IPFS_FS_MIGRATION_11_TO_12_NWORKERS" syncSizeEnvVar := "IPFS_FS_MIGRATION_11_TO_12_SYNC_SIZE_BYTES" + flatfsFastPathEnvVar := "IPFS_FS_MIGRATION_11_TO_12_ENABLE_FLATFS_FASTPATH" if nworkersStr, nworkerInEnv := os.LookupEnv(workerEnvVar); nworkerInEnv { nworkers, err := strconv.Atoi(nworkersStr) if err != nil { @@ -49,6 +52,14 @@ func init() { } SyncSize = syncSize } + + if flatfsFastPathStr, flatfsFastPathInEnv := os.LookupEnv(flatfsFastPathEnvVar); flatfsFastPathInEnv { + enableFlatfsFastPath, err := strconv.ParseBool(flatfsFastPathStr) + if err != nil { + panic(err) + } + EnableFlatFSFastPath = enableFlatfsFastPath + } } // Swap holds the datastore keys for the original CID and for the @@ -286,11 +297,16 @@ func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.Sha // the swapWorker) and undoes them. It ignores NotFound errors so that reverts // can succeed even if they failed half-way. func (cswap *CidSwapper) swapWorker(swapCh <-chan Swap, reverting bool) (uint64, uint64) { - // Use the more generic datastore swapper if not using a simple FlatFS setup. + // Use the more generic datastore swapper if the FlatFS fast path has been explicitly disabled // Also use it for reversion since the FlatFS specific code doesn't specifically // handle some reversion edge cases. + if !EnableFlatFSFastPath || reverting { + return cswap.swapWorkerDS(swapCh, reverting) + } + + // Use the more generic datastore swapper if not using a simple FlatFS setup. fsdsPath, fsDsShard, err := IsBasicFlatFSBlockstore(cswap.Store) - if err != nil || reverting { + if err != nil { return cswap.swapWorkerDS(swapCh, reverting) } From e5286e2bbc05757feabf8ed186427a8ce88d6de8 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 16 Feb 2022 15:41:31 -0500 Subject: [PATCH 5/8] log the number of successful flatfs swaps at the end of the worker cycle so that they are all logged --- fs-repo-11-to-12/migration/swapper.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs-repo-11-to-12/migration/swapper.go b/fs-repo-11-to-12/migration/swapper.go index e821d5ff..f094b678 100644 --- a/fs-repo-11-to-12/migration/swapper.go +++ b/fs-repo-11-to-12/migration/swapper.go @@ -212,6 +212,9 @@ func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.Sha syncPrefix: cswap.Prefix, } + // the frequency with which we log flatfs moves + const swapLogThreshold = 10000 + // Process keys from the results channel for sw := range swapCh { if reverting { @@ -267,7 +270,6 @@ func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.Sha } swapped++ - const swapLogThreshold = 10000 if swapped%swapLogThreshold == 0 { log.Log("%v: Migration worker has moved %d flatfs files and %d in total", time.Now(), swapLogThreshold, swapped) } @@ -277,6 +279,11 @@ func (cswap *CidSwapper) swapWorkerFlatFS(fsdsPath string, fsdsShard *flatfs.Sha } } + // log the leftover flatfs moves that were not already logged + if rem := swapped % swapLogThreshold; rem != 0 { + log.Log("%v: Migration worker has moved %d flatfs files and %d in total", time.Now(), rem, swapped) + } + // handle generic worker sync // final sync to added things err := genericSwker.syncAndDelete() From 2b1695073fbae43d44b0c5221bac9de46863d062 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 16 Feb 2022 15:42:52 -0500 Subject: [PATCH 6/8] changed generic migration worker logging to indicate that it is the generic migration worker --- fs-repo-11-to-12/migration/swapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs-repo-11-to-12/migration/swapper.go b/fs-repo-11-to-12/migration/swapper.go index f094b678..81f4e80d 100644 --- a/fs-repo-11-to-12/migration/swapper.go +++ b/fs-repo-11-to-12/migration/swapper.go @@ -428,7 +428,7 @@ func (sw *swapWorker) syncAndDelete() error { } func (sw *swapWorker) sync() error { - log.Log("%v: Migration worker syncing after %d objects migrated", time.Now(), sw.swapped) + log.Log("%v: Generic migration worker syncing after %d objects migrated", time.Now(), sw.swapped) err := sw.store.Sync(sw.syncPrefix) if err != nil { return err From 0eca6f7613e14fa17cd840a9bf1a484b32e22e2d Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 16 Feb 2022 17:34:35 -0500 Subject: [PATCH 7/8] load plugins as global singleton since the datastore registry is a singleton anyway. close datastore after use in migration tests --- fs-repo-11-to-12/migration/migration.go | 4 +--- fs-repo-11-to-12/migration/migration_test.go | 1 + fs-repo-11-to-12/migration/setup.go | 13 +++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fs-repo-11-to-12/migration/migration.go b/fs-repo-11-to-12/migration/migration.go index c898bac9..231100c3 100644 --- a/fs-repo-11-to-12/migration/migration.go +++ b/fs-repo-11-to-12/migration/migration.go @@ -9,7 +9,6 @@ import ( "fmt" "os" "path/filepath" - "sync" log "github.com/ipfs/fs-repo-migrations/tools/stump" @@ -42,8 +41,7 @@ var migrationPrefixes = []ds.Key{ // Migration implements the migration described above. type Migration struct { - loadPluginsOnce sync.Once - dstore ds.Batching + dstore ds.Batching } // Versions returns the current version string for this migration. diff --git a/fs-repo-11-to-12/migration/migration_test.go b/fs-repo-11-to-12/migration/migration_test.go index d165c1f7..bf2f2ace 100644 --- a/fs-repo-11-to-12/migration/migration_test.go +++ b/fs-repo-11-to-12/migration/migration_test.go @@ -194,6 +194,7 @@ func testMigrationBase(t *testing.T) { if err != nil { t.Fatal(err) } + defer m.dstore.Close() // Check that the CIDv1s that we explicitally pinned or // added to MFS are now retrievable as CIDv1-addressed nodes. diff --git a/fs-repo-11-to-12/migration/setup.go b/fs-repo-11-to-12/migration/setup.go index 738a1bc6..2ec2dd35 100644 --- a/fs-repo-11-to-12/migration/setup.go +++ b/fs-repo-11-to-12/migration/setup.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "reflect" + "sync" "unsafe" ipfslite "github.com/hsanjuan/ipfs-lite" @@ -32,14 +33,18 @@ func (m *Migration) lock(opts migrate.Options) (io.Closer, error) { return lock.Lock2(opts.Path) } +var loadPluginsOnce sync.Once + // this is just setup so that we can open the datastore. // Plugins are loaded once only. -func (m *Migration) setupPlugins(opts migrate.Options) error { +// Note: this means plugins cannot be loaded from multiple repos within the same binary +// however, this does not seem relevant for migrations +func setupPlugins(repoPath string) error { var err error var plugins *loader.PluginLoader - m.loadPluginsOnce.Do(func() { + loadPluginsOnce.Do(func() { log.VLog(" - loading repo configurations") - plugins, err = loader.NewPluginLoader(opts.Path) + plugins, err = loader.NewPluginLoader(repoPath) if err != nil { err = fmt.Errorf("error loading plugins: %s", err) return @@ -62,7 +67,7 @@ func (m *Migration) setupPlugins(opts migrate.Options) error { // user's IPFS configuration says that should be used. If we had a datastore, // we close it and re-open it. func (m *Migration) open(opts migrate.Options) error { - if err := m.setupPlugins(opts); err != nil { + if err := setupPlugins(opts.Path); err != nil { return err } From a0957a06ac60f6f79b09cf40232cc4e636fc3dc4 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Thu, 17 Feb 2022 17:02:35 -0500 Subject: [PATCH 8/8] updated internal error used to indicate a datastore isn't one supported for the flatfs fast path --- fs-repo-11-to-12/migration/setup.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs-repo-11-to-12/migration/setup.go b/fs-repo-11-to-12/migration/setup.go index 2ec2dd35..1495c103 100644 --- a/fs-repo-11-to-12/migration/setup.go +++ b/fs-repo-11-to-12/migration/setup.go @@ -99,25 +99,25 @@ func getUnexportedField(field reflect.Value) interface{} { } func IsBasicFlatFSBlockstore(dstore ds.Datastore) (dsPath string, v1 *flatfs.ShardIdV1, err error) { - errNotDefault := errors.New("not the default config") + errNotSupportedFlatFSConfig := errors.New("not a supported FlatFS config") defer func() { if err := recover(); err != nil { - err = errNotDefault + err = errNotSupportedFlatFSConfig } }() mds, ok := dstore.(*mount.Datastore) if !ok { - return "", nil, errNotDefault + return "", nil, errNotSupportedFlatFSConfig } mnts, ok := getUnexportedField(reflect.ValueOf(mds).Elem().FieldByName("mounts")).([]mount.Mount) if !ok { - return "", nil, errNotDefault + return "", nil, errNotSupportedFlatFSConfig } if len(mnts) != 2 { - return "", nil, errNotDefault + return "", nil, errNotSupportedFlatFSConfig } var blkDs ds.Datastore @@ -126,22 +126,22 @@ func IsBasicFlatFSBlockstore(dstore ds.Datastore) (dsPath string, v1 *flatfs.Sha } else if mnts[1].Prefix.Equal(blocksPrefix) { blkDs = mnts[1].Datastore } else { - return "", nil, errNotDefault + return "", nil, errNotSupportedFlatFSConfig } if reflect.TypeOf(blkDs).String() != "*measure.measure" { - return "", nil, errNotDefault + return "", nil, errNotSupportedFlatFSConfig } fsds, ok := getUnexportedField(reflect.ValueOf(blkDs).Elem().FieldByName("backend")).(*flatfs.Datastore) if !ok { - return "", nil, errNotDefault + return "", nil, errNotSupportedFlatFSConfig } fsdsPath := reflect.ValueOf(fsds).Elem().FieldByName("path").String() shard, err := flatfs.ParseShardFunc(fsds.ShardStr()) if err != nil { - return "", nil, errNotDefault + return "", nil, errNotSupportedFlatFSConfig } return fsdsPath, shard, nil }