Validate and fix memory tracking inconsistencies
(&self)
| 585 | |
| 586 | /// Validate and fix memory tracking inconsistencies |
| 587 | pub fn validate_memory_tracking(&self) -> bool { |
| 588 | let entries = self.entries.read(); |
| 589 | let stats = self.stats.read(); |
| 590 | |
| 591 | // Calculate actual size by summing all entries |
| 592 | let actual_size: usize = entries.values().map(|entry| entry.size_bytes).sum(); |
| 593 | let actual_count = entries.len(); |
| 594 | |
| 595 | // Check for inconsistencies |
| 596 | let size_mismatch = actual_size != stats.total_size_bytes; |
| 597 | let count_mismatch = actual_count != stats.total_entries; |
| 598 | |
| 599 | if size_mismatch || count_mismatch { |
| 600 | debug!("Memory tracking inconsistency detected - Size: actual={}, tracked={}, Count: actual={}, tracked={}", |
| 601 | actual_size, stats.total_size_bytes, actual_count, stats.total_entries); |
| 602 | |
| 603 | drop(stats); |
| 604 | drop(entries); |
| 605 | |
| 606 | // Fix inconsistencies |
| 607 | let mut stats = self.stats.write(); |
| 608 | stats.total_size_bytes = actual_size; |
| 609 | stats.total_entries = actual_count; |
| 610 | |
| 611 | return false; // Found inconsistencies |
| 612 | } |
| 613 | |
| 614 | true // No inconsistencies found |
| 615 | } |
| 616 | |
| 617 | /// Extend TTL for a specific key |
| 618 | pub fn extend_ttl(&self, key: &K, additional_ttl: Duration) -> bool { |