From 9fbeacdeb954a7d743c1fec6a49226ff94373b57 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 09:56:45 +0000 Subject: [PATCH] Add documentation and improve error handling - Add comment about index_store being in-memory (future migration consideration) - Improve exception handling in cas_put to log unexpected errors - Add detailed docstring to count() method noting performance considerations Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- backend/app.py | 3 +++ backend/rocksdb_store.py | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/app.py b/backend/app.py index eb37999..5bcb82a 100644 --- a/backend/app.py +++ b/backend/app.py @@ -52,6 +52,9 @@ ROCKSDB_DIR.mkdir(parents=True, exist_ok=True) # RocksDB KV store (replaces in-memory dict) kv_store = RocksDBStore(str(ROCKSDB_DIR)) + +# Index store - currently in-memory, could be migrated to RocksDB in the future +# for full persistence and consistency across restarts index_store: Dict[str, list] = {} diff --git a/backend/rocksdb_store.py b/backend/rocksdb_store.py index 5fd4a38..23b1779 100644 --- a/backend/rocksdb_store.py +++ b/backend/rocksdb_store.py @@ -105,8 +105,11 @@ class RocksDBStore: value_bytes = self.db.get(key.encode('utf-8')) if value_bytes is not None: return False - except Exception: - pass + except KeyError: + pass # Key doesn't exist + except Exception as e: + # Log unexpected errors but continue with put operation + print(f"Warning: Error checking key existence in cas_put: {e}") # Use internal put to avoid double-counting self.put(key, value, _internal=True) @@ -160,9 +163,12 @@ class RocksDBStore: Returns: Number of keys + + Note: + This method iterates through all keys, which can be expensive for large + datasets. In production, consider maintaining separate counters updated + during put/delete operations for better performance. """ - # For accurate counts, we need to iterate - # In production, consider maintaining separate counters count = 0 if prefix: