Search in sources :

Example 11 with TableMetadata

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();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata)

Example 12 with TableMetadata

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);
    }
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 13 with TableMetadata

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();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata)

Example 14 with TableMetadata

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();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Example 15 with TableMetadata

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;
    }
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata)

Aggregations

TableMetadata (com.palantir.atlasdb.table.description.TableMetadata)26 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ColumnMetadataDescription (com.palantir.atlasdb.table.description.ColumnMetadataDescription)6 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)5 Test (org.junit.Test)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)4 BoundStatement (com.datastax.driver.core.BoundStatement)2 TableCell (com.palantir.atlasdb.api.TableCell)2 NamedColumnDescription (com.palantir.atlasdb.table.description.NamedColumnDescription)2 ResultSet (com.datastax.driver.core.ResultSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 TableCellVal (com.palantir.atlasdb.api.TableCellVal)1 TableRange (com.palantir.atlasdb.api.TableRange)1 TableRowResult (com.palantir.atlasdb.api.TableRowResult)1 TableRowSelection (com.palantir.atlasdb.api.TableRowSelection)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)1 TableMetadataPersistence (com.palantir.atlasdb.protos.generated.TableMetadataPersistence)1 DynamicColumnDescription (com.palantir.atlasdb.table.description.DynamicColumnDescription)1 TableDefinition (com.palantir.atlasdb.table.description.TableDefinition)1