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