Bump RocksDb version and enable autoClose on opt types to prevent memory leaks (#2427)

* Bump RocksDb version and enable autoClose on opt types to prevent memory leaks.
This commit is contained in:
web3-developer 2024-07-02 13:44:09 +08:00 committed by GitHub
parent 3d3831dde8
commit e163b69261
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 10 deletions

View File

@ -45,7 +45,7 @@ proc toRocksDb*(
# data model itself has settled down as their optimal values will depend
# on the shape of the data - it'll also be different per column family..
let tableOpts = defaultTableOptions()
let tableOpts = defaultTableOptions(autoClose = true)
# This bloom filter helps avoid having to read multiple SST files when looking
# for a value.
# A 9.9-bits-per-key ribbon filter takes ~7 bits per key and has a 1% false
@ -57,7 +57,7 @@ proc toRocksDb*(
if opts.blockCacheSize > 0:
# Share a single block cache instance between all column families
tableOpts.blockCache = cacheCreateLRU(opts.blockCacheSize)
tableOpts.blockCache = cacheCreateLRU(opts.blockCacheSize, autoClose = true)
# Single-level indices might cause long stalls due to their large size -
# two-level indexing allows the first level to be kept in memory at all times
@ -75,7 +75,7 @@ proc toRocksDb*(
tableOpts.dataBlockIndexType = DataBlockIndexType.binarySearchAndHash
tableOpts.dataBlockHashRatio = 0.75
let cfOpts = defaultColFamilyOptions()
let cfOpts = defaultColFamilyOptions(autoClose = true)
cfOpts.blockBasedTableFactory = tableOpts
@ -117,7 +117,7 @@ proc toRocksDb*(
cfOpts.targetFileSizeBase = cfOpts.writeBufferSize div 4
cfOpts.targetFileSizeMultiplier = 4
let dbOpts = defaultDbOptions()
let dbOpts = defaultDbOptions(autoClose = true)
dbOpts.maxOpenFiles = opts.maxOpenFiles
if opts.rowCacheSize > 0:
@ -125,7 +125,7 @@ proc toRocksDb*(
# using range queries, we should probably give more attention to the block
# cache
# https://github.com/facebook/rocksdb/blob/af50823069818fc127438e39fef91d2486d6e76c/include/rocksdb/options.h#L1276
dbOpts.rowCache = cacheCreateLRU(opts.rowCacheSize)
dbOpts.rowCache = cacheCreateLRU(opts.rowCacheSize, autoClose = true)
# Without this option, WAL files might never get removed since a small column
# family (like the admin CF) with only tiny writes might keep it open - this

View File

@ -83,10 +83,8 @@ proc init*(
except OSError, IOError:
return err("RocksStoreRef: cannot create database directory")
let dbOpts = defaultDbOptions()
let db = ? openRocksDb(dataDir, dbOpts,
columnFamilies = namespaces.mapIt(initColFamilyDescriptor(it)))
let db = ? openRocksDb(dataDir, columnFamilies = namespaces.mapIt(
initColFamilyDescriptor(it, defaultColFamilyOptions(autoClose = true))))
ok(T(db: db))
# ------------------------------------------------------------------------------

2
vendor/nim-rocksdb vendored

@ -1 +1 @@
Subproject commit ee15ce027b27d5b44b8e2bd3b3d6227568ec0803
Subproject commit 01ced36404cf3667742dd68f8bdd6b73f5affa50