Search in sources :

Example 31 with FDBRecordStore

use of com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore in project SBK by kmgowda.

the class FdbRecordMultiReader method recordReadTime.

@Override
public void recordReadTime(DataType<ByteString> dType, int size, Time time, Status status, PerlChannel perlChannel) throws EOFException, IOException {
    final int recs = params.getRecordsPerSync();
    final Status ret = db.run(context -> {
        long startKey = key;
        Status stat = new Status();
        FDBRecordStore recordStore = recordStoreProvider.apply(context);
        FDBStoredRecord<Message> storedRecord;
        ByteString data;
        for (int i = 0; i < recs; i++) {
            storedRecord = recordStore.loadRecord(Tuple.from(startKey++));
            if (storedRecord != null) {
                FdbRecordLayerProto.Record record = FdbRecordLayerProto.Record.newBuilder().mergeFrom(storedRecord.getRecord()).build();
                data = record.getData();
                stat.bytes += data.size();
                stat.records += 1;
                if (stat.startTime == 0) {
                    stat.startTime = dType.getTime(data);
                }
            } else {
                break;
            }
        }
        return stat;
    });
    status.startTime = ret.startTime;
    status.records = ret.records;
    status.bytes = ret.bytes;
    status.endTime = time.getCurrentTime();
    key += status.records;
    cnt += status.records;
    perlChannel.send(status.startTime, status.endTime, status.bytes, status.records);
}
Also used : Status(io.sbk.api.Status) Message(com.google.protobuf.Message) ByteString(com.google.protobuf.ByteString) FDBRecordStore(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore)

Example 32 with FDBRecordStore

use of com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore in project SBK by kmgowda.

the class FdbRecordMultiWriter method recordWrite.

@Override
public void recordWrite(DataType<ByteString> dType, ByteString data, int size, Time time, Status status, PerlChannel perlChannel) throws IOException {
    final int recs = params.getRecordsPerSync();
    status.bytes = size * recs;
    status.records = recs;
    status.startTime = time.getCurrentTime();
    db.run(context -> {
        long keyCnt = key;
        FDBRecordStore recordStore = recordStoreProvider.apply(context);
        for (int i = 0; i < recs; i++) {
            recordStore.saveRecord(FdbRecordLayerProto.Record.newBuilder().setRecordID(keyCnt++).setData(data).build());
        }
        return null;
    });
    status.endTime = time.getCurrentTime();
    perlChannel.send(status.startTime, status.endTime, status.bytes, status.records);
    key += recs;
    cnt += recs;
}
Also used : FDBRecordStore(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore)

Example 33 with FDBRecordStore

use of com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore in project fdb-record-layer by FoundationDB.

the class Main method readNames.

public static List<String> readNames(FDBRecordStore.Builder recordStoreBuilder, FDBRecordContext cx, RecordQuery query) {
    List<String> names = new ArrayList<>();
    FDBRecordStore store = recordStoreBuilder.copyBuilder().setContext(cx).open();
    RecordQueryPlan plan = store.planQuery(query);
    // The plan string works like a basic "explain" function
    LOGGER.info(KeyValueLogMessage.of("Query planned", LogMessageKeys.PLAN, plan));
    try (RecordCursor<FDBQueriedRecord<Message>> cursor = store.executeQuery(plan)) {
        RecordCursorResult<FDBQueriedRecord<Message>> result;
        do {
            result = cursor.getNext();
            if (result.hasNext()) {
                SampleProto.Customer.Builder builder = SampleProto.Customer.newBuilder().mergeFrom(result.get().getRecord());
                names.add(builder.getFirstName() + " " + builder.getLastName());
            }
        } while (result.hasNext());
    }
    return names;
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) ArrayList(java.util.ArrayList) FDBRecordStore(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore)

Aggregations

FDBRecordStore (com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore)33 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)25 Test (org.junit.jupiter.api.Test)15 JoinedRecordTypeBuilder (com.apple.foundationdb.record.metadata.JoinedRecordTypeBuilder)12 Tuple (com.apple.foundationdb.tuple.Tuple)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Message (com.google.protobuf.Message)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 Index (com.apple.foundationdb.record.metadata.Index)7 RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)5 MySimpleRecord (com.apple.foundationdb.record.TestRecords1Proto.MySimpleRecord)4 GroupingKeyExpression (com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression)4 FDBStoreTimer (com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer)4 IndexEntry (com.apple.foundationdb.record.IndexEntry)3 TupleRange (com.apple.foundationdb.record.TupleRange)3 FDBRecordVersion (com.apple.foundationdb.record.provider.foundationdb.FDBRecordVersion)3 KeySpacePath (com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePath)3 RecordCoreArgumentException (com.apple.foundationdb.record.RecordCoreArgumentException)2 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)2 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)2