Search in sources :

Example 26 with RowResult

use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.

the class OneNodeDownGetTest method getRangeOfTimestampsThrows.

@Test
public void getRangeOfTimestampsThrows() {
    RangeRequest range = RangeRequest.builder().endRowExclusive(OneNodeDownTestSuite.SECOND_ROW).build();
    ClosableIterator<RowResult<Set<Long>>> it = OneNodeDownTestSuite.kvs.getRangeOfTimestamps(OneNodeDownTestSuite.TEST_TABLE, range, Long.MAX_VALUE);
    assertThatThrownBy(() -> it.next()).isExactlyInstanceOf(InsufficientConsistencyException.class).hasMessageContaining(REQUIRES_ALL_CASSANDRA_NODES);
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) InsufficientConsistencyException(com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 27 with RowResult

use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.

the class AbstractSchemaApiTest method testGetMultipleRowsFirstColumn.

@Test
public void testGetMultipleRowsFirstColumn() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    SortedMap<byte[], RowResult<byte[]>> resultsMap = new TreeMap<>(UnsignedBytes.lexicographicalComparator());
    addToResultsMap(resultsMap, TEST_ROW_KEY, FIRST_COL_SHORT_NAME, encodeLong(TEST_VALUE_LONG));
    addToResultsMap(resultsMap, TEST_ROW_KEY2, FIRST_COL_SHORT_NAME, encodeLong(TEST_VALUE_LONG2));
    when(transaction.getRows(eq(tableRef), any(), eq(FIRST_COLUMN_SELECTION))).thenReturn(resultsMap);
    Map<String, Long> result = getMultipleRowsFirstColumn(transaction, Arrays.asList(TEST_ROW_KEY, TEST_ROW_KEY2));
    assertThat(result).isEqualTo(ImmutableMap.of(TEST_ROW_KEY, TEST_VALUE_LONG, TEST_ROW_KEY2, TEST_VALUE_LONG2));
    ArgumentCaptor<Iterable> argument = ArgumentCaptor.forClass(Iterable.class);
    verify(transaction, times(1)).getRows(eq(tableRef), argument.capture(), eq(FIRST_COLUMN_SELECTION));
    List<byte[]> argumentRows = Lists.newArrayList(argument.getValue());
    assertThat(argumentRows.size()).isEqualTo(2);
    assertThat(argumentRows.get(0)).usingComparator(UnsignedBytes.lexicographicalComparator()).isEqualTo(PtBytes.toBytes(TEST_ROW_KEY));
    assertThat(argumentRows.get(1)).usingComparator(UnsignedBytes.lexicographicalComparator()).isEqualTo(PtBytes.toBytes(TEST_ROW_KEY2));
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) BatchingVisitableFromIterable(com.palantir.common.base.BatchingVisitableFromIterable) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 28 with RowResult

use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.

the class AbstractSchemaApiTest method testGetSingleRowFirstColumn.

@Test
public void testGetSingleRowFirstColumn() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    SortedMap<byte[], RowResult<byte[]>> resultsMap = new TreeMap<>(UnsignedBytes.lexicographicalComparator());
    addToResultsMap(resultsMap, TEST_ROW_KEY, FIRST_COL_SHORT_NAME, encodeLong(TEST_VALUE_LONG));
    when(transaction.getRows(eq(tableRef), any(), eq(FIRST_COLUMN_SELECTION))).thenReturn(resultsMap);
    long value = getSingleRowFirstColumn(transaction, TEST_ROW_KEY);
    assertThat(value).isEqualTo(TEST_VALUE_LONG);
    ArgumentCaptor<Iterable> argument = ArgumentCaptor.forClass(Iterable.class);
    verify(transaction, times(1)).getRows(eq(tableRef), argument.capture(), eq(FIRST_COLUMN_SELECTION));
    Iterable<byte[]> argumentRows = argument.getValue();
    assertThat(Iterables.getOnlyElement(argumentRows)).usingComparator(UnsignedBytes.lexicographicalComparator()).isEqualTo(PtBytes.toBytes(TEST_ROW_KEY));
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) BatchingVisitableFromIterable(com.palantir.common.base.BatchingVisitableFromIterable) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 29 with RowResult

use of com.palantir.atlasdb.keyvalue.api.RowResult in project atlasdb by palantir.

the class SnapshotTransaction method getRanges.

@Override
public Iterable<BatchingVisitable<RowResult<byte[]>>> getRanges(final TableReference tableRef, Iterable<RangeRequest> rangeRequests) {
    checkGetPreconditions(tableRef);
    if (perfLogger.isDebugEnabled()) {
        perfLogger.debug("Passed {} ranges to getRanges({}, {})", Iterables.size(rangeRequests), tableRef, rangeRequests);
    }
    if (!Iterables.isEmpty(rangeRequests)) {
        hasReads = true;
    }
    return FluentIterable.from(Iterables.partition(rangeRequests, BATCH_SIZE_GET_FIRST_PAGE)).transformAndConcat(input -> {
        Timer.Context timer = getTimer("processedRangeMillis").time();
        Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> firstPages = keyValueService.getFirstBatchForRanges(tableRef, input, getStartTimestamp());
        validateExternalAndCommitLocksIfNecessary(tableRef, getStartTimestamp());
        SortedMap<Cell, byte[]> postFiltered = postFilterPages(tableRef, firstPages.values());
        List<BatchingVisitable<RowResult<byte[]>>> ret = Lists.newArrayListWithCapacity(input.size());
        for (RangeRequest rangeRequest : input) {
            TokenBackedBasicResultsPage<RowResult<Value>, byte[]> prePostFilter = firstPages.get(rangeRequest);
            byte[] nextStartRowName = getNextStartRowName(rangeRequest, prePostFilter);
            List<Entry<Cell, byte[]>> mergeIterators = getPostFilteredWithLocalWrites(tableRef, postFiltered, rangeRequest, prePostFilter.getResults(), nextStartRowName);
            ret.add(new AbstractBatchingVisitable<RowResult<byte[]>>() {

                @Override
                protected <K extends Exception> void batchAcceptSizeHint(int batchSizeHint, ConsistentVisitor<RowResult<byte[]>, K> visitor) throws K {
                    checkGetPreconditions(tableRef);
                    final Iterator<RowResult<byte[]>> rowResults = Cells.createRowView(mergeIterators);
                    while (rowResults.hasNext()) {
                        if (!visitor.visit(ImmutableList.of(rowResults.next()))) {
                            return;
                        }
                    }
                    if ((nextStartRowName.length == 0) || !prePostFilter.moreResultsAvailable()) {
                        return;
                    }
                    RangeRequest newRange = rangeRequest.getBuilder().startRowInclusive(nextStartRowName).build();
                    getRange(tableRef, newRange).batchAccept(batchSizeHint, visitor);
                }
            });
        }
        long processedRangeMillis = TimeUnit.NANOSECONDS.toMillis(timer.stop());
        log.trace("Processed {} range requests for {} in {}ms", SafeArg.of("numRequests", input.size()), LoggingArgs.tableRef(tableRef), SafeArg.of("millis", processedRangeMillis));
        return ret;
    });
}
Also used : TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) AbstractBatchingVisitable(com.palantir.common.base.AbstractBatchingVisitable) BatchingVisitable(com.palantir.common.base.BatchingVisitable) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Entry(java.util.Map.Entry) Timer(com.codahale.metrics.Timer) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Value(com.palantir.atlasdb.keyvalue.api.Value) PeekingIterator(com.google.common.collect.PeekingIterator) AbstractIterator(com.google.common.collect.AbstractIterator) LocalRowColumnRangeIterator(com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator) ClosableIterator(com.palantir.common.base.ClosableIterator) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) ForwardingClosableIterator(com.palantir.common.base.ForwardingClosableIterator) Iterator(java.util.Iterator) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 30 with RowResult

use of com.palantir.atlasdb.keyvalue.api.RowResult 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)

Aggregations

RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)57 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)40 Test (org.junit.Test)23 Cell (com.palantir.atlasdb.keyvalue.api.Cell)17 Value (com.palantir.atlasdb.keyvalue.api.Value)16 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)10 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)10 Set (java.util.Set)8 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)7 Transaction (com.palantir.atlasdb.transaction.api.Transaction)7 SortedMap (java.util.SortedMap)7 Map (java.util.Map)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Lists (com.google.common.collect.Lists)5 AbstractPagingIterable (com.palantir.util.paging.AbstractPagingIterable)5 Entry (java.util.Map.Entry)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 PtBytes (com.palantir.atlasdb.encoding.PtBytes)4 ClosableIterator (com.palantir.common.base.ClosableIterator)4