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