Retry earlier checkpoints after host replay changes
This commit is contained in:
1 parent
d4e78bc29a
commit
09cd19594c
3 files changed
+247
-61
No files matched your search
@@ -3,7 +3,11 @@ use super::checkpoint_probe::{Call, RecordingHost};
|
||||
use super::*;
|
||||
#[cfg(test)]
|
||||
use std::{collections::BTreeMap, fs};
|
||||
use std::{collections::BTreeSet, ffi::OsString, path::Path};
|
||||
use std::{
|
||||
collections::{BTreeSet, VecDeque},
|
||||
ffi::OsString,
|
||||
path::Path,
|
||||
};
|
||||
use texrra_tex_core::{
|
||||
execution::EntryCheckpoint,
|
||||
resources::{ResourceKind, ResourceLookup},
|
||||
@@ -378,75 +382,94 @@ impl PublishedCheckpoints {
|
||||
.chain(self.previous_body.iter().flat_map(|body| body.candidates()))
|
||||
.collect();
|
||||
candidates.sort_by_key(|candidate| std::cmp::Reverse(candidate.completed_steps()));
|
||||
let mut candidates = candidates.into_iter();
|
||||
let mut rejection = None;
|
||||
let first = candidates
|
||||
.by_ref()
|
||||
.find(|candidate| {
|
||||
let checkpoint = &candidate.set.entries[candidate.index];
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify_project(request))
|
||||
{
|
||||
Ok(_) => true,
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
CompileError::Host(
|
||||
rejection.unwrap_or_else(|| "no entry checkpoint retained".into()),
|
||||
)
|
||||
})?;
|
||||
|
||||
// Host preparation observes the actual generated files while the job
|
||||
// lock is held. Choose a valid prefix before replaying any effects.
|
||||
let mut selected = None;
|
||||
let mut prepared = prepare_checked(
|
||||
request,
|
||||
false,
|
||||
Some(cache),
|
||||
cancellation,
|
||||
evidence,
|
||||
Some(Box::new(|world, preparation| {
|
||||
let mut rejection = None;
|
||||
for candidate in std::iter::once(first).chain(candidates) {
|
||||
let mut candidates = VecDeque::from(candidates);
|
||||
let mut guard_rejection = None;
|
||||
let mut replay_rejection = None;
|
||||
'retry: loop {
|
||||
check(cancellation)?;
|
||||
let first = std::iter::from_fn(|| candidates.pop_front())
|
||||
.find(|candidate| {
|
||||
let checkpoint = &candidate.set.entries[candidate.index];
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify(request, world, preparation))
|
||||
.and_then(|()| checkpoint.guard.verify_project(request))
|
||||
{
|
||||
Ok(()) => {
|
||||
selected = Some(candidate);
|
||||
return Ok(());
|
||||
}
|
||||
Ok(_) => true,
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
guard_rejection.get_or_insert(error);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
replay_rejection
|
||||
.take()
|
||||
.or_else(|| guard_rejection.take().map(CompileError::Host))
|
||||
.unwrap_or_else(|| CompileError::Host("no entry checkpoint retained".into()))
|
||||
})?;
|
||||
|
||||
// Each replay owns a separate draft and observes the generated
|
||||
// initial state under the job lock before writing any effects.
|
||||
let mut selected = None;
|
||||
let mut attempt = AttemptEvidence::new(evidence.revision);
|
||||
attempt.phase = evidence.phase;
|
||||
let mut prepared = prepare_checked(
|
||||
request,
|
||||
false,
|
||||
Some(cache),
|
||||
cancellation,
|
||||
&mut attempt,
|
||||
Some(Box::new(|world, preparation| {
|
||||
let mut rejection = None;
|
||||
let remaining = std::iter::from_fn(|| candidates.pop_front());
|
||||
for candidate in std::iter::once(first).chain(remaining) {
|
||||
let checkpoint = &candidate.set.entries[candidate.index];
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify(request, world, preparation))
|
||||
{
|
||||
Ok(()) => {
|
||||
selected = Some(candidate);
|
||||
return Ok(());
|
||||
}
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(rejection.unwrap_or_else(|| "no entry checkpoint retained".into()))
|
||||
})),
|
||||
EffectMode::Draft,
|
||||
KernelPreparation::Resume,
|
||||
)?;
|
||||
let selected = selected.expect("resume preparation chose a verified checkpoint");
|
||||
let checkpoint = &selected.set.entries[selected.index];
|
||||
for (index, call) in selected.set.calls[..checkpoint.replay_count].iter().enumerate() {
|
||||
check(cancellation)?;
|
||||
if let Err(error) = call(&mut prepared.files) {
|
||||
replay_rejection.get_or_insert(CompileError::Host(error));
|
||||
// Other checkpoints sharing this call cannot use the
|
||||
// invalidated prefix either. Drop the draft on retry.
|
||||
candidates.retain(|candidate| {
|
||||
!Arc::ptr_eq(&candidate.set, &selected.set)
|
||||
|| candidate.set.entries[candidate.index].replay_count <= index
|
||||
});
|
||||
continue 'retry;
|
||||
}
|
||||
Err(rejection.unwrap_or_else(|| "no entry checkpoint retained".into()))
|
||||
})),
|
||||
EffectMode::Draft,
|
||||
KernelPreparation::Resume,
|
||||
)?;
|
||||
let selected = selected.expect("resume preparation chose a verified checkpoint");
|
||||
let checkpoint = &selected.set.entries[selected.index];
|
||||
for call in &selected.set.calls[..checkpoint.replay_count] {
|
||||
check(cancellation)?;
|
||||
call(&mut prepared.files)?;
|
||||
}
|
||||
if !checkpoint
|
||||
.guard
|
||||
.project
|
||||
.immutable_paths()
|
||||
.eq(project.immutable_paths())
|
||||
&& let Err(error) = checkpoint.guard.verify_replayed_lookups(&prepared.files)
|
||||
{
|
||||
replay_rejection.get_or_insert(error);
|
||||
continue;
|
||||
}
|
||||
*evidence = attempt;
|
||||
return Ok((selected, prepared));
|
||||
}
|
||||
if !checkpoint
|
||||
.guard
|
||||
.project
|
||||
.immutable_paths()
|
||||
.eq(project.immutable_paths())
|
||||
{
|
||||
checkpoint.guard.verify_replayed_lookups(&prepared.files)?;
|
||||
}
|
||||
Ok((selected, prepared))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user