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,
)
| 77 | /// with all events currently in the stream's buffer. Without backfill, |
| 78 | /// new MVs start empty and only aggregate future events. |
| 79 | pub 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. |
| 103 | fn update_mv(event: &CdcEvent, mv_state: &MvState) { |
no test coverage detected