Skip to content

test(loadproof): require an outage write the kept slot must carry - #620

Open
Kiran01bm wants to merge 1 commit into
mainfrom
kiran01bm/pd114-outage-writes-below-frontier
Open

Kiran01bm wants to merge 1 commit into
mainfrom
kiran01bm/pd114-outage-writes-below-frontier

Conversation

@Kiran01bm

Copy link
Copy Markdown
Collaborator

The kill proof now makes and requires at least one write during the outage that only the kept replication slot can carry.

Why

The kill proof kills pg-sprite in the middle of a copy, keeps writing to the table while it is down, then resumes and checks that the result matches. It is meant to show that the replication slot pg-sprite keeps across the crash carries those outage writes. But a write to a row the copy has not reached yet is picked up by the resumed copy itself, so if every outage write landed there, the proof passed without the slot carrying anything.

What

  • After the mid-copy kill, the harness reads the saved watermark (WatermarkAtKill) and updates one existing row and deletes another at or below it, so the slot must carry them; the load's own random writes continue as before.
  • It counts outage writes, the harness's and the load's, at or below the watermark and fails the proof when there are none (checkOutageWritesAtOrBelow, a pure function with its own unit test). The count is recorded as outage_writes_at_or_below_watermark.
  • The existing old-vs-live row comparison covers the harness's writes: if the slot missed the delete, the live table would still hold the row.
  • A kill before the copy's first save has no watermark; the check is skipped there, as the proof already asserts less for that case.
  • docs/testing.md: the kill proof section, its "a pass proves" list and the record fields.

make load-proof-kill passes at 20,000 rows: run 1 was killed in copying at watermark 1012, and 9 outage writes landed at or below it.

Before / after

The same kill, at watermark 1012 of a 20,000-row table. Before, the proof could pass with every outage write above 1012, where the resumed copy carries it; after, at least one write at or below 1012 is required, and only the slot can carry that one.

run 1 killed in copying, saved watermark = 1012 (rows 1..1012 already in the shadow)

Before
  outage writes:  id 4410 update, id 15002 delete, ...      all above 1012
  rerun:          copy resumes from 1012, re-reads 4410 and 15002 → carried by the copy
  slot carried:   nothing that mattered               proof still passes

After
  harness writes: id 1011 update, id 1012 delete             at or below 1012
  load writes:    id 4410 update, id 15002 delete, ...
  rerun:          copy resumes above 1012 → only the slot can carry 1011 and 1012
  check:          outage_writes_at_or_below_watermark = 2+  (0 fails the proof)
  row oracle:     live row 1012 gone, row 1011 updated → slot carried them

After the mid-copy kill, writes made during the outage could all land
above the copy's saved watermark, where the resumed copy carries them, so
the claim that the kept slot carries outage writes went unchecked.
@Kiran01bm
Kiran01bm marked this pull request as ready for review November 29, 2026 21:33
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-29T21:33:58.592030Z
We couldn’t complete this review. Comment @codex review to try again.
f281c08 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@aparajon

Copy link
Copy Markdown
Collaborator

🤖 Review 1/2 (correctness) of f281c08: 0 blocking, 3 non-blocking.

Inspected the whole change at f281c08c13b0014c22beee44575984f6ba21f078: the new check and the harness write (kill_outage_test.go#L29-L40, #L47-L81), its wiring in killAndRerun (kill_test.go#L305, #L336-L362), the two doc passages, and the code the assertion leans on: the load's Touches bookkeeping, the row oracle's exclusions (oracle_test.go#L26-L56), checkResumedFrom, and the sibling library proof. The change is test-only: no production code moves.

The question I asked first is whether the new assertion can pass vacuously. It cannot do so in a way that matters. The claim it adds is sound against the repo's own rule: a resumed copy deletes every shadow row above the saved watermark and copies the table above it again, so a write above the watermark reaches the new table without the slot, and only a write at or below it needs the kept slot (CO-4, docs/invariants.md#L215-L220 for the owed clear and #L231-L234 for where it is enforced). The old harness left that to chance, since the load's random keys can all land above a watermark that stands low in the key space. Now the harness picks the two highest keys at or below the save after the dead binary's backends have left and the row has been read, updates one and deletes the next, and counts a key only when RowsAffected() was 1. The delete is the case CO-4 names, a deletion below the watermark (docs/invariants.md#L196-L199). The load's Touches are appended only after a write commits and returns, under the lock (workload.go#L394-L398), and atKill is read after the dead process has been reaped, so a counted load write committed with no binary running. The row oracle compares every key it does not exclude, not only the keys the load named, so the harness's own keys are judged by it at the end. The kill after verifying is left alone, which is right, since the whole copy is already in the shadow and every outage write then needs the slot.

Invariants (docs/invariants.md): this extends the evidence for CO-4 (the resume clause) and ST-4 (#L1435-L1440, a crash that leaves the slot intact resumes clean). No entry changes and no *Enforced:* line moves.

Non-blocking

  1. writeAtOrBelow and the wiring around it have no test that runs here, so most of the PR's production-of-evidence logic is unpinned. The unit test covers only the predicate (kill_outage_test.go#L86). Nothing checks that the query picks the two highest keys at or below the frontier, that the statement pairing (statements[i], #L61-L72) updates the first and deletes the second, or that RowsAffected filters. A change that selects id > $1 makes the harness write only above the save, and the check then passes on the load's writes alone, which is the original gap again. The package already has a testcontainer-backed test for the row oracle (oracle_integration_test.go#L32-L38), so a short one fits beside it.
Test case (not run here): needs a PostgreSQL container, which this review does not start
func TestWriteAtOrBelowUpdatesTheHighestKeyAndDeletesTheNext(t *testing.T) {
	dsn := testutil.StartPostgres(t)
	pool, err := pgxpool.New(t.Context(), dsn)
	require.NoError(t, err)
	t.Cleanup(pool.Close)
	table := testutil.NewWorkloadTable(t, pool)
	require.NoError(t, table.SeedRows(t.Context(), 10))

	written, err := writeAtOrBelow(t.Context(), pool, table, 6)
	require.NoError(t, err)
	assert.Equal(t, []int64{6, 5}, written)

	var label string
	require.NoError(t, pool.QueryRow(t.Context(), `SELECT label FROM `+table.Qualified()+` WHERE id = 6`).Scan(&label))
	assert.Equal(t, "row-6o", label)
	var present int
	require.NoError(t, pool.QueryRow(t.Context(), `SELECT count(*) FROM `+table.Qualified()+` WHERE id IN (4, 5, 7, 10)`).Scan(&present))
	assert.Equal(t, 3, present, "key 5 is deleted; keys 4, 7 and 10 are untouched")
}

Written against the seeding in NewWorkloadTable and SeedRows (ids 1 to 10, label row-<id>); not run.

  1. The library proof keeps the unproven claim this PR corrects for the kill proof. TestLoadProofLibrary waits for the load to commit a few writes while no call runs (library_test.go#L216) and its guide text says the stopped interval "always holds writes that only the kept slot can carry" (docs/testing.md#L397-L402, and the comment at library_resume_test.go#L100-L104). The same random-key argument applies: all of those writes can land above the first call's saved watermark. Reusing writeAtOrBelow and checkOutageWritesAtOrBelow after the first cancelled call would close it; if that is deliberately left for another PR, the library section's "always" is now contradicted by the kill section's own explanation a few lines below it.

  2. The final row oracle judges the harness's keys only while it does not exclude them, and the doc states the guarantee without that condition. The new bullet says the row oracle "then holds the new table to it" (docs/testing.md#L514-L518). excludedKeys leaves out every key the load wrote above the swap's WAL position and every ambiguous key (oracle_test.go#L26-L37). A harness key the load later touches after the swap drops out of the comparison, and nothing records the harness's keys, so the proof cannot say whether it was held. The odds are small (two keys out of the table, and the load keeps writing only briefly after the swap), which is why this is latent rather than blocking, but the keys are already in hand in harnessWrote: carry them to the end and assert they are not in the excluded set, or log them with the result.

Verified

  • Ran only anchored unit tests with a timeout, after confirming the package has no TestMain and no init, and that this test calls only the pure predicate: -run '^TestCheckOutageWritesAtOrBelowRequiresOneWriteTheSlotMustCarry$' passes at f281c08 (about 1 s). go vet ./integration/loadproof is clean. I did not run any load proof, integration or container test, and none of the wiring in killAndRerun.
  • Mutation table (each change alone, the one unit test run, then git checkout):
Mutant Caught by
M1 checkOutageWritesAtOrBelow counts key < frontier the "one write at the frontier" subtest (--- FAIL at kill_outage_test.go:100)
M2 the error fires on len(keys) == 0 instead of n == 0 the "every write above the frontier" subtest (--- FAIL at kill_outage_test.go:90)
M3 writeAtOrBelow selects id > $1, so the harness writes only above the save would survive every unit test; analyzed by reading, not run (finding 1)
M4 frontier never set, so the check is skipped would survive every unit test; analyzed by reading, not run
M5 Touches[atKill.Touched:] replaced by the whole list, counting pre-kill writes would survive every unit test; analyzed by reading, not run
  • The check is satisfied by the harness's own writes whenever they land, so in practice it guards against writeAtOrBelow doing nothing (no row at or below the save, or both rows gone); the load's Touches matter only then. That is the intended shape, but it is why finding 1's test is the one that carries the weight.
  • gofmt and the compile are clean; no go:build tag or database use in the new file, so it runs in the plain go test ./... pass.

This review was generated by Claude Code (claude-sonnet-5-5).

@aparajon

Copy link
Copy Markdown
Collaborator

🤖 Review 2/2 (OSS adoption and integration) of f281c08: 0 blocking, 3 non-blocking.

Read the change from two seats: an importer who wants the same proof for their own host (SchemaBot is the obvious one, driving migrate.Run in process), and an operator or contributor who meets only the guide, the results-kill.json record and a red run. The change is test-only, so nothing in the library surface moves.

Non-blocking

  1. A copy killed before its first save skips the new check, and the green run does not say so. The guide is honest about it ("A copy killed before its first save has no watermark, and this is not asserted", docs/testing.md#L514-L518), and the code takes the skip when WatermarkAtKill is nil (kill_test.go#L336-L347). But the record field is omitempty (kill_test.go#L95-L100), so a skipped run and a run that never reached the code look the same in results-kill.json, and the test log says nothing. The existing resumed_from_save: false marks the analogous skip, and the guide points readers at it; saying the same here (an absent outage_writes_at_or_below_watermark beside an absent watermark_at_kill is the skip), or one t.Logf line when the check is skipped, lets an operator who ran at a smoke size read the result without guessing which proof they got.

  2. Two sentences read awkwardly, and one of them is the field's only definition in the guide. In the record paragraph the new clause is spliced into a list: "the writes the load committed before the next run, after the copy kill how many writes in that interval landed at or below its save (outage_writes_at_or_below_watermark), and, for the last run, the verdict's outcome and code" (docs/testing.md#L537-L541). Splitting it into its own sentence ("After the copy kill it also records how many writes in that interval landed at or below the save (outage_writes_at_or_below_watermark).") reads cleanly. The code comment has the same trouble: "a write above the save the resumed copy carries by itself" (kill_test.go#L251-L252) wants "since the resumed copy carries a write above the save by itself".

  3. The old sentence that the new text corrects is still on the page for the library proof. The kill section now explains why the stopped interval did not always hold a write the slot must carry, while the library section a few paragraphs above still says it "always" does (docs/testing.md#L397-L402). A contributor reading top to bottom meets the claim and then its retraction (see review 1/2, finding 2, for the code side). Either fix the library proof the same way or soften that sentence now.

What reads well for adopters

  • The guide explains the reason before the mechanism: only a write at or below the watermark needs the slot, the load's random keys can all land above it, so the harness writes there itself. That is the paragraph an importer needs to build the same proof for their own resume test, and it states the rule once rather than leaving the reader to infer it from the code.
  • The pure predicate sits in its own file with a unit test that needs no database and no build tag; I ran it (about 1 s), so a contributor with no container runtime still gets a signal on the boundary (a write at the frontier counts) in plain go test ./....
  • The failure message names what went wrong in the operator's words ("no write while the binary was down landed at or below the killed copy's saved watermark: 3 writes, all above key 2002"), including the count and the frontier, so a red run needs no log dive to read.
  • The new record field is named for what it counts and where, parallel to watermark_at_kill and committed_while_stopped, and the guide says the row oracle then holds the new table to those writes.

This review was generated by Claude Code (claude-sonnet-5-5).

@aparajon aparajon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Stamping with comments: 0 blocking, 6 non-blocking (see the review comments above).

This stamp was left by Claude Code (claude-sonnet-5-5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants