use of com.palantir.atlasdb.table.description.TableDefinition in project atlasdb by palantir.
the class StreamTestSchema method generateSchema.
private static Schema generateSchema() {
Schema schema = new Schema("StreamTest", StreamTestSchema.class.getPackage().getName() + ".generated", Namespace.DEFAULT_NAMESPACE, OptionalType.JAVA8);
schema.addTableDefinition("blobs", new TableDefinition() {
{
javaTableName("KeyValue");
rangeScanAllowed();
rowName();
rowComponent("key", ValueType.STRING);
columns();
column("streamId", "s", ValueType.VAR_LONG);
}
});
schema.addStreamStoreDefinition(new StreamStoreDefinitionBuilder("blob", "Value", ValueType.VAR_LONG).inMemoryThreshold(1024 * 1024).tableNameLogSafety(TableMetadataPersistence.LogSafety.SAFE).build());
return schema;
}
use of com.palantir.atlasdb.table.description.TableDefinition 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.TableDefinition in project atlasdb by palantir.
the class TableMigratorTest method testMigrationToDifferentKvs.
// Table/IndexDefinition syntax
@SuppressWarnings({ "checkstyle:Indentation", "checkstyle:RightCurly" })
@Test
public void testMigrationToDifferentKvs() throws TableMappingNotFoundException {
final TableReference tableRef = TableReference.create(Namespace.DEFAULT_NAMESPACE, "table");
final TableReference namespacedTableRef = TableReference.createFromFullyQualifiedName("namespace." + tableRef.getTablename());
TableDefinition definition = new TableDefinition() {
{
rowName();
rowComponent("r", ValueType.BLOB);
columns();
column("c", "c", ValueType.BLOB);
}
};
keyValueService.createTable(tableRef, definition.toTableMetadata().persistToBytes());
keyValueService.createTable(namespacedTableRef, definition.toTableMetadata().persistToBytes());
keyValueService.putMetadataForTable(namespacedTableRef, definition.toTableMetadata().persistToBytes());
final Cell theCell = Cell.create(PtBytes.toBytes("r1"), PtBytes.toBytes("c"));
final byte[] theValue = PtBytes.toBytes("v1");
txManager.runTaskWithRetry((TransactionTask<Void, RuntimeException>) txn -> {
Map<Cell, byte[]> values = ImmutableMap.of(theCell, theValue);
txn.put(tableRef, values);
txn.put(namespacedTableRef, values);
return null;
});
final InMemoryKeyValueService kvs2 = new InMemoryKeyValueService(false);
final ConflictDetectionManager cdm2 = ConflictDetectionManagers.createWithNoConflictDetection();
final SweepStrategyManager ssm2 = SweepStrategyManagers.completelyConservative(kvs2);
final TestTransactionManagerImpl txManager2 = new TestTransactionManagerImpl(kvs2, timestampService, lockClient, lockService, transactionService, cdm2, ssm2, MultiTableSweepQueueWriter.NO_OP);
kvs2.createTable(tableRef, definition.toTableMetadata().persistToBytes());
kvs2.createTable(namespacedTableRef, definition.toTableMetadata().persistToBytes());
TableReference checkpointTable = TableReference.create(Namespace.DEFAULT_NAMESPACE, "checkpoint");
GeneralTaskCheckpointer checkpointer = new GeneralTaskCheckpointer(checkpointTable, kvs2, txManager2);
for (final TableReference name : Lists.newArrayList(tableRef, namespacedTableRef)) {
TransactionRangeMigrator rangeMigrator = new TransactionRangeMigratorBuilder().srcTable(name).readTxManager(txManager).txManager(txManager2).checkpointer(checkpointer).build();
TableMigratorBuilder builder = new TableMigratorBuilder().srcTable(name).partitions(1).executor(PTExecutors.newSingleThreadExecutor()).checkpointer(checkpointer).rangeMigrator(rangeMigrator);
TableMigrator migrator = builder.build();
migrator.migrate();
}
checkpointer.deleteCheckpoints();
final ConflictDetectionManager verifyCdm = ConflictDetectionManagers.createWithNoConflictDetection();
final SweepStrategyManager verifySsm = SweepStrategyManagers.completelyConservative(kvs2);
final TestTransactionManagerImpl verifyTxManager = new TestTransactionManagerImpl(kvs2, timestampService, lockClient, lockService, transactionService, verifyCdm, verifySsm, MultiTableSweepQueueWriter.NO_OP);
final MutableLong count = new MutableLong();
for (final TableReference name : Lists.newArrayList(tableRef, namespacedTableRef)) {
verifyTxManager.runTaskReadOnly((TransactionTask<Void, RuntimeException>) txn -> {
BatchingVisitable<RowResult<byte[]>> bv = txn.getRange(name, RangeRequest.all());
bv.batchAccept(1000, AbortingVisitors.batching(new AbortingVisitor<RowResult<byte[]>, RuntimeException>() {
@Override
public boolean visit(RowResult<byte[]> item) throws RuntimeException {
Iterable<Entry<Cell, byte[]>> cells = item.getCells();
Entry<Cell, byte[]> entry = Iterables.getOnlyElement(cells);
Assert.assertEquals(theCell, entry.getKey());
Assert.assertArrayEquals(theValue, entry.getValue());
count.increment();
return true;
}
}));
return null;
});
}
Assert.assertEquals(2L, count.longValue());
}
use of com.palantir.atlasdb.table.description.TableDefinition in project atlasdb by palantir.
the class ProfileSchema method generateSchema.
private static Schema generateSchema() {
Schema schema = new Schema("Profile", ProfileSchema.class.getPackage().getName() + ".generated", Namespace.DEFAULT_NAMESPACE, OptionalType.JAVA8);
schema.addTableDefinition("user_profile", new TableDefinition() {
{
allSafeForLoggingByDefault();
rowName();
rowComponent("id", ValueType.UUID);
columns();
column("metadata", "m", ProfilePersistence.UserProfile.class);
column("create", "c", CreationData.Persister.class);
column("json", "j", JsonNodePersister.class);
column("photo_stream_id", "p", ValueType.FIXED_LONG);
}
});
schema.addIndexDefinition("user_birthdays", new IndexDefinition(IndexType.CELL_REFERENCING) {
{
onTable("user_profile");
allSafeForLoggingByDefault();
rowName();
componentFromColumn("birthday", ValueType.VAR_SIGNED_LONG, "metadata", "_value.getBirthEpochDay()");
dynamicColumns();
componentFromRow("id", ValueType.UUID);
rangeScanAllowed();
ignoreHotspottingChecks();
}
});
schema.addIndexDefinition("created", new IndexDefinition(IndexType.CELL_REFERENCING) {
{
onTable("user_profile");
allSafeForLoggingByDefault();
rowName();
componentFromColumn("time", ValueType.VAR_LONG, "create", "_value.getTimeCreated()");
dynamicColumns();
componentFromRow("id", ValueType.UUID);
rangeScanAllowed();
ignoreHotspottingChecks();
}
});
schema.addIndexDefinition("cookies", new IndexDefinition(IndexType.CELL_REFERENCING) {
{
onTable("user_profile");
allSafeForLoggingByDefault();
rowName();
componentFromIterableColumn("cookie", ValueType.STRING, ValueByteOrder.ASCENDING, "json", "com.palantir.example.profile.schema.ProfileSchema.getCookies(_value)");
dynamicColumns();
componentFromRow("id", ValueType.UUID);
rangeScanAllowed();
}
});
schema.addStreamStoreDefinition(new StreamStoreDefinitionBuilder("user_photos", "user_photos", ValueType.VAR_LONG).tableNameLogSafety(TableMetadataPersistence.LogSafety.SAFE).build());
return schema;
}
use of com.palantir.atlasdb.table.description.TableDefinition in project atlasdb by palantir.
the class BenchmarksSchema method createTables.
private static void createTables(Schema schema) {
schema.addTableDefinition("KvRows", new TableDefinition() {
{
rowName();
hashFirstRowComponent();
rowComponent("bucket", ValueType.VAR_STRING);
rowComponent("key", ValueType.FIXED_LONG);
columns();
column("data", "d", ValueType.BLOB);
rangeScanAllowed();
}
});
schema.addTableDefinition("KvDynamicColumns", new TableDefinition() {
{
rowName();
hashFirstRowComponent();
rowComponent("bucket", ValueType.VAR_STRING);
dynamicColumns();
columnComponent("key", ValueType.FIXED_LONG);
value(ValueType.BLOB);
rangeScanAllowed();
}
});
schema.addTableDefinition("Blobs", new TableDefinition() {
{
rowName();
rowComponent("key", ValueType.BLOB);
columns();
column("data", "d", ValueType.BLOB);
}
});
schema.addTableDefinition("BlobsSerializable", new TableDefinition() {
{
conflictHandler(ConflictHandler.SERIALIZABLE);
rowName();
rowComponent("key", ValueType.BLOB);
columns();
column("data", "d", ValueType.BLOB);
}
});
schema.addTableDefinition("Metadata", new TableDefinition() {
{
rowName();
hashFirstRowComponent();
rowComponent("key", ValueType.VAR_STRING);
columns();
column("data", "d", ValueType.BLOB);
rangeScanAllowed();
}
});
}
Aggregations