Search in sources :

Example 1 with StartTsResultsCollector

use of com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.StartTsResultsCollector in project atlasdb by palantir.

the class CassandraKeyValueServiceImpl method get.

private Map<Cell, Value> get(String kvsMethodName, TableReference tableRef, Set<Cell> cells, long maxTimestampExclusive) {
    StartTsResultsCollector collector = new StartTsResultsCollector(maxTimestampExclusive);
    cellLoader.loadWithTs(kvsMethodName, tableRef, cells, maxTimestampExclusive, false, collector, readConsistency);
    return collector.getCollectedResults();
}
Also used : StartTsResultsCollector(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.StartTsResultsCollector)

Example 2 with StartTsResultsCollector

use of com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.StartTsResultsCollector in project atlasdb by palantir.

the class CassandraKeyValueServiceImpl method getRowsForSpecificColumns.

private Map<Cell, Value> getRowsForSpecificColumns(final TableReference tableRef, final Iterable<byte[]> rows, ColumnSelection selection, final long startTs) {
    Preconditions.checkArgument(!selection.allColumnsSelected(), "Must select specific columns");
    Collection<byte[]> selectedColumns = selection.getSelectedColumns();
    Set<Cell> cells = Sets.newHashSetWithExpectedSize(selectedColumns.size() * Iterables.size(rows));
    for (byte[] row : rows) {
        for (byte[] col : selectedColumns) {
            cells.add(Cell.create(row, col));
        }
    }
    StartTsResultsCollector collector = new StartTsResultsCollector(startTs);
    cellLoader.loadWithTs("getRows", tableRef, cells, startTs, false, collector, readConsistency);
    return collector.getCollectedResults();
}
Also used : StartTsResultsCollector(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.StartTsResultsCollector) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 3 with StartTsResultsCollector

use of com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.StartTsResultsCollector in project atlasdb by palantir.

the class CassandraKeyValueServiceImpl method get.

/**
 * Gets values from the key-value store.
 * <p>
 * Does not require all Cassandra nodes to be up and available, works as long as quorum is achieved.
 *
 * @param tableRef the name of the table to retrieve values from.
 * @param timestampByCell specifies, for each row, the maximum timestamp (exclusive) at which to
 *        retrieve that rows's value.
 *
 * @return map of retrieved values. Values which do not exist (either
 *         because they were deleted or never created in the first place)
 *         are simply not returned.
 *
 * @throws IllegalArgumentException if any of the requests were invalid
 *         (e.g., attempting to retrieve values from a non-existent table).
 */
@Override
public Map<Cell, Value> get(TableReference tableRef, Map<Cell, Long> timestampByCell) {
    if (timestampByCell.isEmpty()) {
        log.info("Attempted get on '{}' table with empty cells", LoggingArgs.tableRef(tableRef));
        return ImmutableMap.of();
    }
    try {
        Long firstTs = timestampByCell.values().iterator().next();
        if (Iterables.all(timestampByCell.values(), Predicates.equalTo(firstTs))) {
            return get("get", tableRef, timestampByCell.keySet(), firstTs);
        }
        SetMultimap<Long, Cell> cellsByTs = Multimaps.invertFrom(Multimaps.forMap(timestampByCell), HashMultimap.<Long, Cell>create());
        Builder<Cell, Value> builder = ImmutableMap.builder();
        for (long ts : cellsByTs.keySet()) {
            StartTsResultsCollector collector = new StartTsResultsCollector(ts);
            cellLoader.loadWithTs("get", tableRef, cellsByTs.get(ts), ts, false, collector, readConsistency);
            builder.putAll(collector.getCollectedResults());
        }
        return builder.build();
    } catch (Exception e) {
        throw QosAwareThrowables.unwrapAndThrowRateLimitExceededOrAtlasDbDependencyException(e);
    }
}
Also used : StartTsResultsCollector(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.StartTsResultsCollector) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) InsufficientConsistencyException(com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) FunctionCheckedException(com.palantir.common.base.FunctionCheckedException) TException(org.apache.thrift.TException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) PalantirRuntimeException(com.palantir.common.exception.PalantirRuntimeException)

Aggregations

StartTsResultsCollector (com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.StartTsResultsCollector)3 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 CheckAndSetException (com.palantir.atlasdb.keyvalue.api.CheckAndSetException)1 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)1 KeyAlreadyExistsException (com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)1 Value (com.palantir.atlasdb.keyvalue.api.Value)1 FunctionCheckedException (com.palantir.common.base.FunctionCheckedException)1 PalantirRuntimeException (com.palantir.common.exception.PalantirRuntimeException)1 UnavailableException (org.apache.cassandra.thrift.UnavailableException)1 TException (org.apache.thrift.TException)1