Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Remove TimestampLeaseAwareTransactionManger (#7427)
Browse files Browse the repository at this point in the history
  • Loading branch information
kannavkm authored Nov 8, 2024
1 parent da8de2f commit 85b49d3
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 61 deletions.
24 changes: 24 additions & 0 deletions .palantir/revapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LongSupplier>}.
* <p>
* 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.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -415,6 +419,37 @@ <T, C extends PreCommitCondition, E extends Exception> 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.
* <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 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-7427.v2.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 85b49d3

Please sign in to comment.