[HiCache] Clear kvcache in storage backend with fastAPI (#9750)
Co-authored-by: hzh0425 <hzh0425@apache.org>
This commit is contained in:
@@ -102,6 +102,20 @@ class HiCacheStorage(ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete(self, key: str) -> bool:
|
||||
"""
|
||||
Delete the entry associated with the given key.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def clear(self) -> bool:
|
||||
"""
|
||||
Clear all entries in the storage.
|
||||
"""
|
||||
pass
|
||||
|
||||
def batch_exists(self, keys: List[str]) -> int:
|
||||
"""
|
||||
Check if the keys exist in the storage.
|
||||
@@ -214,12 +228,14 @@ class HiCacheFile(HiCacheStorage):
|
||||
logger.warning(f"Key {key} does not exist. Cannot delete.")
|
||||
return
|
||||
|
||||
def clear(self) -> None:
|
||||
def clear(self) -> bool:
|
||||
try:
|
||||
for filename in os.listdir(self.file_path):
|
||||
file_path = os.path.join(self.file_path, filename)
|
||||
if os.path.isfile(file_path):
|
||||
os.remove(file_path)
|
||||
logger.info("Cleared all entries in HiCacheFile storage.")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to clear HiCacheFile storage: {e}")
|
||||
return False
|
||||
|
||||
@@ -125,6 +125,15 @@ class HiRadixCache(RadixCache):
|
||||
height += 1
|
||||
return height
|
||||
|
||||
def clear_storage_backend(self):
|
||||
if self.enable_storage:
|
||||
self.cache_controller.storage_backend.clear()
|
||||
logger.info("Hierarchical cache storage backend cleared successfully!")
|
||||
return True
|
||||
else:
|
||||
logger.warning("Hierarchical cache storage backend is not enabled.")
|
||||
return False
|
||||
|
||||
def write_backup(self, node: TreeNode, write_back=False):
|
||||
host_indices = self.cache_controller.write(
|
||||
device_indices=node.value,
|
||||
|
||||
@@ -393,8 +393,14 @@ class HiCacheHF3FS(HiCacheStorage):
|
||||
|
||||
return len(keys)
|
||||
|
||||
def clear(self) -> None:
|
||||
self.metadata_client.clear(self.rank)
|
||||
def clear(self) -> bool:
|
||||
try:
|
||||
self.metadata_client.clear(self.rank)
|
||||
logger.info(f"Cleared HiCacheHF3FS for rank {self.rank}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to clear HiCacheHF3FS: {e}")
|
||||
return False
|
||||
|
||||
def close(self) -> None:
|
||||
try:
|
||||
|
||||
@@ -254,7 +254,7 @@ class MooncakeStore(HiCacheStorage):
|
||||
pass
|
||||
|
||||
def clear(self) -> None:
|
||||
raise (NotImplementedError)
|
||||
self.store.remove_all()
|
||||
|
||||
def _put_batch_zero_copy_impl(
|
||||
self, key_strs: List[str], buffer_ptrs: List[int], buffer_sizes: List[int]
|
||||
|
||||
Reference in New Issue
Block a user