Skip to content
Closed
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
53 changes: 53 additions & 0 deletions test_max_memory.lua
Original file line number Diff line number Diff line change
@@ -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.")
Loading