Search in sources :

Example 1 with LockImmutableTimestampResponse

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

the class AsyncTimelockServiceIntegrationTest method canLockImmutableTimestamp.

@Test
public void canLockImmutableTimestamp() {
    LockImmutableTimestampResponse response1 = cluster.timelockService().lockImmutableTimestamp(LockImmutableTimestampRequest.create());
    LockImmutableTimestampResponse response2 = cluster.timelockService().lockImmutableTimestamp(LockImmutableTimestampRequest.create());
    long immutableTs = cluster.timelockService().getImmutableTimestamp();
    assertThat(immutableTs).isEqualTo(response1.getImmutableTimestamp());
    cluster.unlock(response1.getLock());
    assertThat(immutableTs).isEqualTo(response2.getImmutableTimestamp());
    cluster.unlock(response2.getLock());
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) Test(org.junit.Test)

Example 2 with LockImmutableTimestampResponse

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

the class SnapshotTransactionManager method setupRunTaskWithConditionThrowOnConflict.

public RawTransaction setupRunTaskWithConditionThrowOnConflict(PreCommitCondition condition) {
    LockImmutableTimestampResponse immutableTsResponse = timelockService.lockImmutableTimestamp(LockImmutableTimestampRequest.create());
    try {
        LockToken immutableTsLock = immutableTsResponse.getLock();
        long immutableTs = immutableTsResponse.getImmutableTimestamp();
        recordImmutableTimestamp(immutableTs);
        Supplier<Long> startTimestampSupplier = getStartTimestampSupplier();
        SnapshotTransaction transaction = createTransaction(immutableTs, startTimestampSupplier, immutableTsLock, condition);
        return new RawTransaction(transaction, immutableTsLock);
    } catch (Throwable e) {
        timelockService.unlock(ImmutableSet.of(immutableTsResponse.getLock()));
        throw Throwables.rewrapAndThrowUncheckedException(e);
    }
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) LockToken(com.palantir.lock.v2.LockToken) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 3 with LockImmutableTimestampResponse

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

the class LegacyTimelockServiceTest method lockImmutableTimestampLocksFreshTimestamp.

@Test
public void lockImmutableTimestampLocksFreshTimestamp() throws InterruptedException {
    long immutableTs = 3L;
    LockRefreshToken expectedToken = mockImmutableTsLockResponse();
    mockMinLockedInVersionIdResponse(immutableTs);
    LockImmutableTimestampResponse expectedResponse = LockImmutableTimestampResponse.of(immutableTs, toTokenV2(expectedToken));
    assertEquals(expectedResponse, timelock.lockImmutableTimestamp(LockImmutableTimestampRequest.create()));
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Example 4 with LockImmutableTimestampResponse

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

the class TimeLockClient method lockImmutableTimestamp.

@Override
public LockImmutableTimestampResponse lockImmutableTimestamp(LockImmutableTimestampRequest request) {
    LockImmutableTimestampResponse response = executeOnTimeLock(() -> delegate.lockImmutableTimestamp(request));
    lockRefresher.registerLock(response.getLock());
    return response;
}
Also used : LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse)

Example 5 with LockImmutableTimestampResponse

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

the class AsyncTimelockServiceImpl method lockImmutableTimestamp.

@Override
public LockImmutableTimestampResponse lockImmutableTimestamp(LockImmutableTimestampRequest request) {
    long timestamp = timestampService.getFreshTimestamp();
    // this will always return synchronously
    LockToken token = lockService.lockImmutableTimestamp(request.getRequestId(), timestamp).get();
    long immutableTs = lockService.getImmutableTimestamp().orElse(timestamp);
    return LockImmutableTimestampResponse.of(immutableTs, token);
}
Also used : LockToken(com.palantir.lock.v2.LockToken)

Aggregations

LockImmutableTimestampResponse (com.palantir.lock.v2.LockImmutableTimestampResponse)4 LockToken (com.palantir.lock.v2.LockToken)2 Test (org.junit.Test)2 LockRefreshToken (com.palantir.lock.LockRefreshToken)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1