Fix index-based Get/Scan to filter out results whose index key no longer matches after lazy recovery rollback#3488
Conversation
…ger matches after lazy recovery rollback
There was a problem hiding this comment.
Code Review
This pull request introduces logic to filter out records that no longer match a secondary index key after a lazy recovery (rollback) in the CrudHandler. This ensures consistency when querying via secondary indexes. Feedback suggests deduplicating the filtering logic between the read and processScanResult methods and adding a safety check when accessing partition key columns in the resultMatchesIndexKey helper to prevent potential IndexOutOfBoundsException.
There was a problem hiding this comment.
Pull request overview
Fixes an inconsistency in index-based reads under Consensus Commit where a record found via the (after-image) secondary index could be lazily recovered (rolled back) to a different index value but still be returned to the caller.
Changes:
- Added post-recovery index-key validation for index-based
GetandScanpaths inCrudHandler. - Introduced
resultMatchesIndexKey()to compare the recovered row’s indexed column value against the requested index key. - Added unit + integration coverage for rolled-back PREPARED records whose restored (before-image) index value no longer matches the queried index key.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java |
Filters recovered results for index-based reads when the returned view is effectively “rolled back” to before-image values. |
core/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java |
Adds unit tests validating filtering behavior for index-based Get/Scan after rollback. |
integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitSpecificIntegrationTestBase.java |
Adds integration tests for Get/Scan/getScanner ensuring rolled-back rows are not returned when the index key no longer matches. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…fter rollback index key filtering
|
/gemini review |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request implements filtering for secondary index results after a lazy recovery (rollback) in the consensus commit transaction protocol. It ensures that if a record's index column value reverts to an original value that no longer matches the query criteria after a rollback, the record is filtered out of the result set. Additionally, the logic prevents caching these filtered-out results as empty in the transaction snapshot to avoid incorrect subsequent reads. I have no feedback to provide as no review comments were submitted.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9309986 to
79c6d46
Compare
…ger matches after lazy recovery rollback (#3488)
…ger matches after lazy recovery rollback (#3488)
…ger matches after lazy recovery rollback (#3488)
Description
When a PREPARED record is found via the normal secondary index during an index-based Get/Scan, and lazy recovery rolls back the transaction, the index column value reverts to its before-image value. If this reverted value no longer matches the queried index key, the result should be filtered out. Previously, such results were returned incorrectly.
For example:
This PR addresses this issue.
Related issues and/or PRs
N/A
Changes made
CrudHandler.read()(Get) andCrudHandler.processScanResult()(Scan). WhenrecoveryResult.rolledBackis true and the operation uses a secondary index, the recovered result is filtered usingresultMatchesIndexKey().resultMatchesIndexKey()private method in CrudHandler that compares the result's index column value against the queried index key.CrudHandlerTestcovering rollback with matching/non-matching index keys for bothGetandScanoperations.ConsensusCommitSpecificIntegrationTestBaseforGet,Scan, andgetScannerthat verify rolled-back PREPARED records are correctly filtered out when the index key matches the after-image.Checklist
Additional notes (optional)
rolledBackis true because roll-forward (commit) preserves the after-image value, which already matches the queried index key by definition — the record was found via the normal index because its after-image matched the query.Release notes
Fixed a bug where index-based Get and Scan operations could return incorrect results after lazy recovery rolled back a PREPARED record whose after-image index value matched the query but whose before-image (restored) value did not.