MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / insert

Method insert

nodedb/src/engine/timeseries/recent_cache.rs:75–103  ·  view source on GitHub ↗

Insert decompressed partition data into the cache.

(&mut self, tenant_id: u64, collection: &str, partition: CachedPartition)

Source from the content-addressed store, hash-verified

73
74 /// Insert decompressed partition data into the cache.
75 pub fn insert(&mut self, tenant_id: u64, collection: &str, partition: CachedPartition) {
76 let key = (tenant_id, collection.to_string(), partition.min_ts);
77 let size = partition.memory_bytes;
78
79 if size > self.max_bytes {
80 return;
81 }
82
83 // Remove existing entry for this key.
84 if let Some(old) = self.entries.remove(&key) {
85 self.current_bytes -= old.memory_bytes;
86 self.order.retain(|k| k != &key);
87 }
88
89 // Evict until room.
90 while self.current_bytes + size > self.max_bytes {
91 if let Some(evict_key) = self.order.pop_front() {
92 if let Some(evicted) = self.entries.remove(&evict_key) {
93 self.current_bytes -= evicted.memory_bytes;
94 }
95 } else {
96 break;
97 }
98 }
99
100 self.current_bytes += size;
101 self.order.push_back(key.clone());
102 self.entries.insert(key, partition);
103 }
104
105 /// Evict partitions that are no longer in the hot window.
106 pub fn evict_cold(&mut self, now_ms: i64) {

Callers 5

basic_insert_and_getFunction · 0.45
tenant_isolationFunction · 0.45
evict_coldFunction · 0.45
evict_tenantFunction · 0.45
lru_evictionFunction · 0.45

Calls 4

to_stringMethod · 0.80
pop_frontMethod · 0.80
removeMethod · 0.45
cloneMethod · 0.45

Tested by 5

basic_insert_and_getFunction · 0.36
tenant_isolationFunction · 0.36
evict_coldFunction · 0.36
evict_tenantFunction · 0.36
lru_evictionFunction · 0.36