Skip to content

Commit 51fe615

Browse files
authored
Merge pull request #33 from tidesdb/checkpoint-feat
checkpoint api feature support to align with tdb v8.3.2+
2 parents e23340b + b18983e commit 51fe615

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

src/tidesdb.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ ffi.cdef[[
159159

160160
// Backup operations
161161
int tidesdb_backup(void* db, const char* dir);
162+
int tidesdb_checkpoint(void* db, const char* checkpoint_dir);
162163

163164
// Configuration operations
164165
int tidesdb_cf_config_load_from_ini(const char* ini_file, const char* section_name, tidesdb_column_family_config_t* config);
@@ -970,6 +971,15 @@ function TidesDB:backup(dir)
970971
check_result(result, "failed to create backup")
971972
end
972973

974+
function TidesDB:checkpoint(dir)
975+
if self._closed then
976+
error(TidesDBError.new("Database is closed"))
977+
end
978+
979+
local result = lib.tidesdb_checkpoint(self._db, dir)
980+
check_result(result, "failed to create checkpoint")
981+
end
982+
973983
function TidesDB:register_comparator(name, fn, ctx_str, ctx)
974984
if self._closed then
975985
error(TidesDBError.new("Database is closed"))
@@ -1032,6 +1042,6 @@ function tidesdb.save_config_to_ini(ini_file, section_name, config)
10321042
end
10331043

10341044
-- Version
1035-
tidesdb._VERSION = "0.5.0"
1045+
tidesdb._VERSION = "0.5.1"
10361046

10371047
return tidesdb

tests/test_tidesdb.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,54 @@ function tests.test_backup()
376376
print("PASS: test_backup")
377377
end
378378

379+
function tests.test_checkpoint()
380+
local path = "./test_db_checkpoint"
381+
local checkpoint_path = "./test_db_checkpoint_snap"
382+
cleanup_db(path)
383+
cleanup_db(checkpoint_path)
384+
385+
local db = tidesdb.TidesDB.open(path)
386+
db:create_column_family("test_cf")
387+
local cf = db:get_column_family("test_cf")
388+
389+
-- Insert data
390+
local txn = db:begin_txn()
391+
txn:put(cf, "key1", "value1")
392+
txn:put(cf, "key2", "value2")
393+
txn:commit()
394+
txn:free()
395+
396+
-- Create checkpoint
397+
db:checkpoint(checkpoint_path)
398+
399+
db:close()
400+
401+
-- Open checkpoint and verify data
402+
local cp_db = tidesdb.TidesDB.open(checkpoint_path)
403+
local cp_cf = cp_db:get_column_family("test_cf")
404+
local read_txn = cp_db:begin_txn()
405+
local v1 = read_txn:get(cp_cf, "key1")
406+
local v2 = read_txn:get(cp_cf, "key2")
407+
assert_eq(v1, "value1", "checkpoint should contain key1")
408+
assert_eq(v2, "value2", "checkpoint should contain key2")
409+
read_txn:free()
410+
411+
-- Verify checkpoint to existing non-empty dir fails
412+
cp_db:close()
413+
414+
local db2 = tidesdb.TidesDB.open(path)
415+
local cf2 = db2:get_column_family("test_cf")
416+
417+
local err = assert_error(function()
418+
db2:checkpoint(checkpoint_path)
419+
end, "checkpoint to non-empty dir should fail")
420+
421+
db2:close()
422+
cleanup_db(path)
423+
cleanup_db(checkpoint_path)
424+
print("PASS: test_checkpoint")
425+
end
426+
379427
function tests.test_update_runtime_config()
380428
local path = "./test_db_runtime_config"
381429
cleanup_db(path)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package = "tidesdb"
2-
version = "0.5.0-1"
2+
version = "0.5.1-1"
33
source = {
44
url = "git://github.com/tidesdb/tidesdb-lua.git",
5-
tag = "v0.5.0"
5+
tag = "v0.5.1"
66
}
77
description = {
88
summary = "Official Lua bindings for TidesDB - A high-performance embedded key-value storage engine",

0 commit comments

Comments
 (0)