Skip to content

Commit

Permalink
feat: enable diff on iavl store (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing authored Jul 4, 2023
1 parent 34790c6 commit 2486622
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 2486622

Please sign in to comment.