use of com.apple.foundationdb.tuple.Tuple in project YCSB by brianfrankcooper.
the class FoundationDBClient method convTupleToMap.
private Status convTupleToMap(Tuple tuple, Set<String> fields, Map<String, ByteIterator> result) {
for (int i = 0; i < tuple.size(); i++) {
Tuple v = tuple.getNestedTuple(i);
String field = v.getString(0);
String value = v.getString(1);
// System.err.println(field + " : " + value);
result.put(field, new StringByteIterator(value));
}
if (fields != null) {
for (String field : fields) {
if (result.get(field) == null) {
logger.debug("field not fount: {}", field);
return Status.NOT_FOUND;
}
}
}
return Status.OK;
}
use of com.apple.foundationdb.tuple.Tuple in project YCSB by brianfrankcooper.
the class FoundationDBClient method read.
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
String rowKey = getRowKey(dbName, table, key);
logger.debug("read key = {}", rowKey);
try {
byte[] row = db.run(tr -> {
byte[] r = tr.get(Tuple.from(rowKey).pack()).join();
return r;
});
Tuple t = Tuple.fromBytes(row);
if (t.size() == 0) {
logger.debug("key not fount: {}", rowKey);
return Status.NOT_FOUND;
}
return convTupleToMap(t, fields, result);
} catch (FDBException e) {
logger.error(MessageFormatter.format("Error reading key: {}", rowKey).getMessage(), e);
e.printStackTrace();
} catch (Exception e) {
logger.error(MessageFormatter.format("Error reading key: {}", rowKey).getMessage(), e);
e.printStackTrace();
}
return Status.ERROR;
}
use of com.apple.foundationdb.tuple.Tuple in project YCSB by brianfrankcooper.
the class FoundationDBClient method scan.
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
String startRowKey = getRowKey(dbName, table, startkey);
String endRowKey = getEndRowKey(table);
logger.debug("scan key from {} to {} limit {} ", startkey, endRowKey, recordcount);
try (Transaction tr = db.createTransaction()) {
tr.options().setReadYourWritesDisable();
AsyncIterable<KeyValue> entryList = tr.getRange(Tuple.from(startRowKey).pack(), Tuple.from(endRowKey).pack(), recordcount > 0 ? recordcount : 0);
List<KeyValue> entries = entryList.asList().join();
for (int i = 0; i < entries.size(); ++i) {
final HashMap<String, ByteIterator> map = new HashMap<>();
Tuple value = Tuple.fromBytes(entries.get(i).getValue());
if (convTupleToMap(value, fields, map) == Status.OK) {
result.add(map);
} else {
logger.error("Error scanning keys: from {} to {} limit {} ", startRowKey, endRowKey, recordcount);
return Status.ERROR;
}
}
return Status.OK;
} catch (FDBException e) {
logger.error(MessageFormatter.format("Error scanning keys: from {} to {} ", startRowKey, endRowKey).getMessage(), e);
e.printStackTrace();
} catch (Exception e) {
logger.error(MessageFormatter.format("Error scanning keys: from {} to {} ", startRowKey, endRowKey).getMessage(), e);
e.printStackTrace();
}
return Status.ERROR;
}
use of com.apple.foundationdb.tuple.Tuple in project fdb-record-layer by FoundationDB.
the class ScanComparisons method toTupleRange.
@Nonnull
public TupleRange toTupleRange(@Nullable FDBRecordStoreBase<?> store, @Nullable EvaluationContext context) {
if (isEmpty()) {
return TupleRange.ALL;
}
final List<Object> items = new ArrayList<>(equalityComparisons.size());
for (Comparisons.Comparison comparison : equalityComparisons) {
addComparandToList(items, comparison, store, context);
}
final Tuple baseTuple = Tuple.fromList(items);
if (inequalityComparisons.isEmpty()) {
return TupleRange.allOf(baseTuple);
}
if (inequalityComparisons.size() == 1) {
final Comparisons.Comparison inequalityComparison = inequalityComparisons.iterator().next();
if (inequalityComparison.getType() == Comparisons.Type.STARTS_WITH) {
final Tuple startTuple = baseTuple.addObject(toTupleItem(inequalityComparison.getComparand(store, context)));
return new TupleRange(startTuple, startTuple, EndpointType.PREFIX_STRING, EndpointType.PREFIX_STRING);
}
}
InequalityRangeCombiner rangeCombiner = new InequalityRangeCombiner(store, context, baseTuple, inequalityComparisons);
return rangeCombiner.toTupleRange();
}
use of com.apple.foundationdb.tuple.Tuple in project fdb-record-layer by FoundationDB.
the class IndexingMultiTargetByRecords method rebuildIndexInternalAsync.
// support rebuildIndexAsync
@Nonnull
@Override
CompletableFuture<Void> rebuildIndexInternalAsync(FDBRecordStore store) {
AtomicReference<Tuple> nextResultCont = new AtomicReference<>(null);
AtomicLong recordScanned = new AtomicLong();
return AsyncUtil.whileTrue(() -> rebuildRangeOnly(store, nextResultCont.get(), recordScanned).thenApply(cont -> {
if (cont == null) {
return false;
}
nextResultCont.set(cont);
return true;
}), store.getExecutor());
}
Aggregations