@@ -80,6 +80,8 @@ ffi.cdef[[
8080 uint64_t min_disk_space ;
8181 int l1_file_count_trigger ;
8282 int l0_queue_stall_threshold ;
83+ double tombstone_density_trigger ;
84+ uint64_t tombstone_density_min_entries ;
8385 int use_btree ;
8486 tidesdb_commit_hook_fn commit_hook_fn ;
8587 void * commit_hook_ctx ;
@@ -126,6 +128,7 @@ ffi.cdef[[
126128 uint64_t unified_memtable_sync_interval_us ;
127129 void * object_store ;
128130 tidesdb_objstore_config_t * object_store_config ;
131+ int max_concurrent_flushes ;
129132 } tidesdb_config_t ;
130133
131134 typedef struct {
@@ -145,6 +148,11 @@ ffi.cdef[[
145148 uint64_t btree_total_nodes ;
146149 uint32_t btree_max_height ;
147150 double btree_avg_height ;
151+ uint64_t total_tombstones ;
152+ double tombstone_ratio ;
153+ uint64_t * level_tombstone_counts ;
154+ double max_sst_density ;
155+ int max_sst_density_level ;
148156 } tidesdb_stats_t ;
149157
150158 typedef struct {
@@ -206,6 +214,8 @@ ffi.cdef[[
206214
207215 // Column family operations
208216 int tidesdb_compact (void * cf );
217+ int tidesdb_compact_range (void * cf , const uint8_t * start_key , size_t start_key_size ,
218+ const uint8_t * end_key , size_t end_key_size );
209219 int tidesdb_flush_memtable (void * cf );
210220 int tidesdb_is_flushing (void * cf );
211221 int tidesdb_is_compacting (void * cf );
@@ -442,22 +452,24 @@ end
442452
443453-- Default configurations
444454function tidesdb .default_config ()
455+ local c_config = lib .tidesdb_default_config ()
445456 return {
446457 db_path = " " ,
447- num_flush_threads = 2 ,
448- num_compaction_threads = 2 ,
449- log_level = tidesdb .LogLevel .LOG_INFO ,
450- block_cache_size = 64 * 1024 * 1024 ,
451- max_open_sstables = 256 ,
452- log_to_file = false ,
453- log_truncation_at = 24 * 1024 * 1024 ,
454- max_memory_usage = 0 ,
455- unified_memtable = false ,
456- unified_memtable_write_buffer_size = 64 * 1024 * 1024 ,
457- unified_memtable_skip_list_max_level = 12 ,
458- unified_memtable_skip_list_probability = 0.25 ,
459- unified_memtable_sync_mode = tidesdb .SyncMode .SYNC_INTERVAL ,
460- unified_memtable_sync_interval_us = 128000 ,
458+ num_flush_threads = c_config .num_flush_threads ,
459+ num_compaction_threads = c_config .num_compaction_threads ,
460+ log_level = c_config .log_level ,
461+ block_cache_size = tonumber (c_config .block_cache_size ),
462+ max_open_sstables = tonumber (c_config .max_open_sstables ),
463+ log_to_file = c_config .log_to_file ~= 0 ,
464+ log_truncation_at = tonumber (c_config .log_truncation_at ),
465+ max_memory_usage = tonumber (c_config .max_memory_usage ),
466+ unified_memtable = c_config .unified_memtable ~= 0 ,
467+ unified_memtable_write_buffer_size = tonumber (c_config .unified_memtable_write_buffer_size ),
468+ unified_memtable_skip_list_max_level = c_config .unified_memtable_skip_list_max_level ,
469+ unified_memtable_skip_list_probability = c_config .unified_memtable_skip_list_probability ,
470+ unified_memtable_sync_mode = c_config .unified_memtable_sync_mode ,
471+ unified_memtable_sync_interval_us = tonumber (c_config .unified_memtable_sync_interval_us ),
472+ max_concurrent_flushes = c_config .max_concurrent_flushes ,
461473 }
462474end
463475
@@ -484,6 +496,8 @@ function tidesdb.default_column_family_config()
484496 min_disk_space = tonumber (c_config .min_disk_space ),
485497 l1_file_count_trigger = c_config .l1_file_count_trigger ,
486498 l0_queue_stall_threshold = c_config .l0_queue_stall_threshold ,
499+ tombstone_density_trigger = c_config .tombstone_density_trigger ,
500+ tombstone_density_min_entries = tonumber (c_config .tombstone_density_min_entries ),
487501 use_btree = c_config .use_btree ~= 0 ,
488502 object_lazy_compaction = c_config .object_lazy_compaction ~= 0 ,
489503 object_prefetch_compaction = c_config .object_prefetch_compaction ~= 0 ,
@@ -573,6 +587,8 @@ local function config_to_c_struct(config, cf_name)
573587 c_config .min_disk_space = config .min_disk_space or 100 * 1024 * 1024
574588 c_config .l1_file_count_trigger = config .l1_file_count_trigger or 4
575589 c_config .l0_queue_stall_threshold = config .l0_queue_stall_threshold or 20
590+ c_config .tombstone_density_trigger = config .tombstone_density_trigger or 0.0
591+ c_config .tombstone_density_min_entries = config .tombstone_density_min_entries or 1024
576592 c_config .use_btree = config .use_btree and 1 or 0
577593 c_config .object_lazy_compaction = config .object_lazy_compaction and 1 or 0
578594 c_config .object_prefetch_compaction = config .object_prefetch_compaction and 1 or 0
@@ -715,6 +731,21 @@ function ColumnFamily:compact()
715731 check_result (result , " failed to compact column family" )
716732end
717733
734+ function ColumnFamily :compact_range (start_key , end_key )
735+ local start_ptr , start_len = nil , 0
736+ if start_key ~= nil and # start_key > 0 then
737+ start_ptr = start_key
738+ start_len = # start_key
739+ end
740+ local end_ptr , end_len = nil , 0
741+ if end_key ~= nil and # end_key > 0 then
742+ end_ptr = end_key
743+ end_len = # end_key
744+ end
745+ local result = lib .tidesdb_compact_range (self ._cf , start_ptr , start_len , end_ptr , end_len )
746+ check_result (result , " failed to compact range" )
747+ end
748+
718749function ColumnFamily :flush_memtable ()
719750 local result = lib .tidesdb_flush_memtable (self ._cf )
720751 check_result (result , " failed to flush memtable" )
@@ -810,6 +841,8 @@ function ColumnFamily:get_stats()
810841 min_disk_space = tonumber (c_cfg .min_disk_space ),
811842 l1_file_count_trigger = c_cfg .l1_file_count_trigger ,
812843 l0_queue_stall_threshold = c_cfg .l0_queue_stall_threshold ,
844+ tombstone_density_trigger = c_cfg .tombstone_density_trigger ,
845+ tombstone_density_min_entries = tonumber (c_cfg .tombstone_density_min_entries ),
813846 use_btree = c_cfg .use_btree ~= 0 ,
814847 }
815848 end
@@ -821,6 +854,13 @@ function ColumnFamily:get_stats()
821854 end
822855 end
823856
857+ local level_tombstone_counts = {}
858+ if c_stats .num_levels > 0 and c_stats .level_tombstone_counts ~= nil then
859+ for i = 0 , c_stats .num_levels - 1 do
860+ table.insert (level_tombstone_counts , tonumber (c_stats .level_tombstone_counts [i ]))
861+ end
862+ end
863+
824864 local stats = {
825865 num_levels = c_stats .num_levels ,
826866 memtable_size = tonumber (c_stats .memtable_size ),
@@ -838,6 +878,11 @@ function ColumnFamily:get_stats()
838878 btree_total_nodes = tonumber (c_stats .btree_total_nodes ),
839879 btree_max_height = c_stats .btree_max_height ,
840880 btree_avg_height = c_stats .btree_avg_height ,
881+ total_tombstones = tonumber (c_stats .total_tombstones ),
882+ tombstone_ratio = c_stats .tombstone_ratio ,
883+ level_tombstone_counts = level_tombstone_counts ,
884+ max_sst_density = c_stats .max_sst_density ,
885+ max_sst_density_level = c_stats .max_sst_density_level ,
841886 }
842887
843888 lib .tidesdb_free_stats (stats_ptr [0 ])
@@ -1045,6 +1090,7 @@ function TidesDB.new(config)
10451090 c_config .unified_memtable_skip_list_probability = config .unified_memtable_skip_list_probability or 0.25
10461091 c_config .unified_memtable_sync_mode = config .unified_memtable_sync_mode or tidesdb .SyncMode .SYNC_INTERVAL
10471092 c_config .unified_memtable_sync_interval_us = config .unified_memtable_sync_interval_us or 128000
1093+ c_config .max_concurrent_flushes = config .max_concurrent_flushes or 0
10481094
10491095 -- Object store configuration
10501096 if config .object_store then
@@ -1083,6 +1129,7 @@ function TidesDB.open(path, options)
10831129 unified_memtable_skip_list_probability = options .unified_memtable_skip_list_probability ,
10841130 unified_memtable_sync_mode = options .unified_memtable_sync_mode ,
10851131 unified_memtable_sync_interval_us = options .unified_memtable_sync_interval_us ,
1132+ max_concurrent_flushes = options .max_concurrent_flushes ,
10861133 object_store = options .object_store ,
10871134 object_store_config = options .object_store_config ,
10881135 }
@@ -1365,6 +1412,8 @@ function tidesdb.load_config_from_ini(ini_file, section_name)
13651412 min_disk_space = tonumber (c_config .min_disk_space ),
13661413 l1_file_count_trigger = c_config .l1_file_count_trigger ,
13671414 l0_queue_stall_threshold = c_config .l0_queue_stall_threshold ,
1415+ tombstone_density_trigger = c_config .tombstone_density_trigger ,
1416+ tombstone_density_min_entries = tonumber (c_config .tombstone_density_min_entries ),
13681417 use_btree = c_config .use_btree ~= 0 ,
13691418 object_lazy_compaction = c_config .object_lazy_compaction ~= 0 ,
13701419 object_prefetch_compaction = c_config .object_prefetch_compaction ~= 0 ,
@@ -1378,6 +1427,6 @@ function tidesdb.save_config_to_ini(ini_file, section_name, config)
13781427end
13791428
13801429-- Version
1381- tidesdb ._VERSION = " 0.6 .0"
1430+ tidesdb ._VERSION = " 0.7 .0"
13821431
13831432return tidesdb
0 commit comments