Search in sources :

Example 1 with SchemaMetadata

use of com.palantir.atlasdb.schema.SchemaMetadata in project atlasdb by palantir.

the class SchemaMetadataServiceImpl method putSchemaMetadata.

@Override
public void putSchemaMetadata(String schemaName, SchemaMetadata schemaMetadata) {
    byte[] serializedMetadata = schemaMetadata.persistToBytes();
    while (!Thread.currentThread().isInterrupted()) {
        Optional<byte[]> existingMetadata = loadMetadataCellFromKeyValueService(schemaName);
        CheckAndSetRequest request = existingMetadata.map(existingData -> CheckAndSetRequest.singleCell(AtlasDbConstants.DEFAULT_SCHEMA_METADATA_TABLE, createCellForGivenSchemaName(schemaName), existingData, serializedMetadata)).orElse(CheckAndSetRequest.newCell(AtlasDbConstants.DEFAULT_SCHEMA_METADATA_TABLE, createCellForGivenSchemaName(schemaName), serializedMetadata));
        try {
            keyValueService.checkAndSet(request);
            log.info("Successfully updated the schema metadata to {}.", UnsafeArg.of("committedUpdate", request));
            return;
        } catch (CheckAndSetException e) {
            log.info("Failed to update the schema metadata: {}. Retrying.", UnsafeArg.of("attemptedUpdate", request));
        }
    }
}
Also used : Iterables(com.google.common.collect.Iterables) Logger(org.slf4j.Logger) Value(com.palantir.atlasdb.keyvalue.api.Value) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) LoggerFactory(org.slf4j.LoggerFactory) CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest) AutoDelegate(com.palantir.processors.AutoDelegate) Collectors(java.util.stream.Collectors) AsyncInitializer(com.palantir.async.initializer.AsyncInitializer) PtBytes(com.palantir.atlasdb.encoding.PtBytes) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) UnsafeArg(com.palantir.logsafe.UnsafeArg) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) Map(java.util.Map) Optional(java.util.Optional) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) SchemaMetadata(com.palantir.atlasdb.schema.SchemaMetadata) CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException)

Example 2 with SchemaMetadata

use of com.palantir.atlasdb.schema.SchemaMetadata in project atlasdb by palantir.

the class SchemaMetadataServiceImplTest method canDeleteAndRestoreSchemaMetadata.

@Test
public void canDeleteAndRestoreSchemaMetadata() {
    IntStream.range(0, 10).forEach(index -> {
        SchemaMetadata metadataToPut = index % 2 == 0 ? SCHEMA_METADATA_ONE : SCHEMA_METADATA_TWO;
        schemaMetadataService.putSchemaMetadata(SCHEMA_NAME_ONE, metadataToPut);
        assertThat(schemaMetadataService.loadSchemaMetadata(SCHEMA_NAME_ONE)).contains(metadataToPut);
        schemaMetadataService.deleteSchemaMetadata(SCHEMA_NAME_ONE);
        assertThat(schemaMetadataService.loadSchemaMetadata(SCHEMA_NAME_ONE)).isEmpty();
    });
}
Also used : ImmutableSchemaMetadata(com.palantir.atlasdb.schema.ImmutableSchemaMetadata) SchemaMetadata(com.palantir.atlasdb.schema.SchemaMetadata) Test(org.junit.Test)

Aggregations

SchemaMetadata (com.palantir.atlasdb.schema.SchemaMetadata)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Iterables (com.google.common.collect.Iterables)1 AsyncInitializer (com.palantir.async.initializer.AsyncInitializer)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 PtBytes (com.palantir.atlasdb.encoding.PtBytes)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 CheckAndSetException (com.palantir.atlasdb.keyvalue.api.CheckAndSetException)1 CheckAndSetRequest (com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest)1 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)1 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)1 Value (com.palantir.atlasdb.keyvalue.api.Value)1 ImmutableSchemaMetadata (com.palantir.atlasdb.schema.ImmutableSchemaMetadata)1 UnsafeArg (com.palantir.logsafe.UnsafeArg)1 AutoDelegate (com.palantir.processors.AutoDelegate)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1