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>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-29 09:56:45 +00:00
parent a582d733ea
commit 9fbeacdeb9
2 changed files with 13 additions and 4 deletions

View File

@@ -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] = {}

View File

@@ -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: