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

Method on_memtable_flushed

nodedb-columnar/src/mutation/flush.rs:19–55  ·  view source on GitHub ↗

Notify the engine that the memtable was flushed to a new segment. Updates the PK index to remap memtable entries to the new segment. Returns the WAL record for the flush event, or `SegmentIdExhausted` if the u64 segment ID counter has wrapped past its maximum.

(
        &mut self,
        new_segment_id: u64,
    )

Source from the content-addressed store, hash-verified

17 /// Returns the WAL record for the flush event, or `SegmentIdExhausted`
18 /// if the u64 segment ID counter has wrapped past its maximum.
19 pub fn on_memtable_flushed(
20 &mut self,
21 new_segment_id: u64,
22 ) -> Result<MutationResult, ColumnarError> {
23 let row_count = self.memtable_row_counter;
24
25 // Remap PK index entries from virtual memtable segment to real segment.
26 self.pk_index
27 .remap_segment(self.memtable_segment_id, |old_row| {
28 Some(RowLocation {
29 segment_id: new_segment_id,
30 row_index: old_row,
31 })
32 });
33
34 // Advance the segment ID counter with overflow protection.
35 let next = self
36 .next_segment_id
37 .checked_add(1)
38 .ok_or(ColumnarError::SegmentIdExhausted)?;
39
40 // Reset memtable tracking.
41 self.memtable_segment_id = self.next_segment_id;
42 self.next_segment_id = next;
43 self.memtable_row_counter = 0;
44 self.memtable_surrogates.clear();
45
46 let wal = ColumnarWalRecord::MemtableFlushed {
47 collection: self.collection.clone(),
48 segment_id: new_segment_id,
49 row_count: row_count as u64,
50 };
51
52 Ok(MutationResult {
53 wal_records: vec![wal],
54 })
55 }
56
57 /// Notify the engine that compaction completed.
58 ///

Calls 3

remap_segmentMethod · 0.80
clearMethod · 0.45
cloneMethod · 0.45