Search in sources :

Example 6 with TransactionTableEntry

use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.

the class TransactionAborter method tryAbortTransactions.

private boolean tryAbortTransactions(String keyspace, 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", keyspace));
    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", keyspace));
    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", keyspace));
    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 7 with TransactionTableEntry

use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.

the class TransactionAborter method abortTransactions.

private void abortTransactions(CqlMetadata clusterMetadata, String keyspaceName, long timestamp, TransactionsTableInteraction txnInteraction) {
    log.info("Aborting transactions after backup timestamp", SafeArg.of("backupTimestamp", timestamp), SafeArg.of("keyspace", keyspaceName), SafeArg.of("table", txnInteraction.getTransactionsTableName()));
    TableMetadata transactionsTable = ClusterMetadataUtils.getTableMetadata(clusterMetadata, keyspaceName, txnInteraction.getTransactionsTableName());
    PreparedStatement preparedAbortStatement = txnInteraction.prepareAbortStatement(transactionsTable, cqlSession);
    PreparedStatement preparedCheckStatement = txnInteraction.prepareCheckStatement(transactionsTable, cqlSession);
    Stream<TransactionTableEntry> keysToAbort = getTransactionsToAbort(keyspaceName, txnInteraction, transactionsTable, timestamp);
    executeTransactionAborts(keyspaceName, txnInteraction, preparedAbortStatement, preparedCheckStatement, keysToAbort);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) TransactionTableEntry(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry) PreparedStatement(com.datastax.driver.core.PreparedStatement)

Example 8 with TransactionTableEntry

use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.

the class TransactionAborterTest method executeWithRetryTriesSingleTimeIfAbortSucceeds.

@Test
public void executeWithRetryTriesSingleTimeIfAbortSucceeds() {
    ResultSet abortResponse = createAbortResponse(true);
    when(cqlSession.execute(abortStatement)).thenReturn(abortResponse);
    Stream<TransactionTableEntry> entries = Stream.of(TransactionTableEntries.committedLegacy(100L, 101L));
    transactionAborter.executeTransactionAborts(transactionInteraction, preparedAbortStatement, preparedCheckStatement, entries);
    verify(cqlSession).execute(abortStatement);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) TransactionTableEntry(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry) Test(org.junit.Test)

Example 9 with TransactionTableEntry

use of com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry in project atlasdb by palantir.

the class TransactionAborter method abortTransactions.

private void abortTransactions(CqlMetadata clusterMetadata, long timestamp, TransactionsTableInteraction txnInteraction) {
    log.info("Aborting transactions after backup timestamp", SafeArg.of("backupTimestamp", timestamp), SafeArg.of("keyspace", namespace), SafeArg.of("table", txnInteraction.getTransactionsTableName()));
    TableMetadata transactionsTable = ClusterMetadataUtils.getTableMetadata(clusterMetadata, namespace, txnInteraction.getTransactionsTableName());
    PreparedStatement preparedAbortStatement = txnInteraction.prepareAbortStatement(transactionsTable, cqlSession);
    PreparedStatement preparedCheckStatement = txnInteraction.prepareCheckStatement(transactionsTable, cqlSession);
    Stream<TransactionTableEntry> keysToAbort = getTransactionsToAbort(txnInteraction, transactionsTable, timestamp);
    executeTransactionAborts(txnInteraction, preparedAbortStatement, preparedCheckStatement, keysToAbort);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) TransactionTableEntry(com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry) PreparedStatement(com.datastax.driver.core.PreparedStatement)

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