Skip to content

Commit d9b2054

Browse files
committed
Problem: slices in ReadOptions is freed by gc while referenced in rocksdb (#1751)
* Problem: no deallocate read options * doc * sync deps
1 parent d39a361 commit d9b2054

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### Bug Fixes
66

77
* [#1720](https://github.com/crypto-org-chain/cronos/pull/1720) Include the fix of performance regression after upgrade in iavl.
8+
* [#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.
9+
* (versiondb) [#1751](https://github.com/crypto-org-chain/cronos/pull/1751) Add missing Destroy for read options to properly hold and release options reference.
810

911
### Improvements
1012

versiondb/tsrocksdb/store.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ func (s Store) PutAtVersion(version int64, changeSet []types.StoreKVPair) error
9494
}
9595

9696
func (s Store) GetAtVersionSlice(storeKey string, key []byte, version *int64) (*grocksdb.Slice, error) {
97+
readOpts := newTSReadOptions(version)
98+
defer readOpts.Destroy()
9799
value, ts, err := s.db.GetCFWithTS(
98-
newTSReadOptions(version),
100+
readOpts,
99101
s.cfHandle,
100102
prependStoreKey(storeKey, key),
101103
)
@@ -164,7 +166,9 @@ func (s Store) iteratorAtVersion(storeKey string, start, end []byte, version *in
164166
prefix := storePrefix(storeKey)
165167
start, end = iterateWithPrefix(prefix, start, end)
166168

167-
itr := s.db.NewIteratorCF(newTSReadOptions(version), s.cfHandle)
169+
readOpts := newTSReadOptions(version)
170+
defer readOpts.Destroy()
171+
itr := s.db.NewIteratorCF(readOpts, s.cfHandle)
168172
return newRocksDBIterator(itr, prefix, start, end, reverse, s.skipVersionZero), nil
169173
}
170174

0 commit comments

Comments
 (0)