-
Notifications
You must be signed in to change notification settings - Fork 38
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
Should perform lazy recovery in implicit pre-read #1476
Merged
feeblefakie
merged 2 commits into
master
from
should-perform-lazy-recovery-in-implicit-pre-read
Jan 31, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
import com.scalar.db.api.Put; | ||
import com.scalar.db.api.Result; | ||
import com.scalar.db.api.Scan; | ||
import com.scalar.db.api.Selection; | ||
import com.scalar.db.api.TransactionState; | ||
import com.scalar.db.common.AbstractTwoPhaseCommitTransaction; | ||
import com.scalar.db.exception.storage.ExecutionException; | ||
|
@@ -65,7 +64,7 @@ public Optional<Result> get(Get get) throws CrudException { | |
try { | ||
return crud.get(get); | ||
} catch (UncommittedRecordException e) { | ||
lazyRecovery(get, e.getResults()); | ||
lazyRecovery(e); | ||
throw e; | ||
} | ||
} | ||
|
@@ -76,7 +75,7 @@ public List<Result> scan(Scan scan) throws CrudException { | |
try { | ||
return crud.scan(scan); | ||
} catch (UncommittedRecordException e) { | ||
lazyRecovery(scan, e.getResults()); | ||
lazyRecovery(e); | ||
throw e; | ||
} | ||
} | ||
|
@@ -137,6 +136,9 @@ public void prepare() throws PreparationException { | |
try { | ||
crud.readIfImplicitPreReadEnabled(); | ||
} catch (CrudConflictException e) { | ||
if (e instanceof UncommittedRecordException) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Same as above |
||
lazyRecovery((UncommittedRecordException) e); | ||
} | ||
throw new PreparationConflictException( | ||
"Conflict occurred while implicit pre-read", e, getId()); | ||
} catch (CrudException e) { | ||
|
@@ -216,10 +218,10 @@ void setBeforeRecoveryHook(Runnable beforeRecoveryHook) { | |
this.beforeRecoveryHook = beforeRecoveryHook; | ||
} | ||
|
||
private void lazyRecovery(Selection selection, List<TransactionResult> results) { | ||
logger.debug("Recover uncommitted records: {}", results); | ||
private void lazyRecovery(UncommittedRecordException e) { | ||
logger.debug("Recover uncommitted records: {}", e.getResults()); | ||
beforeRecoveryHook.run(); | ||
results.forEach(r -> recovery.recover(selection, r)); | ||
e.getResults().forEach(r -> recovery.recover(e.getSelection(), r)); | ||
} | ||
|
||
private void checkMutation(Mutation mutation) throws CrudException { | ||
|
34 changes: 13 additions & 21 deletions
34
core/src/main/java/com/scalar/db/transaction/consensuscommit/UncommittedRecordException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,30 @@ | ||
package com.scalar.db.transaction.consensuscommit; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.scalar.db.api.Selection; | ||
import com.scalar.db.exception.transaction.CrudConflictException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import java.util.List; | ||
|
||
public class UncommittedRecordException extends CrudConflictException { | ||
private final List<TransactionResult> results; | ||
|
||
public UncommittedRecordException( | ||
TransactionResult result, String message, String transactionId) { | ||
this(result, message, null, transactionId); | ||
} | ||
|
||
public UncommittedRecordException( | ||
TransactionResult result, String message, Throwable cause, String transactionId) { | ||
super(message, cause, transactionId); | ||
results = Collections.singletonList(result); | ||
} | ||
private final Selection selection; | ||
private final List<TransactionResult> results; | ||
|
||
@SuppressFBWarnings("EI_EXPOSE_REP2") | ||
public UncommittedRecordException( | ||
List<TransactionResult> results, String message, String transactionId) { | ||
this(results, message, null, transactionId); | ||
Selection selection, TransactionResult result, String message, String transactionId) { | ||
super(message, transactionId); | ||
this.selection = selection; | ||
results = ImmutableList.of(result); | ||
} | ||
|
||
public UncommittedRecordException( | ||
List<TransactionResult> results, String message, Throwable cause, String transactionId) { | ||
super(message, cause, transactionId); | ||
this.results = new ArrayList<>(); | ||
this.results.addAll(results); | ||
@SuppressFBWarnings("EI_EXPOSE_REP") | ||
public Selection getSelection() { | ||
return selection; | ||
} | ||
|
||
public List<TransactionResult> getResults() { | ||
return ImmutableList.copyOf(results); | ||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
[minor] Or, explicitly catching UncommittedRecordException is also an option?
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.
Yeah, that's an option. I didn't do that because I didn't think we needed to change the error message base on the cause, as we pass the cause exception to
CommitConflictException
.What do you think?
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.
Sounds good