From d9b205437beec79a97967dc54174a99be678f0a4 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 24 Feb 2025 14:54:07 +0800 Subject: [PATCH] Problem: slices in ReadOptions is freed by gc while referenced in rocksdb (#1751) * Problem: no deallocate read options * doc * sync deps --- CHANGELOG.md | 2 ++ versiondb/tsrocksdb/store.go | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9aa52d987..af3bd4dfa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/versiondb/tsrocksdb/store.go b/versiondb/tsrocksdb/store.go index 344a9e69d3..4337d96671 100644 --- a/versiondb/tsrocksdb/store.go +++ b/versiondb/tsrocksdb/store.go @@ -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), ) @@ -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 }