Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/tidesdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ ffi.cdef[[

// Backup operations
int tidesdb_backup(void* db, const char* dir);
int tidesdb_checkpoint(void* db, const char* checkpoint_dir);

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

function TidesDB:checkpoint(dir)
if self._closed then
error(TidesDBError.new("Database is closed"))
end

local result = lib.tidesdb_checkpoint(self._db, dir)
check_result(result, "failed to create checkpoint")
end

function TidesDB:register_comparator(name, fn, ctx_str, ctx)
if self._closed then
error(TidesDBError.new("Database is closed"))
Expand Down Expand Up @@ -1032,6 +1042,6 @@ function tidesdb.save_config_to_ini(ini_file, section_name, config)
end

-- Version
tidesdb._VERSION = "0.5.0"
tidesdb._VERSION = "0.5.1"

return tidesdb
48 changes: 48 additions & 0 deletions tests/test_tidesdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,54 @@ function tests.test_backup()
print("PASS: test_backup")
end

function tests.test_checkpoint()
local path = "./test_db_checkpoint"
local checkpoint_path = "./test_db_checkpoint_snap"
cleanup_db(path)
cleanup_db(checkpoint_path)

local db = tidesdb.TidesDB.open(path)
db:create_column_family("test_cf")
local cf = db:get_column_family("test_cf")

-- Insert data
local txn = db:begin_txn()
txn:put(cf, "key1", "value1")
txn:put(cf, "key2", "value2")
txn:commit()
txn:free()

-- Create checkpoint
db:checkpoint(checkpoint_path)

db:close()

-- Open checkpoint and verify data
local cp_db = tidesdb.TidesDB.open(checkpoint_path)
local cp_cf = cp_db:get_column_family("test_cf")
local read_txn = cp_db:begin_txn()
local v1 = read_txn:get(cp_cf, "key1")
local v2 = read_txn:get(cp_cf, "key2")
assert_eq(v1, "value1", "checkpoint should contain key1")
assert_eq(v2, "value2", "checkpoint should contain key2")
read_txn:free()

-- Verify checkpoint to existing non-empty dir fails
cp_db:close()

local db2 = tidesdb.TidesDB.open(path)
local cf2 = db2:get_column_family("test_cf")

local err = assert_error(function()
db2:checkpoint(checkpoint_path)
end, "checkpoint to non-empty dir should fail")

db2:close()
cleanup_db(path)
cleanup_db(checkpoint_path)
print("PASS: test_checkpoint")
end

function tests.test_update_runtime_config()
local path = "./test_db_runtime_config"
cleanup_db(path)
Expand Down
4 changes: 2 additions & 2 deletions tidesdb-0.5.0-1.rockspec → tidesdb-0.5.1-1.rockspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package = "tidesdb"
version = "0.5.0-1"
version = "0.5.1-1"
source = {
url = "git://github.com/tidesdb/tidesdb-lua.git",
tag = "v0.5.0"
tag = "v0.5.1"
}
description = {
summary = "Official Lua bindings for TidesDB - A high-performance embedded key-value storage engine",
Expand Down
Loading