Skip to content

Commit

Permalink
Improve close functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Jun 27, 2024
1 parent e49f3c4 commit 8d5417c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 7 additions & 4 deletions rocksdb/rocksdb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions rocksdb/transactiondb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 8d5417c

Please sign in to comment.