use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.
the class TableRowResultSerializer method serialize.
@Override
public void serialize(TableRowResult value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
TableMetadata metadata = metadataCache.getMetadata(value.getTableName());
Preconditions.checkNotNull(metadata, "Unknown table %s", value.getTableName());
jgen.writeStartObject();
jgen.writeStringField("table", value.getTableName());
jgen.writeArrayFieldStart("data");
for (RowResult<byte[]> result : value.getResults()) {
serialize(jgen, metadata, result);
}
jgen.writeEndArray();
jgen.writeEndObject();
}
use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.
the class CqlKeyValueServices method setSettingsForTable.
static void setSettingsForTable(TableReference tableRef, byte[] rawMetadata, CqlKeyValueService kvs) {
int explicitCompressionBlockSizeKb = 0;
boolean negativeLookups = false;
double falsePositiveChance = CassandraConstants.DEFAULT_LEVELED_COMPACTION_BLOOM_FILTER_FP_CHANCE;
boolean appendHeavyAndReadLight = false;
if (rawMetadata != null && rawMetadata.length != 0) {
TableMetadata tableMetadata = TableMetadata.BYTES_HYDRATOR.hydrateFromBytes(rawMetadata);
explicitCompressionBlockSizeKb = tableMetadata.getExplicitCompressionBlockSizeKB();
negativeLookups = tableMetadata.hasNegativeLookups();
appendHeavyAndReadLight = tableMetadata.isAppendHeavyAndReadLight();
}
if (negativeLookups) {
falsePositiveChance = CassandraConstants.NEGATIVE_LOOKUPS_BLOOM_FILTER_FP_CHANCE;
} else if (appendHeavyAndReadLight) {
falsePositiveChance = CassandraConstants.DEFAULT_SIZE_TIERED_COMPACTION_BLOOM_FILTER_FP_CHANCE;
}
int chunkLength = AtlasDbConstants.MINIMUM_COMPRESSION_BLOCK_SIZE_KB;
if (explicitCompressionBlockSizeKb != 0) {
chunkLength = explicitCompressionBlockSizeKb;
}
StringBuilder sb = new StringBuilder();
sb.append("ALTER TABLE " + kvs.getFullTableName(tableRef) + " WITH " + "bloom_filter_fp_chance = " + falsePositiveChance + " ");
sb.append("AND caching = '{\"keys\":\"ALL\", \"rows_per_partition\":\"ALL\"}' ");
if (appendHeavyAndReadLight) {
sb.append("AND compaction = { 'class': '" + CassandraConstants.SIZE_TIERED_COMPACTION_STRATEGY + "'} ");
} else {
sb.append("AND compaction = {'sstable_size_in_mb': '80', 'class': '" + CassandraConstants.LEVELED_COMPACTION_STRATEGY + "'} ");
}
sb.append("AND compression = {'chunk_length_kb': '" + chunkLength + "', " + "'sstable_compression': '" + CassandraConstants.DEFAULT_COMPRESSION_TYPE + "'}");
BoundStatement alterTableStatement = kvs.getPreparedStatement(tableRef, sb.toString(), kvs.longRunningQuerySession).setConsistencyLevel(ConsistencyLevel.ALL).bind();
try {
kvs.longRunningQuerySession.execute(alterTableStatement);
} catch (Throwable t) {
throw Throwables.throwUncheckedException(t);
}
}
use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.
the class SafeLoggableDataUtils method fromTableMetadata.
public static SafeLoggableData fromTableMetadata(Map<TableReference, byte[]> tableRefToMetadata) {
ImmutableSafeLoggableData.Builder builder = ImmutableSafeLoggableData.builder();
tableRefToMetadata.forEach((ref, metadataBytes) -> {
try {
TableMetadata tableMetadata = TableMetadata.BYTES_HYDRATOR.hydrateFromBytes(metadataBytes);
addLoggableNamesToBuilder(builder, ref, tableMetadata);
} catch (Exception e) {
log.warn("Exception thrown hydrating table metadata for table {}.", UnsafeArg.of("tableName", ref), e);
}
});
return builder.build();
}
use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.
the class AtlasConsoleServiceTest method testGetMetadata.
@Test
public void testGetMetadata() throws IOException {
final TableMetadata output = context.mock(TableMetadata.class);
final String table = "t";
context.checking(new Expectations() {
{
oneOf(delegate).getTableMetadata(table);
will(returnValue(output));
}
});
context.checking(toJson(output, TableMetadata.class));
assertEquals(service.getMetadata(table), RESULT);
context.assertIsSatisfied();
}
use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.
the class TableMetadataCache method getOrReturnEmpty.
private TableMetadata getOrReturnEmpty(TableReference tableRef, ConnectionSupplier conns) {
TableMetadata cached = cache.getIfPresent(tableRef);
if (cached != null) {
return cached;
} else {
byte[] rawMetadata = dbTables.createMetadata(tableRef, conns).getMetadata();
TableMetadata hydrated = hydrateMetadata(rawMetadata);
cache.put(tableRef, hydrated);
return hydrated;
}
}
Aggregations