Skip to content

Commit

Permalink
Second refactor to add interfaces and simplified logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 committed Dec 7, 2023
1 parent e40b6f1 commit f682096
Show file tree
Hide file tree
Showing 33 changed files with 688 additions and 329 deletions.
3 changes: 2 additions & 1 deletion common/utils/errors.go → common/errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package errors

import (
"errors"
Expand All @@ -9,6 +9,7 @@ var (
ErrKeyEmpty = errors.New("key empty")
ErrRecordNotFound = errors.New("record not found")
ErrStartAfterEnd = errors.New("start key after end key")
ErrorExportDone = errors.New("export is complete")
)

// Join returns an error that wraps the given errors.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package errors

import (
"errors"
Expand Down
40 changes: 27 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package config

const (
DefaultCacheSize = 100000
DefaultSnapshotInterval = 10000
DefaultSnapshotInterval = 10000
DefaultSnapshotKeepRecent = 1
DefaultSnapshotWriterLimit = 4
DefaultAsyncCommitBuffer = 100
DefaultCacheSize = 100000
DefaultSSKeepRecent = 100000
DefaultSSPruneInterval = 600
DefaultSSImportWorkers = 1
DefaultSSAsyncBuffer = 100
)

type StateCommitConfig struct {
Expand All @@ -11,6 +18,10 @@ type StateCommitConfig struct {
// defaults to false.
Enable bool `mapstructure:"enable"`

// Directory defines the state-commit store directory
// If not explicitly set, default to application home directory
Directory string `mapstructure:"directory"`

// ZeroCopy defines if the memiavl should return slices pointing to mmap-ed buffers directly (zero-copy),
// the zero-copied slices must not be retained beyond current block's execution.
// the sdk address cache will be disabled if zero-copy is enabled.
Expand All @@ -29,6 +40,9 @@ type StateCommitConfig struct {
// SnapshotInterval defines the block interval the memiavl snapshot is taken, default to 10000.
SnapshotInterval uint32 `mapstructure:"snapshot-interval"`

// SnapshotWriterLimit defines the concurrency for taking commit store snapshot
SnapshotWriterLimit int `mapstructure:"snapshot-writer-limit"`

// CacheSize defines the size of the cache for each memiavl store.
// defaults to 100000.
CacheSize int `mapstructure:"cache-size"`
Expand All @@ -39,6 +53,11 @@ type StateStoreConfig struct {
// Enable defines if the state-store should be enabled for historical queries.
Enable bool `mapstructure:"enable"`

// DBDirectory defines the directory to store the state store db files
// If not explicitly set, default to application home directory
// default to empty
DBDirectory string `mapstructure:"db-directory"`

// Backend defines the backend database used for state-store
// Supported backends: pebbledb, rocksdb
// defaults to pebbledb
Expand All @@ -60,28 +79,23 @@ type StateStoreConfig struct {
// ImportNumWorkers defines the number of goroutines used during import
// defaults to 1
ImportNumWorkers int `mapstructure:"import-num-workers"`

// DBDirectory defines the directory to store the state store db files
// If not explicitly set, default to application home directory
// default to empty
DBDirectory string `mapstructure:"db-directory"`
}

func DefaultStateCommitConfig() StateCommitConfig {
return StateCommitConfig{
AsyncCommitBuffer: 100,
AsyncCommitBuffer: DefaultAsyncCommitBuffer,
CacheSize: DefaultCacheSize,
SnapshotInterval: DefaultSnapshotInterval,
SnapshotKeepRecent: 1,
SnapshotKeepRecent: DefaultSnapshotKeepRecent,
}
}

func DefaultStateStoreConfig() StateStoreConfig {
return StateStoreConfig{
Backend: "pebbledb",
AsyncWriteBuffer: 100,
KeepRecent: 0,
PruneIntervalSeconds: 60,
ImportNumWorkers: 1,
AsyncWriteBuffer: DefaultSSAsyncBuffer,
KeepRecent: DefaultSSKeepRecent,
PruneIntervalSeconds: DefaultSSPruneInterval,
ImportNumWorkers: DefaultSSImportWorkers,
}
}
39 changes: 22 additions & 17 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,38 @@ package config

// DefaultConfigTemplate defines the configuration template for the seiDB configuration
const DefaultConfigTemplate = `
###############################################################################
#############################################################################
### SeiDB Configuration ###
###############################################################################
#############################################################################
[state-commit]
# Enable defines if the state-commit (memiavl) should be enabled to override existing IAVL db backend.
sc-enable = {{ .StateCommit.Enable }}
# Directory defines the state-commit store directory, if not explicitly set, default to application home directory
sc-directory = {{ .StateCommit.Directory }}
# ZeroCopy defines if memiavl should return slices pointing to mmap-ed buffers directly (zero-copy),
# the zero-copied slices must not be retained beyond current block's execution.
# the sdk address cache will be disabled if zero-copy is enabled.
zero-copy = {{ .StateCommit.ZeroCopy }}
sc-zero-copy = {{ .StateCommit.ZeroCopy }}
# AsyncCommitBuffer defines the size of asynchronous commit queue, this greatly improve block catching-up
# performance, <=0 means synchronous commit.
async-commit-buffer = {{ .StateCommit.AsyncCommitBuffer }}
sc-async-commit-buffer = {{ .StateCommit.AsyncCommitBuffer }}
# SnapshotKeepRecent defines how many state-commit snapshots (besides the latest one) to keep
# defaults to 1 to make sure ibc relayers work.
sc-keep-recent = {{ .StateCommit.SnapshotKeepRecent }}
# SnapshotInterval defines the block interval the SC snapshot is taken, default to 10000.
# SnapshotInterval defines the block interval the snapshot is taken, default to 10000 blocks.
sc-snapshot-interval = {{ .StateCommit.SnapshotInterval }}
# CacheSize defines the size of the cache for each memiavl store, default to 100000.
# SnapshotWriterLimit defines the max concurrency for taking commit store snapshot
sc-snapshot-writer-limit = {{ .StateCommit.SnapshotWriterLimit }}
# CacheSize defines the size of the LRU cache for each store on top of the tree, default to 100000.
sc-cache-size = {{ .StateCommit.CacheSize }}
[state-store]
Expand All @@ -36,32 +42,31 @@ sc-cache-size = {{ .StateCommit.CacheSize }}
# In order to use state-store, you need to make sure to enable state-commit at the same time
ss-enable = {{ .StateStore.Enable }}
# Directory defines the directory to store the state store db files
# If not explicitly set, default to application home directory
ss-db-directory = {{ .StateStore.DBDirectory }}
# DBBackend defines the backend database used for state-store.
# Supported backends: pebbledb, rocksdb
# defaults to pebbledb
# Supported backends: pebbledb, rocksdb, sqlite
# defaults to pebbledb (recommended)
ss-backend = "{{ .StateStore.Backend }}"
# AsyncWriteBuffer defines the async queue length for commits to be applied to State Store
# Set <= 0 for synchronous writes, which means commits also need to wait for data to be persisted in State Store.
# defaults to 100
async-write-buffer = {{ .StateStore.AsyncWriteBuffer }}
ss-async-write-buffer = {{ .StateStore.AsyncWriteBuffer }}
# KeepRecent defines the number of versions to keep in state store
# Setting it to 0 means keep everything, default to 0
ss-keep-recent = {{ .StateStore.KeepRecent }}
# PruneIntervalSeconds defines the minimum interval in seconds + some random delay to trigger pruning.
# It is more efficient to trigger pruning less frequently with large interval.
# default to 60 seconds
# default to 600 seconds
ss-prune-interval = {{ .StateStore.PruneIntervalSeconds }}
# ImportNumWorkers defines the number of goroutines used during import
# ImportNumWorkers defines the concurrency for state sync import
# defaults to 1
import-num-workers = {{ .StateStore.ImportNumWorkers }}
# Directory defines the directory to store the state store db files
# If not explicitly set, default to application home directory
# default to empty
ss-db-directory = {{ .StateStore.DBDirectory }}
ss-import-num-workers = {{ .StateStore.ImportNumWorkers }}
`
4 changes: 2 additions & 2 deletions sc/memiavl/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func BenchmarkRandomGet(b *testing.B) {

tree := New(0)
for _, item := range items {
tree.set(item.key, item.value)
tree.Set(item.key, item.value)
}

snapshotDir := b.TempDir()
Expand Down Expand Up @@ -158,7 +158,7 @@ func BenchmarkRandomSet(b *testing.B) {
for i := 0; i < b.N; i++ {
tree := New(0)
for _, item := range items {
tree.set(item.key, item.value)
tree.Set(item.key, item.value)
}
}
})
Expand Down
Loading

0 comments on commit f682096

Please sign in to comment.