@@ -38,6 +38,7 @@ ffi.cdef[[
3838 static const int TDB_ERR_INVALID_DB = -10 ;
3939 static const int TDB_ERR_UNKNOWN = -11 ;
4040 static const int TDB_ERR_LOCKED = -12 ;
41+ static const int TDB_ERR_READONLY = -13 ;
4142
4243 // Structures
4344 static const int TDB_MAX_CF_NAME_LEN = 128 ;
@@ -82,6 +83,9 @@ ffi.cdef[[
8283 int use_btree ;
8384 tidesdb_commit_hook_fn commit_hook_fn ;
8485 void * commit_hook_ctx ;
86+ size_t object_target_file_size ;
87+ int object_lazy_compaction ;
88+ int object_prefetch_compaction ;
8589 } tidesdb_column_family_config_t ;
8690
8791 typedef struct {
@@ -94,6 +98,14 @@ ffi.cdef[[
9498 int log_to_file ;
9599 size_t log_truncation_at ;
96100 size_t max_memory_usage ;
101+ int unified_memtable ;
102+ size_t unified_memtable_write_buffer_size ;
103+ int unified_memtable_skip_list_max_level ;
104+ float unified_memtable_skip_list_probability ;
105+ int unified_memtable_sync_mode ;
106+ uint64_t unified_memtable_sync_interval_us ;
107+ void * object_store ;
108+ void * object_store_config ;
97109 } tidesdb_config_t ;
98110
99111 typedef struct {
@@ -204,6 +216,22 @@ ffi.cdef[[
204216 int64_t txn_memory_bytes ;
205217 size_t compaction_queue_size ;
206218 size_t flush_queue_size ;
219+ int unified_memtable_enabled ;
220+ int64_t unified_memtable_bytes ;
221+ int unified_immutable_count ;
222+ int unified_is_flushing ;
223+ uint32_t unified_next_cf_index ;
224+ uint64_t unified_wal_generation ;
225+ int object_store_enabled ;
226+ const char * object_store_connector ;
227+ size_t local_cache_bytes_used ;
228+ size_t local_cache_bytes_max ;
229+ int local_cache_num_files ;
230+ uint64_t last_uploaded_generation ;
231+ size_t upload_queue_depth ;
232+ uint64_t total_uploads ;
233+ uint64_t total_upload_failures ;
234+ int replica_mode ;
207235 } tidesdb_db_stats_t ;
208236 int tidesdb_get_db_stats (void * db , tidesdb_db_stats_t * stats );
209237
@@ -229,6 +257,12 @@ ffi.cdef[[
229257 int tidesdb_comparator_reverse_memcmp (const uint8_t * key1 , size_t key1_size , const uint8_t * key2 , size_t key2_size , void * ctx );
230258 int tidesdb_comparator_case_insensitive (const uint8_t * key1 , size_t key1_size , const uint8_t * key2 , size_t key2_size , void * ctx );
231259
260+ // Iterator combined key-value
261+ int tidesdb_iter_key_value (void * iter , uint8_t ** key , size_t * key_size , uint8_t ** value , size_t * value_size );
262+
263+ // Replica promotion
264+ int tidesdb_promote_to_primary (void * db );
265+
232266 // Memory management
233267 void tidesdb_free (void * ptr );
234268
@@ -293,6 +327,7 @@ tidesdb.TDB_ERR_MEMORY_LIMIT = -9
293327tidesdb .TDB_ERR_INVALID_DB = - 10
294328tidesdb .TDB_ERR_UNKNOWN = - 11
295329tidesdb .TDB_ERR_LOCKED = - 12
330+ tidesdb .TDB_ERR_READONLY = - 13
296331
297332-- Compression algorithms
298333tidesdb .CompressionAlgorithm = {
@@ -343,6 +378,7 @@ local error_messages = {
343378 [tidesdb .TDB_ERR_INVALID_DB ] = " invalid database handle" ,
344379 [tidesdb .TDB_ERR_UNKNOWN ] = " unknown error" ,
345380 [tidesdb .TDB_ERR_LOCKED ] = " database is locked" ,
381+ [tidesdb .TDB_ERR_READONLY ] = " database is read-only" ,
346382}
347383
348384-- TidesDBError class
@@ -391,6 +427,12 @@ function tidesdb.default_config()
391427 log_to_file = false ,
392428 log_truncation_at = 24 * 1024 * 1024 ,
393429 max_memory_usage = 0 ,
430+ unified_memtable = false ,
431+ unified_memtable_write_buffer_size = 64 * 1024 * 1024 ,
432+ unified_memtable_skip_list_max_level = 12 ,
433+ unified_memtable_skip_list_probability = 0.25 ,
434+ unified_memtable_sync_mode = tidesdb .SyncMode .SYNC_INTERVAL ,
435+ unified_memtable_sync_interval_us = 128000 ,
394436 }
395437end
396438
@@ -418,6 +460,9 @@ function tidesdb.default_column_family_config()
418460 l1_file_count_trigger = c_config .l1_file_count_trigger ,
419461 l0_queue_stall_threshold = c_config .l0_queue_stall_threshold ,
420462 use_btree = c_config .use_btree ~= 0 ,
463+ object_target_file_size = tonumber (c_config .object_target_file_size ),
464+ object_lazy_compaction = c_config .object_lazy_compaction ~= 0 ,
465+ object_prefetch_compaction = c_config .object_prefetch_compaction ~= 0 ,
421466 }
422467end
423468
@@ -452,6 +497,9 @@ local function config_to_c_struct(config, cf_name)
452497 c_config .l1_file_count_trigger = config .l1_file_count_trigger or 4
453498 c_config .l0_queue_stall_threshold = config .l0_queue_stall_threshold or 20
454499 c_config .use_btree = config .use_btree and 1 or 0
500+ c_config .object_target_file_size = config .object_target_file_size or 0
501+ c_config .object_lazy_compaction = config .object_lazy_compaction and 1 or 0
502+ c_config .object_prefetch_compaction = config .object_prefetch_compaction and 1 or 0
455503
456504 local name = config .comparator_name or " memcmp"
457505 local name_len = math.min (# name , 63 )
@@ -549,6 +597,19 @@ function Iterator:value()
549597 return ffi .string (value_ptr [0 ], value_size [0 ])
550598end
551599
600+ function Iterator :key_value ()
601+ if self ._closed then
602+ error (TidesDBError .new (" Iterator is closed" ))
603+ end
604+ local key_ptr = ffi .new (" uint8_t*[1]" )
605+ local key_size = ffi .new (" size_t[1]" )
606+ local value_ptr = ffi .new (" uint8_t*[1]" )
607+ local value_size = ffi .new (" size_t[1]" )
608+ local result = lib .tidesdb_iter_key_value (self ._iter , key_ptr , key_size , value_ptr , value_size )
609+ check_result (result , " failed to get key-value" )
610+ return ffi .string (key_ptr [0 ], key_size [0 ]), ffi .string (value_ptr [0 ], value_size [0 ])
611+ end
612+
552613function Iterator :close ()
553614 if not self ._closed and self ._iter ~= nil then
554615 lib .tidesdb_iter_free (self ._iter )
@@ -889,6 +950,12 @@ function TidesDB.new(config)
889950 c_config .log_to_file = config .log_to_file and 1 or 0
890951 c_config .log_truncation_at = config .log_truncation_at or 24 * 1024 * 1024
891952 c_config .max_memory_usage = config .max_memory_usage or 0
953+ c_config .unified_memtable = config .unified_memtable and 1 or 0
954+ c_config .unified_memtable_write_buffer_size = config .unified_memtable_write_buffer_size or 64 * 1024 * 1024
955+ c_config .unified_memtable_skip_list_max_level = config .unified_memtable_skip_list_max_level or 12
956+ c_config .unified_memtable_skip_list_probability = config .unified_memtable_skip_list_probability or 0.25
957+ c_config .unified_memtable_sync_mode = config .unified_memtable_sync_mode or tidesdb .SyncMode .SYNC_INTERVAL
958+ c_config .unified_memtable_sync_interval_us = config .unified_memtable_sync_interval_us or 128000
892959
893960 local db_ptr = ffi .new (" void*[1]" )
894961 local result = lib .tidesdb_open (c_config , db_ptr )
@@ -910,6 +977,12 @@ function TidesDB.open(path, options)
910977 log_to_file = options .log_to_file or false ,
911978 log_truncation_at = options .log_truncation_at or 24 * 1024 * 1024 ,
912979 max_memory_usage = options .max_memory_usage or 0 ,
980+ unified_memtable = options .unified_memtable or false ,
981+ unified_memtable_write_buffer_size = options .unified_memtable_write_buffer_size ,
982+ unified_memtable_skip_list_max_level = options .unified_memtable_skip_list_max_level ,
983+ unified_memtable_skip_list_probability = options .unified_memtable_skip_list_probability ,
984+ unified_memtable_sync_mode = options .unified_memtable_sync_mode ,
985+ unified_memtable_sync_interval_us = options .unified_memtable_sync_interval_us ,
913986 }
914987 return TidesDB .new (config )
915988end
@@ -1093,6 +1166,22 @@ function TidesDB:get_db_stats()
10931166 txn_memory_bytes = tonumber (c_stats .txn_memory_bytes ),
10941167 compaction_queue_size = tonumber (c_stats .compaction_queue_size ),
10951168 flush_queue_size = tonumber (c_stats .flush_queue_size ),
1169+ unified_memtable_enabled = c_stats .unified_memtable_enabled ~= 0 ,
1170+ unified_memtable_bytes = tonumber (c_stats .unified_memtable_bytes ),
1171+ unified_immutable_count = c_stats .unified_immutable_count ,
1172+ unified_is_flushing = c_stats .unified_is_flushing ~= 0 ,
1173+ unified_next_cf_index = tonumber (c_stats .unified_next_cf_index ),
1174+ unified_wal_generation = tonumber (c_stats .unified_wal_generation ),
1175+ object_store_enabled = c_stats .object_store_enabled ~= 0 ,
1176+ object_store_connector = c_stats .object_store_connector ~= nil and ffi .string (c_stats .object_store_connector ) or nil ,
1177+ local_cache_bytes_used = tonumber (c_stats .local_cache_bytes_used ),
1178+ local_cache_bytes_max = tonumber (c_stats .local_cache_bytes_max ),
1179+ local_cache_num_files = c_stats .local_cache_num_files ,
1180+ last_uploaded_generation = tonumber (c_stats .last_uploaded_generation ),
1181+ upload_queue_depth = tonumber (c_stats .upload_queue_depth ),
1182+ total_uploads = tonumber (c_stats .total_uploads ),
1183+ total_upload_failures = tonumber (c_stats .total_upload_failures ),
1184+ replica_mode = c_stats .replica_mode ~= 0 ,
10961185 }
10971186end
10981187
@@ -1136,6 +1225,15 @@ function TidesDB:get_comparator(name)
11361225 return fn_ptr [0 ], ctx_ptr [0 ]
11371226end
11381227
1228+ function TidesDB :promote_to_primary ()
1229+ if self ._closed then
1230+ error (TidesDBError .new (" Database is closed" ))
1231+ end
1232+
1233+ local result = lib .tidesdb_promote_to_primary (self ._db )
1234+ check_result (result , " failed to promote to primary" )
1235+ end
1236+
11391237tidesdb .TidesDB = TidesDB
11401238
11411239-- Configuration file operations
@@ -1166,6 +1264,9 @@ function tidesdb.load_config_from_ini(ini_file, section_name)
11661264 l1_file_count_trigger = c_config .l1_file_count_trigger ,
11671265 l0_queue_stall_threshold = c_config .l0_queue_stall_threshold ,
11681266 use_btree = c_config .use_btree ~= 0 ,
1267+ object_target_file_size = tonumber (c_config .object_target_file_size ),
1268+ object_lazy_compaction = c_config .object_lazy_compaction ~= 0 ,
1269+ object_prefetch_compaction = c_config .object_prefetch_compaction ~= 0 ,
11691270 }
11701271end
11711272
@@ -1176,6 +1277,6 @@ function tidesdb.save_config_to_ini(ini_file, section_name, config)
11761277end
11771278
11781279-- Version
1179- tidesdb ._VERSION = " 0.5.6 "
1280+ tidesdb ._VERSION = " 0.5.7 "
11801281
11811282return tidesdb
0 commit comments