Prevent concurrent attestation from generating multiple envelopes #1218
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Serialize attestation processing and identity update inserts to prevent concurrent attestation from generating multiple envelopes in
pkg/payerreport/store.CreateAttestationandpkg/payerreport/workers.AttestationWorker.AttestReportsIntroduce a transaction-scoped advisory locking helper and apply row-level locking to coordinate attestation and identity update operations. The changes add
db.AdvisoryLockeranddb.TransactionScopedAdvisoryLocker, replace sequence-based identity update locks with originator node ID-based locks, lock payer report rows during attestation, and serialize worker execution via a fixed advisory lock.db.AdvisoryLockeranddb.TransactionScopedAdvisoryLockerwithLockIdentityUpdateInsertandLockAttestationWorkermethods in advisory_lock.go and constructor functionsqueries.AdvisoryLockWithKeyin advisory_locks.sql.go with SQL defined in advisory_locks.sqlqueries.AdvisoryLockIdentityUpdateInsertand its SQL in identity_updates.sql.go and identity_updates.sqlqueries.FetchPayerReportLockedwithFOR UPDATEin payer_reports.sql.go and payer_reports.sqlindexer.IdentityUpdateStorer.StoreLogto usedb.NewAdvisoryLocker().LockIdentityUpdateInsertkeyed by originator node ID in identity_update_storer.gopayerreport.IPayerReportStoreto exposeGetAdvisoryLockerand implement it in interface.go and store.gopayerreport.Store.CreateAttestationto lock the report row, short-circuit non-pending statuses, and stage a single originator envelope in store.go📍Where to Start
Start with the
payerreport.Store.CreateAttestationcall path in store.go, then review the advisory locking helper indb.TransactionScopedAdvisoryLockeranddb.AdvisoryLockerin advisory_lock.go, followed byqueries.FetchPayerReportLockedin payer_reports.sql.go and the worker changes inpayerreport.AttestationWorker.AttestReportsin attestation.goMacroscope summarized b54fd81.