Reconcile byte-identical historical offers without allowing another execution
This commit is contained in:
@@ -24,7 +24,6 @@ pub fn accept(
|
|||||||
&& hex_hash(&offer.plan_hash),
|
&& hex_hash(&offer.plan_hash),
|
||||||
"OFFER_BINDING"
|
"OFFER_BINDING"
|
||||||
);
|
);
|
||||||
ensure!(supported(&job), "UNSUPPORTED_CAPABILITY");
|
|
||||||
let bytes = offer.encode_to_vec();
|
let bytes = offer.encode_to_vec();
|
||||||
let existing: Option<Vec<u8>> = db
|
let existing: Option<Vec<u8>> = db
|
||||||
.query_row(
|
.query_row(
|
||||||
@@ -37,6 +36,9 @@ pub fn accept(
|
|||||||
ensure!(old == bytes, "OFFER_CONFLICT");
|
ensure!(old == bytes, "OFFER_CONFLICT");
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
// An identical journal receipt is evidence of a previous delivery. Current
|
||||||
|
// executable capabilities apply to newly accepted offers.
|
||||||
|
ensure!(supported(&job), "UNSUPPORTED_CAPABILITY");
|
||||||
let count: i64 = db.query_row("SELECT count(*) FROM job_attempts", [], |r| r.get(0))?;
|
let count: i64 = db.query_row("SELECT count(*) FROM job_attempts", [], |r| r.get(0))?;
|
||||||
ensure!(count < 10000, "JOURNAL_CAPACITY_NEW_EFFECTS_BLOCKED");
|
ensure!(count < 10000, "JOURNAL_CAPACITY_NEW_EFFECTS_BLOCKED");
|
||||||
db.execute(
|
db.execute(
|
||||||
|
|||||||
@@ -326,6 +326,40 @@ fn consumed_attempt_and_unknown_lock_survive_reopen_without_reexecution() {
|
|||||||
std::fs::remove_file(path).unwrap();
|
std::fs::remove_file(path).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn retired_reboot_redelivery_preserves_the_original_attempt_and_enrollment() {
|
||||||
|
let (binding, request, permit, _) = fixture();
|
||||||
|
let mut old = binding.job(&request.job_bytes).unwrap();
|
||||||
|
old.action = Action::Reboot {
|
||||||
|
reason: "historical reboot".into(),
|
||||||
|
reconnect_timeout_seconds: 60,
|
||||||
|
dependency_group: "test".into(),
|
||||||
|
};
|
||||||
|
old.execution_identity = "root".into();
|
||||||
|
let payload = encode(&old).unwrap();
|
||||||
|
let offer = JobOffer {
|
||||||
|
job_id: old.job_id.to_string(),
|
||||||
|
attempt_id: old.attempt_id.to_string(),
|
||||||
|
job_payload_hash: hash(&payload),
|
||||||
|
payload_bytes: payload,
|
||||||
|
plan_hash: permit.plan_hash,
|
||||||
|
authorization_id: permit.authorization_id.to_string(),
|
||||||
|
};
|
||||||
|
let db = Connection::open_in_memory().unwrap();
|
||||||
|
db.execute_batch("CREATE TABLE job_attempts(job TEXT,attempt TEXT,offer BLOB,state TEXT,PRIMARY KEY(job,attempt))").unwrap();
|
||||||
|
assert!(jobs::accept(&db, &binding, &offer, |_| false).is_err());
|
||||||
|
assert!(jobs::accept(&db, &binding, &offer, |_| true).unwrap());
|
||||||
|
db.execute("UPDATE job_attempts SET state='unknown'", []).unwrap();
|
||||||
|
assert!(!jobs::accept(&db, &binding, &offer, |_| panic!("historical delivery invoked the execution probe")).unwrap());
|
||||||
|
let mut altered = offer.clone();
|
||||||
|
altered.authorization_id = Uuid::new_v4().to_string();
|
||||||
|
assert!(jobs::accept(&db, &binding, &altered, |_| false).is_err());
|
||||||
|
let mut other = binding;
|
||||||
|
other.enrollment_generation += 1;
|
||||||
|
assert!(jobs::accept(&db, &other, &offer, |_| true).is_err());
|
||||||
|
assert_eq!(db.query_row("SELECT count(*) FROM job_attempts WHERE state='unknown'", [], |r| r.get::<_,u32>(0)).unwrap(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn portable_acceptance_requires_platform_capability_and_exact_redelivery() {
|
fn portable_acceptance_requires_platform_capability_and_exact_redelivery() {
|
||||||
let (binding, request, permit, _) = fixture();
|
let (binding, request, permit, _) = fixture();
|
||||||
|
|||||||
@@ -776,7 +776,8 @@ impl<C: reconcile::SyncClock> Agent<C> {
|
|||||||
let job = self.binding.as_ref().context("binding")?.job(&offer.payload_bytes)?;
|
let job = self.binding.as_ref().context("binding")?.job(&offer.payload_bytes)?;
|
||||||
if Utc::now() >= job.start_before {
|
if Utc::now() >= job.start_before {
|
||||||
self.record(generation, &offer, "", jobs::no_start("expired", "START_DEADLINE_EXPIRED"))?;
|
self.record(generation, &offer, "", jobs::no_start("expired", "START_DEADLINE_EXPIRED"))?;
|
||||||
} else if !matches!(job.action,rmm_domain::jobs::Action::RunScript{..}) {
|
} else if !matches!(job.action,rmm_domain::jobs::Action::RunScript{..})
|
||||||
|
|| (job.execution_identity=="root" && !job.action.full_maintenance()) {
|
||||||
self.record(generation, &offer, "", jobs::no_start("failed","LEGACY_ACTION_RETIRED"))?;
|
self.record(generation, &offer, "", jobs::no_start("failed","LEGACY_ACTION_RETIRED"))?;
|
||||||
} else if !self.ready(generation,job.execution_identity=="root") {
|
} else if !self.ready(generation,job.execution_identity=="root") {
|
||||||
needs_sync=true;
|
needs_sync=true;
|
||||||
|
|||||||
Reference in New Issue
Block a user