pub struct LateDataRetractionGenerator { /* private fields */ }Expand description
Generates retractions for late data corrections.
When late data arrives and updates an already-emitted window result, this generator produces:
- A retraction (-1 weight) for the old result
- An insert (+1 weight) for the new result
§Example
use laminar_core::operator::changelog::LateDataRetractionGenerator;
use laminar_core::operator::window::WindowId;
let mut gen = LateDataRetractionGenerator::new(true);
let window_id = WindowId::new(0, 60000);
// First emission - no retraction needed
let result1 = gen.check_retraction(&window_id, b"count=5", 1000);
assert!(result1.is_none());
// Late data changes result - generates retraction
let result2 = gen.check_retraction(&window_id, b"count=7", 2000);
assert!(result2.is_some());
let (old, new) = result2.unwrap();
assert_eq!(old.as_slice(), b"count=5");
assert_eq!(new.as_slice(), b"count=7");
// Same result - no retraction
let result3 = gen.check_retraction(&window_id, b"count=7", 3000);
assert!(result3.is_none());Implementations§
Source§impl LateDataRetractionGenerator
impl LateDataRetractionGenerator
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true if retraction generation is enabled.
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Enables or disables retraction generation.
Sourcepub fn check_retraction(
&mut self,
window_id: &WindowId,
new_data: &[u8],
timestamp: i64,
) -> Option<(Vec<u8>, Vec<u8>)>
pub fn check_retraction( &mut self, window_id: &WindowId, new_data: &[u8], timestamp: i64, ) -> Option<(Vec<u8>, Vec<u8>)>
Checks if we need to generate a retraction for this window.
Returns Some((old_data, new_data)) if the window was previously
emitted with different data. Returns None if this is the first
emission or the data hasn’t changed.
Sourcepub fn check_retraction_ref(
&mut self,
window_id: &WindowId,
new_data: &[u8],
timestamp: i64,
) -> Option<Vec<u8>>
pub fn check_retraction_ref( &mut self, window_id: &WindowId, new_data: &[u8], timestamp: i64, ) -> Option<Vec<u8>>
Checks for retraction and returns borrowed slices (avoiding allocation when no retraction is needed).
Returns Some(old_data) if retraction is needed. The caller should
then emit the retraction for old_data and insert for new_data.
Sourcepub fn cleanup_window(&mut self, window_id: &WindowId)
pub fn cleanup_window(&mut self, window_id: &WindowId)
Cleans up state for closed windows.
Call this when a window is closed to prevent unbounded memory growth.
Sourcepub fn cleanup_before_watermark(&mut self, watermark: i64)
pub fn cleanup_before_watermark(&mut self, watermark: i64)
Cleans up state for windows that ended before the given watermark.
This should be called periodically to bound memory usage.
Sourcepub fn retractions_generated(&self) -> u64
pub fn retractions_generated(&self) -> u64
Returns the number of retractions generated.
Sourcepub fn windows_tracked(&self) -> usize
pub fn windows_tracked(&self) -> usize
Returns the number of windows currently being tracked.
Sourcepub fn reset_metrics(&mut self)
pub fn reset_metrics(&mut self)
Resets all metrics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LateDataRetractionGenerator
impl RefUnwindSafe for LateDataRetractionGenerator
impl Send for LateDataRetractionGenerator
impl Sync for LateDataRetractionGenerator
impl Unpin for LateDataRetractionGenerator
impl UnsafeUnpin for LateDataRetractionGenerator
impl UnwindSafe for LateDataRetractionGenerator
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more