-
Notifications
You must be signed in to change notification settings - Fork 146
fix(storage): scope ledger queries with bucket hint #1250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughDriver now queries the system store for the number of ledgers in a bucket when creating or opening a ledger and sets a shared per-bucket AloneInBucket flag on the ledger store; ledger query logic uses this flag to conditionally skip ledger-name filtering. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Driver
participant SystemStore
participant LedgerStore
Client->>Driver: CreateLedger/OpenLedger(bucket, name)
Driver->>SystemStore: CountLedgersInBucket(ctx, bucket)
SystemStore->>SystemStore: Execute COUNT query on _system.ledgers
SystemStore-->>Driver: return count (n) or error
Driver->>LedgerStore: SetAloneInBucket(n == 1)
LedgerStore->>LedgerStore: update shared per-bucket atomic flag
Driver-->>Client: return ledger store handle
Note over LedgerStore: Subsequent queries use the flag to skip<br/>ledger-name filtering when true
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
…coping The per-query sub-select on _system.ledgers to determine if a ledger is alone in its bucket is replaced by a boolean flag set at store open/create time. This avoids repeated cross-schema queries and prepares the ground for safe store caching (the flag must be invalidated when bucket composition changes). Backport of #1250.
Replace the dynamic _system.ledgers subquery in newScopedSelect() with a pre-computed isAloneInBucket boolean flag. The flag is set at store creation/opening time via CountLedgersInBucket, avoiding degraded PostgreSQL query plans when a ledger is alone in its bucket. Backport of #1250.
…Factory The previous per-store bool meant that when a second ledger was created in the same bucket, existing stores kept isAloneInBucket=true and skipped the WHERE ledger=? predicate, causing cross-ledger data leaks in queries (e.g. TestAccountsList). Replace the private bool with a *atomic.Bool shared across all stores of the same bucket through the DefaultFactory. Any call to SetAloneInBucket now immediately propagates to every store in that bucket.
|
Superseded by a new PR targeting release/v2.2 |
Summary
isAloneInBuckethint set at store open/create timeCountLedgersInBucketto system store and wire it in driver create/open flowsValidation