diff --git a/README.md b/README.md index 33ba613..f9e9517 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,3 @@ Multiple licenses apply: ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. - -## Support - -- [Discord](https://discord.gg/tWEmjR66cy) -- [GitHub Issues](https://github.com/tidesdb/tidesdb-lua/issues) diff --git a/src/tidesdb.lua b/src/tidesdb.lua index 8a8afbd..9990e21 100644 --- a/src/tidesdb.lua +++ b/src/tidesdb.lua @@ -83,7 +83,7 @@ ffi.cdef[[ int use_btree; tidesdb_commit_hook_fn commit_hook_fn; void *commit_hook_ctx; - size_t object_target_file_size; + size_t object_target_file_size; /* reserved, retired from public API */ int object_lazy_compaction; int object_prefetch_compaction; } tidesdb_column_family_config_t; @@ -182,6 +182,7 @@ ffi.cdef[[ int tidesdb_txn_put(void* txn, void* cf, const uint8_t* key, size_t key_len, const uint8_t* value, size_t value_len, int ttl); int tidesdb_txn_get(void* txn, void* cf, const uint8_t* key, size_t key_len, uint8_t** value, size_t* value_len); int tidesdb_txn_delete(void* txn, void* cf, const uint8_t* key, size_t key_len); + int tidesdb_txn_single_delete(void* txn, void* cf, const uint8_t* key, size_t key_len); int tidesdb_txn_commit(void* txn); int tidesdb_txn_rollback(void* txn); void tidesdb_txn_free(void* txn); @@ -484,7 +485,6 @@ function tidesdb.default_column_family_config() l1_file_count_trigger = c_config.l1_file_count_trigger, l0_queue_stall_threshold = c_config.l0_queue_stall_threshold, use_btree = c_config.use_btree ~= 0, - object_target_file_size = tonumber(c_config.object_target_file_size), object_lazy_compaction = c_config.object_lazy_compaction ~= 0, object_prefetch_compaction = c_config.object_prefetch_compaction ~= 0, } @@ -574,7 +574,6 @@ local function config_to_c_struct(config, cf_name) c_config.l1_file_count_trigger = config.l1_file_count_trigger or 4 c_config.l0_queue_stall_threshold = config.l0_queue_stall_threshold or 20 c_config.use_btree = config.use_btree and 1 or 0 - c_config.object_target_file_size = config.object_target_file_size or 0 c_config.object_lazy_compaction = config.object_lazy_compaction and 1 or 0 c_config.object_prefetch_compaction = config.object_prefetch_compaction and 1 or 0 @@ -905,6 +904,19 @@ function Transaction:delete(cf, key) check_result(result, "failed to delete key") end +function Transaction:single_delete(cf, key) + if self._closed then + error(TidesDBError.new("Transaction is closed")) + end + if self._committed then + error(TidesDBError.new("Transaction already committed")) + end + + local key_len = #key + local result = lib.tidesdb_txn_single_delete(self._txn, cf._cf, key, key_len) + check_result(result, "failed to single delete key") +end + function Transaction:commit() if self._closed then error(TidesDBError.new("Transaction is closed")) @@ -1354,7 +1366,6 @@ function tidesdb.load_config_from_ini(ini_file, section_name) l1_file_count_trigger = c_config.l1_file_count_trigger, l0_queue_stall_threshold = c_config.l0_queue_stall_threshold, use_btree = c_config.use_btree ~= 0, - object_target_file_size = tonumber(c_config.object_target_file_size), object_lazy_compaction = c_config.object_lazy_compaction ~= 0, object_prefetch_compaction = c_config.object_prefetch_compaction ~= 0, } @@ -1367,6 +1378,6 @@ function tidesdb.save_config_to_ini(ini_file, section_name, config) end -- Version -tidesdb._VERSION = "0.5.8" +tidesdb._VERSION = "0.6.0" return tidesdb diff --git a/tests/test_tidesdb.lua b/tests/test_tidesdb.lua index 62ea86e..f51d03c 100644 --- a/tests/test_tidesdb.lua +++ b/tests/test_tidesdb.lua @@ -1167,14 +1167,13 @@ function tests.test_object_cf_config_fields() -- Test default column family config includes object_* fields local default_cf = tidesdb.default_column_family_config() - assert_true(default_cf.object_target_file_size ~= nil, "object_target_file_size should exist") assert_true(default_cf.object_lazy_compaction ~= nil, "object_lazy_compaction should exist") assert_true(default_cf.object_prefetch_compaction ~= nil, "object_prefetch_compaction should exist") + assert_true(default_cf.object_target_file_size == nil, "object_target_file_size should be retired from public API") -- Test creating CF with custom object_* fields local db = tidesdb.TidesDB.open(path) local cf_config = tidesdb.default_column_family_config() - cf_config.object_target_file_size = 16 * 1024 * 1024 cf_config.object_lazy_compaction = true cf_config.object_prefetch_compaction = false db:create_column_family("test_cf", cf_config) @@ -1342,6 +1341,55 @@ function tests.test_error_readonly_constant() print("PASS: test_error_readonly_constant") end +function tests.test_txn_single_delete() + local path = "./test_db_single_delete" + cleanup_db(path) + + local db = tidesdb.TidesDB.open(path) + db:create_column_family("test_cf") + local cf = db:get_column_family("test_cf") + + -- Insert a key that will be single-deleted + local txn = db:begin_txn() + txn:put(cf, "sd_key", "sd_value") + txn:put(cf, "keep_key", "keep_value") + txn:commit() + txn:free() + + -- Verify the key exists + local read_txn = db:begin_txn() + local v = read_txn:get(cf, "sd_key") + assert_eq(v, "sd_value", "sd_key should exist before single_delete") + read_txn:free() + + -- Single-delete the key + local del_txn = db:begin_txn() + del_txn:single_delete(cf, "sd_key") + del_txn:commit() + del_txn:free() + + -- Verify the key is gone + local verify_txn = db:begin_txn() + local err = assert_error(function() + verify_txn:get(cf, "sd_key") + end, "sd_key should not exist after single_delete") + local kept = verify_txn:get(cf, "keep_key") + assert_eq(kept, "keep_value", "unrelated key should remain after single_delete") + verify_txn:free() + + -- single_delete on a closed transaction should raise + local closed_txn = db:begin_txn() + closed_txn:free() + local closed_err = assert_error(function() + closed_txn:single_delete(cf, "any_key") + end, "single_delete on closed transaction should error") + + db:drop_column_family("test_cf") + db:close() + cleanup_db(path) + print("PASS: test_txn_single_delete") +end + -- Run all tests local function run_tests() print("Running TidesDB Lua tests...") diff --git a/tidesdb-0.5.8-1.rockspec b/tidesdb-0.6.0-1.rockspec similarity index 95% rename from tidesdb-0.5.8-1.rockspec rename to tidesdb-0.6.0-1.rockspec index 934483a..394ba6e 100644 --- a/tidesdb-0.5.8-1.rockspec +++ b/tidesdb-0.6.0-1.rockspec @@ -1,8 +1,8 @@ package = "tidesdb" -version = "0.5.8-1" +version = "0.6.0-1" source = { url = "git://github.com/tidesdb/tidesdb-lua.git", - tag = "v0.5.8" + tag = "v0.6.0" } description = { summary = "Official Lua bindings for TidesDB - A high-performance embedded key-value storage engine",