Search in sources :

Example 1 with TransactionTableEntry

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;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) TransactionTableEntry(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry) Row(com.datastax.driver.core.Row)

Example 2 with TransactionTableEntry

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PutUnlessExistsValue(com.palantir.atlasdb.pue.PutUnlessExistsValue) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) TransactionsTableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.TransactionsTableInteraction) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Row(com.datastax.driver.core.Row) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) FullyBoundedTimestampRange(com.palantir.timestamp.FullyBoundedTimestampRange) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) PreparedStatement(com.datastax.driver.core.PreparedStatement) ResultSet(com.datastax.driver.core.ResultSet) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Mockito.doReturn(org.mockito.Mockito.doReturn) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Before(org.junit.Before) TableMetadata(com.datastax.driver.core.TableMetadata) TransactionTableEntries(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntries) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) TransactionTableEntry(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry) List(java.util.List) Stream(java.util.stream.Stream) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) Statement(com.datastax.driver.core.Statement) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) PreparedStatement(com.datastax.driver.core.PreparedStatement) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row)

Example 3 with TransactionTableEntry

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);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) TransactionTableEntry(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 4 with TransactionTableEntry

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);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) TransactionTableEntry(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 5 with TransactionTableEntry

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);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) TransactionTableEntry(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Aggregations

TransactionTableEntry (com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry)9 ResultSet (com.datastax.driver.core.ResultSet)7 Row (com.datastax.driver.core.Row)6 Test (org.junit.Test)5 PreparedStatement (com.datastax.driver.core.PreparedStatement)3 TableMetadata (com.datastax.driver.core.TableMetadata)3 ConsistencyLevel (com.datastax.driver.core.ConsistencyLevel)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 Statement (com.datastax.driver.core.Statement)1 ImmutableList (com.google.common.collect.ImmutableList)1 Range (com.google.common.collect.Range)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)1 TransactionTableEntries (com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntries)1 TransactionsTableInteraction (com.palantir.atlasdb.cassandra.backup.transaction.TransactionsTableInteraction)1 PutUnlessExistsValue (com.palantir.atlasdb.pue.PutUnlessExistsValue)1 Namespace (com.palantir.atlasdb.timelock.api.Namespace)1 FullyBoundedTimestampRange (com.palantir.timestamp.FullyBoundedTimestampRange)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1