Skip to content

Commit

Permalink
Add majority of option type getter and setters.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Jul 3, 2024
1 parent aaaa2be commit 45f5753
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
24 changes: 16 additions & 8 deletions rocksdb/options/backupopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@ proc cPtr*(backupOpts: BackupEngineOptionsRef): BackupEngineOptionsPtr =
doAssert not backupOpts.isClosed()
backupOpts.cPtr

# template opt(nname, ntyp, ctyp: untyped) =
# proc `nname=`*(backupOpts: BackupEngineOptionsRef, value: ntyp) =
# doAssert not backupOpts.isClosed()
# `rocksdb_options_set nname`(backupOpts.cPtr, value.ctyp)
template opt(nname, ntyp, ctyp: untyped) =
proc `nname=`*(backupOpts: BackupEngineOptionsRef, value: ntyp) =
doAssert not backupOpts.isClosed()
`rocksdb_backup_engine_options_set nname`(backupOpts.cPtr, value.ctyp)

# proc `nname`*(backupOpts: BackupEngineOptionsRef): ntyp =
# doAssert not backupOpts.isClosed()
# ntyp `rocksdb_options_get nname`(backupOpts.cPtr)
proc `nname`*(backupOpts: BackupEngineOptionsRef): ntyp =
doAssert not backupOpts.isClosed()
ntyp `rocksdb_backup_engine_options_get nname`(backupOpts.cPtr)

# opt shareTableFiles, bool, uint8
opt shareTableFiles, bool, uint8
opt sync, bool, uint8
opt destroyOldData, bool, uint8
opt backupLogFiles, bool, uint8
opt backupRateLimit, int, uint64
opt restoreRateLimit, int, uint64
opt shareFilesWithChecksumNaming, bool, cint
opt maxBackgroundOperations, int, cint
opt callbackTriggerIntervalSize, int, uint64

proc defaultBackupEngineOptions*(
backupDir: string, autoClose = false
Expand Down
14 changes: 12 additions & 2 deletions rocksdb/transactions/txdbopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ proc cPtr*(txDbOpts: TransactionDbOptionsRef): TransactionDbOptionsPtr =
doAssert not txDbOpts.isClosed()
txDbOpts.cPtr

# TODO: Add setters and getters for backup options properties.
template setOpt(nname, ntyp, ctyp: untyped) =
proc `nname=`*(txDbOpts: TransactionDbOptionsRef, value: ntyp) =
doAssert not txDbOpts.isClosed()
`rocksdb_transactiondb_options_set nname`(txDbOpts.cPtr, value.ctyp)

setOpt maxNumLocks, int, int64
setOpt numStripes, int, csize_t
setOpt transactionLockTimeout, int, int64
setOpt defaultLockTimeout, int, int64

proc defaultTransactionDbOptions*(
autoClose = false
): TransactionDbOptionsRef {.inline.} =
createTransactionDbOptions(autoClose)
let txDbOpts = createTransactionDbOptions(autoClose)

# TODO: set prefered defaults
txDbOpts

proc close*(txDbOpts: TransactionDbOptionsRef) =
if not txDbOpts.isClosed():
Expand Down
12 changes: 11 additions & 1 deletion rocksdb/transactions/txopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ proc cPtr*(txOpts: TransactionOptionsRef): TransactionOptionsPtr =
doAssert not txOpts.isClosed()
txOpts.cPtr

# TODO: Add setters and getters for backup options properties.
template setOpt(nname, ntyp, ctyp: untyped) =
proc `nname=`*(txOpts: TransactionOptionsRef, value: ntyp) =
doAssert not txOpts.isClosed()
`rocksdb_transaction_options_set nname`(txOpts.cPtr, value.ctyp)

setOpt setSnapshot, bool, uint8
setOpt deadlockDetect, bool, uint8
setOpt lockTimeout, int, int64
setOpt deadlockDetectDepth, int, int64
setOpt maxWriteBatchSize, int, csize_t
setOpt skipPrepare, bool, uint8

proc defaultTransactionOptions*(autoClose = false): TransactionOptionsRef {.inline.} =
createTransactionOptions(autoClose)
Expand Down
4 changes: 2 additions & 2 deletions tests/options/test_backupopts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ suite "BackupEngineOptionsRef Tests":
backupOpts.close()

test "Test defaultBackupEngineOptions":
let backupOpts = defaultBackupEngineOptions()
let backupOpts = defaultBackupEngineOptions(".")

check not backupOpts.cPtr.isNil()

backupOpts.close()

test "Test close":
let backupOpts = defaultBackupEngineOptions()
let backupOpts = defaultBackupEngineOptions(".")

check not backupOpts.isClosed()
backupOpts.close()
Expand Down
1 change: 0 additions & 1 deletion tests/test_rocksdb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ suite "RocksDbRef Tests":

cfOpts.compression = lz4Compression
check cfOpts.compression == lz4Compression
let cfDescriptor = initColFamilyDescriptor(CF_DEFAULT, cfOpts)
let db1 = openRocksDb(dbPath, columnFamilies = @[cfDescriptor]).get()
check db1.put(key, val).isOk()
db1.close()
Expand Down

0 comments on commit 45f5753

Please sign in to comment.