Carry verified suffix checkpoints into later native edits
This commit is contained in:
1 parent
1cf985469c
commit
c42a1a72aa
5 files changed
+208
-28
No files matched your search
@@ -153,6 +153,84 @@ impl EntryCheckpoint {
|
||||
accounts_event_history: completed.accounts_event_history,
|
||||
})
|
||||
}
|
||||
/// Carry later checkpoints from the suffix accepted by
|
||||
/// splice_settled_suffix into this revision. The host must still replay
|
||||
/// each prefix and verify the resulting I/O boundary before keeping it.
|
||||
pub fn prepare_suffix_rebase<'a>(
|
||||
&'a self,
|
||||
prior: &'a Self,
|
||||
) -> impl Fn(&Self) -> Option<Self> + 'a {
|
||||
// Keep the old allocation for an unchanged event. Later snapshots
|
||||
// can still refer to it even when the live run rebuilt that event.
|
||||
let mut prefix = prior.executor.events.clone();
|
||||
let mut current = self.executor.events.iter();
|
||||
for chunk in &mut prefix.prefix {
|
||||
let changes: Vec<_> = chunk.iter().zip(current.by_ref()).enumerate()
|
||||
.filter(|(_, (old, new))| !std::ptr::eq(*old, *new) && old != new)
|
||||
.map(|(index, (_, new))| (index, new.clone()))
|
||||
.collect();
|
||||
if !changes.is_empty() {
|
||||
let events = Arc::make_mut(chunk);
|
||||
for (index, event) in changes {
|
||||
events[index] = event;
|
||||
}
|
||||
}
|
||||
}
|
||||
move |later| self.rebase_verified_suffix(prior, later, &prefix)
|
||||
}
|
||||
|
||||
fn rebase_verified_suffix(
|
||||
&self,
|
||||
prior: &Self,
|
||||
later: &Self,
|
||||
prefix: &ExecutionEvents,
|
||||
) -> Option<Self> {
|
||||
let old = &prior.executor;
|
||||
let next = &later.executor;
|
||||
let current = &self.executor;
|
||||
if later.entry != self.entry
|
||||
|| later.active_source != self.entry
|
||||
|| later.frontier < self.frontier
|
||||
|| later.completed_steps() <= self.completed_steps()
|
||||
|| later.incoming_state != self.incoming_state
|
||||
|| next.reads_event_history
|
||||
|| !Arc::ptr_eq(&next.sources[later.entry], &old.sources[prior.entry])
|
||||
|| old.events.prefix.len() > next.events.prefix.len()
|
||||
|| !old.events.prefix.iter().zip(&next.events.prefix).all(|(a, b)| Arc::ptr_eq(a, b))
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut executor = next.clone();
|
||||
let mut events = prefix.clone();
|
||||
// Checkpoint capture seals the event log. Share the old suffix
|
||||
// chunks so all carried checkpoints keep the same allocation graph.
|
||||
events.prefix.extend_from_slice(&next.events.prefix[old.events.prefix.len()..]);
|
||||
events.prefix_len += next.events.prefix_len - old.events.prefix_len;
|
||||
executor.events = events;
|
||||
executor.sources[self.entry] = current.sources[self.entry].clone();
|
||||
let InputFrame::Source { source, mouth, .. } = executor.inputs.first_mut()? else {
|
||||
return None;
|
||||
};
|
||||
if *source != self.entry || !mouth.rebind_after_convergence(self.source_mouth(self.entry)) {
|
||||
return None;
|
||||
}
|
||||
// A later edit can turn on tracing or force a capacity recount.
|
||||
// Keep a live checkpoint only if the merged history preserves
|
||||
// the sharing relationships needed by either accounting path.
|
||||
if !executor.equivalent_accounting_history(next) {
|
||||
return None;
|
||||
}
|
||||
Some(Self {
|
||||
executor,
|
||||
entry: later.entry,
|
||||
active_source: later.active_source,
|
||||
initial_depth: later.initial_depth,
|
||||
incoming_state: later.incoming_state,
|
||||
frontier: later.frontier,
|
||||
pages_processed: later.pages_processed,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn same_kernel_continuation(current: &Executor, prior: &Executor) -> bool {
|
||||
|
||||
@@ -350,6 +350,15 @@ impl Mouth {
|
||||
debug_assert!(self.matches_loaded_prefix(&data));
|
||||
self.data = Arc::new(data);
|
||||
}
|
||||
pub(super) fn rebind_after_convergence(&mut self, current: &Self) -> bool {
|
||||
if self.offset < current.offset
|
||||
|| self.data.get(current.offset..) != current.data.get(current.offset..)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
self.data = current.data.clone();
|
||||
true
|
||||
}
|
||||
pub(super) fn payload_bytes(&self) -> usize {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user