Search in sources :

Example 6 with AgnosticLightResultRow

use of com.palantir.nexus.db.sql.AgnosticLightResultRow in project atlasdb by palantir.

the class DbKvs method getColumnCountsUnordered.

private Map<Sha256Hash, Integer> getColumnCountsUnordered(TableReference tableRef, List<byte[]> rowList, ColumnRangeSelection columnRangeSelection, long timestamp) {
    return runRead(tableRef, dbReadTable -> {
        Map<Sha256Hash, Integer> counts = new HashMap<>(rowList.size());
        try (ClosableIterator<AgnosticLightResultRow> iter = dbReadTable.getRowsColumnRangeCounts(rowList, timestamp, columnRangeSelection)) {
            while (iter.hasNext()) {
                AgnosticLightResultRow row = iter.next();
                Sha256Hash rowHash = Sha256Hash.computeHash(row.getBytes(ROW));
                counts.put(rowHash, row.getInteger("column_count"));
            }
        }
        return counts;
    });
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Sha256Hash(com.palantir.util.crypto.Sha256Hash) AgnosticLightResultRow(com.palantir.nexus.db.sql.AgnosticLightResultRow)

Example 7 with AgnosticLightResultRow

use of com.palantir.nexus.db.sql.AgnosticLightResultRow in project atlasdb by palantir.

the class DbKvs method getTimestampsPageInternal.

private TokenBackedBasicResultsPage<RowResult<Set<Long>>, Token> getTimestampsPageInternal(DbReadTable table, RangeRequest range, long timestamp, long batchSize, Token token) {
    Set<byte[]> rows = Sets.newHashSet();
    int maxRows = getMaxRowsFromBatchHint(range.getBatchHint());
    try (ClosableIterator<AgnosticLightResultRow> rangeResults = table.getRange(range, timestamp, maxRows)) {
        while (rows.size() < maxRows && rangeResults.hasNext()) {
            byte[] rowName = rangeResults.next().getBytes(ROW);
            if (rowName != null) {
                rows.add(rowName);
            }
        }
        if (rows.isEmpty()) {
            return SimpleTokenBackedResultsPage.create(null, ImmutableList.<RowResult<Set<Long>>>of(), false);
        }
    }
    ColumnSelection cols = range.getColumnNames().isEmpty() ? ColumnSelection.all() : ColumnSelection.create(range.getColumnNames());
    TimestampsByCellResultWithToken result = getTimestampsByCell(table, rows, cols, timestamp, batchSize, range.isReverse(), token);
    NavigableMap<byte[], SortedMap<byte[], Set<Long>>> cellsByRow = Cells.breakCellsUpByRow(Multimaps.asMap(result.entries));
    if (range.isReverse()) {
        cellsByRow = cellsByRow.descendingMap();
    }
    List<RowResult<Set<Long>>> finalResults = cellsByRow.entrySet().stream().map(entry -> RowResult.create(entry.getKey(), entry.getValue())).collect(Collectors.toList());
    return SimpleTokenBackedResultsPage.create(result.getToken(), finalResults, result.mayHaveMoreResults());
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ImmutablePostgresDdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.ImmutablePostgresDdlConfig) Arrays(java.util.Arrays) PalantirSqlException(com.palantir.exception.PalantirSqlException) Throwables(com.palantir.common.base.Throwables) CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest) OracleDdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.OracleDdlConfig) Collections2(com.google.common.collect.Collections2) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) CandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping) CellTsPairLoader(com.palantir.atlasdb.keyvalue.dbkvs.impl.sweep.CellTsPairLoader) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) DdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.DdlConfig) AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) NamedThreadFactory(com.palantir.common.concurrent.NamedThreadFactory) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) AgnosticLightResultRow(com.palantir.nexus.db.sql.AgnosticLightResultRow) OracleGetRange(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OracleGetRange) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) Cells(com.palantir.atlasdb.keyvalue.impl.Cells) AbstractKeyValueService(com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Iterables(com.google.common.collect.Iterables) ParallelTaskRunner(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.ParallelTaskRunner) BatchingTaskRunner(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.BatchingTaskRunner) DbKvsPartitioners(com.palantir.atlasdb.keyvalue.dbkvs.util.DbKvsPartitioners) DbkvsVersionException(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.DbkvsVersionException) PostgresPrefixedTableNames(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.PostgresPrefixedTableNames) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Multimaps(com.google.common.collect.Multimaps) LinkedHashMap(java.util.LinkedHashMap) ClusterAvailabilityStatus(com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) Atomics(com.google.common.util.concurrent.Atomics) PostgresCellTsPageLoader(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.PostgresCellTsPageLoader) Sha256Hash(com.palantir.util.crypto.Sha256Hash) Nullable(javax.annotation.Nullable) Functions(com.google.common.base.Functions) AbstractIterator(com.google.common.collect.AbstractIterator) DbKvsGetRange(com.palantir.atlasdb.keyvalue.dbkvs.impl.ranges.DbKvsGetRange) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) DbKvsGetCandidateCellsForSweeping(com.palantir.atlasdb.keyvalue.dbkvs.impl.sweep.DbKvsGetCandidateCellsForSweeping) PostgresDdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.PostgresDdlConfig) Preconditions(com.google.common.base.Preconditions) LocalRowColumnRangeIterator(com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator) RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) OracleCellTsPageLoader(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OracleCellTsPageLoader) Connection(java.sql.Connection) ImmediateSingleBatchTaskRunner(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.ImmediateSingleBatchTaskRunner) ListIterator(java.util.ListIterator) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ClosableIterator(com.palantir.common.base.ClosableIterator) LoggerFactory(org.slf4j.LoggerFactory) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchingStrategies(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.BatchingStrategies) PTExecutors(com.palantir.common.concurrent.PTExecutors) DbKvsGetRanges(com.palantir.atlasdb.keyvalue.dbkvs.impl.ranges.DbKvsGetRanges) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractPagingIterable(com.palantir.util.paging.AbstractPagingIterable) Collection(java.util.Collection) AgnosticResultRow(com.palantir.nexus.db.sql.AgnosticResultRow) NavigableMap(java.util.NavigableMap) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Objects(java.util.Objects) List(java.util.List) CandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest) DbKeyValueServiceConfig(com.palantir.atlasdb.keyvalue.dbkvs.DbKeyValueServiceConfig) Entry(java.util.Map.Entry) Optional(java.util.Optional) OracleOverflowValueLoader(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OracleOverflowValueLoader) SortedMap(java.util.SortedMap) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Stopwatch(com.google.common.base.Stopwatch) Output(com.palantir.common.annotation.Output) AccumulatorStrategies(com.palantir.atlasdb.keyvalue.dbkvs.impl.batch.AccumulatorStrategies) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) AtomicReference(java.util.concurrent.atomic.AtomicReference) OracleTableNameGetter(com.palantir.atlasdb.keyvalue.dbkvs.OracleTableNameGetter) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Iterators(com.google.common.collect.Iterators) ImmutableList(com.google.common.collect.ImmutableList) Suppliers(com.google.common.base.Suppliers) Nonnull(javax.annotation.Nonnull) ClosableIterators(com.palantir.common.base.ClosableIterators) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) H2DdlConfig(com.palantir.atlasdb.keyvalue.dbkvs.H2DdlConfig) Iterator(java.util.Iterator) Value(com.palantir.atlasdb.keyvalue.api.Value) IterablePartitioner(com.palantir.atlasdb.keyvalue.impl.IterablePartitioner) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) PostgresGetRange(com.palantir.atlasdb.keyvalue.dbkvs.impl.postgres.PostgresGetRange) Ordering(com.google.common.collect.Ordering) SimpleTokenBackedResultsPage(com.palantir.util.paging.SimpleTokenBackedResultsPage) Collections(java.util.Collections) AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) Set(java.util.Set) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) SortedMap(java.util.SortedMap) AgnosticLightResultRow(com.palantir.nexus.db.sql.AgnosticLightResultRow)

Example 8 with AgnosticLightResultRow

use of com.palantir.nexus.db.sql.AgnosticLightResultRow in project atlasdb by palantir.

the class DbKvs method doGetLatestTimestamps.

private static Map<Cell, Long> doGetLatestTimestamps(DbReadTable table, Map<Cell, Long> timestampByCell) {
    try (ClosableIterator<AgnosticLightResultRow> iter = table.getLatestCells(timestampByCell, false)) {
        Map<Cell, Long> results = Maps.newHashMap();
        while (iter.hasNext()) {
            AgnosticLightResultRow row = iter.next();
            Cell cell = Cell.create(row.getBytes(ROW), row.getBytes(COL));
            long ts = row.getLong(TIMESTAMP);
            Long oldTs = results.put(cell, ts);
            if (oldTs != null && oldTs > ts) {
                results.put(cell, oldTs);
            }
        }
        return results;
    }
}
Also used : AgnosticLightResultRow(com.palantir.nexus.db.sql.AgnosticLightResultRow) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 9 with AgnosticLightResultRow

use of com.palantir.nexus.db.sql.AgnosticLightResultRow in project atlasdb by palantir.

the class TimestampsByCellResultWithToken method moveForward.

/**
 * @param oldToken token from previous page, specifying if we have already processed some entries from the current
 * row and should therefore skip them. If oldToken.shouldSkip() is true, we iterate until the end or the first
 * result that is either:
 *  1. In another row
 *  2. In a greater column
 */
private TimestampsByCellResultWithToken moveForward(Token oldToken) {
    boolean skipping = oldToken.shouldSkip();
    while (skipping && iterator.hasNext()) {
        AgnosticLightResultRow nextResult = iterator.peek();
        if (finishedSkipping(oldToken, nextResult)) {
            skipping = false;
        } else {
            iterator.next();
        }
    }
    entries.putAll(rowBuffer);
    return this;
}
Also used : AgnosticLightResultRow(com.palantir.nexus.db.sql.AgnosticLightResultRow)

Example 10 with AgnosticLightResultRow

use of com.palantir.nexus.db.sql.AgnosticLightResultRow in project atlasdb by palantir.

the class OracleOverflowValueLoader method loadOverflowValues.

@Override
public Map<Long, byte[]> loadOverflowValues(ConnectionSupplier conns, TableReference tableRef, Collection<Long> overflowIds) {
    if (overflowIds.isEmpty()) {
        return Collections.emptyMap();
    } else {
        Map<Long, byte[]> ret = Maps.newHashMapWithExpectedSize(overflowIds.size());
        for (FullQuery query : getOverflowQueries(conns, tableRef, overflowIds)) {
            try (ClosableIterator<AgnosticLightResultRow> overflowIter = select(conns, query)) {
                while (overflowIter.hasNext()) {
                    AgnosticLightResultRow row = overflowIter.next();
                    // QA-94468 LONG RAW typed columns ("val" in this case) must be retrieved first from the result
                    // set. See https://docs.oracle.com/cd/B19306_01/java.102/b14355/jstreams.htm#i1007581
                    byte[] val = row.getBytes("val");
                    long id = row.getLong("id");
                    ret.put(id, val);
                }
            }
        }
        return ret;
    }
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery) AgnosticLightResultRow(com.palantir.nexus.db.sql.AgnosticLightResultRow)

Aggregations

AgnosticLightResultRow (com.palantir.nexus.db.sql.AgnosticLightResultRow)10 Cell (com.palantir.atlasdb.keyvalue.api.Cell)5 Value (com.palantir.atlasdb.keyvalue.api.Value)3 Sha256Hash (com.palantir.util.crypto.Sha256Hash)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Function (com.google.common.base.Function)1 Functions (com.google.common.base.Functions)1 Preconditions (com.google.common.base.Preconditions)1 Stopwatch (com.google.common.base.Stopwatch)1 Suppliers (com.google.common.base.Suppliers)1 AbstractIterator (com.google.common.collect.AbstractIterator)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Collections2 (com.google.common.collect.Collections2)1 Iterables (com.google.common.collect.Iterables)1 Iterators (com.google.common.collect.Iterators)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1