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);
}
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));
}
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));
}
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;
});
}
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());
}
Aggregations