Browse Source

Fix: Include version history in memory estimate for proper eviction

Fszontagh 5 months ago
parent
commit
c4ce6bd950
1 changed files with 11 additions and 1 deletions
  1. 11 1
      service/src/memory_store.cpp

+ 11 - 1
service/src/memory_store.cpp

@@ -889,14 +889,24 @@ MemoryStore::Stats MemoryStore::getStats() const {
 
     Stats stats = stats_;
 
-    // Calculate estimated memory
+    // Calculate estimated memory (documents + version history)
     std::shared_lock<std::shared_mutex> globalLock(globalMutex_);
     stats.estimatedMemoryBytes = 0;
     for (const auto& [name, coll] : collections_) {
         std::shared_lock<std::shared_mutex> collLock(coll->mutex);
+
+        // Count document memory
         for (const auto& [id, doc] : coll->documents) {
             stats.estimatedMemoryBytes += estimateDocumentSize(doc);
         }
+
+        // Count version history memory
+        for (const auto& [docId, history] : coll->versionHistory) {
+            for (const auto& ver : history) {
+                // Estimate version entry size: data + metadata
+                stats.estimatedMemoryBytes += ver.data.dump().size() + 256;
+            }
+        }
     }
 
     return stats;