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));
}
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);
}
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();
}
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)));
}
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);
}
Aggregations