feat(store/v2): remove the pruning manager (#19411)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
co-authored by
Aleksandr Bezobchuk
parent
92eb6de6e3
commit
8fb9ca87b2
@@ -14,14 +14,14 @@ import (
|
||||
|
||||
func TestCommitterSuite(t *testing.T) {
|
||||
s := &commitment.CommitStoreTestSuite{
|
||||
NewStore: func(db store.RawDB, storeKeys []string, logger log.Logger) (*commitment.CommitStore, error) {
|
||||
NewStore: func(db store.RawDB, storeKeys []string, pruneOpts *store.PruneOptions, logger log.Logger) (*commitment.CommitStore, error) {
|
||||
multiTrees := make(map[string]commitment.Tree)
|
||||
cfg := DefaultConfig()
|
||||
for _, storeKey := range storeKeys {
|
||||
prefixDB := dbm.NewPrefixDB(db, []byte(storeKey))
|
||||
multiTrees[storeKey] = NewIavlTree(prefixDB, logger, cfg)
|
||||
}
|
||||
return commitment.NewCommitStore(multiTrees, db, logger)
|
||||
return commitment.NewCommitStore(multiTrees, db, pruneOpts, logger)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -36,14 +36,22 @@ type CommitStore struct {
|
||||
logger log.Logger
|
||||
db store.RawDB
|
||||
multiTrees map[string]Tree
|
||||
|
||||
// pruneOptions is the pruning configuration.
|
||||
pruneOptions *store.PruneOptions
|
||||
}
|
||||
|
||||
// NewCommitStore creates a new CommitStore instance.
|
||||
func NewCommitStore(multiTrees map[string]Tree, db store.RawDB, logger log.Logger) (*CommitStore, error) {
|
||||
func NewCommitStore(multiTrees map[string]Tree, db store.RawDB, pruneOpts *store.PruneOptions, logger log.Logger) (*CommitStore, error) {
|
||||
if pruneOpts == nil {
|
||||
pruneOpts = store.DefaultPruneOptions()
|
||||
}
|
||||
|
||||
return &CommitStore{
|
||||
logger: logger,
|
||||
db: db,
|
||||
multiTrees: multiTrees,
|
||||
logger: logger,
|
||||
db: db,
|
||||
multiTrees: multiTrees,
|
||||
pruneOptions: pruneOpts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -216,6 +224,13 @@ func (c *CommitStore) Commit(version uint64) (*proof.CommitInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Prune the old versions.
|
||||
if prune, pruneVersion := c.pruneOptions.ShouldPrune(version); prune {
|
||||
if err := c.Prune(pruneVersion); err != nil {
|
||||
c.logger.Info("failed to prune SC", "prune_version", pruneVersion, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
return cInfo, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ const (
|
||||
type CommitStoreTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
NewStore func(db store.RawDB, storeKeys []string, logger log.Logger) (*CommitStore, error)
|
||||
NewStore func(db store.RawDB, storeKeys []string, pruneOpts *store.PruneOptions, logger log.Logger) (*CommitStore, error)
|
||||
}
|
||||
|
||||
func (s *CommitStoreTestSuite) TestSnapshotter() {
|
||||
func (s *CommitStoreTestSuite) TestStore_Snapshotter() {
|
||||
storeKeys := []string{storeKey1, storeKey2}
|
||||
commitStore, err := s.NewStore(dbm.NewMemDB(), storeKeys, log.NewNopLogger())
|
||||
commitStore, err := s.NewStore(dbm.NewMemDB(), storeKeys, nil, log.NewNopLogger())
|
||||
s.Require().NoError(err)
|
||||
|
||||
latestVersion := uint64(10)
|
||||
@@ -62,7 +62,7 @@ func (s *CommitStoreTestSuite) TestSnapshotter() {
|
||||
},
|
||||
}
|
||||
|
||||
targetStore, err := s.NewStore(dbm.NewMemDB(), storeKeys, log.NewNopLogger())
|
||||
targetStore, err := s.NewStore(dbm.NewMemDB(), storeKeys, nil, log.NewNopLogger())
|
||||
s.Require().NoError(err)
|
||||
|
||||
chunks := make(chan io.ReadCloser, kvCount*int(latestVersion))
|
||||
@@ -118,3 +118,42 @@ func (s *CommitStoreTestSuite) TestSnapshotter() {
|
||||
s.Require().True(matched)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CommitStoreTestSuite) TestStore_Pruning() {
|
||||
storeKeys := []string{storeKey1, storeKey2}
|
||||
pruneOpts := &store.PruneOptions{
|
||||
KeepRecent: 10,
|
||||
Interval: 5,
|
||||
}
|
||||
commitStore, err := s.NewStore(dbm.NewMemDB(), storeKeys, pruneOpts, log.NewNopLogger())
|
||||
s.Require().NoError(err)
|
||||
|
||||
latestVersion := uint64(100)
|
||||
kvCount := 10
|
||||
for i := uint64(1); i <= latestVersion; i++ {
|
||||
kvPairs := make(map[string]store.KVPairs)
|
||||
for _, storeKey := range storeKeys {
|
||||
kvPairs[storeKey] = store.KVPairs{}
|
||||
for j := 0; j < kvCount; j++ {
|
||||
key := []byte(fmt.Sprintf("key-%d-%d", i, j))
|
||||
value := []byte(fmt.Sprintf("value-%d-%d", i, j))
|
||||
kvPairs[storeKey] = append(kvPairs[storeKey], store.KVPair{Key: key, Value: value})
|
||||
}
|
||||
}
|
||||
s.Require().NoError(commitStore.WriteBatch(store.NewChangesetWithPairs(kvPairs)))
|
||||
|
||||
_, err = commitStore.Commit(i)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
pruneVersion := latestVersion - pruneOpts.KeepRecent - 1
|
||||
// check the store
|
||||
for i := uint64(1); i <= latestVersion; i++ {
|
||||
commitInfo, _ := commitStore.GetCommitInfo(i)
|
||||
if i <= pruneVersion {
|
||||
s.Require().Nil(commitInfo)
|
||||
} else {
|
||||
s.Require().NotNil(commitInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user