Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable diff on iavl store #231

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
type Store struct {
tree Tree
logger log.Logger
diff map[string]struct{}
}

// LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the
Expand Down Expand Up @@ -190,6 +191,18 @@ func (st *Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.Ca
return cachekv.NewStore(tracekv.NewStore(st, w, tc))
}

func (st *Store) EnableDiff() {
st.diff = map[string]struct{}{}
}

func (st *Store) GetDiff() map[string]struct{} {
return st.diff
}

func (st *Store) ResetDiff() {
st.diff = map[string]struct{}{}
}

// Implements types.KVStore.
func (st *Store) Set(key, value []byte) {
types.AssertValidKey(key)
Expand All @@ -198,6 +211,10 @@ func (st *Store) Set(key, value []byte) {
if err != nil && st.logger != nil {
st.logger.Error("iavl set error", "error", err.Error())
}

if st.diff != nil {
st.diff[string(key)] = struct{}{}
}
}

// Implements types.KVStore.
Expand All @@ -224,6 +241,10 @@ func (st *Store) Has(key []byte) (exists bool) {
func (st *Store) Delete(key []byte) {
defer telemetry.MeasureSince(time.Now(), "store", "iavl", "delete")
st.tree.Remove(key)

if st.diff != nil {
st.diff[string(key)] = struct{}{}
}
}

// DeleteVersions deletes a series of versions from the MutableTree. An error
Expand Down