From ab3fb4153b08aff986543072d77034d4b35bab43 Mon Sep 17 00:00:00 2001 From: mukesh-2096 Date: Mon, 23 Feb 2026 16:38:11 +0530 Subject: [PATCH 1/2] Add max_memory_usage field to tidesdb_config_t --- src/tidesdb.lua | 4 ++++ test_max_memory.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test_max_memory.lua diff --git a/src/tidesdb.lua b/src/tidesdb.lua index 2678b2c..8a0dd46 100644 --- a/src/tidesdb.lua +++ b/src/tidesdb.lua @@ -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 { @@ -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 @@ -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) @@ -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 diff --git a/test_max_memory.lua b/test_max_memory.lua new file mode 100644 index 0000000..ce497f5 --- /dev/null +++ b/test_max_memory.lua @@ -0,0 +1,53 @@ +--[[ +Test script to verify max_memory_usage field addition to tidesdb_config_t +This tests that the new field can be set and the database opens successfully. +]] + +local tidesdb = require("tidesdb") + +print("=== Testing max_memory_usage field ===\n") + +-- Test 1: Default config includes max_memory_usage +print("Test 1: Checking default_config()...") +local default_cfg = tidesdb.default_config() +assert(default_cfg.max_memory_usage ~= nil, "max_memory_usage should exist in default config") +print("✓ max_memory_usage found in default config: " .. tostring(default_cfg.max_memory_usage)) + +-- Test 2: Open database with default max_memory_usage (0 = unlimited) +print("\nTest 2: Opening database with default max_memory_usage...") +local path1 = "./test_db_max_mem_default" +os.execute("rm -rf " .. path1) +local db1 = tidesdb.TidesDB.open(path1) +print("✓ Database opened successfully with default max_memory_usage") +db1:close() +os.execute("rm -rf " .. path1) + +-- Test 3: Open database with custom max_memory_usage +print("\nTest 3: Opening database with custom max_memory_usage...") +local path2 = "./test_db_max_mem_custom" +os.execute("rm -rf " .. path2) +local db2 = tidesdb.TidesDB.open(path2, { + max_memory_usage = 512 * 1024 * 1024 -- 512 MB +}) +print("✓ Database opened successfully with max_memory_usage = 512 MB") +db2:close() +os.execute("rm -rf " .. path2) + +-- Test 4: Test with TidesDB.new() constructor +print("\nTest 4: Testing with TidesDB.new() constructor...") +local path3 = "./test_db_max_mem_new" +os.execute("rm -rf " .. path3) +local config = { + db_path = path3, + num_flush_threads = 2, + num_compaction_threads = 2, + max_memory_usage = 256 * 1024 * 1024 -- 256 MB +} +local db3 = tidesdb.TidesDB.new(config) +print("✓ Database created with TidesDB.new() with max_memory_usage = 256 MB") +db3:close() +os.execute("rm -rf " .. path3) + +print("\n=== All tests passed! ===") +print("\nThe max_memory_usage field has been successfully added to tidesdb_config_t.") +print("You can now configure memory limits when opening a TidesDB database.") From c8a52a081571683169147c59a360697aa7224298 Mon Sep 17 00:00:00 2001 From: mukesh-2096 Date: Mon, 23 Feb 2026 16:51:21 +0530 Subject: [PATCH 2/2] Move max_memory tests --- test_max_memory.lua | 53 ------------------------------------------ tests/test_tidesdb.lua | 37 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 53 deletions(-) delete mode 100644 test_max_memory.lua diff --git a/test_max_memory.lua b/test_max_memory.lua deleted file mode 100644 index ce497f5..0000000 --- a/test_max_memory.lua +++ /dev/null @@ -1,53 +0,0 @@ ---[[ -Test script to verify max_memory_usage field addition to tidesdb_config_t -This tests that the new field can be set and the database opens successfully. -]] - -local tidesdb = require("tidesdb") - -print("=== Testing max_memory_usage field ===\n") - --- Test 1: Default config includes max_memory_usage -print("Test 1: Checking default_config()...") -local default_cfg = tidesdb.default_config() -assert(default_cfg.max_memory_usage ~= nil, "max_memory_usage should exist in default config") -print("✓ max_memory_usage found in default config: " .. tostring(default_cfg.max_memory_usage)) - --- Test 2: Open database with default max_memory_usage (0 = unlimited) -print("\nTest 2: Opening database with default max_memory_usage...") -local path1 = "./test_db_max_mem_default" -os.execute("rm -rf " .. path1) -local db1 = tidesdb.TidesDB.open(path1) -print("✓ Database opened successfully with default max_memory_usage") -db1:close() -os.execute("rm -rf " .. path1) - --- Test 3: Open database with custom max_memory_usage -print("\nTest 3: Opening database with custom max_memory_usage...") -local path2 = "./test_db_max_mem_custom" -os.execute("rm -rf " .. path2) -local db2 = tidesdb.TidesDB.open(path2, { - max_memory_usage = 512 * 1024 * 1024 -- 512 MB -}) -print("✓ Database opened successfully with max_memory_usage = 512 MB") -db2:close() -os.execute("rm -rf " .. path2) - --- Test 4: Test with TidesDB.new() constructor -print("\nTest 4: Testing with TidesDB.new() constructor...") -local path3 = "./test_db_max_mem_new" -os.execute("rm -rf " .. path3) -local config = { - db_path = path3, - num_flush_threads = 2, - num_compaction_threads = 2, - max_memory_usage = 256 * 1024 * 1024 -- 256 MB -} -local db3 = tidesdb.TidesDB.new(config) -print("✓ Database created with TidesDB.new() with max_memory_usage = 256 MB") -db3:close() -os.execute("rm -rf " .. path3) - -print("\n=== All tests passed! ===") -print("\nThe max_memory_usage field has been successfully added to tidesdb_config_t.") -print("You can now configure memory limits when opening a TidesDB database.") diff --git a/tests/test_tidesdb.lua b/tests/test_tidesdb.lua index 6473374..6be9be5 100644 --- a/tests/test_tidesdb.lua +++ b/tests/test_tidesdb.lua @@ -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...")