Skip to content

Commit

Permalink
Problem: slices in ReadOptions is freed by gc while referenced in roc…
Browse files Browse the repository at this point in the history
…ksdb (crypto-org-chain#1751)

* Problem: no deallocate read options

* doc

* sync deps
  • Loading branch information
mmsqe committed Feb 24, 2025
1 parent d39a361 commit d9b2054
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Bug Fixes

* [#1720](https://github.com/crypto-org-chain/cronos/pull/1720) Include the fix of performance regression after upgrade in iavl.
* [#1748](https://github.com/crypto-org-chain/cronos/pull/1748) Query with GetCFWithTS to compare both timestamp and key to avoid run fixdata multiple times.
* (versiondb) [#1751](https://github.com/crypto-org-chain/cronos/pull/1751) Add missing Destroy for read options to properly hold and release options reference.

### Improvements

Expand Down
8 changes: 6 additions & 2 deletions versiondb/tsrocksdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ func (s Store) PutAtVersion(version int64, changeSet []types.StoreKVPair) error
}

func (s Store) GetAtVersionSlice(storeKey string, key []byte, version *int64) (*grocksdb.Slice, error) {
readOpts := newTSReadOptions(version)
defer readOpts.Destroy()
value, ts, err := s.db.GetCFWithTS(
newTSReadOptions(version),
readOpts,
s.cfHandle,
prependStoreKey(storeKey, key),
)
Expand Down Expand Up @@ -164,7 +166,9 @@ func (s Store) iteratorAtVersion(storeKey string, start, end []byte, version *in
prefix := storePrefix(storeKey)
start, end = iterateWithPrefix(prefix, start, end)

itr := s.db.NewIteratorCF(newTSReadOptions(version), s.cfHandle)
readOpts := newTSReadOptions(version)
defer readOpts.Destroy()
itr := s.db.NewIteratorCF(readOpts, s.cfHandle)
return newRocksDBIterator(itr, prefix, start, end, reverse, s.skipVersionZero), nil
}

Expand Down

0 comments on commit d9b2054

Please sign in to comment.