feat: Remove immediate persistence in delete operation

- Enhance delete implementation in JsonKVStorage by removing immediate persistence in delete operation
- Update documentation for drop method to clarify persistence behavior
- Add abstract delete method to BaseKVStorage
This commit is contained in:
yangdx
2025-03-31 14:14:32 +08:00
parent bbc770d1ed
commit 81f887ebab
2 changed files with 31 additions and 1 deletions

View File

@@ -123,6 +123,7 @@ class StorageNameSpace(ABC):
3. Reset the storage to its initial state
4. Handle cleanup of any resources
5. Notify other processes if necessary
6. This action should persistent the data to disk immediately.
Returns:
dict[str, str]: Operation status and message with the following format:
@@ -207,6 +208,22 @@ class BaseKVStorage(StorageNameSpace, ABC):
async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
"""Upsert data"""
@abstractmethod
async def delete(self, ids: list[str]) -> None:
"""Delete specific records from storage by their IDs
This method will:
1. Remove the specified records from in-memory storage
2. For in-memory DB, update flags to notify other processes that data persistence is needed
3. For in-memory DB, changes will be persisted to disk during the next index_done_callback
Args:
ids (list[str]): List of document IDs to be deleted from storage
Returns:
None
"""
@dataclass
class BaseGraphStorage(StorageNameSpace, ABC):

View File

@@ -122,14 +122,27 @@ class JsonKVStorage(BaseKVStorage):
await set_all_update_flags(self.namespace)
async def delete(self, ids: list[str]) -> None:
"""Delete specific records from storage by their IDs
This method will:
1. Remove the specified records from in-memory storage
2. Update flags to notify other processes that data persistence is needed
3. The changes will be persisted to disk during the next index_done_callback
Args:
ids (list[str]): List of document IDs to be deleted from storage
Returns:
None
"""
async with self._storage_lock:
for doc_id in ids:
self._data.pop(doc_id, None)
await set_all_update_flags(self.namespace)
await self.index_done_callback()
async def drop(self) -> dict[str, str]:
"""Drop all data from storage and clean up resources
This action will persistent the data to disk immediately.
This method will:
1. Clear all data from memory