Skip to content

Commit f8106b8

Browse files
committed
Fix dynamic NIXL filename safety and persist path edge case
1 parent 6ce2705 commit f8106b8

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

lmcache/v1/distributed/internal_api.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,3 @@ class EvictionAction:
160160
"""The key of the object to be evicted"""
161161

162162

163-
@dataclass(frozen=True)
164-
class PersistDesc:
165-
"""
166-
Descriptor for persist/recover operations on L2 adapters.
167-
"""
168-
169-
disk_persist_path: str
170-
""" Path on disk where adapter metadata should be persisted/recovered """

lmcache/v1/distributed/l2_adapters/nixl_store_dynamic_l2_adapter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
logger = init_logger(__name__)
4949

50+
_PATH_SLASH_REPLACEMENT = "-SEP-"
51+
5052

5153
# ---------------------------------------------------------------
5254
# ObjectKey <-> file path helpers
@@ -56,15 +58,16 @@
5658
def _object_key_to_filename(key: ObjectKey) -> str:
5759
"""Derive a deterministic file name from an ObjectKey."""
5860
chunk_hex = key.chunk_hash.hex()
59-
return f"{key.model_name}_{key.kv_rank:08x}_{chunk_hex}.bin"
61+
safe_model_name = key.model_name.replace("/", _PATH_SLASH_REPLACEMENT)
62+
return f"{safe_model_name}_{key.kv_rank:08x}_{chunk_hex}.bin"
6063

6164

6265
def _filename_to_object_key(filename: str) -> ObjectKey:
6366
"""Reverse a filename produced by ``_object_key_to_filename``."""
6467
stem = filename.removesuffix(".bin")
6568
# Split from the right: last part is chunk_hash, second-last is kv_rank
6669
parts = stem.rsplit("_", 2)
67-
model_name = parts[0]
70+
model_name = parts[0].replace(_PATH_SLASH_REPLACEMENT, "/")
6871
kv_rank = int(parts[1], 16)
6972
chunk_hash = bytes.fromhex(parts[2])
7073
return ObjectKey(chunk_hash=chunk_hash, model_name=model_name, kv_rank=kv_rank)
@@ -453,7 +456,9 @@ def persist(self, config: PersistConfig) -> bool:
453456
}
454457
entries.append(entry)
455458

456-
os.makedirs(os.path.dirname(config.persist_path), exist_ok=True)
459+
persist_dir = os.path.dirname(config.persist_path)
460+
if persist_dir:
461+
os.makedirs(persist_dir, exist_ok=True)
457462
with open(config.persist_path, "w") as f:
458463
json.dump(entries, f)
459464

0 commit comments

Comments
 (0)