diff --git a/.palantir/revapi.yml b/.palantir/revapi.yml index 4b3ab287bbe..73ea49b6584 100644 --- a/.palantir/revapi.yml +++ b/.palantir/revapi.yml @@ -452,6 +452,30 @@ acceptedBreaks: - code: "java.method.addedToInterface" new: "method void com.palantir.atlasdb.transaction.api.Transaction::onCommitOrAbort(java.lang.Runnable)" justification: "similar to onSuccess, already used in other prod codepaths" + "0.1187.0": + com.palantir.atlasdb:atlasdb-api: + - code: "java.class.removed" + old: "interface com.palantir.atlasdb.transaction.api.TimestampLeaseAwareTransactionManager" + justification: "Discussed: break is intended, see Compatibility section here\ + \ https://github.com/palantir/atlasdb/pull/7427#issue-2638127226" + - code: "java.method.addedToInterface" + new: "method long com.palantir.atlasdb.transaction.api.TransactionManager::getLeasedTimestamp(com.palantir.atlasdb.common.api.timelock.TimestampLeaseName)" + justification: "Discussed: break is intended, see Compatibility section here\ + \ https://github.com/palantir/atlasdb/pull/7427#issue-2638127226" + "0.1188.0-rc1": + com.palantir.atlasdb:atlasdb-api: + - code: "java.method.addedToInterface" + new: "method long com.palantir.atlasdb.transaction.api.TransactionManager::getMinLeasedTimestamp(com.palantir.atlasdb.common.api.timelock.TimestampLeaseName)" + justification: "Discussed: break is intended, see Compatibility section here\ + \ https://github.com/palantir/atlasdb/pull/7427\\#issue-2638127226" + - code: "java.method.removed" + old: "method long com.palantir.atlasdb.transaction.api.AutoDelegate_TransactionManager::getLeasedTimestamp(com.palantir.atlasdb.common.api.timelock.TimestampLeaseName)" + justification: "Discussed: break is intended, see Compatibility section here\ + \ https://github.com/palantir/atlasdb/pull/7427\\#issue-2638127226" + - code: "java.method.removed" + old: "method long com.palantir.atlasdb.transaction.api.TransactionManager::getLeasedTimestamp(com.palantir.atlasdb.common.api.timelock.TimestampLeaseName)" + justification: "Discussed: break is intended, see Compatibility section here\ + \ https://github.com/palantir/atlasdb/pull/7427\\#issue-2638127226" "0.770.0": com.palantir.atlasdb:atlasdb-api: - code: "java.class.removed" diff --git a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransaction.java b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransaction.java index 9c38b096174..996aebcf0d2 100644 --- a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransaction.java +++ b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransaction.java @@ -35,7 +35,7 @@ public interface TimestampLeaseAwareTransaction { * 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}. *

- * Clients can use {@link TimestampLeaseAwareTransactionManager#getLeasedTimestamp(TimestampLeaseName)} + * Clients can use {@link TransactionManager#getLeasedTimestamp(TimestampLeaseName)} * to fetch a timestamp before the earliest leased timestamp for a given {@code timestampLeaseName} on open * transactions. * diff --git a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransactionManager.java b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransactionManager.java deleted file mode 100644 index fea4ead27fb..00000000000 --- a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TimestampLeaseAwareTransactionManager.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * (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 com.palantir.atlasdb.transaction.api.TimestampLeaseAwareTransaction.PreCommitAction; -import com.palantir.lock.v2.TimelockService; - -@Beta -public interface TimestampLeaseAwareTransactionManager { - /** - * Returns a timestamp that is before any leased timestamps returned by the consumer on {@link TimestampLeaseAwareTransaction#preCommit(TimestampLeaseName, int, PreCommitAction)} - * for a {@code timestampLeaseName} in open transactions. - *

- * 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. - *

- * If no transactions with a {@code timestampLeaseName} lock are open, this method returns a new fresh timestamp - * (i.e. equivalent to {@link TimelockService#getFreshTimestamp()}). - *

- * Consumers should 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, PreCommitAction)} - * 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 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); -} diff --git a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionManager.java b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionManager.java index cfdaf54caec..58e2fdef70d 100644 --- a/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionManager.java +++ b/atlasdb-api/src/main/java/com/palantir/atlasdb/transaction/api/TransactionManager.java @@ -15,11 +15,15 @@ */ package com.palantir.atlasdb.transaction.api; +import com.google.errorprone.annotations.RestrictedApi; import com.palantir.atlasdb.cell.api.DdlManager; import com.palantir.atlasdb.cleaner.api.Cleaner; +import com.palantir.atlasdb.common.api.annotations.ReviewedRestrictedApiUsage; +import com.palantir.atlasdb.common.api.timelock.TimestampLeaseName; import com.palantir.atlasdb.keyvalue.api.KeyValueService; import com.palantir.atlasdb.keyvalue.api.watch.LockWatchManager; import com.palantir.atlasdb.metrics.Timed; +import com.palantir.atlasdb.transaction.api.TimestampLeaseAwareTransaction.PreCommitAction; import com.palantir.atlasdb.transaction.service.TransactionService; import com.palantir.exception.NotInitializedException; import com.palantir.lock.HeldLocksToken; @@ -415,6 +419,37 @@ T runTaskWithConditionRea @Timed long getUnreadableTimestamp(); + /** + * Returns a timestamp that is before any leased timestamps returned by the consumer on + * {@link TimestampLeaseAwareTransaction#preCommit(TimestampLeaseName, int, PreCommitAction)} + * for a {@code timestampLeaseName} in open transactions. + *

+ * 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. + *

+ * If no transactions with a {@code timestampLeaseName} lock are open, this method returns a new fresh timestamp + * (i.e. equivalent to {@link TimelockService#getFreshTimestamp()}). + *

+ * Consumers should 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, PreCommitAction)} + * 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 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 getMinLeasedTimestamp(TimestampLeaseName leaseName); + /** * Clear the timestamp cache. This is mostly useful for tests that perform operations that would invalidate * the cache, although this can also be used to free up some memory. diff --git a/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/transaction/impl/SnapshotTransactionManager.java b/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/transaction/impl/SnapshotTransactionManager.java index 1d58f12d1f4..c2cc202407a 100644 --- a/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/transaction/impl/SnapshotTransactionManager.java +++ b/atlasdb-impl-shared/src/main/java/com/palantir/atlasdb/transaction/impl/SnapshotTransactionManager.java @@ -44,7 +44,6 @@ import com.palantir.atlasdb.transaction.api.KeyValueServiceStatus; import com.palantir.atlasdb.transaction.api.OpenTransaction; import com.palantir.atlasdb.transaction.api.PreCommitCondition; -import com.palantir.atlasdb.transaction.api.TimestampLeaseAwareTransactionManager; import com.palantir.atlasdb.transaction.api.Transaction; import com.palantir.atlasdb.transaction.api.Transaction.TransactionType; import com.palantir.atlasdb.transaction.api.TransactionFailedRetriableException; @@ -86,8 +85,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -/* package */ class SnapshotTransactionManager extends AbstractLockAwareTransactionManager - implements TimestampLeaseAwareTransactionManager { +/* package */ class SnapshotTransactionManager extends AbstractLockAwareTransactionManager { private static final SafeLogger log = SafeLoggerFactory.get(SnapshotTransactionManager.class); private static final int NUM_RETRIES = 10; @@ -527,7 +525,7 @@ public long getUnreadableTimestamp() { @Override @ReviewedRestrictedApiUsage - public long getLeasedTimestamp(TimestampLeaseName leaseName) { + public long getMinLeasedTimestamp(TimestampLeaseName leaseName) { return timelockService.getMinLeasedTimestamps(Set.of(leaseName)).get(leaseName); } diff --git a/changelog/@unreleased/pr-7427.v2.yml b/changelog/@unreleased/pr-7427.v2.yml new file mode 100644 index 00000000000..a2c1af5357b --- /dev/null +++ b/changelog/@unreleased/pr-7427.v2.yml @@ -0,0 +1,6 @@ +type: fix +fix: + description: Remove `TimestampLeaseAwareTransactionManger` and move `getMinLeasedTimestamp` + to be part of `TransactionManager` + links: + - https://github.com/palantir/atlasdb/pull/7427