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