Skip to content

Commit

Permalink
fix accounts trie remover config value
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed Sep 27, 2022
1 parent f992a46 commit 07415bd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
17 changes: 17 additions & 0 deletions storage/databaseremover/factory/customDatabaseRemoverCreator.go
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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))
})
}
3 changes: 2 additions & 1 deletion storage/factory/pruningStorerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 07415bd

Please sign in to comment.