fix(storage): share aloneInBucket flag per bucket via atomic.Bool #1253
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.
Summary
isAloneInBucket bool(from the subquery-based approach on v2.2) with a shared*atomic.Boolper bucket, managed by theDefaultFactorySetAloneInBucket(false)now propagates immediately to all existing stores in that bucketCountLedgersInBucketto the system store interface soCreateLedgerandOpenLedgercan seed the flag correctlyRoot cause
The previous approach (subquery in
newScopedSelecton v2.2, or cachedboolper store on main) could miss bucket membership changes: when multiple ledgers share a bucket, a store created before the second ledger still believed it was alone, skipping theWHERE ledger = ?predicate and leaking rows from other ledgers (e.g.TestAccountsListfailures).Changes
internal/storage/ledger/store.go:aloneInBucket *atomic.Boolfield +SetAloneInBucket/newScopedSelectusing atomic loadinternal/storage/ledger/factory.go:bucketFlags map[string]*atomic.Boolshared across all stores of the same bucketinternal/storage/driver/driver.go:CreateLedgerandOpenLedgercallCountLedgersInBucketandSetAloneInBucketinternal/storage/system/store.go: newCountLedgersInBucketmethod on interface + implementationinternal/storage/driver/system_generated_test.go: mock updated for new methodTest plan
earthly -P +testspasses (all unit, integration, e2e, stress tests)TestAccountsListno longer flaky with multiple ledgers in the same bucket