use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class CassandraKvsWrapperTest method ifWrapperIsInitializedDelegateIsCalled.
@Test
public void ifWrapperIsInitializedDelegateIsCalled() {
when(kvsWrapper.isInitialized()).thenReturn(true);
TableReference tableRef = TableReference.create(Namespace.DEFAULT_NAMESPACE, "test");
kvsWrapper.createTable(tableRef, AtlasDbConstants.GENERIC_TABLE_METADATA);
verify(kvs).createTable(any(TableReference.class), any());
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class CassandraKvsWrapperTest method ifWrapperIsNotInitializedDelegateIsNotCalled.
@Test
public void ifWrapperIsNotInitializedDelegateIsNotCalled() {
when(kvsWrapper.isInitialized()).thenReturn(false);
TableReference tableRef = TableReference.create(Namespace.DEFAULT_NAMESPACE, "test");
assertThatThrownBy(() -> kvsWrapper.createTable(tableRef, AtlasDbConstants.GENERIC_TABLE_METADATA)).isInstanceOf(NotInitializedException.class);
verify(kvs, never()).createTable(any(TableReference.class), any());
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class SchemaMutationLock method queryExistingLockColumn.
private Optional<Column> queryExistingLockColumn(CassandraClient client) throws TException {
TableReference lockTableRef = lockTable.get();
Column existingColumn = null;
ConsistencyLevel localQuorum = ConsistencyLevel.LOCAL_QUORUM;
try {
ColumnOrSuperColumn result = queryRunner.run(client, lockTableRef, () -> client.get(lockTableRef, getGlobalDdlLockRowName(), getGlobalDdlLockColumnName(), localQuorum));
existingColumn = result.getColumn();
} catch (UnavailableException e) {
throw new InsufficientConsistencyException("Checking the schema lock requires " + localQuorum + " Cassandra nodes to be up and available.", e);
} catch (NotFoundException e) {
log.debug("No existing schema lock found in table [{}]", SafeArg.of("tableName", lockTableRef));
}
return Optional.ofNullable(existingColumn);
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class JdbcKeyValueService method addGarbageCollectionSentinelValues.
@Override
public void addGarbageCollectionSentinelValues(final TableReference tableRef, Iterable<Cell> cells) {
int numCells = Iterables.size(cells);
if (numCells == 0) {
return;
}
for (List<Cell> partCells : Iterables.partition(cells, batchSizeForMutations)) {
Long timestamp = Value.INVALID_VALUE_TIMESTAMP;
byte[] value = new byte[0];
final RowN[] rows = new RowN[numCells];
int i = 0;
for (Cell cell : partCells) {
rows[i++] = row(new Object[] { cell.getRowName(), cell.getColumnName(), timestamp, value });
}
run((Function<DSLContext, Void>) ctx -> {
ctx.insertInto(table(tableName(tableRef)), field(ROW_NAME, byte[].class), field(COL_NAME, byte[].class), field(TIMESTAMP, Long.class), field(VALUE, byte[].class)).select(ctx.select(T1_ROW_NAME, T1_COL_NAME, T1_TIMESTAMP, T1_VALUE).from(values(ctx, rows, TEMP_TABLE_1, ROW_NAME, COL_NAME, TIMESTAMP, VALUE)).whereNotExists(ctx.selectOne().from(atlasTable(tableRef).as(ATLAS_TABLE)).where(A_ROW_NAME.eq(T1_ROW_NAME).and(A_COL_NAME.eq(T1_COL_NAME)).and(A_TIMESTAMP.eq(T1_TIMESTAMP))))).execute();
return null;
});
}
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class JdbcKeyValueService method getMetadataForTables.
@Override
public Map<TableReference, byte[]> getMetadataForTables() {
return run(ctx -> {
Result<? extends Record> records = ctx.select(TABLE_NAME, METADATA).from(METADATA_TABLE).fetch();
Map<TableReference, byte[]> metadata = Maps.newHashMapWithExpectedSize(records.size());
for (Record record : records) {
metadata.put(TableReference.createUnsafe(record.getValue(TABLE_NAME)), record.getValue(METADATA));
}
return metadata;
});
}
Aggregations