From 07415bd8b3e78ebf1f6c9bed151b00469ccbd603 Mon Sep 17 00:00:00 2001 From: Bogdan Rosianu Date: Tue, 27 Sep 2022 11:11:48 +0300 Subject: [PATCH] fix accounts trie remover config value --- .../factory/customDatabaseRemoverCreator.go | 17 ++++++++ .../customDatabaseRemoverCreator_test.go | 41 +++++++++++++++++++ storage/factory/pruningStorerFactory.go | 3 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 storage/databaseremover/factory/customDatabaseRemoverCreator.go create mode 100644 storage/databaseremover/factory/customDatabaseRemoverCreator_test.go diff --git a/storage/databaseremover/factory/customDatabaseRemoverCreator.go b/storage/databaseremover/factory/customDatabaseRemoverCreator.go new file mode 100644 index 00000000000..47c163e52ab --- /dev/null +++ b/storage/databaseremover/factory/customDatabaseRemoverCreator.go @@ -0,0 +1,17 @@ +package factory + +import ( + "github.com/ElrondNetwork/elrond-go/config" + "github.com/ElrondNetwork/elrond-go/storage" + "github.com/ElrondNetwork/elrond-go/storage/databaseremover" + "github.com/ElrondNetwork/elrond-go/storage/databaseremover/disabled" +) + +// CreateCustomDatabaseRemover will handle the creation of a custom database remover based on the configuration +func CreateCustomDatabaseRemover(storagePruningConfig config.StoragePruningConfig) (storage.CustomDatabaseRemoverHandler, error) { + if storagePruningConfig.AccountsTrieCleanOldEpochsData { + return databaseremover.NewCustomDatabaseRemover(storagePruningConfig) + } + + return disabled.NewDisabledCustomDatabaseRemover(), nil +} diff --git a/storage/databaseremover/factory/customDatabaseRemoverCreator_test.go b/storage/databaseremover/factory/customDatabaseRemoverCreator_test.go new file mode 100644 index 00000000000..acf4cd5f6fc --- /dev/null +++ b/storage/databaseremover/factory/customDatabaseRemoverCreator_test.go @@ -0,0 +1,41 @@ +package factory + +import ( + "fmt" + "testing" + + "github.com/ElrondNetwork/elrond-go/config" + "github.com/stretchr/testify/require" +) + +func TestCreateCustomDatabaseRemover(t *testing.T) { + t.Parallel() + + t.Run("should create real custom database remover", func(t *testing.T) { + t.Parallel() + + storagePruningArgs := config.StoragePruningConfig{ + AccountsTrieCleanOldEpochsData: true, + AccountsTrieSkipRemovalCustomPattern: "%1", + } + + removerInstance, err := CreateCustomDatabaseRemover(storagePruningArgs) + require.NoError(t, err) + + require.Equal(t, "*databaseremover.customDatabaseRemover", fmt.Sprintf("%T", removerInstance)) + }) + + t.Run("should create disabled custom database remover", func(t *testing.T) { + t.Parallel() + + storagePruningArgs := config.StoragePruningConfig{ + AccountsTrieCleanOldEpochsData: false, + AccountsTrieSkipRemovalCustomPattern: "%1", + } + + removerInstance, err := CreateCustomDatabaseRemover(storagePruningArgs) + require.NoError(t, err) + + require.Equal(t, "*disabled.disabledCustomDatabaseRemover", fmt.Sprintf("%T", removerInstance)) + }) +} diff --git a/storage/factory/pruningStorerFactory.go b/storage/factory/pruningStorerFactory.go index fb1d84645fb..e7e114e9c2d 100644 --- a/storage/factory/pruningStorerFactory.go +++ b/storage/factory/pruningStorerFactory.go @@ -13,6 +13,7 @@ import ( "github.com/ElrondNetwork/elrond-go/storage/clean" "github.com/ElrondNetwork/elrond-go/storage/databaseremover" "github.com/ElrondNetwork/elrond-go/storage/databaseremover/disabled" + "github.com/ElrondNetwork/elrond-go/storage/databaseremover/factory" storageDisabled "github.com/ElrondNetwork/elrond-go/storage/disabled" "github.com/ElrondNetwork/elrond-go/storage/pruning" "github.com/ElrondNetwork/elrond-go/storage/storageUnit" @@ -118,7 +119,7 @@ func (psf *StorageServiceFactory) CreateForShard() (dataRetriever.StorageService // in case of a failure while creating (not opening). disabledCustomDatabaseRemover := disabled.NewDisabledCustomDatabaseRemover() - customDatabaseRemover, err := databaseremover.NewCustomDatabaseRemover(psf.generalConfig.StoragePruning) + customDatabaseRemover, err := factory.CreateCustomDatabaseRemover(psf.generalConfig.StoragePruning) if err != nil { return nil, err }