Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Commit ca514d7

Browse files
authored
Merge pull request #92 from sei-protocol/yzang/add-config-for-export
Add config for to OnlyAllowExportOnSnapshotVersion
2 parents a90aa3a + 65bef6a commit ca514d7

6 files changed

Lines changed: 27 additions & 14 deletions

File tree

config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ type StateCommitConfig struct {
4747
// CacheSize defines the size of the cache for each memiavl store.
4848
// Deprecated: this is removed, we will just rely on mmap page cache
4949
CacheSize int `mapstructure:"cache-size"`
50+
51+
// OnlyAllowExportOnSnapshotVersion defines whether we only allow state sync
52+
// snapshot creation happens after the memiavl snapshot is created
53+
OnlyAllowExportOnSnapshotVersion bool `mapstructure:"only-allow-export-on-snapshot-version"`
5054
}
5155

5256
type StateStoreConfig struct {

config/toml.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ sc-snapshot-interval = {{ .StateCommit.SnapshotInterval }}
3232
# SnapshotWriterLimit defines the max concurrency for taking commit store snapshot
3333
sc-snapshot-writer-limit = {{ .StateCommit.SnapshotWriterLimit }}
3434
35+
# OnlyAllowExportOnSnapshotVersion defines whether we only allow state sync
36+
# snapshot creation happens after the memiavl snapshot is created.
37+
sc-only-allow-export-on-snapshot-version = {{ .StateCommit.OnlyAllowExportOnSnapshotVersion }}
38+
3539
[state-store]
3640
# Enable defines whether the state-store should be enabled for storing historical data.
3741
# Supporting historical queries or exporting state snapshot requires setting this to true

sc/memiavl/export.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ type MultiTreeExporter struct {
2626
exporter *Exporter
2727
}
2828

29-
func NewMultiTreeExporter(dir string, version uint32, supportExportNonSnapshotVersion bool) (exporter *MultiTreeExporter, err error) {
29+
func NewMultiTreeExporter(dir string, version uint32, onlyAllowExportOnSnapshotVersion bool) (exporter *MultiTreeExporter, err error) {
3030
var (
3131
db *DB
3232
mtree *MultiTree
3333
)
34-
if supportExportNonSnapshotVersion {
34+
if !onlyAllowExportOnSnapshotVersion {
3535
db, err = OpenDB(logger.NewNopLogger(), int64(version), Options{
3636
Dir: dir,
3737
ZeroCopy: true,
@@ -47,11 +47,11 @@ func NewMultiTreeExporter(dir string, version uint32, supportExportNonSnapshotVe
4747
return nil, fmt.Errorf("failed to load current version: %w", err)
4848
}
4949
if int64(version) > curVersion {
50-
return nil, fmt.Errorf("snapshot is not created yet: height: %d", version)
50+
return nil, fmt.Errorf("export skipped because memiavl snapshot is not created yet for height: %d", version)
5151
}
5252
mtree, err = LoadMultiTree(filepath.Join(dir, snapshotName(int64(version))), true, 0)
5353
if err != nil {
54-
return nil, fmt.Errorf("snapshot don't exists: height: %d, %w", version, err)
54+
return nil, fmt.Errorf("memiavl snapshot don't exist for height: %d, %w", version, err)
5555
}
5656
}
5757

sc/memiavl/opts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ type Options struct {
2929
// it do nothing if the target version is `0`.
3030
LoadForOverwriting bool
3131

32+
// OnlyAllowExportOnSnapshotVersion defines whether the state sync exporter should only export the
33+
// version that matches wit the current memiavl snapshot version
34+
OnlyAllowExportOnSnapshotVersion bool
35+
3236
// Limit the number of concurrent snapshot writers
3337
SnapshotWriterLimit int
3438
}

sc/memiavl/snapshot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func TestDBSnapshotRestore(t *testing.T) {
169169
}
170170

171171
func testSnapshotRoundTrip(t *testing.T, db *DB) {
172-
exporter, err := NewMultiTreeExporter(db.dir, uint32(db.Version()), true)
172+
exporter, err := NewMultiTreeExporter(db.dir, uint32(db.Version()), false)
173173
require.NoError(t, err)
174174

175175
restoreDir := t.TempDir()

sc/store.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ func NewCommitStore(homeDir string, logger logger.Logger, config config.StateCom
2525
scDir = config.Directory
2626
}
2727
opts := memiavl.Options{
28-
Dir: utils.GetCommitStorePath(scDir),
29-
ZeroCopy: config.ZeroCopy,
30-
AsyncCommitBuffer: config.AsyncCommitBuffer,
31-
SnapshotInterval: config.SnapshotInterval,
32-
SnapshotKeepRecent: config.SnapshotKeepRecent,
33-
SnapshotWriterLimit: config.SnapshotWriterLimit,
34-
CacheSize: config.CacheSize,
35-
CreateIfMissing: true,
28+
Dir: utils.GetCommitStorePath(scDir),
29+
ZeroCopy: config.ZeroCopy,
30+
AsyncCommitBuffer: config.AsyncCommitBuffer,
31+
SnapshotInterval: config.SnapshotInterval,
32+
SnapshotKeepRecent: config.SnapshotKeepRecent,
33+
SnapshotWriterLimit: config.SnapshotWriterLimit,
34+
CacheSize: config.CacheSize,
35+
CreateIfMissing: true,
36+
OnlyAllowExportOnSnapshotVersion: config.OnlyAllowExportOnSnapshotVersion,
3637
}
3738
commitStore := &CommitStore{
3839
logger: logger,
@@ -128,7 +129,7 @@ func (cs *CommitStore) GetTreeByName(name string) types.Tree {
128129
}
129130

130131
func (cs *CommitStore) Exporter(version int64) (types.Exporter, error) {
131-
exporter, err := memiavl.NewMultiTreeExporter(cs.opts.Dir, uint32(version), true)
132+
exporter, err := memiavl.NewMultiTreeExporter(cs.opts.Dir, uint32(version), cs.opts.OnlyAllowExportOnSnapshotVersion)
132133
if err != nil {
133134
return nil, err
134135
}

0 commit comments

Comments
 (0)