Search in sources :

Example 16 with Value

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

Example 17 with Value

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);
}
Also used : Value(com.palantir.atlasdb.keyvalue.api.Value) Row(com.datastax.driver.core.Row) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 18 with Value

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

Example 19 with Value

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;
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) PreparedStatement(com.datastax.driver.core.PreparedStatement) Value(com.palantir.atlasdb.keyvalue.api.Value) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 20 with Value

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

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