2024-03-05 03:12:37 +00:00
|
|
|
# Nim-RocksDB
|
|
|
|
# Copyright 2024 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
#
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * GPL license, version 2.0, ([LICENSE-GPLv2](LICENSE-GPLv2) or https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
|
|
|
|
#
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
2024-06-26 15:00:10 +00:00
|
|
|
import ../lib/librocksdb
|
2024-03-05 03:12:37 +00:00
|
|
|
|
|
|
|
type
|
2024-07-03 15:46:42 +00:00
|
|
|
BackupEngineOptionsPtr* = ptr rocksdb_backup_engine_options_t
|
2024-03-05 03:12:37 +00:00
|
|
|
|
|
|
|
BackupEngineOptionsRef* = ref object
|
|
|
|
cPtr: BackupEngineOptionsPtr
|
2024-06-28 02:04:37 +00:00
|
|
|
autoClose*: bool # if true then close will be called when the backup engine is closed
|
2024-03-05 03:12:37 +00:00
|
|
|
|
2024-07-03 15:46:42 +00:00
|
|
|
proc createBackupEngineOptions*(
|
|
|
|
backupDir: string, autoClose = false
|
|
|
|
): BackupEngineOptionsRef =
|
|
|
|
BackupEngineOptionsRef(
|
|
|
|
cPtr: rocksdb_backup_engine_options_create(backupDir.cstring), autoClose: autoClose
|
|
|
|
)
|
2024-03-05 03:12:37 +00:00
|
|
|
|
2024-07-03 15:46:42 +00:00
|
|
|
proc isClosed*(backupOpts: BackupEngineOptionsRef): bool {.inline.} =
|
|
|
|
backupOpts.cPtr.isNil()
|
2024-03-05 03:12:37 +00:00
|
|
|
|
2024-07-03 15:46:42 +00:00
|
|
|
proc cPtr*(backupOpts: BackupEngineOptionsRef): BackupEngineOptionsPtr =
|
|
|
|
doAssert not backupOpts.isClosed()
|
|
|
|
backupOpts.cPtr
|
2024-03-05 03:12:37 +00:00
|
|
|
|
2024-07-03 15:46:42 +00:00
|
|
|
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)
|
2024-03-05 03:12:37 +00:00
|
|
|
|
2024-07-03 15:46:42 +00:00
|
|
|
proc `nname`*(backupOpts: BackupEngineOptionsRef): ntyp =
|
|
|
|
doAssert not backupOpts.isClosed()
|
|
|
|
ntyp `rocksdb_backup_engine_options_get nname`(backupOpts.cPtr)
|
2024-06-28 02:04:37 +00:00
|
|
|
|
2024-07-03 15:46:42 +00:00
|
|
|
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
|
|
|
|
): BackupEngineOptionsRef {.inline.} =
|
|
|
|
let backupOpts = createBackupEngineOptions(backupDir, autoClose)
|
2024-06-28 02:04:37 +00:00
|
|
|
|
2024-07-03 15:46:42 +00:00
|
|
|
# TODO: set defaults here
|
|
|
|
backupOpts
|
2024-03-27 06:18:21 +00:00
|
|
|
|
2024-07-03 15:46:42 +00:00
|
|
|
proc close*(backupOpts: BackupEngineOptionsRef) =
|
|
|
|
if not backupOpts.isClosed():
|
|
|
|
rocksdb_backup_engine_options_destroy(backupOpts.cPtr)
|
|
|
|
backupOpts.cPtr = nil
|