Skip to content

fix(control): let a publisher lose the race for a report another one removed - #95

Open
mrgoonie wants to merge 2 commits into
mainfrom
fix/report-publish-race
Open

mrgoonie wants to merge 2 commits into
mainfrom
fix/report-publish-race

Conversation

@mrgoonie

Copy link
Copy Markdown
Contributor

Closes #78.

What was wrong

On PostgreSQL at read committed, two publishers sharing the store could both read a report. The one that lost the race found the document already removed: its versioned DeleteKV removed nothing and answered NOT_FOUND, which the publisher treated as a failure. SQLite serializes transactions, so it never showed.

Fix

  • internal/control/report_store.go: deleteRead turns a NOT_FOUND on a versioned delete into CONFLICT ("read it again"). dropReport, dropIndexOf, the client store and the refusal path use it, and their callers already retry on CONFLICT.
  • markPublished: a report another publisher removed meanwhile is still recorded as published.
  • noteError: clearing an error note that changed or disappeared meanwhile fails nothing.

Tests

internal/control/report_publish_removed_meanwhile_test.go wraps the store so that the first armed delete really removes the document and then answers NOT_FOUND, which is what the losing PostgreSQL transaction sees. Each of the three tests fails without the fix. They run on SQLite, so CI covers the race deterministically. CI's test-postgres job does not run internal/control, which takes about 12 minutes on PostgreSQL; locally the whole package passed on PostgreSQL with -race.

Locally:

  • go build, go vet, gofmt and golangci-lint are clean.
  • go test ./... passes.
  • -race passes on internal/control on SQLite and on PostgreSQL.
  • internal/control/api passes with -race (590 s, unrelated to this change).

…removed

On PostgreSQL at read committed, two publishers that both find the issue
of an in-flight attempt both record it; the second's versioned removal of
the report finds nothing and failed the whole call with NOT_FOUND.

A report removed between its read and its removal is now taken as gone:
the published entry is still recorded. A removal elsewhere in the report
store that finds nothing answers CONFLICT, which every caller already
retries or leaves to the next pass, and clearing the note of the last
publishing error after another publisher did so fails nothing.

Closes #78

Signed-off-by: Goon <duy@wearetopgroup.com>
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.

TestTwoPublishersTogetherKeepToTheDailyBudget fails on PostgreSQL: report document NOT_FOUND

1 participant