Search in sources :

Example 1 with FullyBoundedTimestampRange

use of com.palantir.timestamp.FullyBoundedTimestampRange in project atlasdb by palantir.

the class AtlasRestoreService method repairTransactionsTables.

private void repairTransactionsTables(RestoreRequest restoreRequest, CompletedBackup completedBackup, BiConsumer<String, RangesForRepair> repairTable) {
    Map<FullyBoundedTimestampRange, Integer> coordinationMap = getCoordinationMap(restoreRequest.oldAtlasService(), completedBackup);
    List<TransactionsTableInteraction> transactionsTableInteractions = TransactionsTableInteraction.getTransactionTableInteractions(coordinationMap, DefaultRetryPolicy.INSTANCE);
    AtlasService atlasService = restoreRequest.newAtlasService();
    cassandraRepairHelper.repairTransactionsTables(atlasService, transactionsTableInteractions, repairTable);
    cassandraRepairHelper.cleanTransactionsTables(atlasService, completedBackup.getBackupStartTimestamp(), transactionsTableInteractions);
}
Also used : FullyBoundedTimestampRange(com.palantir.timestamp.FullyBoundedTimestampRange) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) TransactionsTableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.TransactionsTableInteraction)

Example 2 with FullyBoundedTimestampRange

use of com.palantir.timestamp.FullyBoundedTimestampRange 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 FullyBoundedTimestampRange

use of com.palantir.timestamp.FullyBoundedTimestampRange in project atlasdb by palantir.

the class CoordinationServiceUtilitiesTest method correctlyBoundsTimestampsForRestore.

// During restores, we need to clean transactions tables in between two timestamps.
// It's possible that, in between _those_ timestamps, AtlasDB changed which transactions
// table to use. This is recorded in InternalSchemaMetadata.
// 
// In this test, we simulate a switch from transactions1 to transactions2 at timestamp 10
// We should return the [5-10] range for transactions1, and the (10-15] range for transactions2.
@Test
public void correctlyBoundsTimestampsForRestore() {
    long lowerBoundForRestore = 5L;
    long maxTimestampForTransactions1 = 10L;
    long upperBoundForRestore = 15L;
    RangeMap<Long, Integer> rangeMap = ImmutableRangeMap.<Long, Integer>builder().put(Range.closed(1L, maxTimestampForTransactions1), 1).put(Range.greaterThan(maxTimestampForTransactions1), 2).build();
    TimestampPartitioningMap<Integer> timestampsMap = TimestampPartitioningMap.of(rangeMap);
    InternalSchemaMetadata metadata = InternalSchemaMetadata.builder().timestampToTransactionsTableSchemaVersion(timestampsMap).build();
    ValueAndBound<InternalSchemaMetadata> value = ValueAndBound.of(metadata, 1000L);
    InternalSchemaMetadataState state = InternalSchemaMetadataState.of(value);
    Map<FullyBoundedTimestampRange, Integer> boundedMap = CoordinationServiceUtilities.getCoordinationMapOnRestore(Optional.of(state), upperBoundForRestore, lowerBoundForRestore);
    Map<FullyBoundedTimestampRange, Integer> expected = ImmutableMap.of(FullyBoundedTimestampRange.of(Range.closed(lowerBoundForRestore, maxTimestampForTransactions1)), 1, FullyBoundedTimestampRange.of(Range.openClosed(maxTimestampForTransactions1, upperBoundForRestore)), 2);
    assertThat(boundedMap).hasSize(2);
    assertThat(boundedMap).containsExactlyInAnyOrderEntriesOf(expected);
}
Also used : FullyBoundedTimestampRange(com.palantir.timestamp.FullyBoundedTimestampRange) InternalSchemaMetadataState(com.palantir.atlasdb.internalschema.InternalSchemaMetadataState) InternalSchemaMetadata(com.palantir.atlasdb.internalschema.InternalSchemaMetadata) Test(org.junit.Test)

Aggregations

FullyBoundedTimestampRange (com.palantir.timestamp.FullyBoundedTimestampRange)3 TransactionsTableInteraction (com.palantir.atlasdb.cassandra.backup.transaction.TransactionsTableInteraction)2 Test (org.junit.Test)2 ConsistencyLevel (com.datastax.driver.core.ConsistencyLevel)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 Statement (com.datastax.driver.core.Statement)1 TableMetadata (com.datastax.driver.core.TableMetadata)1 ImmutableList (com.google.common.collect.ImmutableList)1 Range (com.google.common.collect.Range)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)1 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)1 TransactionTableEntries (com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntries)1 TransactionTableEntry (com.palantir.atlasdb.cassandra.backup.transaction.TransactionTableEntry)1 InternalSchemaMetadata (com.palantir.atlasdb.internalschema.InternalSchemaMetadata)1 InternalSchemaMetadataState (com.palantir.atlasdb.internalschema.InternalSchemaMetadataState)1 PutUnlessExistsValue (com.palantir.atlasdb.pue.PutUnlessExistsValue)1