Skip to content
24 changes: 22 additions & 2 deletions lmcache/v1/storage_backend/maru_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def _create_handler(
# Convert maru:// scheme to tcp:// for ZMQ
server_url = config.maru_path
if server_url.startswith("maru://"):
server_url = "tcp://" + server_url[len("maru://"):]
server_url = "tcp://" + server_url[len("maru://") :]

extra = config.extra_config or {}
maru_config = MaruConfig(
maru_kwargs = dict(
server_url=server_url,
instance_id=extra.get("maru_instance_id"),
pool_size=self._parse_pool_size(config.maru_pool_size),
Expand All @@ -150,6 +150,26 @@ def _create_handler(
max_inflight=extra.get("maru_max_inflight", 64),
eager_map=extra.get("maru_eager_map", True),
)
pool_id = extra.get("maru_pool_id")
if pool_id is not None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit] Empty list / empty string edge cases.

  • maru_pool_id: []isinstance(pool_id, list) is true → maru_kwargs["pool_id"] = []
  • maru_pool_id: "" → falls to else: int("")ValueError
  • maru_pool_id: ","split(",")["", ""]int("")ValueError

Empty values could be treated the same as None (i.e. skip and let maru_resourced decide).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9897fce. Empty values now treated as None (skip):

  • []if pool_id: guard, skips
  • ""if stripped: guard, skips
  • ","if p.strip() filter in list comprehension, produces empty → skips

All result in maru_resourced deciding the pool.

try:
if isinstance(pool_id, list):
if pool_id:
maru_kwargs["pool_id"] = [int(p) for p in pool_id]
elif isinstance(pool_id, str):
stripped = pool_id.strip()
if stripped:
if "," in stripped:
maru_kwargs["pool_id"] = [
int(p.strip()) for p in stripped.split(",") if p.strip()
]
else:
maru_kwargs["pool_id"] = int(stripped)
else:
maru_kwargs["pool_id"] = int(pool_id)
except (ValueError, TypeError) as e:
raise ValueError(f"Invalid maru_pool_id={pool_id!r}: {e}") from e
maru_config = MaruConfig(**maru_kwargs)

handler = MaruHandler(maru_config)
if not handler.connect():
Expand Down
Loading