From 8d5417cbd075b2ab2202260f8011a86a52d0fc9d Mon Sep 17 00:00:00 2001 From: web3-developer <51288821+web3-developer@users.noreply.github.com> Date: Thu, 27 Jun 2024 15:58:17 +0800 Subject: [PATCH] Improve close functions. --- rocksdb/rocksdb.nim | 11 +++++++---- rocksdb/transactiondb.nim | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/rocksdb/rocksdb.nim b/rocksdb/rocksdb.nim index 57565f5..55a1818 100644 --- a/rocksdb/rocksdb.nim +++ b/rocksdb/rocksdb.nim @@ -392,15 +392,18 @@ proc close*(db: RocksDbRef) = withLock(db.lock): if not db.isClosed(): + # the column families should be closed before the database + db.cfTable.close() + + rocksdb_close(db.cPtr) + db.cPtr = nil + + # opts should be closed after the database is closed db.dbOpts.close() db.readOpts.close() - db.cfTable.close() if db of RocksDbReadWriteRef: let db = RocksDbReadWriteRef(db) db.writeOpts.close() rocksdb_ingestexternalfileoptions_destroy(db.ingestOptsPtr) db.ingestOptsPtr = nil - - rocksdb_close(db.cPtr) - db.cPtr = nil diff --git a/rocksdb/transactiondb.nim b/rocksdb/transactiondb.nim index 4e3e098..dabfbd0 100644 --- a/rocksdb/transactiondb.nim +++ b/rocksdb/transactiondb.nim @@ -117,11 +117,15 @@ proc beginTransaction*( proc close*(db: TransactionDbRef) = ## Close the `TransactionDbRef`. + withLock(db.lock): if not db.isClosed(): - db.dbOpts.close() - db.txDbOpts.close() + # the column families should be closed before the database db.cfTable.close() rocksdb_transactiondb_close(db.cPtr) db.cPtr = nil + + # opts should be closed after the database is closed + db.dbOpts.close() + db.txDbOpts.close()