use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class StreamStoreRemappingSweepPriorityCalculatorTest method unsweptTableIsAlwaysPrioritised.
@Test
public void unsweptTableIsAlwaysPrioritised() {
TableReference unsweptTable = table("unswept1");
given(unsweptTable);
whenCalculatingSweepPriorities();
thenOnlyTablePrioritisedIs(unsweptTable);
thenTableHasPriority(unsweptTable);
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class StreamStoreRemappingSweepPriorityCalculatorTest method unsweptTableAndNormalTable_prioritiseUnsweptTable.
@Test
public void unsweptTableAndNormalTable_prioritiseUnsweptTable() {
TableReference unsweptTable = table("unswept1");
SweepPriorityHistory normalTable = new SweepPriorityHistory("normalTable").withOld(sweepPriority().writeCount(50).build()).withNew(sweepPriority().writeCount(100).build());
given(unsweptTable);
given(normalTable);
whenCalculatingSweepPriorities();
thenOnlyTablePrioritisedIs(unsweptTable);
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class InMemoryKeyValueService method checkAndSet.
@Override
public void checkAndSet(CheckAndSetRequest request) throws CheckAndSetException {
TableReference tableRef = request.table();
Table table = getTableMap(tableRef);
Cell cell = request.cell();
Optional<byte[]> oldValue = request.oldValue();
byte[] contents = request.newValue();
Key key = getKey(table, cell, AtlasDbConstants.TRANSACTION_TS);
if (oldValue.isPresent()) {
byte[] storedValue = table.entries.get(key);
boolean succeeded = Arrays.equals(storedValue, oldValue.get()) && table.entries.replace(key, storedValue, copyOf(contents));
if (!succeeded) {
// Re-fetch, something may have happened between get and replace
byte[] actual = table.entries.get(key);
throwCheckAndSetException(cell, tableRef, oldValue.get(), actual);
}
} else {
byte[] oldContents = putIfAbsent(table, key, contents);
if (oldContents != null) {
throwCheckAndSetException(cell, tableRef, null, oldContents);
}
}
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class CassandraKeyValueServiceImpl method executeCheckAndSet.
private CASResult executeCheckAndSet(CassandraClient client, CheckAndSetRequest request) throws TException {
try {
TableReference table = request.table();
Cell cell = request.cell();
long timestamp = AtlasDbConstants.TRANSACTION_TS;
ByteBuffer rowName = ByteBuffer.wrap(cell.getRowName());
byte[] colName = CassandraKeyValueServices.makeCompositeBuffer(cell.getColumnName(), timestamp).array();
List<Column> oldColumns;
java.util.Optional<byte[]> oldValue = request.oldValue();
if (oldValue.isPresent()) {
oldColumns = ImmutableList.of(makeColumn(colName, oldValue.get(), timestamp));
} else {
oldColumns = ImmutableList.of();
}
Column newColumn = makeColumn(colName, request.newValue(), timestamp);
return queryRunner.run(client, table, () -> client.cas(table, rowName, oldColumns, ImmutableList.of(newColumn), ConsistencyLevel.SERIAL, writeConsistency));
} catch (UnavailableException e) {
throw new InsufficientConsistencyException("Check-and-set requires " + writeConsistency + " Cassandra nodes to be up and available.", e);
}
}
use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.
the class CassandraKeyValueServiceImpl method getMetadataForTables.
/**
* Gets the metadata for all non-hidden tables.
* <p>
* Does not require all Cassandra nodes to be up and available, works as long as quorum is achieved.
*
* @return a mapping of table names to their respective metadata in form of a byte array. Consider
* {@link TableMetadata#BYTES_HYDRATOR} for hydrating.
*/
@Override
public Map<TableReference, byte[]> getMetadataForTables() {
Map<TableReference, byte[]> tableToMetadataContents = Maps.newHashMap();
// we don't even have a metadata table yet. Return empty map.
if (!getAllTableReferencesWithoutFiltering().contains(AtlasDbConstants.DEFAULT_METADATA_TABLE)) {
log.trace("getMetadata called with no _metadata table present");
return tableToMetadataContents;
}
try (ClosableIterator<RowResult<Value>> range = getRange(AtlasDbConstants.DEFAULT_METADATA_TABLE, RangeRequest.all(), Long.MAX_VALUE)) {
while (range.hasNext()) {
RowResult<Value> valueRow = range.next();
Iterable<Entry<Cell, Value>> cells = valueRow.getCells();
for (Entry<Cell, Value> entry : cells) {
Value value = entry.getValue();
TableReference tableRef = CassandraKeyValueServices.tableReferenceFromBytes(entry.getKey().getRowName());
byte[] contents;
if (value == null) {
contents = AtlasDbConstants.EMPTY_TABLE_METADATA;
} else {
contents = value.getContents();
}
if (!HiddenTables.isHidden(tableRef)) {
tableToMetadataContents.put(tableRef, contents);
}
}
}
}
return tableToMetadataContents;
}
Aggregations