Search in sources :

Example 41 with RangeRequest

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

the class WhereClausesTest method endOnly.

@Test
public void endOnly() {
    RangeRequest request = RangeRequest.builder().endRowExclusive(END).build();
    WhereClauses whereClauses = WhereClauses.create("i", request);
    List<String> expectedClauses = ImmutableList.of("i.row_name < ?");
    assertEquals(whereClauses.getClauses(), expectedClauses);
    checkWhereArguments(whereClauses, ImmutableList.of(END));
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 42 with RangeRequest

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

the class DbKvsGetRanges method getFirstPages.

private Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> getFirstPages(TableReference tableRef, List<RangeRequest> requests, long timestamp) {
    List<String> subQueries = Lists.newArrayList();
    List<Object> argsList = Lists.newArrayList();
    for (int i = 0; i < requests.size(); i++) {
        RangeRequest request = requests.get(i);
        Pair<String, List<Object>> queryAndArgs = getRangeQueryAndArgs(tableRef, request.getStartInclusive(), request.getEndExclusive(), request.isReverse(), request.getBatchHint() == null ? 1 : request.getBatchHint(), i);
        subQueries.add(queryAndArgs.lhSide);
        argsList.addAll(queryAndArgs.rhSide);
    }
    String query = Joiner.on(") UNION ALL (").appendTo(new StringBuilder("("), subQueries).append(")").toString();
    Object[] args = argsList.toArray();
    TimingState timer = logTimer.begin("Table: " + tableRef.getQualifiedName() + " get_page");
    try {
        return getFirstPagesFromDb(tableRef, requests, timestamp, query, args);
    } finally {
        timer.end();
    }
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) TimingState(com.palantir.util.jmx.OperationTimer.TimingState) List(java.util.List)

Example 43 with RangeRequest

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

the class KeyValueServiceValidator method validateTable.

private void validateTable(TableReference table, int limit, Transaction t1, Transaction t2) {
    RangeRequest.Builder builder = RangeRequest.builder().batchHint(limit);
    byte[] nextRowName = new byte[0];
    while (nextRowName != null) {
        RangeRequest range = builder.startRowInclusive(nextRowName).build();
        nextRowName = validateAndGetNextRowName(table, limit, t1, t2, range);
    }
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 44 with RangeRequest

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

the class KeyValueServicePuncherStore method get.

@Override
public Long get(Long timeMillis) {
    byte[] row = EncodingUtils.encodeUnsignedVarLong(timeMillis);
    EncodingUtils.flipAllBitsInPlace(row);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(row).batchHint(1).build();
    ClosableIterator<RowResult<Value>> result = keyValueService.getRange(AtlasDbConstants.PUNCH_TABLE, rangeRequest, Long.MAX_VALUE);
    try {
        if (result.hasNext()) {
            return EncodingUtils.decodeUnsignedVarLong(result.next().getColumns().get(COLUMN).getContents());
        } else {
            return Long.MIN_VALUE;
        }
    } finally {
        result.close();
    }
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Example 45 with RangeRequest

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

the class KeyValueServicePuncherStore method getMillisForTimestamp.

public static long getMillisForTimestamp(KeyValueService kvs, long timestamp) {
    long timestampExclusive = timestamp + 1;
    // punch table is keyed by the real value we're trying to find so we have to do a whole table
    // scan, which is fine because this table should be really small
    byte[] startRow = EncodingUtils.encodeUnsignedVarLong(Long.MAX_VALUE);
    EncodingUtils.flipAllBitsInPlace(startRow);
    RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(startRow).batchHint(1).build();
    ClosableIterator<RowResult<Value>> result = kvs.getRange(AtlasDbConstants.PUNCH_TABLE, rangeRequest, timestampExclusive);
    try {
        if (result.hasNext()) {
            byte[] encodedMillis = result.next().getRowName();
            EncodingUtils.flipAllBitsInPlace(encodedMillis);
            return EncodingUtils.decodeUnsignedVarLong(encodedMillis);
        } else {
            return 0L;
        }
    } finally {
        result.close();
    }
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest)

Aggregations

RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)68 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)36 Test (org.junit.Test)35 Value (com.palantir.atlasdb.keyvalue.api.Value)17 TokenBackedBasicResultsPage (com.palantir.util.paging.TokenBackedBasicResultsPage)14 Cell (com.palantir.atlasdb.keyvalue.api.Cell)12 Transaction (com.palantir.atlasdb.transaction.api.Transaction)7 List (java.util.List)5 Set (java.util.Set)5 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)4 StringValue (com.palantir.atlasdb.table.description.test.StringValue)4 AbstractPagingIterable (com.palantir.util.paging.AbstractPagingIterable)4 Map (java.util.Map)4 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)3 AbstractIterator (com.google.common.collect.AbstractIterator)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Hashing (com.google.common.hash.Hashing)2 NameComponentDescription (com.palantir.atlasdb.table.description.NameComponentDescription)2 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)2 ClosableIterator (com.palantir.common.base.ClosableIterator)2