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