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.
- Loading branch information
1 parent
119900c
commit 9afedb1
Showing
39 changed files
with
376 additions
and
38 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...pi/src/main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransaction.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,54 @@ | ||
/* | ||
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.api; | ||
|
||
import com.google.common.annotations.Beta; | ||
import com.google.errorprone.annotations.RestrictedApi; | ||
import com.palantir.atlasdb.common.api.annotations.ReviewedRestrictedApiUsage; | ||
import com.palantir.atlasdb.common.api.timelock.TimestampLeaseName; | ||
import java.util.function.Consumer; | ||
import java.util.function.LongSupplier; | ||
|
||
@Beta | ||
public interface TimestampLeaseAwareTransaction { | ||
/** | ||
* Register pre-commit lambdas that are run on commit() just before the transaction is closed. | ||
* <p> | ||
* In the pre-commit lambdas, consumers can perform any actions they would inside a transaction. | ||
* It is valid, for example, to read to or write from a table. | ||
* <p> | ||
* If {@code numLeasedTimestamps} is greater than 0, fresh timestamps will be fetched from {@link TransactionManager#getTimelockService()} | ||
* and will be provided to the pre-commit lambda via the supplier on {@code Consumer<LongSupplier>}. | ||
* <p> | ||
* Clients can use {@link TimestampLeaseAwareTransactionManager#getLeasedTimestamp(TimestampLeaseName)} | ||
* to fetch a timestamp before the earliest leased timestamp for a given {@code timestampLeaseName} on open | ||
* transactions. | ||
* | ||
* @param leaseName the name of the lease the timestamps are bound to | ||
* @param numLeasedTimestamps the number of timestamps that should be fetched and used in the pre-commit lambda | ||
* @param preCommitAction the lambda executed just before commit. Note the consumer throws {@code RuntimeException} | ||
* if a client requests more than specified in {@code numLeasedTimestamps}. | ||
*/ | ||
@RestrictedApi( | ||
explanation = "This API is only meant to be used by AtlasDb proxies that want to make use of the " | ||
+ "performance improvements by tracking leased timestamps timestamps of open transactions." | ||
+ " Misuse of this feature can cause correctness issues.", | ||
link = "https://github.com/palantir/atlasdb/pull/7305", | ||
allowedOnPath = ".*/src/test/.*", // Unsafe behavior in tests is ok. | ||
allowlistAnnotations = {ReviewedRestrictedApiUsage.class}) | ||
void preCommit(TimestampLeaseName leaseName, int numLeasedTimestamps, Consumer<LongSupplier> preCommitAction); | ||
} |
54 changes: 54 additions & 0 deletions
54
...main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransactionManager.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,54 @@ | ||
/* | ||
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.api; | ||
|
||
import com.google.errorprone.annotations.RestrictedApi; | ||
import com.palantir.atlasdb.common.api.annotations.ReviewedRestrictedApiUsage; | ||
import com.palantir.atlasdb.common.api.timelock.TimestampLeaseName; | ||
import com.palantir.lock.v2.TimelockService; | ||
import java.util.function.Consumer; | ||
|
||
public interface TimestampLeaseAwareTransactionManager { | ||
/** | ||
* Returns the timestamp that is before leased timestamps returned by the consumer on {@link TimestampLeaseAwareTransaction#preCommit(TimestampLeaseName, int, Consumer)} | ||
* for a {@code timestampLeaseName} in open transactions. | ||
* <p> | ||
* This is similar to {@link TransactionManager#getImmutableTimestamp()} as it returns a timestamp before timestamps | ||
* in open transactions, but for the immutable timestamp the timestamps considered are start timestamps for open | ||
* transactions, while for leased timestamps the timestamps considered are leased timestamps from the corresponding | ||
* {@code timestampLeaseName} in open transactions. | ||
* <p> | ||
* If no transactions with a {@code timestampLeaseName} lock are open, this method returns a new fresh timestamp | ||
* (i.e. equivalent to {@link TimelockService#getFreshTimestamp()}). | ||
* <p> | ||
* Consumers should to fetch the leased timestamp outside of transactions that potentially use it - if fetching the | ||
* leased timestamp inside a transaction, it's possible for the transaction's start timestamp < leased timestamp, | ||
* meaning the transaction cannot read all data up to leased timestamp. | ||
* | ||
* @param leaseName the name of the lease the timestamps are bound to | ||
* @return the timestamp that is before any timestamp returned by the consumer of {@link TimestampLeaseAwareTransaction#preCommit(TimestampLeaseName, int, Consumer)} | ||
* for open transactions. | ||
*/ | ||
@RestrictedApi( | ||
explanation = "This API is only meant to be used by AtlasDb proxies that want to make use of the" | ||
+ " performance improvements by tracking leased timestamps timestamps of open transactions." | ||
+ " Misuse of this feature can cause correctness issues.", | ||
link = "https://github.com/palantir/atlasdb/pull/7305", | ||
allowedOnPath = ".*/src/test/.*", // Unsafe behavior in tests is ok. | ||
allowlistAnnotations = {ReviewedRestrictedApiUsage.class}) | ||
long getLeasedTimestamp(TimestampLeaseName leaseName); | ||
} |
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 +1,15 @@ | ||
apply from: "../gradle/shared.gradle" | ||
|
||
dependencies { | ||
compileOnly 'org.immutables:value::annotations' | ||
annotationProcessor 'org.immutables:value' | ||
|
||
implementation 'com.fasterxml.jackson.core:jackson-annotations' | ||
implementation 'com.fasterxml.jackson.core:jackson-databind' | ||
implementation 'com.google.errorprone:error_prone_annotations' | ||
implementation 'com.palantir.safe-logging:preconditions' | ||
|
||
testImplementation 'org.assertj:assertj-core' | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
testImplementation 'com.palantir.safe-logging:preconditions-assertj' | ||
} |
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
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.