expose more options (#46)

This commit is contained in:
Jacek Sieka 2024-06-12 11:51:03 +02:00 committed by GitHub
parent e34c8e825c
commit 138dadac9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 111 additions and 0 deletions

View File

@ -18,6 +18,17 @@ type
ColFamilyOptionsRef* = ref object ColFamilyOptionsRef* = ref object
cPtr: ColFamilyOptionsPtr cPtr: ColFamilyOptionsPtr
Compression* {.pure.} = enum
# Use a slightly clunky name here to avoid global symbol conflicts
noCompression = rocksdb_no_compression
snappyCompression = rocksdb_snappy_compression
zlibCompression = rocksdb_zlib_compression
bz2Compression = rocksdb_bz2_compression
lz4Compression = rocksdb_lz4_compression
lz4hcCompression = rocksdb_lz4hc_compression
xpressCompression = rocksdb_xpress_compression
zstdCompression = rocksdb_zstd_compression
proc newColFamilyOptions*(): ColFamilyOptionsRef = proc newColFamilyOptions*(): ColFamilyOptionsRef =
ColFamilyOptionsRef(cPtr: rocksdb_options_create()) ColFamilyOptionsRef(cPtr: rocksdb_options_create())
@ -54,6 +65,49 @@ proc setWriteBufferSize*(dbOpts: ColFamilyOptionsRef, maxBufferSize: int) =
doAssert not dbOpts.isClosed() doAssert not dbOpts.isClosed()
rocksdb_options_set_write_buffer_size(dbOpts.cPtr, maxBufferSize.csize_t) rocksdb_options_set_write_buffer_size(dbOpts.cPtr, maxBufferSize.csize_t)
# https://github.com/facebook/rocksdb/wiki/MemTable
proc setHashSkipListRep*(
dbOpts: ColFamilyOptionsRef, bucketCount, skipListHeight,
skipListBranchingFactor: int) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_hash_skip_list_rep(
dbOpts.cPtr, bucketCount.csize_t, skipListHeight.cint,
skipListBranchingFactor.cint)
proc setHashLinkListRep*(
dbOpts: ColFamilyOptionsRef, bucketCount: int) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_hash_link_list_rep(dbOpts.cPtr, bucketCount.csize_t)
proc setMemtableVectorRep*(dbOpts: ColFamilyOptionsRef) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_memtable_vector_rep(dbOpts.cPtr)
proc setMemtableWholeKeyFiltering*(dbOpts: ColFamilyOptionsRef, value: bool) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_memtable_whole_key_filtering(dbOpts.cPtr, value.uint8)
proc setMemtablePrefixBloomSizeRatio*(dbOpts: ColFamilyOptionsRef, value: float) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_memtable_prefix_bloom_size_ratio(dbOpts.cPtr, value)
proc setFixedPrefixExtractor*(dbOpts: ColFamilyOptionsRef, length: int) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_prefix_extractor(
dbOpts.cPtr, rocksdb_slicetransform_create_fixed_prefix(length.csize_t))
proc setMaxTotalWalSize*(dbOpts: ColFamilyOptionsRef, size: int) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_max_total_wal_size(dbOpts.cPtr, size.csize_t)
proc setCompression*(dbOpts: ColFamilyOptionsRef, value: Compression) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_compression(dbOpts.cPtr, value.cint)
proc setBottommostCompression*(dbOpts: ColFamilyOptionsRef, value: Compression) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_bottommost_compression(dbOpts.cPtr, value.cint)
proc close*(cfOpts: ColFamilyOptionsRef) = proc close*(cfOpts: ColFamilyOptionsRef) =
if not cfOpts.isClosed(): if not cfOpts.isClosed():
rocksdb_options_destroy(cfOpts.cPtr) rocksdb_options_destroy(cfOpts.cPtr)

View File

@ -82,6 +82,14 @@ proc setMaxBytesForLevelMultiplier*(dbOpts: DbOptionsRef, multiplier: float) =
doAssert not dbOpts.isClosed() doAssert not dbOpts.isClosed()
rocksdb_options_set_max_bytes_for_level_multiplier(dbOpts.cPtr, multiplier.cdouble) rocksdb_options_set_max_bytes_for_level_multiplier(dbOpts.cPtr, multiplier.cdouble)
proc setAllowConcurrentMemtableWrite*(dbOpts: DbOptionsRef, value: bool) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_allow_concurrent_memtable_write(dbOpts.cPtr, value.uint8)
proc setOptimizeFiltersForHits*(dbOpts: DbOptionsRef, value: bool) =
doAssert not dbOpts.isClosed()
rocksdb_options_set_optimize_filters_for_hits(dbOpts.cPtr, value.cint)
proc defaultDbOptions*(): DbOptionsRef = proc defaultDbOptions*(): DbOptionsRef =
let opts: DbOptionsRef = newDbOptions() let opts: DbOptionsRef = newDbOptions()

View File

@ -9,6 +9,34 @@ type
TableOptionsRef* = ref object TableOptionsRef* = ref object
cPtr*: TableOptionsPtr cPtr*: TableOptionsPtr
FilterPolicyPtr* = ptr rocksdb_filterpolicy_t
FilterPolicyRef* = ref object
cPtr*: FilterPolicyPtr
IndexType* {.pure.} = enum
binarySearch = rocksdb_block_based_table_index_type_binary_search
hashSearch = rocksdb_block_based_table_index_type_hash_search
twoLevelIndexSearch = rocksdb_block_based_table_index_type_two_level_index_search
DataBlockIndexType* {.pure.} = enum
binarySearch = rocksdb_block_based_table_data_block_index_type_binary_search
binarySearchAndHash = rocksdb_block_based_table_data_block_index_type_binary_search_and_hash
proc createRibbon*(bitsPerKey: float): FilterPolicyRef =
FilterPolicyRef(cPtr: rocksdb_filterpolicy_create_ribbon(bitsPerKey))
proc createRibbonHybrid*(bitsPerKey: float, bloomBeforeLevel: int = 0): FilterPolicyRef =
FilterPolicyRef(cPtr: rocksdb_filterpolicy_create_ribbon_hybrid(bitsPerKey, bloomBeforeLevel.cint))
proc isClosed*(policy: FilterPolicyRef): bool =
isNil(policy.cPtr)
proc close*(policy: FilterPolicyRef) =
if not isClosed(policy):
rocksdb_filterpolicy_destroy(policy.cPtr)
policy.cPtr = nil
proc createTableOptions*(): TableOptionsRef = proc createTableOptions*(): TableOptionsRef =
TableOptionsRef(cPtr: rocksdb_block_based_options_create()) TableOptionsRef(cPtr: rocksdb_block_based_options_create())
@ -37,6 +65,27 @@ proc setCacheIndexAndFilterBlocks*(opts: TableOptionsRef, value: bool) =
proc setPinL0FilterAndIndexBlocksInCache*(opts: TableOptionsRef, value: bool) = proc setPinL0FilterAndIndexBlocksInCache*(opts: TableOptionsRef, value: bool) =
rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache(opts.cPtr, value.uint8) rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache(opts.cPtr, value.uint8)
proc setPinTopLevelIndexAndFilter*(opts: TableOptionsRef, value: bool) =
rocksdb_block_based_options_set_pin_top_level_index_and_filter(opts.cPtr, value.uint8)
proc setCacheIndexAndFilterBlocksWithHighPriority*(opts: TableOptionsRef, value: bool) =
rocksdb_block_based_options_set_cache_index_and_filter_blocks_with_high_priority(opts.cPtr, value.uint8)
proc setFilterPolicy*(opts: TableOptionsRef, policy: FilterPolicyRef) =
rocksdb_block_based_options_set_filter_policy(opts.cPtr, policy.cPtr)
proc setIndexType*(opts: TableOptionsRef, typ: IndexType) =
rocksdb_block_based_options_set_index_type(opts.cPtr, typ.cint)
proc setPartitionFilters*(opts: TableOptionsRef, value: bool) =
rocksdb_block_based_options_set_partition_filters(opts.cPtr, value.uint8)
proc setDataBlockIndexType*(opts: TableOptionsRef, value: DataBlockIndexType) =
rocksdb_block_based_options_set_data_block_index_type(opts.cPtr, value.cint)
proc setDataBlockHashRatio*(opts: TableOptionsRef, value: float) =
rocksdb_block_based_options_set_data_block_hash_ratio(opts.cPtr, value.cdouble)
proc defaultTableOptions*(): TableOptionsRef = proc defaultTableOptions*(): TableOptionsRef =
# https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning#other-general-options # https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning#other-general-options
let opts = createTableOptions() let opts = createTableOptions()