use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class Helper method get.
public String get(TableReference tableRef, String rowString, String colString, long ts) {
Cell cell = Cell.create(rowString.getBytes(), colString.getBytes());
Map<Cell, Value> map = keyValueService.get(tableRef, ImmutableMap.of(cell, ts));
Value value = map.get(cell);
if (value == null) {
return "";
} else {
return new String(value.getContents());
}
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class CqlKeyValueService method visitResults.
private void visitResults(ResultSet resultSet, Visitor<Multimap<Cell, Value>> visitor, String query, boolean loadAllTs) {
List<Row> rows = resultSet.all();
Multimap<Cell, Value> res;
if (loadAllTs) {
res = HashMultimap.create();
} else {
res = HashMultimap.create(rows.size(), 1);
}
for (Row row : rows) {
res.put(Cell.create(getRowName(row), getColName(row)), Value.create(getValue(row), getTs(row)));
}
cqlKeyValueServices.logTracedQuery(query, resultSet, session, cqlStatementCache.normalQuery);
visitor.visit(res);
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class CqlKeyValueService method get.
@Override
public Map<Cell, Value> get(TableReference tableRef, Map<Cell, Long> timestampByCell) {
if (timestampByCell.isEmpty()) {
log.info("Attempted get on '{}' table with empty cells", tableRef);
return ImmutableMap.of();
}
try {
long firstTs = timestampByCell.values().iterator().next();
if (Iterables.all(timestampByCell.values(), Predicates.equalTo(firstTs))) {
StartTsResultsCollector collector = new StartTsResultsCollector(firstTs);
loadWithTs(tableRef, timestampByCell.keySet(), firstTs, false, collector, readConsistency);
return collector.getCollectedResults();
}
SetMultimap<Long, Cell> cellsByTs = HashMultimap.create();
Multimaps.invertFrom(Multimaps.forMap(timestampByCell), cellsByTs);
Builder<Cell, Value> builder = ImmutableMap.builder();
for (long ts : cellsByTs.keySet()) {
StartTsResultsCollector collector = new StartTsResultsCollector(ts);
loadWithTs(tableRef, cellsByTs.get(ts), ts, false, collector, readConsistency);
builder.putAll(collector.getCollectedResults());
}
return builder.build();
} catch (Throwable t) {
throw Throwables.throwUncheckedException(t);
}
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class CqlKeyValueService method getRowsAllColsInternal.
private Map<Cell, Value> getRowsAllColsInternal(final TableReference tableRef, final Iterable<byte[]> rows, final long startTs) throws Exception {
int rowCount = 0;
Map<Cell, Value> result = Maps.newHashMap();
int fetchBatchCount = config.fetchBatchCount();
List<ResultSetFuture> resultSetFutures = Lists.newArrayListWithExpectedSize(rowCount);
for (final List<byte[]> batch : Iterables.partition(rows, fetchBatchCount)) {
rowCount += batch.size();
String getRowsQuery = String.format("SELECT * FROM %s WHERE %s IN (%s)", getFullTableName(tableRef), fieldNameProvider.row(), Joiner.on(",").join(Iterables.limit(Iterables.cycle("?"), batch.size())));
PreparedStatement preparedStatement = getPreparedStatement(tableRef, getRowsQuery, session);
Object[] args = batch.stream().map(ByteBuffer::wrap).toArray();
resultSetFutures.add(session.executeAsync(preparedStatement.bind(args)));
for (ResultSetFuture resultSetFuture : resultSetFutures) {
ResultSet resultSet;
try {
resultSet = resultSetFuture.getUninterruptibly();
} catch (Throwable t) {
throw Throwables.throwUncheckedException(t);
}
for (Row row : resultSet.all()) {
Cell cell = Cell.create(getRowName(row), getColName(row));
if ((getTs(row) < startTs) && (!result.containsKey(cell) || (result.get(cell).getTimestamp() < getTs(row)))) {
result.put(Cell.create(getRowName(row), getColName(row)), Value.create(getValue(row), getTs(row)));
}
}
cqlKeyValueServices.logTracedQuery(getRowsQuery, resultSet, session, cqlStatementCache.normalQuery);
}
}
if (rowCount > fetchBatchCount) {
log.warn("Rebatched in getRows a call to {} that attempted to multiget {} rows; " + "this may indicate overly-large batching on a higher level.\n{}", tableRef.getQualifiedName(), rowCount, CassandraKeyValueServices.getFilteredStackTrace("com.palantir"));
}
return result;
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class ScrubQueueMigrationCommand method runOnce.
private static void runOnce(Context context, ClosableIterator<RowResult<Value>> iter) {
Multimap<Cell, Value> batchToCreate = ArrayListMultimap.create();
Multimap<Cell, Long> batchToDelete = ArrayListMultimap.create();
while (iter.hasNext()) {
RowResult<Value> rowResult = iter.next();
byte[] row = rowResult.getRowName();
for (Entry<byte[], Value> entry : rowResult.getColumns().entrySet()) {
byte[] col = entry.getKey();
Value value = entry.getValue();
long timestamp = value.getTimestamp();
String[] tableNames = StringUtils.split(PtBytes.toString(value.getContents()), AtlasDbConstants.OLD_SCRUB_TABLE_SEPARATOR_CHAR);
for (String tableName : tableNames) {
byte[] tableBytes = EncodingUtils.encodeVarString(tableName);
byte[] newCol = EncodingUtils.add(tableBytes, col);
Cell newCell = Cell.create(row, newCol);
batchToCreate.put(newCell, Value.create(DUMMY_CONTENTS, timestamp));
}
batchToDelete.put(Cell.create(row, col), timestamp);
if (batchToDelete.size() >= context.batchSize) {
flush(context, batchToCreate, batchToDelete);
}
}
}
if (!batchToDelete.isEmpty()) {
flush(context, batchToCreate, batchToDelete);
}
}
Aggregations