Skip to content

Commit a7db1f3

Browse files
authored
Merge pull request #41 from tidesdb/updates22
align column family config with new name field
2 parents d9cef36 + 5965adc commit a7db1f3

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "tidesdb"
7-
version = "0.9.1"
7+
version = "0.9.2"
88
description = "Official Python bindings for TidesDB - A high-performance embedded key-value storage engine"
99
readme = "README.md"
1010
requires-python = ">=3.10"

src/tidesdb/tidesdb.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def _load_library() -> ctypes.CDLL:
7979

8080
TDB_MAX_COMPARATOR_NAME = 64
8181
TDB_MAX_COMPARATOR_CTX = 256
82+
TDB_MAX_CF_NAME_LEN = 128
8283

8384
TDB_SUCCESS = 0
8485
TDB_ERR_MEMORY = -1
@@ -172,6 +173,7 @@ class _CColumnFamilyConfig(Structure):
172173
"""C structure for tidesdb_column_family_config_t."""
173174

174175
_fields_ = [
176+
("name", c_char * TDB_MAX_CF_NAME_LEN),
175177
("write_buffer_size", c_size_t),
176178
("level_size_ratio", c_size_t),
177179
("min_levels", c_int),
@@ -446,9 +448,15 @@ class ColumnFamilyConfig:
446448
l0_queue_stall_threshold: int = 20
447449
use_btree: bool = False
448450

449-
def _to_c_struct(self) -> _CColumnFamilyConfig:
451+
def _to_c_struct(self, name: str = "") -> _CColumnFamilyConfig:
450452
"""Convert to C structure."""
451453
c_config = _CColumnFamilyConfig()
454+
455+
# Set the name field
456+
cf_name_bytes = name.encode("utf-8")[:TDB_MAX_CF_NAME_LEN - 1]
457+
cf_name_bytes = cf_name_bytes + b"\x00" * (TDB_MAX_CF_NAME_LEN - len(cf_name_bytes))
458+
c_config.name = cf_name_bytes
459+
452460
c_config.write_buffer_size = self.write_buffer_size
453461
c_config.level_size_ratio = self.level_size_ratio
454462
c_config.min_levels = self.min_levels
@@ -554,7 +562,7 @@ def save_config_to_ini(file_path: str, cf_name: str, config: ColumnFamilyConfig)
554562
cf_name: Name of the column family (used as section name)
555563
config: Configuration to save
556564
"""
557-
c_config = config._to_c_struct()
565+
c_config = config._to_c_struct(cf_name)
558566
result = _lib.tidesdb_cf_config_save_to_ini(
559567
file_path.encode("utf-8"), cf_name.encode("utf-8"), ctypes.byref(c_config)
560568
)
@@ -727,7 +735,7 @@ def update_runtime_config(self, config: ColumnFamilyConfig, persist_to_disk: boo
727735
config: New configuration settings
728736
persist_to_disk: If True, save changes to config.ini
729737
"""
730-
c_config = config._to_c_struct()
738+
c_config = config._to_c_struct(self.name)
731739
result = _lib.tidesdb_cf_update_runtime_config(
732740
self._cf, ctypes.byref(c_config), 1 if persist_to_disk else 0
733741
)
@@ -1128,7 +1136,7 @@ def create_column_family(
11281136
if config is None:
11291137
config = default_column_family_config()
11301138

1131-
c_config = config._to_c_struct()
1139+
c_config = config._to_c_struct(name)
11321140

11331141
result = _lib.tidesdb_create_column_family(
11341142
self._db, name.encode("utf-8"), ctypes.byref(c_config)

0 commit comments

Comments
 (0)