Search in sources :

Example 41 with Value

use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.

the class DbKvs method putIfNotUpdate.

private void putIfNotUpdate(DbReadTable readTable, DbWriteTable writeTable, TableReference tableRef, List<Entry<Cell, Value>> batch, KeyAlreadyExistsException ex) {
    Map<Cell, Long> timestampByCell = Maps.newHashMap();
    for (Entry<Cell, Value> entry : batch) {
        timestampByCell.put(entry.getKey(), entry.getValue().getTimestamp() + 1);
    }
    Map<Cell, Value> results = extractResults(readTable, tableRef, readTable.getLatestCells(timestampByCell, true));
    ListIterator<Entry<Cell, Value>> iter = batch.listIterator();
    while (iter.hasNext()) {
        Entry<Cell, Value> entry = iter.next();
        Cell key = entry.getKey();
        Value value = entry.getValue();
        if (results.containsKey(key)) {
            if (results.get(key).equals(value)) {
                iter.remove();
            } else {
                throw new KeyAlreadyExistsException("primary key violation for key " + key + " with value " + value, ex);
            }
        }
    }
    writeTable.put(batch);
}
Also used : Entry(java.util.Map.Entry) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)

Example 42 with Value

use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.

the class OracleOverflowWriteTable method put.

@Override
public void put(Collection<Map.Entry<Cell, Value>> data) {
    List<Object[]> args = Lists.newArrayListWithCapacity(data.size());
    List<Object[]> overflowArgs = Lists.newArrayList();
    for (Entry<Cell, Value> entry : data) {
        Cell cell = entry.getKey();
        Value val = entry.getValue();
        if (val.getContents().length <= AtlasDbConstants.ORACLE_OVERFLOW_THRESHOLD) {
            args.add(new Object[] { cell.getRowName(), cell.getColumnName(), val.getTimestamp(), val.getContents(), null });
        } else {
            long overflowId = config.overflowIds().orElse(overflowSequenceSupplier).get();
            overflowArgs.add(new Object[] { overflowId, val.getContents() });
            args.add(new Object[] { cell.getRowName(), cell.getColumnName(), val.getTimestamp(), null, overflowId });
        }
    }
    put(args, overflowArgs);
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 43 with Value

use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.

the class KvTableMappingService method readTableMap.

@Override
protected BiMap<TableReference, TableReference> readTableMap() {
    BiMap<TableReference, TableReference> ret = HashBiMap.create();
    ClosableIterator<RowResult<Value>> range = kv.getRange(AtlasDbConstants.NAMESPACE_TABLE, RangeRequest.builder().build(), Long.MAX_VALUE);
    try {
        while (range.hasNext()) {
            RowResult<Value> row = range.next();
            String shortName = PtBytes.toString(row.getColumns().get(AtlasDbConstants.NAMESPACE_SHORT_COLUMN_BYTES).getContents());
            TableReference ref = getTableRefFromBytes(row.getRowName());
            ret.put(ref, TableReference.createWithEmptyNamespace(shortName));
        }
    } finally {
        range.close();
    }
    return ret;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Value(com.palantir.atlasdb.keyvalue.api.Value)

Example 44 with Value

use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.

the class KeyValueServiceScrubberStore method transformRows.

private SortedMap<Long, Multimap<TableReference, Cell>> transformRows(List<RowResult<Value>> input) {
    SortedMap<Long, Multimap<TableReference, Cell>> scrubTimestampToTableNameToCell = Maps.newTreeMap();
    for (RowResult<Value> rowResult : input) {
        byte[] row = rowResult.getRowName();
        for (Entry<byte[], Value> entry : rowResult.getColumns().entrySet()) {
            byte[] fullCol = entry.getKey();
            String table = EncodingUtils.decodeVarString(fullCol);
            byte[] col = Arrays.copyOfRange(fullCol, EncodingUtils.sizeOfVarString(table), fullCol.length);
            TableReference tableRef = TableReference.fromString(table);
            Cell cell = Cell.create(row, col);
            long timestamp = entry.getValue().getTimestamp();
            Multimap<TableReference, Cell> cells = scrubTimestampToTableNameToCell.get(timestamp);
            if (cells == null) {
                cells = ArrayListMultimap.create();
                scrubTimestampToTableNameToCell.put(timestamp, cells);
            }
            cells.put(tableRef, cell);
        }
    }
    return scrubTimestampToTableNameToCell;
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Multimap(com.google.common.collect.Multimap) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 45 with Value

use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.

the class TransactionKvsWrapper method get.

public Map<Long, Long> get(Iterable<Long> startTimestamps) {
    Map<Long, Long> result = Maps.newHashMap();
    Map<Cell, Long> startTsMap = Maps.newHashMap();
    for (Long startTimestamp : startTimestamps) {
        Cell cell = getTransactionCell(startTimestamp);
        startTsMap.put(cell, MAX_TIMESTAMP);
    }
    Map<Cell, Value> rawResults = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, startTsMap);
    for (Map.Entry<Cell, Value> e : rawResults.entrySet()) {
        long startTs = TransactionConstants.getTimestampForValue(e.getKey().getRowName());
        long commitTs = TransactionConstants.getTimestampForValue(e.getValue().getContents());
        result.put(startTs, commitTs);
    }
    return result;
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Value (com.palantir.atlasdb.keyvalue.api.Value)74 Cell (com.palantir.atlasdb.keyvalue.api.Cell)55 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)20 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)18 Test (org.junit.Test)18 Entry (java.util.Map.Entry)16 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)15 Map (java.util.Map)15 SortedMap (java.util.SortedMap)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)10 LinkedHashMap (java.util.LinkedHashMap)9 ImmutableList (com.google.common.collect.ImmutableList)7 KeyAlreadyExistsException (com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)7 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)6 RowColumnRangeIterator (com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)6 List (java.util.List)6 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)5 BatchColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection)5 LocalRowColumnRangeIterator (com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator)5