use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.
the class TransactionAborter method tryAbortTransactions.
private boolean tryAbortTransactions(TransactionsTableInteraction txnInteraction, Statement abortStatement, Statement checkStatement, long startTs, long commitTs) {
log.info("Aborting transaction", SafeArg.of("startTs", startTs), SafeArg.of("commitTs", commitTs), SafeArg.of("keyspace", namespace));
ResultSet abortResultSet = cqlSession.execute(abortStatement);
if (abortResultSet.wasApplied()) {
return true;
}
log.debug("Executing check statement", SafeArg.of("startTs", startTs), SafeArg.of("commitTs", commitTs), SafeArg.of("keyspace", namespace));
ResultSet checkResultSet = cqlSession.execute(checkStatement);
Row result = Iterators.getOnlyElement(checkResultSet.all().iterator());
TransactionTableEntry transactionTableEntry = txnInteraction.extractTimestamps(result);
if (isAborted(transactionTableEntry)) {
return true;
}
log.warn("Retrying abort statement", SafeArg.of("startTs", startTs), SafeArg.of("commitTs", commitTs), SafeArg.of("keyspace", namespace));
return false;
}
use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.
the class TransactionAborterTest method setupAbortTimestampTask.
private void setupAbortTimestampTask(ImmutableList<TransactionTableEntry> entries, FullyBoundedTimestampRange range) {
when(transactionInteraction.getTimestampRange()).thenReturn(range);
List<Row> rows = entries.stream().map(entry -> {
Row row = mock(Row.class);
when(transactionInteraction.extractTimestamps(row)).thenReturn(entry);
return row;
}).collect(Collectors.toList());
ResultSet selectResponse = createSelectResponse(rows);
when(transactionInteraction.createSelectStatementsForScanningFullTimestampRange(any())).thenReturn(ImmutableList.of(mock(Statement.class)));
when(cqlSession.execute(any(Statement.class))).thenReturn(selectResponse);
}
use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.
the class TransactionAborterTest method executeWithRetryChecksEventuallyFails.
@Test
public void executeWithRetryChecksEventuallyFails() {
ResultSet abortResponse = createAbortResponse(false);
when(cqlSession.execute(abortStatement)).thenReturn(abortResponse);
Row row = mock(Row.class);
ResultSet checkResponse = createSelectResponse(ImmutableList.of(row));
when(cqlSession.execute(checkStatement)).thenReturn(checkResponse);
Stream<TransactionTableEntry> entries = Stream.of(TransactionTableEntries.committedLegacy(100L, 101L));
assertThatThrownBy(() -> transactionAborter.executeTransactionAborts(transactionInteraction, preparedAbortStatement, preparedCheckStatement, entries)).isInstanceOf(IllegalStateException.class);
verify(cqlSession, times(3)).execute(abortStatement);
verify(cqlSession, times(3)).execute(checkStatement);
}
use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.
the class TransactionAborterTest method executeWithRetryChecksIfAbortWasNotAppliedAndRetriesIfNoMatch.
@Test
public void executeWithRetryChecksIfAbortWasNotAppliedAndRetriesIfNoMatch() {
ResultSet abortResponse1 = createAbortResponse(false);
ResultSet abortResponse2 = createAbortResponse(true);
when(cqlSession.execute(abortStatement)).thenReturn(abortResponse1).thenReturn(abortResponse2);
Row row = mock(Row.class);
ResultSet checkResponse = createSelectResponse(ImmutableList.of(row));
when(cqlSession.execute(checkStatement)).thenReturn(checkResponse);
Stream<TransactionTableEntry> entries = Stream.of(TransactionTableEntries.committedLegacy(100L, 101L));
transactionAborter.executeTransactionAborts(transactionInteraction, preparedAbortStatement, preparedCheckStatement, entries);
verify(cqlSession, times(2)).execute(abortStatement);
verify(cqlSession).execute(checkStatement);
}
use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.
the class TransactionAborterTest method executeWithRetryChecksIfAbortWasNotAppliedAndDoesNotRetryIfEqualsAbortTimestamp.
@Test
public void executeWithRetryChecksIfAbortWasNotAppliedAndDoesNotRetryIfEqualsAbortTimestamp() {
ResultSet abortResponse = createAbortResponse(false);
when(cqlSession.execute(abortStatement)).thenReturn(abortResponse);
Row row = mock(Row.class);
ResultSet checkResponse = createSelectResponse(ImmutableList.of(row));
TransactionTableEntry entry = TransactionTableEntries.explicitlyAborted(100L);
when(cqlSession.execute(checkStatement)).thenReturn(checkResponse);
when(transactionInteraction.extractTimestamps(row)).thenReturn(entry);
TransactionTableEntry notYetAborted = TransactionTableEntries.committedLegacy(100L, 101L);
Stream<TransactionTableEntry> entries = Stream.of(notYetAborted);
transactionAborter.executeTransactionAborts(transactionInteraction, preparedAbortStatement, preparedCheckStatement, entries);
verify(cqlSession, times(1)).execute(abortStatement);
verify(cqlSession, times(1)).execute(checkStatement);
}
Aggregations