use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method getSortedBatchedStartTimestamps.
private List<Long> getSortedBatchedStartTimestamps(UUID requestorUuid, int numRequestedTimestamps) {
ConjureStartTransactionsRequest request = ConjureStartTransactionsRequest.builder().requestId(UUID.randomUUID()).requestorId(requestorUuid).numTransactions(numRequestedTimestamps).lastKnownVersion(Optional.empty()).build();
ConjureStartTransactionsResponse response = namespace.namespacedConjureTimelockService().startTransactions(request);
return response.getTimestamps().stream().boxed().collect(Collectors.toList());
}
use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.
the class MultiNodePaxosTimeLockServerIntegrationTest method invalidateDoesNotAffectLockWatchesInOtherNamespaces.
@Test
public void invalidateDoesNotAffectLockWatchesInOtherNamespaces() {
ConjureStartTransactionsResponse responseBeforeInvalidation = client.namespacedConjureTimelockService().startTransactions(ConjureStartTransactionsRequest.builder().numTransactions(10).requestId(UUID.randomUUID()).requestorId(UUID.randomUUID()).build());
invalidateClientResources("someoneElse");
ConjureStartTransactionsResponse responseAfterInvalidation = client.namespacedConjureTimelockService().startTransactions(ConjureStartTransactionsRequest.builder().numTransactions(10).requestId(UUID.randomUUID()).requestorId(UUID.randomUUID()).build());
assertThat(responseBeforeInvalidation.getTimestamps().stream().max().orElseThrow()).as("timestamps must strictly increase").isLessThan(responseAfterInvalidation.getTimestamps().stream().min().orElseThrow());
assertThat(responseBeforeInvalidation.getLockWatchUpdate().logId()).as("lock watch log IDs had no reason to change").isEqualTo(responseAfterInvalidation.getLockWatchUpdate().logId());
}
use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.
the class SnapshotTransactionTest method getSortedColumnsThrowsIfLockIsLost.
@Test
// Part of an assertion!
@SuppressWarnings("ReturnValueIgnored")
public void getSortedColumnsThrowsIfLockIsLost() {
List<Cell> cells = ImmutableList.of(Cell.create(ROW_FOO, COL_A));
putCellsInTable(cells, TABLE_SWEPT_THOROUGH);
ConjureStartTransactionsResponse conjureResponse = startTransactionWithWatches();
LockImmutableTimestampResponse res = conjureResponse.getImmutableTimestamp();
long transactionTs = conjureResponse.getTimestamps().start();
Transaction transaction = getSnapshotTransactionWith(timelockService, () -> transactionTs, res, PreCommitConditions.NO_OP, true);
timelockService.unlock(ImmutableSet.of(res.getLock()));
Iterator<Map.Entry<Cell, byte[]>> sortedColumns = transaction.getSortedColumns(TABLE_SWEPT_THOROUGH, ImmutableList.of(ROW_FOO), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1000));
assertThatThrownBy(() -> Streams.stream(sortedColumns).forEach(Map.Entry::getKey)).isInstanceOf(TransactionLockTimeoutException.class);
}
use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.
the class SnapshotTransactionTest method commitThrowsIfRolledBackAtCommitTime_alreadyAborted.
@Test
public void commitThrowsIfRolledBackAtCommitTime_alreadyAborted() {
final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1"));
TimelockService timelockService = inMemoryTimeLockRule.getLegacyTimelockService();
ConjureStartTransactionsResponse conjureResponse = startTransactionWithWatches();
LockImmutableTimestampResponse res = conjureResponse.getImmutableTimestamp();
long transactionTs = conjureResponse.getTimestamps().start();
Transaction snapshot = getSnapshotTransactionWith(timelockService, () -> transactionTs, res, PreCommitConditions.NO_OP);
// forcing to try to commit a transaction that is already committed
transactionService.putUnlessExists(transactionTs, TransactionConstants.FAILED_COMMIT_TS);
snapshot.put(TABLE, ImmutableMap.of(cell, PtBytes.toBytes("value")));
assertThatExceptionOfType(TransactionCommitFailedException.class).isThrownBy(snapshot::commit);
timelockService.unlock(Collections.singleton(res.getLock()));
}
use of com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse in project atlasdb by palantir.
the class SnapshotTransactionTest method verifyPrefetchValidations.
private void verifyPrefetchValidations(List<byte[]> rows, List<Cell> cells, int batchHint, int expectedNumberOfInvocations, int numElementsToBeAccessed) {
TimelockService spiedTimeLockService = spy(timelockService);
ConjureStartTransactionsResponse conjureResponse = startTransactionWithWatches();
LockImmutableTimestampResponse res = conjureResponse.getImmutableTimestamp();
long transactionTs = conjureResponse.getTimestamps().start();
Transaction transaction = getSnapshotTransactionWith(spiedTimeLockService, () -> transactionTs, res, PreCommitConditions.NO_OP, true);
Iterator<Map.Entry<Cell, byte[]>> sortedColumns = transaction.getSortedColumns(TABLE_SWEPT_THOROUGH, rows, BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, batchHint));
List<Cell> entries = IntStream.range(0, numElementsToBeAccessed).mapToObj(_unused -> sortedColumns.next().getKey()).collect(Collectors.toList());
Assertions.assertThat(entries).containsExactlyElementsOf(cells.subList(0, numElementsToBeAccessed));
verify(spiedTimeLockService, times(expectedNumberOfInvocations)).refreshLockLeases(ImmutableSet.of(res.getLock()));
}
Aggregations