Search in sources :

Example 26 with TableReference

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);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test)

Example 27 with TableReference

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);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test)

Example 28 with TableReference

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);
        }
    }
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 29 with TableReference

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);
    }
}
Also used : InsufficientConsistencyException(com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Column(org.apache.cassandra.thrift.Column) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) UnavailableException(org.apache.cassandra.thrift.UnavailableException) Cell(com.palantir.atlasdb.keyvalue.api.Cell) ByteBuffer(java.nio.ByteBuffer)

Example 30 with TableReference

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;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Entry(java.util.Map.Entry) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Aggregations

TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)112 Cell (com.palantir.atlasdb.keyvalue.api.Cell)41 Test (org.junit.Test)41 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)13 Multimap (com.google.common.collect.Multimap)13 Entry (java.util.Map.Entry)13 Set (java.util.Set)13 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)12 Value (com.palantir.atlasdb.keyvalue.api.Value)12 Collection (java.util.Collection)12 List (java.util.List)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)11 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)11 SortedMap (java.util.SortedMap)11 Lists (com.google.common.collect.Lists)10 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)10 Sets (com.google.common.collect.Sets)9 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)9