Skip to content

Commit

Permalink
Drop implementation for Tracker (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
antiguru authored Jun 10, 2023
1 parent b4bce96 commit b990fab
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
11 changes: 11 additions & 0 deletions timely/src/progress/frontier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,17 @@ impl<T> MutableAntichain<T> {
.map(|td| td.1)
.sum()
}

/// Reports the updates that form the frontier. Returns an iterator of timestamps and their frequency.
///
/// Rebuilds the internal representation before revealing times and frequencies.
pub fn updates(&mut self) -> impl Iterator<Item=&(T, i64)>
where
T: Clone + PartialOrder + Ord,
{
self.rebuild();
self.updates.iter()
}
}

impl<T> Default for MutableAntichain<T> {
Expand Down
46 changes: 45 additions & 1 deletion timely/src/progress/reachability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,4 +897,48 @@ pub mod logging {
impl From<TargetUpdate> for TrackerEvent {
fn from(v: TargetUpdate) -> TrackerEvent { TrackerEvent::TargetUpdate(v) }
}
}
}

// The Drop implementation for `Tracker` makes sure that reachability logging is correct for
// prematurely dropped dataflows. At the moment, this is only possible through `drop_dataflow`,
// because in all other cases the tracker stays alive while it has outstanding work, leaving no
// remaining work for this Drop implementation.
impl<T: Timestamp> Drop for Tracker<T> {
fn drop(&mut self) {
let logger = if let Some(logger) = &mut self.logger {
logger
} else {
// No cleanup necessary when there is no logger.
return;
};

// Retract pending data that `propagate_all` would normally log.
for (index, per_operator) in self.per_operator.iter_mut().enumerate() {
let target_changes = per_operator.targets
.iter_mut()
.enumerate()
.flat_map(|(port, target)| {
target.pointstamps
.updates()
.map(move |(time, diff)| (index, port, time.clone(), -diff))
})
.collect::<Vec<_>>();
if !target_changes.is_empty() {
logger.log_target_updates(Box::new(target_changes));
}

let source_changes = per_operator.sources
.iter_mut()
.enumerate()
.flat_map(|(port, source)| {
source.pointstamps
.updates()
.map(move |(time, diff)| (index, port, time.clone(), -diff))
})
.collect::<Vec<_>>();
if !source_changes.is_empty() {
logger.log_source_updates(Box::new(source_changes));
}
}
}
}

0 comments on commit b990fab

Please sign in to comment.