Search in sources :

Example 21 with TableMetadata

use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.

the class AbstractTransactionTest method testTableMetadata.

@Test
public void testTableMetadata() {
    keyValueService.dropTable(TEST_TABLE);
    keyValueService.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA);
    byte[] metadataForTable = keyValueService.getMetadataForTable(TEST_TABLE);
    assertTrue(metadataForTable == null || Arrays.equals(AtlasDbConstants.GENERIC_TABLE_METADATA, metadataForTable));
    byte[] bytes = new TableMetadata().persistToBytes();
    keyValueService.putMetadataForTable(TEST_TABLE, bytes);
    byte[] bytesRead = keyValueService.getMetadataForTable(TEST_TABLE);
    assertTrue(Arrays.equals(bytes, bytesRead));
    bytes = new TableDefinition() {

        {
            rowName();
            rowComponent("row", ValueType.FIXED_LONG);
            columns();
            column("col", "c", ValueType.VAR_STRING);
            conflictHandler(ConflictHandler.RETRY_ON_VALUE_CHANGED);
            negativeLookups();
            rangeScanAllowed();
            sweepStrategy(TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
            explicitCompressionRequested();
            explicitCompressionBlockSizeKB(128);
        }
    }.toTableMetadata().persistToBytes();
    keyValueService.putMetadataForTable(TEST_TABLE, bytes);
    bytesRead = keyValueService.getMetadataForTable(TEST_TABLE);
    assertTrue(Arrays.equals(bytes, bytesRead));
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) Test(org.junit.Test)

Example 22 with TableMetadata

use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.

the class TransactionTestSetup method setUp.

@Before
public void setUp() throws Exception {
    lockService = LockServiceImpl.create(LockServerOptions.builder().isStandaloneServer(false).build());
    lockClient = LockClient.of("test_client");
    keyValueService = getKeyValueService();
    keyValueService.createTables(ImmutableMap.of(TEST_TABLE_THOROUGH, new TableMetadata(new NameMetadataDescription(), new ColumnMetadataDescription(), ConflictHandler.RETRY_ON_WRITE_WRITE, TableMetadataPersistence.CachePriority.WARM, true, 4, true, TableMetadataPersistence.SweepStrategy.THOROUGH, false, TableMetadataPersistence.LogSafety.UNSAFE).persistToBytes(), TEST_TABLE, new TableMetadata(new NameMetadataDescription(), new ColumnMetadataDescription(), ConflictHandler.RETRY_ON_WRITE_WRITE, TableMetadataPersistence.CachePriority.WARM, true, 4, true, TableMetadataPersistence.SweepStrategy.NOTHING, false, TableMetadataPersistence.LogSafety.UNSAFE).persistToBytes(), TransactionConstants.TRANSACTION_TABLE, TransactionConstants.TRANSACTION_TABLE_METADATA.persistToBytes()));
    keyValueService.truncateTables(ImmutableSet.of(TEST_TABLE, TransactionConstants.TRANSACTION_TABLE));
    timestampService = new InMemoryTimestampService();
    transactionService = TransactionServices.createTransactionService(keyValueService);
    conflictDetectionManager = ConflictDetectionManagers.createWithoutWarmingCache(keyValueService);
    sweepStrategyManager = SweepStrategyManagers.createDefault(keyValueService);
    txMgr = getManager();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) Before(org.junit.Before)

Example 23 with TableMetadata

use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.

the class OneNodeDownMetadataTest method putMetadataForTablesThrows.

@Test
public void putMetadataForTablesThrows() {
    TableMetadata newTableMetadata = new TableMetadata(new NameMetadataDescription(), new ColumnMetadataDescription(), ConflictHandler.IGNORE_ALL);
    assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.putMetadataForTables(ImmutableMap.of(OneNodeDownTestSuite.TEST_TABLE, newTableMetadata.persistToBytes()))).isExactlyInstanceOf(AtlasDbDependencyException.class).hasCauseInstanceOf(IllegalStateException.class).hasStackTraceContaining("At schema version UNREACHABLE");
    canGetMetadataForTable();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) Test(org.junit.Test)

Example 24 with TableMetadata

use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.

the class OneNodeDownMetadataTest method putMetadataForTableThrows.

@Test
public void putMetadataForTableThrows() {
    TableMetadata newTableMetadata = new TableMetadata(new NameMetadataDescription(), new ColumnMetadataDescription(), ConflictHandler.IGNORE_ALL);
    assertThatThrownBy(() -> OneNodeDownTestSuite.kvs.putMetadataForTable(OneNodeDownTestSuite.TEST_TABLE, newTableMetadata.persistToBytes())).isExactlyInstanceOf(AtlasDbDependencyException.class).hasCauseInstanceOf(IllegalStateException.class).hasStackTraceContaining("At schema version UNREACHABLE");
    canGetMetadataForTable();
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) Test(org.junit.Test)

Example 25 with TableMetadata

use of com.palantir.atlasdb.table.description.TableMetadata in project atlasdb by palantir.

the class CqlKeyValueServices method createTableWithSettings.

void createTableWithSettings(TableReference tableRef, byte[] rawMetadata, CqlKeyValueService kvs) {
    StringBuilder queryBuilder = new StringBuilder();
    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;
    }
    queryBuilder.append("CREATE TABLE IF NOT EXISTS " + kvs.getFullTableName(tableRef) + " ( " + kvs.fieldNameProvider.row() + " blob, " + kvs.fieldNameProvider.column() + " blob, " + kvs.fieldNameProvider.timestamp() + " bigint, " + kvs.fieldNameProvider.value() + " blob, " + "PRIMARY KEY (" + kvs.fieldNameProvider.row() + ", " + kvs.fieldNameProvider.column() + ", " + kvs.fieldNameProvider.timestamp() + ")) " + "WITH COMPACT STORAGE ");
    queryBuilder.append("AND " + "bloom_filter_fp_chance = " + falsePositiveChance + " ");
    queryBuilder.append("AND caching = '{\"keys\":\"ALL\", \"rows_per_partition\":\"ALL\"}' ");
    if (appendHeavyAndReadLight) {
        queryBuilder.append("AND compaction = { 'class': '" + CassandraConstants.SIZE_TIERED_COMPACTION_STRATEGY + "'} ");
    } else {
        queryBuilder.append("AND compaction = {'sstable_size_in_mb': '80', 'class': '" + CassandraConstants.LEVELED_COMPACTION_STRATEGY + "'} ");
    }
    queryBuilder.append("AND compression = {'chunk_length_kb': '" + chunkLength + "', " + "'sstable_compression': '" + CassandraConstants.DEFAULT_COMPRESSION_TYPE + "'}");
    queryBuilder.append("AND CLUSTERING ORDER BY (" + kvs.fieldNameProvider.column() + " ASC, " + kvs.fieldNameProvider.timestamp() + " ASC) ");
    BoundStatement createTableStatement = kvs.getPreparedStatement(tableRef, queryBuilder.toString(), kvs.longRunningQuerySession).setConsistencyLevel(ConsistencyLevel.ALL).bind();
    try {
        ResultSet resultSet = kvs.longRunningQuerySession.execute(createTableStatement);
        logTracedQuery(queryBuilder.toString(), resultSet, kvs.session, kvs.cqlStatementCache.normalQuery);
    } catch (Throwable t) {
        throw Throwables.throwUncheckedException(t);
    }
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ResultSet(com.datastax.driver.core.ResultSet) BoundStatement(com.datastax.driver.core.BoundStatement)

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