use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class CassandraKeyValueServiceImpl method filterOutNoOpMetadataChanges.
private Map<TableReference, byte[]> filterOutNoOpMetadataChanges(final Map<TableReference, byte[]> tableNamesToTableMetadata) {
Map<TableReference, byte[]> existingTableMetadata = getMetadataForTables();
Map<TableReference, byte[]> tableMetadataUpdates = Maps.newHashMap();
for (Entry<TableReference, byte[]> entry : tableNamesToTableMetadata.entrySet()) {
TableReference tableReference = entry.getKey();
byte[] newMetadata = entry.getValue();
// if no existing table or if existing table's metadata is different
if (metadataIsDifferent(existingTableMetadata.get(tableReference), newMetadata)) {
Set<TableReference> matchingTables = Sets.filter(existingTableMetadata.keySet(), existingTableRef -> existingTableRef.getQualifiedName().equalsIgnoreCase(tableReference.getQualifiedName()));
// completely new table, not an update
if (matchingTables.isEmpty()) {
tableMetadataUpdates.put(tableReference, newMetadata);
} else {
// existing case-insensitive table, maybe an update
if (Arrays.equals(existingTableMetadata.get(Iterables.getOnlyElement(matchingTables)), newMetadata)) {
log.debug("Case-insensitive matched table already existed with same metadata," + " skipping update to {}", LoggingArgs.tableRef(tableReference));
} else {
// existing table has different metadata, so we should perform an update
tableMetadataUpdates.put(tableReference, newMetadata);
}
}
} else {
log.debug("Table already existed with same metadata, skipping update to {}", LoggingArgs.tableRef(tableReference));
}
}
return tableMetadataUpdates;
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class CassandraSchemaLockTest method shouldCreateTablesConsistentlyWithMultipleCassandraNodes.
@Test
public void shouldCreateTablesConsistentlyWithMultipleCassandraNodes() throws Exception {
TableReference table1 = TableReference.createFromFullyQualifiedName("ns.table1");
CassandraKeyValueServiceConfig config = ThreeNodeCassandraCluster.KVS_CONFIG;
try {
CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);
for (int i = 0; i < THREAD_COUNT; i++) {
async(() -> {
CassandraKeyValueService keyValueService = CassandraKeyValueServiceImpl.create(config, Optional.empty());
barrier.await();
keyValueService.createTable(table1, AtlasDbConstants.GENERIC_TABLE_METADATA);
return null;
});
}
} finally {
executorService.shutdown();
assertTrue(executorService.awaitTermination(4, TimeUnit.MINUTES));
}
CassandraKeyValueService kvs = CassandraKeyValueServiceImpl.create(config, Optional.empty());
assertThat(kvs.getAllTableNames(), hasItem(table1));
assertThat(new File(CONTAINERS.getLogDirectory()), containsFiles(everyItem(doesNotContainTheColumnFamilyIdMismatchError())));
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class CassandraKeyValueServiceIntegrationTest method testCreateTableCaseInsensitive.
@Test
public void testCreateTableCaseInsensitive() throws TException {
TableReference table1 = TableReference.createFromFullyQualifiedName("ns.tAbLe");
TableReference table2 = TableReference.createFromFullyQualifiedName("ns.table");
TableReference table3 = TableReference.createFromFullyQualifiedName("ns.TABle");
keyValueService.createTable(table1, AtlasDbConstants.GENERIC_TABLE_METADATA);
keyValueService.createTable(table2, AtlasDbConstants.GENERIC_TABLE_METADATA);
keyValueService.createTable(table3, AtlasDbConstants.GENERIC_TABLE_METADATA);
Set<TableReference> allTables = keyValueService.getAllTableNames();
Preconditions.checkArgument(allTables.contains(table1));
Preconditions.checkArgument(!allTables.contains(table2));
Preconditions.checkArgument(!allTables.contains(table3));
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class StreamTableTypeTest method getIndexTableFromValueTableWorksWithTableWithEmptyNamespace.
@Test
public void getIndexTableFromValueTableWorksWithTableWithEmptyNamespace() {
String valueTableName = StreamTableType.VALUE.getTableName(TEST_TABLE);
TableReference valueTable = TableReference.createWithEmptyNamespace(valueTableName);
String indexTableName = StreamTableType.INDEX.getTableName(TEST_TABLE);
TableReference expectedIndexTable = TableReference.createWithEmptyNamespace(indexTableName);
TableReference indexTableFromValueTable = StreamTableType.getIndexTableFromValueTable(valueTable);
assertThat(indexTableFromValueTable).isNotEqualTo(valueTable);
assertEquals(expectedIndexTable, indexTableFromValueTable);
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class StreamTableTypeTest method getIndexTableFromValueTableWorksWithTableWithNamespace.
@Test
public void getIndexTableFromValueTableWorksWithTableWithNamespace() {
String valueTableName = StreamTableType.VALUE.getTableName(TEST_TABLE);
TableReference valueTable = TableReference.create(TEST_NAMESPACE, valueTableName);
String indexTableName = StreamTableType.INDEX.getTableName(TEST_TABLE);
TableReference expectedIndexTable = TableReference.create(TEST_NAMESPACE, indexTableName);
TableReference indexTableFromValueTable = StreamTableType.getIndexTableFromValueTable(valueTable);
assertThat(indexTableFromValueTable).isNotEqualTo(valueTable);
assertEquals(expectedIndexTable, indexTableFromValueTable);
}
Aggregations