Search in sources :

Example 31 with RowResult

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

the class KvTableMappingService method readTableMap.

@Override
protected BiMap<TableReference, TableReference> readTableMap() {
    BiMap<TableReference, TableReference> ret = HashBiMap.create();
    ClosableIterator<RowResult<Value>> range = kv.getRange(AtlasDbConstants.NAMESPACE_TABLE, RangeRequest.builder().build(), Long.MAX_VALUE);
    try {
        while (range.hasNext()) {
            RowResult<Value> row = range.next();
            String shortName = PtBytes.toString(row.getColumns().get(AtlasDbConstants.NAMESPACE_SHORT_COLUMN_BYTES).getContents());
            TableReference ref = getTableRefFromBytes(row.getRowName());
            ret.put(ref, TableReference.createWithEmptyNamespace(shortName));
        }
    } finally {
        range.close();
    }
    return ret;
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Value(com.palantir.atlasdb.keyvalue.api.Value)

Example 32 with RowResult

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

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

Example 34 with RowResult

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

the class SerializableTransaction method verifyRanges.

private void verifyRanges(Transaction readOnlyTransaction) {
    // verify each set of reads to ensure they are the same.
    for (Entry<TableReference, ConcurrentMap<RangeRequest, byte[]>> tableAndRange : rangeEndByTable.entrySet()) {
        TableReference table = tableAndRange.getKey();
        Map<RangeRequest, byte[]> rangeEnds = tableAndRange.getValue();
        for (Entry<RangeRequest, byte[]> rangeAndRangeEndEntry : rangeEnds.entrySet()) {
            RangeRequest range = rangeAndRangeEndEntry.getKey();
            byte[] rangeEnd = rangeAndRangeEndEntry.getValue();
            if (rangeEnd.length != 0 && !RangeRequests.isTerminalRow(range.isReverse(), rangeEnd)) {
                range = range.getBuilder().endRowExclusive(RangeRequests.getNextStartRow(range.isReverse(), rangeEnd)).build();
            }
            ConcurrentNavigableMap<Cell, byte[]> writes = writesByTable.get(table);
            BatchingVisitableView<RowResult<byte[]>> bv = BatchingVisitableView.of(readOnlyTransaction.getRange(table, range));
            NavigableMap<Cell, ByteBuffer> readsInRange = Maps.transformValues(getReadsInRange(table, range), ByteBuffer::wrap);
            if (!bv.transformBatch(input -> filterWritesFromRows(input, writes)).isEqual(readsInRange.entrySet())) {
                handleTransactionConflict(table);
            }
        }
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) ByteBuffer(java.nio.ByteBuffer) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 35 with RowResult

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

the class LockEntryTest method fromRowResultProducesLockEntry.

@Test
public void fromRowResultProducesLockEntry() {
    KeyValueService kvs = new InMemoryKeyValueService(false);
    kvs.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA);
    kvs.checkAndSet(CheckAndSetRequest.newCell(TEST_TABLE, LOCK_ENTRY.cell(), LOCK_ENTRY.value()));
    Iterator<RowResult<Value>> range = kvs.getRange(TEST_TABLE, RangeRequest.all(), AtlasDbConstants.TRANSACTION_TS + 1);
    RowResult<Value> onlyEntry = Iterables.getOnlyElement(ImmutableSet.copyOf(range));
    LockEntry lockEntry = LockEntry.fromRowResult(onlyEntry);
    assertEquals(LOCK_ENTRY, lockEntry);
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) Value(com.palantir.atlasdb.keyvalue.api.Value) Test(org.junit.Test)

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