From 62cbb72a5edd045d7d037402fe68b98a615d7abe Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 4 Jul 2024 10:11:30 +0300 Subject: [PATCH] [#1226] blobovniczatree: Delete fix db extensions in Init() Since several releases have been released, this code is not relevant. Signed-off-by: Dmitrii Stepanov --- internal/logs/logs.go | 6 -- .../blobstor/blobovniczatree/control.go | 47 -------------- .../blobstor/blobovniczatree/control_test.go | 63 ------------------- 3 files changed, 116 deletions(-) diff --git a/internal/logs/logs.go b/internal/logs/logs.go index 4f0b2912..ae883451 100644 --- a/internal/logs/logs.go +++ b/internal/logs/logs.go @@ -480,12 +480,6 @@ const ( BlobstoreRebuildStarted = "blobstore rebuild started" BlobstoreRebuildCompletedSuccessfully = "blobstore rebuild completed successfully" BlobstoreRebuildStopped = "blobstore rebuild stopped" - BlobovniczaTreeFixingFileExtensions = "fixing blobovnicza tree file extensions..." - BlobovniczaTreeFixingFileExtensionsCompletedSuccessfully = "fixing blobovnicza tree file extensions completed successfully" - BlobovniczaTreeFixingFileExtensionsFailed = "failed to fix blobovnicza tree file extensions" - BlobovniczaTreeFixingFileExtensionForFile = "fixing blobovnicza file extension..." - BlobovniczaTreeFixingFileExtensionCompletedSuccessfully = "fixing blobovnicza file extension completed successfully" - BlobovniczaTreeFixingFileExtensionFailed = "failed to fix blobovnicza file extension" BlobstorRebuildFailedToRebuildStorages = "failed to rebuild storages" BlobstorRebuildRebuildStoragesCompleted = "storages rebuild completed" BlobovniczaTreeCollectingDBToRebuild = "collecting blobovniczas to rebuild..." diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/control.go b/pkg/local_object_storage/blobstor/blobovniczatree/control.go index eeade942..a31e9d6c 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/control.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/control.go @@ -2,10 +2,6 @@ package blobovniczatree import ( "context" - "errors" - "os" - "path/filepath" - "strings" "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" @@ -14,8 +10,6 @@ import ( "golang.org/x/sync/errgroup" ) -var errFailedToChangeExtensionReadOnly = errors.New("failed to change blobovnicza extension: read only mode") - // Open opens blobovnicza tree. func (b *Blobovniczas) Open(mode mode.ComponentMode) error { b.readOnly = mode.ReadOnly() @@ -31,13 +25,6 @@ func (b *Blobovniczas) Open(mode mode.ComponentMode) error { func (b *Blobovniczas) Init() error { b.log.Debug(logs.BlobovniczatreeInitializingBlobovniczas) - b.log.Debug(logs.BlobovniczaTreeFixingFileExtensions) - if err := b.addDBExtensionToDBs(b.rootPath, 0); err != nil { - b.log.Error(logs.BlobovniczaTreeFixingFileExtensionsFailed, zap.Error(err)) - return err - } - b.log.Debug(logs.BlobovniczaTreeFixingFileExtensionsCompletedSuccessfully) - if b.readOnly { b.log.Debug(logs.BlobovniczatreeReadonlyModeSkipBlobovniczasInitialization) return nil @@ -111,37 +98,3 @@ func (b *Blobovniczas) getBlobovnicza(p string) *sharedDB { func (b *Blobovniczas) getBlobovniczaWithoutCaching(p string) *sharedDB { return b.commondbManager.GetByPath(p) } - -func (b *Blobovniczas) addDBExtensionToDBs(path string, depth uint64) error { - entries, err := os.ReadDir(path) - if os.IsNotExist(err) && depth == 0 { - return nil - } - - for _, entry := range entries { - if entry.IsDir() { - if err := b.addDBExtensionToDBs(filepath.Join(path, entry.Name()), depth+1); err != nil { - return err - } - continue - } - - if strings.HasSuffix(entry.Name(), dbExtension) { - continue - } - if b.readOnly { - return errFailedToChangeExtensionReadOnly - } - - sourcePath := filepath.Join(path, entry.Name()) - targetPath := filepath.Join(path, entry.Name()+dbExtension) - b.log.Debug(logs.BlobovniczaTreeFixingFileExtensionForFile, zap.String("source", sourcePath), zap.String("target", targetPath)) - if err := os.Rename(sourcePath, targetPath); err != nil { - b.log.Error(logs.BlobovniczaTreeFixingFileExtensionFailed, zap.String("source", sourcePath), zap.String("target", targetPath), zap.Error(err)) - return err - } - b.log.Debug(logs.BlobovniczaTreeFixingFileExtensionCompletedSuccessfully, zap.String("source", sourcePath), zap.String("target", targetPath)) - } - - return nil -} diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/control_test.go b/pkg/local_object_storage/blobstor/blobovniczatree/control_test.go index 7218cd6b..f0a32ded 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/control_test.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/control_test.go @@ -2,78 +2,15 @@ package blobovniczatree import ( "context" - "os" - "path/filepath" - "strings" "testing" objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/internal/blobstortest" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" "github.com/stretchr/testify/require" ) -func TestDBExtensionFix(t *testing.T) { - root := t.TempDir() - createTestTree(t, 0, 2, 3, root) - t.Run("adds suffix if not exists", func(t *testing.T) { - openAndCloseTestTree(t, 2, 3, root) - validateTestTree(t, root) - }) - - t.Run("not adds second suffix if exists", func(t *testing.T) { - openAndCloseTestTree(t, 2, 3, root) - validateTestTree(t, root) - }) -} - -func createTestTree(t *testing.T, currentDepth, depth, width uint64, path string) { - if currentDepth == depth { - var w uint64 - for ; w < width; w++ { - dbPath := filepath.Join(path, u64ToHexString(w)) - b := blobovnicza.New(blobovnicza.WithPath(dbPath)) - require.NoError(t, b.Open()) - require.NoError(t, b.Init()) - require.NoError(t, b.Close()) - } - return - } - - var w uint64 - for ; w < width; w++ { - createTestTree(t, currentDepth+1, depth, width, filepath.Join(path, u64ToHexString(w))) - } -} - -func openAndCloseTestTree(t *testing.T, depth, width uint64, path string) { - blz := NewBlobovniczaTree( - context.Background(), - WithBlobovniczaShallowDepth(depth), - WithBlobovniczaShallowWidth(width), - WithRootPath(path), - ) - require.NoError(t, blz.Open(mode.ComponentReadWrite)) - require.NoError(t, blz.Init()) - require.NoError(t, blz.Close()) -} - -func validateTestTree(t *testing.T, path string) { - entries, err := os.ReadDir(path) - require.NoError(t, err) - - for _, entry := range entries { - if entry.IsDir() { - validateTestTree(t, filepath.Join(path, entry.Name())) - } else { - require.True(t, strings.HasSuffix(entry.Name(), dbExtension)) - require.False(t, strings.HasSuffix(strings.TrimSuffix(entry.Name(), dbExtension), dbExtension)) - } - } -} - func TestObjectsAvailableAfterDepthAndWidthEdit(t *testing.T) { t.Parallel()