Search in sources :

Example 1 with InternalSchemaMetadataState

use of com.palantir.atlasdb.internalschema.InternalSchemaMetadataState in project atlasdb by palantir.

the class CoordinationServiceRecorder method storeFastForwardState.

public void storeFastForwardState(CompletedBackup completedBackup) {
    Namespace namespace = completedBackup.getNamespace();
    Optional<InternalSchemaMetadataState> maybeMetadata = fetchSchemaMetadata(namespace, completedBackup.getBackupEndTimestamp());
    maybeMetadata.ifPresentOrElse(metadata -> backupPersister.storeSchemaMetadata(namespace, metadata), () -> logEmptyMetadata(namespace));
}
Also used : InternalSchemaMetadataState(com.palantir.atlasdb.internalschema.InternalSchemaMetadataState) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Example 2 with InternalSchemaMetadataState

use of com.palantir.atlasdb.internalschema.InternalSchemaMetadataState in project atlasdb by palantir.

the class ExternalBackupPersisterTest method putAndGetSchemaMetadata.

@Test
public void putAndGetSchemaMetadata() {
    InternalSchemaMetadata internalSchemaMetadata = InternalSchemaMetadata.defaultValue();
    InternalSchemaMetadataState state = InternalSchemaMetadataState.of(ValueAndBound.of(internalSchemaMetadata, 100L));
    externalBackupPersister.storeSchemaMetadata(ATLAS_SERVICE, state);
    assertThat(externalBackupPersister.getSchemaMetadata(ATLAS_SERVICE)).contains(state);
}
Also used : InternalSchemaMetadataState(com.palantir.atlasdb.internalschema.InternalSchemaMetadataState) InternalSchemaMetadata(com.palantir.atlasdb.internalschema.InternalSchemaMetadata) Test(org.junit.Test)

Example 3 with InternalSchemaMetadataState

use of com.palantir.atlasdb.internalschema.InternalSchemaMetadataState in project atlasdb by palantir.

the class ExternalBackupPersisterTest method testLegacyCasing.

@Test
public void testLegacyCasing() throws IOException {
    String legacyState = "{\"value\":{\"value\":{\"timestampToTransactionsTableSchemaVersion\":{\"timestampMappings" + "\":[{\"longRange\":{\"lower-endpoint\":1316020054,\"lower-bound-type\":\"CLOSED\"},\"value\":3},{\"longRange\":{\"lower-endpoint\":1,\"lower-bound-type\":\"CLOSED\",\"upper-endpoint\":1316020054,\"upper-bound-type\":\"OPEN\"},\"value\":1}]}},\"bound\":1318613869}}";
    File tempFile = tempFolder.newFile();
    Files.copy(new ByteArrayInputStream(legacyState.getBytes(StandardCharsets.UTF_8)), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    InternalSchemaMetadataState parsed = externalBackupPersister.loadFromFile(ATLAS_SERVICE, tempFile, InternalSchemaMetadataState.class).get();
    assertThat(parsed).isNotNull();
}
Also used : InternalSchemaMetadataState(com.palantir.atlasdb.internalschema.InternalSchemaMetadataState) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) Test(org.junit.Test)

Example 4 with InternalSchemaMetadataState

use of com.palantir.atlasdb.internalschema.InternalSchemaMetadataState in project atlasdb by palantir.

the class CoordinationServiceUtilitiesTest method cleanMultipleRangesWithSchemasWithinBounds.

@Test
public void cleanMultipleRangesWithSchemasWithinBounds() {
    final long migrateToTxns2 = IMMUTABLE_TIMESTAMP + FASTFORWARD_TIMESTAMP / 2;
    Map<Range<Long>, Integer> rangesWithSchemas = ImmutableMap.of(Range.closedOpen(AtlasDbConstants.STARTING_TS, migrateToTxns2), 1, Range.atLeast(migrateToTxns2), 2);
    final long coordServiceBound = FASTFORWARD_TIMESTAMP + 1000L;
    Optional<InternalSchemaMetadataState> coordService = createCoordService(rangesWithSchemas, coordServiceBound);
    List<TransactionsTableInteraction> txnInteractions = TransactionsTableInteraction.getTransactionTableInteractions(CoordinationServiceUtilities.getCoordinationMapOnRestore(coordService, FASTFORWARD_TIMESTAMP, IMMUTABLE_TIMESTAMP), POLICY);
    assertThat(txnInteractions).hasSize(2);
    TransactionsTableInteraction txn1 = txnInteractions.stream().filter(txn -> txn instanceof Transactions1TableInteraction).findFirst().get();
    TransactionsTableInteraction txn2 = txnInteractions.stream().filter(txn -> txn instanceof Transactions2TableInteraction).findFirst().get();
    assertThat(txn1).extracting(TransactionsTableInteraction::getTimestampRange).isEqualTo(FullyBoundedTimestampRange.of(Range.closedOpen(IMMUTABLE_TIMESTAMP, migrateToTxns2)));
    assertThat(txn2).extracting(TransactionsTableInteraction::getTimestampRange).isEqualTo(FullyBoundedTimestampRange.of(Range.closed(migrateToTxns2, FASTFORWARD_TIMESTAMP)));
}
Also used : InternalSchemaMetadataState(com.palantir.atlasdb.internalschema.InternalSchemaMetadataState) Transactions2TableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.Transactions2TableInteraction) Transactions1TableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.Transactions1TableInteraction) Range(com.google.common.collect.Range) FullyBoundedTimestampRange(com.palantir.timestamp.FullyBoundedTimestampRange) TransactionsTableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.TransactionsTableInteraction) Test(org.junit.Test)

Example 5 with InternalSchemaMetadataState

use of com.palantir.atlasdb.internalschema.InternalSchemaMetadataState 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

InternalSchemaMetadataState (com.palantir.atlasdb.internalschema.InternalSchemaMetadataState)5 Test (org.junit.Test)4 InternalSchemaMetadata (com.palantir.atlasdb.internalschema.InternalSchemaMetadata)2 FullyBoundedTimestampRange (com.palantir.timestamp.FullyBoundedTimestampRange)2 Range (com.google.common.collect.Range)1 Transactions1TableInteraction (com.palantir.atlasdb.cassandra.backup.transaction.Transactions1TableInteraction)1 Transactions2TableInteraction (com.palantir.atlasdb.cassandra.backup.transaction.Transactions2TableInteraction)1 TransactionsTableInteraction (com.palantir.atlasdb.cassandra.backup.transaction.TransactionsTableInteraction)1 Namespace (com.palantir.atlasdb.timelock.api.Namespace)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1