[Feat] hicache: Notify storage backends when the initial host-pool registration burst completes (#44030)
Co-authored-by: Zhangheng <hzh0425@apache.org>
This commit is contained in:
@@ -530,6 +530,10 @@ class HiCacheController:
|
||||
)
|
||||
raise RuntimeError("Failed to stop HiCache storage threads cleanly.")
|
||||
|
||||
# A subclass whose attach continues registering host pools after super()
|
||||
# returns fires on_host_pools_registered() itself, once.
|
||||
_registers_host_pools_after_super_attach = False
|
||||
|
||||
def attach_storage_backend(
|
||||
self,
|
||||
storage_backend: str,
|
||||
@@ -578,6 +582,8 @@ class HiCacheController:
|
||||
storage_backend, self.storage_config, self.storage_host_pool
|
||||
)
|
||||
self.storage_backend.register_mem_pool_host(self.storage_host_pool)
|
||||
if not self._registers_host_pools_after_super_attach:
|
||||
self.storage_backend.on_host_pools_registered()
|
||||
|
||||
self.enable_storage = True
|
||||
# todo: threshold policy for prefetching
|
||||
|
||||
@@ -188,6 +188,16 @@ class HiCacheStorage(ABC):
|
||||
self.registered_pools = {}
|
||||
self.registered_pools[host_pool_name] = host_pool
|
||||
|
||||
def on_host_pools_registered(self) -> None:
|
||||
"""The initial host-pool registration burst is over: the anchor pool
|
||||
(``register_mem_pool_host``) and every host pool group entry
|
||||
(``register_mem_host_pool_v2``). Fires once per attach; pools
|
||||
registered later (dynamic sidecars) arrive through v2 alone and do
|
||||
not re-fire it. Backends that must finalize once the pool set is
|
||||
known -- e.g. register with a remote cache manager whose spec cannot
|
||||
be amended -- should do so here; raising fails the attach.
|
||||
"""
|
||||
|
||||
def batch_exists_v2(
|
||||
self,
|
||||
keys: List[str],
|
||||
|
||||
@@ -297,6 +297,10 @@ class HybridCacheController(BaseHiCacheController):
|
||||
"""Only opt in backends whose FULL object is the complete shared page."""
|
||||
return storage_backend is None or storage_backend == "mori"
|
||||
|
||||
# The per-pool v2 burst runs after super() returns; on_host_pools_registered()
|
||||
# fires at its end, so the base class leaves the firing to us.
|
||||
_registers_host_pools_after_super_attach = True
|
||||
|
||||
def attach_storage_backend(
|
||||
self,
|
||||
storage_backend: str,
|
||||
@@ -343,6 +347,7 @@ class HybridCacheController(BaseHiCacheController):
|
||||
|
||||
for entry in host_pools or []:
|
||||
self.storage_backend.register_mem_host_pool_v2(entry.host_pool, entry.name)
|
||||
self.storage_backend.on_host_pools_registered()
|
||||
|
||||
def detach_storage_backend(self):
|
||||
super().detach_storage_backend()
|
||||
|
||||
@@ -1122,6 +1122,9 @@ def test_controller_tensorcast_factory_and_host_pool_group_use_v1_anchor(
|
||||
def register_mem_pool_host(self, pool: HostKVCache) -> None:
|
||||
self.registered.append(pool)
|
||||
|
||||
def on_host_pools_registered(self) -> None:
|
||||
pass
|
||||
|
||||
backend = FakeStorageBackend()
|
||||
|
||||
def create_backend(
|
||||
|
||||
Reference in New Issue
Block a user