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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations