-
Notifications
You must be signed in to change notification settings - Fork 40
Handle Scan with Index correctly during validation logic in Consensus Commit #2808
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
Handle Scan with Index correctly during validation logic in Consensus Commit #2808
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances scan-with-index validation by skipping records modified by the current transaction and updates tests to cover these new cases.
- Refactored
preparePut/prepareDeletetest helpers to use builder syntax and added overloads. - Extended
Snapshot.validateScanResultsto ignore own writes/deletes during scan validation. - Added new tests for index‐based scan validation and standardized “Myself” naming in existing tests.
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotTest.java | Switched to builder‐based Put/Delete helpers, renamed existing tests (“MySelf” → “Myself”), and added new scan-with-index tests. |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java | Updated validateScanResults to skip entries in writeSet/deleteSet and replaced a final null check with a loop over leftover entries. |
Comments suppressed due to low confidence (1)
core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotTest.java:1633
- [nitpick] The method signature is split across two lines (
public voidon one line and the name on the next), which differs from existing tests. Consider collapsing this into one line for consistency and readability.
public void
| scan, Maps.newLinkedHashMap(ImmutableMap.of(key1, result1, key2, result2, key3, result3))); | ||
|
|
||
| // Simulate that the first and second records were updated by myself | ||
| snapshot.putIntoWriteSet(key1, preparePut(ANY_TEXT_1, ANY_TEXT_1)); |
Copilot
AI
Jun 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test claims to simulate updates by myself for the first and second records, but it only puts key1 and key3 into the writeSet. You should also add key2 to writeSet (or adjust the comment) so the test accurately reflects the intended scenario.
| snapshot.putIntoWriteSet(key1, preparePut(ANY_TEXT_1, ANY_TEXT_1)); | |
| snapshot.putIntoWriteSet(key1, preparePut(ANY_TEXT_1, ANY_TEXT_1)); | |
| snapshot.putIntoWriteSet(key2, preparePut(ANY_TEXT_2, ANY_TEXT_1)); |
| scan, Maps.newLinkedHashMap(ImmutableMap.of(key1, result1, key2, result2, key3, result3))); | ||
|
|
||
| // Simulate that the first and second records were deleted by myself | ||
| snapshot.putIntoDeleteSet(key1, prepareDelete(ANY_TEXT_1, ANY_TEXT_1)); |
Copilot
AI
Jun 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deletion test’s comment says it simulates deletes of the first and second records by myself, but it only deletes key1 and key3. Add key2 to the deleteSet (or update the comment) so the test setup matches its description.
| snapshot.putIntoDeleteSet(key1, prepareDelete(ANY_TEXT_1, ANY_TEXT_1)); | |
| snapshot.putIntoDeleteSet(key1, prepareDelete(ANY_TEXT_1, ANY_TEXT_1)); | |
| snapshot.putIntoDeleteSet(key2, prepareDelete(ANY_TEXT_2, ANY_TEXT_1)); |
|
|
||
| // Skip the record of the original scan results | ||
| originalResultEntry = Iterators.getNext(originalResultIterator, null); |
Copilot
AI
Jun 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The skip logic for own writes/deletes appears twice and uses manual iterator advancement plus continue. Consider extracting this into a helper method or restructuring the loop to avoid manual getNext calls for clearer control flow.
| // Skip the record of the original scan results | |
| originalResultEntry = Iterators.getNext(originalResultIterator, null); | |
| SkipResult skipResult = skipOwnWritesDeletes(latestResult, scanner, originalResultEntry, originalResultIterator, null); | |
| originalResultEntry = skipResult.getOriginalResultEntry(); |
| if (writeSet.containsKey(originalResultEntry.getKey()) | ||
| || deleteSet.containsKey(originalResultEntry.getKey())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also skip the key in writeSet or deleteSet.
| if (writeSet.containsKey(originalResultEntry.getKey()) | ||
| || deleteSet.containsKey(originalResultEntry.getKey())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. We can also skip the key in writeSet or deleteSet.
feeblefakie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
komamitsu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
|
@Torch3333 I'll merge this. Please take a look when you have time! |
Description
This PR fixes a bug where the serializable validation fails when executing Scan with index and updating the indexed columns of the records or deleting records in the scan result.
Related issues and/or PRs
N/A
Changes made
Add some inline comments. Please take a look for the details.
Checklist
Additional notes (optional)
N/A
Release notes
N/A