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

Function compact_deduplicates_by_key

nodedb/src/event/cdc/compaction.rs:124–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

122
123 #[test]
124 fn compact_deduplicates_by_key() {
125 let buf = StreamBuffer::new(
126 "test".into(),
127 RetentionConfig {
128 max_events: 1000,
129 max_age_secs: 3600,
130 },
131 );
132
133 // Three updates to the same key "alice"
134 buf.push(make_event(1, "alice", "INSERT"));
135 buf.push(make_event(2, "alice", "UPDATE"));
136 buf.push(make_event(3, "alice", "UPDATE"));
137 // One event for key "bob"
138 buf.push(make_event(4, "bob", "INSERT"));
139
140 assert_eq!(buf.len(), 4);
141
142 let removed = buf.compact("id", 86_400);
143 assert_eq!(removed, 2); // Two older "alice" events removed.
144 assert_eq!(buf.len(), 2); // Latest "alice" + "bob" remain.
145
146 let events = buf.read_from_lsn(0, 10);
147 // Latest alice (seq 3) and bob (seq 4) remain.
148 assert_eq!(events.len(), 2);
149 }
150
151 #[test]
152 fn compact_retains_tombstones_within_grace_period() {

Callers

nothing calls this directly

Calls 4

read_from_lsnMethod · 0.80
make_eventFunction · 0.70
pushMethod · 0.45
compactMethod · 0.45

Tested by

no test coverage detected