Search in sources :

Example 1 with Tuple

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;
}
Also used : Tuple(com.apple.foundationdb.tuple.Tuple)

Example 2 with Tuple

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;
}
Also used : Tuple(com.apple.foundationdb.tuple.Tuple)

Example 3 with Tuple

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;
}
Also used : Tuple(com.apple.foundationdb.tuple.Tuple)

Example 4 with Tuple

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();
}
Also used : Comparisons(com.apple.foundationdb.record.query.expressions.Comparisons) ArrayList(java.util.ArrayList) TupleRange(com.apple.foundationdb.record.TupleRange) Tuple(com.apple.foundationdb.tuple.Tuple) Nonnull(javax.annotation.Nonnull)

Example 5 with Tuple

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());
}
Also used : Arrays(java.util.Arrays) LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) AsyncIterator(com.apple.foundationdb.async.AsyncIterator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) RangeSet(com.apple.foundationdb.async.RangeSet) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subspace(com.apple.foundationdb.subspace.Subspace) Transaction(com.apple.foundationdb.Transaction) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) Tuple(com.apple.foundationdb.tuple.Tuple) Range(com.apple.foundationdb.Range) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) ScanProperties(com.apple.foundationdb.record.ScanProperties) IndexBuildProto(com.apple.foundationdb.record.IndexBuildProto) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IsolationLevel(com.apple.foundationdb.record.IsolationLevel) Collectors(java.util.stream.Collectors) TupleRange(com.apple.foundationdb.record.TupleRange) Objects(java.util.Objects) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Index(com.apple.foundationdb.record.metadata.Index) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) API(com.apple.foundationdb.annotation.API) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicReference(java.util.concurrent.atomic.AtomicReference) Tuple(com.apple.foundationdb.tuple.Tuple) Nonnull(javax.annotation.Nonnull)

Aggregations

Tuple (com.apple.foundationdb.tuple.Tuple)163 Nonnull (javax.annotation.Nonnull)80 List (java.util.List)66 Test (org.junit.jupiter.api.Test)66 TupleRange (com.apple.foundationdb.record.TupleRange)62 ArrayList (java.util.ArrayList)57 Message (com.google.protobuf.Message)56 Nullable (javax.annotation.Nullable)50 IndexEntry (com.apple.foundationdb.record.IndexEntry)48 Index (com.apple.foundationdb.record.metadata.Index)47 Subspace (com.apple.foundationdb.subspace.Subspace)47 CompletableFuture (java.util.concurrent.CompletableFuture)46 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)45 ScanProperties (com.apple.foundationdb.record.ScanProperties)43 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)42 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)41 Collectors (java.util.stream.Collectors)41 Collections (java.util.Collections)40 Transaction (com.apple.foundationdb.Transaction)38 RecordCursor (com.apple.foundationdb.record.RecordCursor)38