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

Function backfill_from_buffer

nodedb/src/event/streaming_mv/processor.rs:79–100  ·  view source on GitHub ↗

Backfill a streaming MV from the source stream's retention buffer. Called on `CREATE MATERIALIZED VIEW ... STREAMING` to bootstrap the MV with all events currently in the stream's buffer. Without backfill, new MVs start empty and only aggregate future events.

(
    mv_state: &MvState,
    buffer: &crate::event::cdc::buffer::StreamBuffer,
)

Source from the content-addressed store, hash-verified

77/// with all events currently in the stream's buffer. Without backfill,
78/// new MVs start empty and only aggregate future events.
79pub fn backfill_from_buffer(
80 mv_state: &MvState,
81 buffer: &crate::event::cdc::buffer::StreamBuffer,
82) -> u64 {
83 let events = buffer.read_from_lsn(0, usize::MAX);
84 let mut processed = 0u64;
85
86 for event in &events {
87 update_mv(event, mv_state);
88 processed += 1;
89 }
90
91 if processed > 0 {
92 tracing::info!(
93 mv = %mv_state.name,
94 events = processed,
95 "streaming MV backfilled from buffer"
96 );
97 }
98
99 processed
100}
101
102/// Update a single MV's state from a CdcEvent.
103fn update_mv(event: &CdcEvent, mv_state: &MvState) {

Callers 1

create_streaming_mvFunction · 0.85

Calls 2

update_mvFunction · 0.85
read_from_lsnMethod · 0.80

Tested by

no test coverage detected