Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Jul 1, 2024
1 parent 9a7edd7 commit a9cebfb
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 33 deletions.
4 changes: 2 additions & 2 deletions rocksdb/columnfamily/cfopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ proc close*(s: SlicetransformRef) =
rocksdb_slicetransform_destroy(s.cPtr)
s.cPtr = nil

proc newColFamilyOptions*(autoClose = false): ColFamilyOptionsRef =
proc createColFamilyOptions*(autoClose = false): ColFamilyOptionsRef =
ColFamilyOptionsRef(cPtr: rocksdb_options_create(), autoClose: autoClose)

proc isClosed*(cfOpts: ColFamilyOptionsRef): bool {.inline.} =
Expand Down Expand Up @@ -122,7 +122,7 @@ opt blobCompactionReadaheadSize, int, uint64
opt blobFileStartingLevel, int, cint

proc defaultColFamilyOptions*(autoClose = false): ColFamilyOptionsRef =
newColFamilyOptions(autoClose)
createColFamilyOptions(autoClose)

# proc setFixedPrefixExtractor*(dbOpts: ColFamilyOptionsRef, length: int) =
# doAssert not dbOpts.isClosed()
Expand Down
4 changes: 2 additions & 2 deletions rocksdb/options/backupopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type
cPtr: BackupEngineOptionsPtr
autoClose*: bool # if true then close will be called when the backup engine is closed

proc newBackupEngineOptions*(autoClose = false): BackupEngineOptionsRef =
proc createBackupEngineOptions*(autoClose = false): BackupEngineOptionsRef =
BackupEngineOptionsRef(cPtr: rocksdb_options_create(), autoClose: autoClose)

proc isClosed*(engineOpts: BackupEngineOptionsRef): bool {.inline.} =
Expand All @@ -31,7 +31,7 @@ proc cPtr*(engineOpts: BackupEngineOptionsRef): BackupEngineOptionsPtr =
# TODO: Add setters and getters for backup options properties.

proc defaultBackupEngineOptions*(autoClose = false): BackupEngineOptionsRef {.inline.} =
let opts = newBackupEngineOptions(autoClose)
let opts = createBackupEngineOptions(autoClose)

# TODO: set defaults here

Expand Down
6 changes: 5 additions & 1 deletion rocksdb/options/cache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type
CachePtr* = ptr rocksdb_cache_t

CacheRef* = ref object
cPtr*: CachePtr
cPtr: CachePtr
autoClose*: bool # if true then close will be called when it's parent is closed

proc cacheCreateLRU*(size: int, autoClose = false): CacheRef =
Expand All @@ -13,6 +13,10 @@ proc cacheCreateLRU*(size: int, autoClose = false): CacheRef =
proc isClosed*(cache: CacheRef): bool =
isNil(cache.cPtr)

proc cPtr*(cache: CacheRef): CachePtr =
doAssert not cache.isClosed()
cache.cPtr

proc close*(cache: CacheRef) =
if cache.cPtr != nil:
rocksdb_cache_destroy(cache.cPtr)
Expand Down
4 changes: 2 additions & 2 deletions rocksdb/options/dbopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type
cache: CacheRef
autoClose*: bool # if true then close will be called when the database is closed

proc newDbOptions*(autoClose = false): DbOptionsRef =
proc createDbOptions*(autoClose = false): DbOptionsRef =
DbOptionsRef(cPtr: rocksdb_options_create(), autoClose: autoClose)

proc isClosed*(dbOpts: DbOptionsRef): bool {.inline.} =
Expand Down Expand Up @@ -102,7 +102,7 @@ proc `rowCache=`*(dbOpts: DbOptionsRef, cache: CacheRef) =
dbOpts.cache = cache

proc defaultDbOptions*(autoClose = false): DbOptionsRef =
let opts: DbOptionsRef = newDbOptions(autoClose)
let opts: DbOptionsRef = createDbOptions(autoClose)

# Optimize RocksDB. This is the easiest way to get RocksDB to perform well:
opts.increaseParallelism(countProcessors())
Expand Down
4 changes: 2 additions & 2 deletions rocksdb/options/readopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type
cPtr: ReadOptionsPtr
autoClose*: bool # if true then close will be called when the database is closed

proc newReadOptions*(autoClose = false): ReadOptionsRef =
proc createReadOptions*(autoClose = false): ReadOptionsRef =
ReadOptionsRef(cPtr: rocksdb_readoptions_create(), autoClose: autoClose)

proc isClosed*(readOpts: ReadOptionsRef): bool {.inline.} =
Expand All @@ -31,7 +31,7 @@ proc cPtr*(readOpts: ReadOptionsRef): ReadOptionsPtr =
# TODO: Add setters and getters for read options properties.

proc defaultReadOptions*(autoClose = false): ReadOptionsRef {.inline.} =
newReadOptions(autoClose)
createReadOptions(autoClose)
# TODO: set prefered defaults

proc close*(readOpts: ReadOptionsRef) =
Expand Down
24 changes: 16 additions & 8 deletions rocksdb/options/tableopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ type
TableOptionsPtr* = ptr rocksdb_block_based_table_options_t

TableOptionsRef* = ref object
cPtr*: TableOptionsPtr
cPtr: TableOptionsPtr
cache: CacheRef
autoClose*: bool # if true then close will be called when it's parent is closed

FilterPolicyPtr* = ptr rocksdb_filterpolicy_t

FilterPolicyRef* = ref object
cPtr*: FilterPolicyPtr
cPtr: FilterPolicyPtr

IndexType* {.pure.} = enum
binarySearch = rocksdb_block_based_table_index_type_binary_search
Expand All @@ -39,6 +39,10 @@ proc createRibbonHybrid*(
proc isClosed*(policy: FilterPolicyRef): bool =
isNil(policy.cPtr)

proc cPtr*(policy: FilterPolicyRef): FilterPolicyPtr =
doAssert not policy.isClosed()
policy.cPtr

proc close*(policy: FilterPolicyRef) =
if not isClosed(policy):
rocksdb_filterpolicy_destroy(policy.cPtr)
Expand All @@ -50,12 +54,9 @@ proc createTableOptions*(autoClose = false): TableOptionsRef =
proc isClosed*(opts: TableOptionsRef): bool =
isNil(opts.cPtr)

proc close*(opts: TableOptionsRef) =
if not isClosed(opts):
rocksdb_block_based_options_destroy(opts.cPtr)
opts.cPtr = nil

autoCloseNonNil(opts.cache)
proc cPtr*(opts: TableOptionsRef): TableOptionsPtr =
doAssert not opts.isClosed()
opts.cPtr

template opt(nname, ntyp, ctyp: untyped) =
proc `nname=`*(opts: TableOptionsRef, value: ntyp) =
Expand Down Expand Up @@ -109,3 +110,10 @@ proc defaultTableOptions*(autoClose = false): TableOptionsRef =
opts.pinL0FilterAndIndexBlocksInCache = true

opts

proc close*(opts: TableOptionsRef) =
if not isClosed(opts):
rocksdb_block_based_options_destroy(opts.cPtr)
opts.cPtr = nil

autoCloseNonNil(opts.cache)
4 changes: 2 additions & 2 deletions rocksdb/options/writeopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type
cPtr: WriteOptionsPtr
autoClose*: bool # if true then close will be called when the database is closed

proc newWriteOptions*(autoClose = false): WriteOptionsRef =
proc createWriteOptions*(autoClose = false): WriteOptionsRef =
WriteOptionsRef(cPtr: rocksdb_writeoptions_create(), autoClose: autoClose)

proc isClosed*(writeOpts: WriteOptionsRef): bool {.inline.} =
Expand All @@ -31,7 +31,7 @@ proc cPtr*(writeOpts: WriteOptionsRef): WriteOptionsPtr =
# TODO: Add setters and getters for write options properties.

proc defaultWriteOptions*(autoClose = false): WriteOptionsRef {.inline.} =
newWriteOptions(autoClose)
createWriteOptions(autoClose)
# TODO: set prefered defaults

proc close*(writeOpts: WriteOptionsRef) =
Expand Down
2 changes: 1 addition & 1 deletion rocksdb/rocksdb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ proc openWriteBatch*(
## Opens a `WriteBatchRef` which defaults to using the specified column family.
doAssert not db.isClosed()

newWriteBatch(cfHandle)
createWriteBatch(cfHandle)

proc write*(db: RocksDbReadWriteRef, updates: WriteBatchRef): RocksDBResult[void] =
## Apply the updates in the `WriteBatchRef` to the database.
Expand Down
4 changes: 2 additions & 2 deletions rocksdb/transactions/txdbopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type
cPtr: TransactionDbOptionsPtr
autoClose*: bool # if true then close will be called when the database is closed

proc newTransactionDbOptions*(autoClose = false): TransactionDbOptionsRef =
proc createTransactionDbOptions*(autoClose = false): TransactionDbOptionsRef =
TransactionDbOptionsRef(
cPtr: rocksdb_transactiondb_options_create(), autoClose: autoClose
)
Expand All @@ -35,7 +35,7 @@ proc cPtr*(txDbOpts: TransactionDbOptionsRef): TransactionDbOptionsPtr =
proc defaultTransactionDbOptions*(
autoClose = false
): TransactionDbOptionsRef {.inline.} =
newTransactionDbOptions(autoClose)
createTransactionDbOptions(autoClose)
# TODO: set prefered defaults

proc close*(txDbOpts: TransactionDbOptionsRef) =
Expand Down
4 changes: 2 additions & 2 deletions rocksdb/transactions/txopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type
cPtr: TransactionOptionsPtr
autoClose*: bool # if true then close will be called when the transaction is closed

proc newTransactionOptions*(autoClose = false): TransactionOptionsRef =
proc createTransactionOptions*(autoClose = false): TransactionOptionsRef =
TransactionOptionsRef(
cPtr: rocksdb_transaction_options_create(), autoClose: autoClose
)
Expand All @@ -33,7 +33,7 @@ proc cPtr*(txOpts: TransactionOptionsRef): TransactionOptionsPtr =
# TODO: Add setters and getters for backup options properties.

proc defaultTransactionOptions*(autoClose = false): TransactionOptionsRef {.inline.} =
newTransactionOptions(autoClose)
createTransactionOptions(autoClose)
# TODO: set prefered defaults

proc close*(txOpts: TransactionOptionsRef) =
Expand Down
2 changes: 1 addition & 1 deletion rocksdb/writebatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type
cPtr: WriteBatchPtr
defaultCfHandle: ColFamilyHandleRef

proc newWriteBatch*(defaultCfHandle: ColFamilyHandleRef): WriteBatchRef =
proc createWriteBatch*(defaultCfHandle: ColFamilyHandleRef): WriteBatchRef =
WriteBatchRef(cPtr: rocksdb_writebatch_create(), defaultCfHandle: defaultCfHandle)

proc isClosed*(batch: WriteBatchRef): bool {.inline.} =
Expand Down
4 changes: 2 additions & 2 deletions tests/columnfamily/test_cfhandle.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ suite "ColFamilyHandleRef Tests":
removeDir($dbPath)

test "Test newColFamilyHandle":
var cfHandle = newColFamilyHandle(cfHandlePtr)
let cfHandle = newColFamilyHandle(cfHandlePtr)

check:
not cfHandle.cPtr.isNil()
Expand All @@ -53,7 +53,7 @@ suite "ColFamilyHandleRef Tests":
cfHandle.close()

test "Test close":
var cfHandle = newColFamilyHandle(cfHandlePtr)
let cfHandle = newColFamilyHandle(cfHandlePtr)

check not cfHandle.isClosed()
cfHandle.close()
Expand Down
2 changes: 1 addition & 1 deletion tests/options/test_backupopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import unittest2, ../../rocksdb/options/backupopts

suite "BackupEngineOptionsRef Tests":
test "Test newBackupEngineOptions":
var backupOpts = newBackupEngineOptions()
var backupOpts = createBackupEngineOptions()

check not backupOpts.cPtr.isNil()

Expand Down
2 changes: 1 addition & 1 deletion tests/options/test_dbopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import unittest2, ../../rocksdb/options/dbopts

suite "DbOptionsRef Tests":
test "Test newDbOptions":
let dbOpts = newDbOptions()
let dbOpts = createDbOptions()

check not dbOpts.cPtr.isNil()

Expand Down
2 changes: 1 addition & 1 deletion tests/options/test_readopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import unittest2, ../../rocksdb/options/readopts

suite "ReadOptionsRef Tests":
test "Test newReadOptions":
var readOpts = newReadOptions()
var readOpts = createReadOptions()

check not readOpts.cPtr.isNil()

Expand Down
2 changes: 1 addition & 1 deletion tests/options/test_writeopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import unittest2, ../../rocksdb/options/writeopts

suite "WriteOptionsRef Tests":
test "Test newWriteOptions":
var writeOpts = newWriteOptions()
var writeOpts = createWriteOptions()

check not writeOpts.cPtr.isNil()

Expand Down
2 changes: 1 addition & 1 deletion tests/transactions/test_txdbopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import unittest2, ../../rocksdb/transactions/txdbopts

suite "TransactionDbOptionsRef Tests":
test "Test newTransactionDbOptions":
var txDbOpts = newTransactionDbOptions()
var txDbOpts = createTransactionDbOptions()

check not txDbOpts.cPtr.isNil()

Expand Down
2 changes: 1 addition & 1 deletion tests/transactions/test_txopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import unittest2, ../../rocksdb/transactions/txopts

suite "TransactionOptionsRef Tests":
test "Test newTransactionOptions":
var txOpts = newTransactionOptions()
var txOpts = createTransactionOptions()

check not txOpts.cPtr.isNil()

Expand Down

0 comments on commit a9cebfb

Please sign in to comment.