This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
optional validation of immutable ts on read operations #3414
Merged
gozakdag
merged 8 commits into
develop
from
gozakdag/optional-validation-of-immutable-ts
Aug 16, 2018
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bfca148
validate on reads if necessary
gozakdag c7fe9e4
add tests
gozakdag 3a5f028
renaming
gozakdag bb1bc42
fix merge conflict
gozakdag 2aabe24
adding wrapping task
gozakdag 517ff03
wrapping transaction task to check immutable ts lock
gozakdag 9c4ce05
merge develop, fix conflicts
gozakdag ec4d13f
release notes
gozakdag 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
66 changes: 66 additions & 0 deletions
66
...ared/src/main/java/com/palantir/atlasdb/transaction/impl/LockCheckingTransactionTask.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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the BSD-3 License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.transaction.impl; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.palantir.atlasdb.transaction.api.Transaction; | ||
import com.palantir.atlasdb.transaction.api.TransactionFailedNonRetriableException; | ||
import com.palantir.atlasdb.transaction.api.TransactionLockTimeoutException; | ||
import com.palantir.atlasdb.transaction.api.TransactionTask; | ||
import com.palantir.lock.v2.LockToken; | ||
import com.palantir.lock.v2.TimelockService; | ||
|
||
/** | ||
* Best effort attempt to keep backwards compatibility while making immutableTs lock validation optional on reads. | ||
* Validating immutableTs lock only on commits rather than on every read may cause the TransactionTask to throw | ||
* an unexpected non-retriable error as reads are not idempotent. This wrapper task will convert the exception thrown | ||
* by the underlying task into a retriable lock timeout exception if immutableTs lock is not valid anymore. | ||
*/ | ||
public class LockCheckingTransactionTask<T, E extends Exception> implements TransactionTask<T, E> { | ||
private final TransactionTask<T, E> delegate; | ||
private final TimelockService timelockService; | ||
private final LockToken immutableTsLock; | ||
|
||
public LockCheckingTransactionTask(TransactionTask<T, E> delegate, | ||
TimelockService timelockService, | ||
LockToken immutableTsLock) { | ||
this.delegate = delegate; | ||
this.timelockService = timelockService; | ||
this.immutableTsLock = immutableTsLock; | ||
|
||
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. nit: whitespace |
||
} | ||
|
||
public T execute(Transaction transaction) throws E { | ||
try { | ||
return delegate.execute(transaction); | ||
} catch (Exception ex) { | ||
if (shouldRethrowWithoutLockValidation(ex) || immutableTsLockIsValid()) { | ||
throw ex; | ||
} | ||
throw new TransactionLockTimeoutException( | ||
"The following immutable timestamp lock is no longer valid: " + immutableTsLock); | ||
} | ||
} | ||
|
||
private boolean shouldRethrowWithoutLockValidation(Exception ex) { | ||
return ex instanceof InterruptedException || ex instanceof TransactionFailedNonRetriableException; | ||
} | ||
|
||
private boolean immutableTsLockIsValid() { | ||
return !timelockService.refreshLockLeases(ImmutableSet.of(immutableTsLock)).isEmpty(); | ||
} | ||
} |
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
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
Oops, something went wrong.
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.
Two issues: