Skip to content
Merged

#39 #41

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
4 changes: 4 additions & 0 deletions src/tidesdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ffi.cdef[[
size_t max_open_sstables;
int log_to_file;
size_t log_truncation_at;
size_t max_memory_usage;
} tidesdb_config_t;

typedef struct {
Expand Down Expand Up @@ -361,6 +362,7 @@ function tidesdb.default_config()
max_open_sstables = 256,
log_to_file = false,
log_truncation_at = 24 * 1024 * 1024,
max_memory_usage = 0,
}
end

Expand Down Expand Up @@ -848,6 +850,7 @@ function TidesDB.new(config)
c_config.max_open_sstables = config.max_open_sstables or 256
c_config.log_to_file = config.log_to_file and 1 or 0
c_config.log_truncation_at = config.log_truncation_at or 24 * 1024 * 1024
c_config.max_memory_usage = config.max_memory_usage or 0

local db_ptr = ffi.new("void*[1]")
local result = lib.tidesdb_open(c_config, db_ptr)
Expand All @@ -868,6 +871,7 @@ function TidesDB.open(path, options)
max_open_sstables = options.max_open_sstables or 256,
log_to_file = options.log_to_file or false,
log_truncation_at = options.log_truncation_at or 24 * 1024 * 1024,
max_memory_usage = options.max_memory_usage or 0,
}
return TidesDB.new(config)
end
Expand Down
37 changes: 37 additions & 0 deletions tests/test_tidesdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,43 @@ function tests.test_commit_hook()
print("PASS: test_commit_hook")
end

function tests.test_max_memory_usage()
local path = "./test_db_max_mem"
cleanup_db(path)

-- Test default config includes max_memory_usage
local default_cfg = tidesdb.default_config()
assert_true(default_cfg.max_memory_usage ~= nil, "max_memory_usage should exist in default config")

-- Test opening database with default max_memory_usage (0 = unlimited)
local db1 = tidesdb.TidesDB.open(path)
assert_true(db1 ~= nil, "database should open with default max_memory_usage")
db1:close()
cleanup_db(path)

-- Test opening database with custom max_memory_usage
local db2 = tidesdb.TidesDB.open(path, {
max_memory_usage = 512 * 1024 * 1024 -- 512 MB
})
assert_true(db2 ~= nil, "database should open with custom max_memory_usage")
db2:close()
cleanup_db(path)

-- Test with TidesDB.new() constructor
local config = {
db_path = path,
num_flush_threads = 2,
num_compaction_threads = 2,
max_memory_usage = 256 * 1024 * 1024 -- 256 MB
}
local db3 = tidesdb.TidesDB.new(config)
assert_true(db3 ~= nil, "database should be created with TidesDB.new() and max_memory_usage")
db3:close()

cleanup_db(path)
print("PASS: test_max_memory_usage")
end

-- Run all tests
local function run_tests()
print("Running TidesDB Lua tests...")
Expand Down
Loading