Search in sources :

Example 6 with LeaderTime

use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.

the class HeldLocksCollectionTest method emptyRefreshResponse.

@Test
public void emptyRefreshResponse() {
    LockToken t1 = LockToken.of(UUID.randomUUID());
    LockToken t2 = LockToken.of(UUID.randomUUID());
    Leased<Set<LockToken>> refreshResult = heldLocksCollection.refresh(ImmutableSet.of(t1, t2));
    assertThat(refreshResult.value()).isEmpty();
    assertThat(refreshResult.lease().leaderTime().currentTime()).isLessThanOrEqualTo(time.get());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 7 with LeaderTime

use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.

the class HeldLocksCollectionTest method leaseShouldStartBeforeRefreshTime.

@Test
public void leaseShouldStartBeforeRefreshTime() {
    LockToken t1 = lockSync(REQUEST_ID);
    LockToken t2 = lockSync(REQUEST_ID_2);
    Set<LockToken> tokens = ImmutableSet.of(t1, t2);
    Leased<Set<LockToken>> refreshResult = heldLocksCollection.refresh(tokens);
    NanoTime t1RefreshTime = heldLocksCollection.heldLocksById.get(t1.getRequestId()).get().lastRefreshTime();
    NanoTime t2RefreshTime = heldLocksCollection.heldLocksById.get(t2.getRequestId()).get().lastRefreshTime();
    NanoTime minRefreshTime = t1RefreshTime.isBefore(t2RefreshTime) ? t1RefreshTime : t2RefreshTime;
    assertThat(refreshResult.lease().leaderTime().currentTime()).isLessThan(minRefreshTime);
}
Also used : NanoTime(com.palantir.common.time.NanoTime) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 8 with LeaderTime

use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.

the class LockLeaseService method refreshLockLeases.

Set<LockToken> refreshLockLeases(Set<LockToken> uncastedTokens) {
    if (uncastedTokens.isEmpty()) {
        return uncastedTokens;
    }
    LeaderTime leaderTime = leaderTimeGetter.leaderTime();
    Set<LeasedLockToken> allTokens = leasedTokens(uncastedTokens);
    Set<LeasedLockToken> validByLease = allTokens.stream().filter(token -> token.isValid(leaderTime)).collect(Collectors.toSet());
    Set<LeasedLockToken> toRefresh = Sets.difference(allTokens, validByLease);
    Set<LeasedLockToken> refreshedTokens = refreshTokens(toRefresh);
    return Sets.union(refreshedTokens, validByLease);
}
Also used : LeaderTime(com.palantir.lock.v2.LeaderTime) LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) StartTransactionResponseV4(com.palantir.lock.v2.StartTransactionResponseV4) GetCommitTimestampsRequest(com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest) ConjureRefreshLocksResponse(com.palantir.atlasdb.timelock.api.ConjureRefreshLocksResponse) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) ConjureStartTransactionsRequest(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest) LeaderTime(com.palantir.lock.v2.LeaderTime) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) Lease(com.palantir.lock.v2.Lease) LockResponse(com.palantir.lock.v2.LockResponse) ConjureLockToken(com.palantir.atlasdb.timelock.api.ConjureLockToken) LockToken(com.palantir.lock.v2.LockToken) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) Set(java.util.Set) ConjureUnlockRequest(com.palantir.atlasdb.timelock.api.ConjureUnlockRequest) ConjureRefreshLocksRequest(com.palantir.atlasdb.timelock.api.ConjureRefreshLocksRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) LockRequest(com.palantir.lock.v2.LockRequest) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) Preconditions(com.palantir.logsafe.Preconditions)

Example 9 with LeaderTime

use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method leaderIdChangesAcrossFailovers.

@Test
public void leaderIdChangesAcrossFailovers() {
    Set<LeaderTime> leaderTimes = new HashSet<>();
    leaderTimes.add(client.namespacedConjureTimelockService().leaderTime());
    for (int i = 0; i < 3; i++) {
        cluster.failoverToNewLeader(client.namespace());
        LeaderTime leaderTime = client.namespacedConjureTimelockService().leaderTime();
        leaderTimes.forEach(previousLeaderTime -> assertThat(previousLeaderTime.isComparableWith(leaderTime)).isFalse());
        leaderTimes.add(leaderTime);
    }
}
Also used : LeaderTime(com.palantir.lock.v2.LeaderTime) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with LeaderTime

use of com.palantir.lock.v2.LeaderTime in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method invalidateChangesLeaderIdentifier.

@Test
public void invalidateChangesLeaderIdentifier() {
    LeaderTime timeBeforeInvalidation = client.conjureTimelockService().leaderTime(AUTH_HEADER, client.namespace());
    invalidateMainClientResources();
    LeaderTime timeAfterInvalidation = client.conjureTimelockService().leaderTime(AUTH_HEADER, client.namespace());
    assertThat(timeBeforeInvalidation.id()).isNotEqualTo(timeAfterInvalidation.id());
}
Also used : LeaderTime(com.palantir.lock.v2.LeaderTime) Test(org.junit.Test)

Aggregations

LeaderTime (com.palantir.lock.v2.LeaderTime)8 Test (org.junit.Test)8 LeaderTimes (com.palantir.atlasdb.timelock.api.LeaderTimes)3 Namespace (com.palantir.atlasdb.timelock.api.Namespace)3 LockToken (com.palantir.lock.v2.LockToken)3 Set (java.util.Set)3 UUID (java.util.UUID)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 LeadershipId (com.palantir.lock.v2.LeadershipId)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Sets (com.google.common.collect.Sets)1 AsyncTimelockService (com.palantir.atlasdb.timelock.AsyncTimelockService)1 ConjureLockToken (com.palantir.atlasdb.timelock.api.ConjureLockToken)1 ConjureRefreshLocksRequest (com.palantir.atlasdb.timelock.api.ConjureRefreshLocksRequest)1 ConjureRefreshLocksResponse (com.palantir.atlasdb.timelock.api.ConjureRefreshLocksResponse)1 ConjureStartTransactionsRequest (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest)1 ConjureStartTransactionsResponse (com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse)1 ConjureUnlockRequest (com.palantir.atlasdb.timelock.api.ConjureUnlockRequest)1 GetCommitTimestampsRequest (com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest)1 GetCommitTimestampsResponse (com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse)1