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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optional validation of immutable ts on read operations (#3414)
* validate on reads if necessary * add tests * renaming * adding wrapping task * release notes
- Loading branch information
Showing
19 changed files
with
384 additions
and
103 deletions.
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
70 changes: 70 additions & 0 deletions
70
...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,70 @@ | ||
/* | ||
* 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. | ||
* <p> | ||
* If a read is performed without validating immutableTs lock on a thoroughly swept table, there is no guarantee on | ||
* consistency of data read; as sweep may remove data that is being read. This will not cause any correctness | ||
* issues as immutableTs lock will be checked on commit time, and transaction will be aborted if lock is invalid. | ||
* Although this prevents committing corrupted values, reading inconsistent data may cause tasks to throw | ||
* non-retriable exceptions; causing a possible behaviour change. | ||
* <p> | ||
* 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; | ||
} | ||
|
||
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.