Repository navigation
fix(oracle): repeat the lease predicates at the ExpireLeases lock level - #42
Conversation
|
review-gate: passed a921d31 Reviewer: independent Open findings, with the reason each stays:
|
|
|
|
Closes the open medium from the gate: the skill and the spec header no longer pin the branch-only SHA |
The sweep picks lapsed leases in a ROWNUM subquery and locks them in an outer SELECT ... FOR UPDATE SKIP LOCKED. Oracle skips a row that changed after the statement snapshot only when the change touches a column that the locking level reads. Until now only the outer ORDER BY lease_expiry kept the sweep off a row that an outcome or heartbeat wrote after the snapshot. Repeat state = Leased and lease_expiry <= :now in the outer WHERE, as the claim does, so the guard no longer rests on the ORDER BY.
The Oracle sweep now repeats state = 2 AND lease_expiry <= :now in the outer WHERE of its SKIP LOCKED select, so LockLevelCols for the sweep holds attempt, state, and lease_expiry. Add the ExpireNoOuterWhere mutant. Removing the outer WHERE or the outer ORDER BY alone now passes, because each reads lease_expiry. Removing both breaks ExpireOnce. Move the sync commit to 7716d9e and update the shifted Oracle citations.
3579cb3 to
8d8ef3d
Compare
|
verify: PASS+NOTES 8d8ef3d Base: main f958b77 (merge base). Patch-id: 95df42ea8b3d7084d09e3649969862a6552e98d9 (matches).
Notes (not blocking):
|
Why
The Oracle
ExpireLeasessweep picks lapsed leases in aROWNUMsubquery and locks them in an outerSELECT ... FOR UPDATE SKIP LOCKED. Oracle skips a row that changed after the statement snapshot only when the change touches a column that the locking level reads. Today only the outerORDER BY lease_expirykeeps the sweep off a row that an outcome or heartbeat wrote after the snapshot. Without it, the sweep writes aSucceededjob back toScheduledand the job runs again. Nothing documented or tested that theORDER BYcarries this load.Today's code is safe on Oracle 21 and 23 because of the
ORDER BY(probe casenoorder, measured on both). This PR is hardening, not a fix to a live bug. It was stacked on #39, which has merged, so it now targetsmain.What changed
OracleJobStore.ExpireLeasesUntracedAsyncrepeatsstate = {(int)JobState.Leased} AND lease_expiry <= :nowin the outerWHERE, the same way the Oracle claim repeats its predicates. The comment above the sweep says why.LeaseFencing.tla: the sweep'sLockLevelColsnow holdsattempt,state, andlease_expiry. A newExpireNoOuterWheremutant gates the outerWHERE.expire-no-outer-order-oraclenow passes as a redundant guard. The newexpire-no-outer-where-oracle(the old code) passes too. The newexpire-no-outer-where-and-order-oracledrops both and breaksExpireOnce.OracleJobStore.cs:1471.Scope
Product code: one predicate and two comment lines in the Oracle sweep. Postgres and SQL Server are unchanged.
Tradeoffs
7716d9e, the code commit of this branch. A squash merge rewrites it, so the landing step must move the sync commit to the main SHA that carries the outerWHERE. Keepingad5b0abwould be wrong, because the model no longer describes it.outerwheremeasures that a column read only in the outerWHEREmakes SKIP LOCKED skip the row.Blast Radius
Every Oracle
ExpireLeasescall. The outer predicates only drop rows that the subquery picked from a stale snapshot. Statement count is unchanged, and the round-trip budget tests pass. The query plan was not inspected.Verification
tests/formal/lease-fencing/check.sh: every config as expected (table in a comment below).gvenzl/oracle-free:23-slim, private container: 355 passed, 0 failed,OracleConformanceTestsandOracleRoundTripBudgetTestsincluded.dotnet build: 0 warnings, 0 errors.