use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class ScalarTranslationVisitor method visitExpression.
@Nonnull
@Override
public Value visitExpression(@Nonnull final ThenKeyExpression thenKeyExpression) {
if (thenKeyExpression.getColumnSize() > 1) {
throw new RecordCoreException("cannot expand ThenKeyExpression in scalar expansion");
}
final ScalarVisitorState state = getCurrentState();
final KeyExpression child = Iterables.getOnlyElement(thenKeyExpression.getChildren());
return pop(child.expand(push(state)));
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class ScalarTranslationVisitor method visitExpression.
@Nonnull
@Override
public Value visitExpression(@Nonnull final NestingKeyExpression nestingKeyExpression) {
final FieldKeyExpression parent = nestingKeyExpression.getParent();
final KeyExpression.FanType fanType = parent.getFanType();
if (fanType != KeyExpression.FanType.None) {
throw new RecordCoreException("cannot expand fan outs in scalar expansion");
}
final ScalarVisitorState state = getCurrentState();
final List<String> fieldNamePrefix = state.getFieldNamePrefix();
final KeyExpression child = nestingKeyExpression.getChild();
final List<String> newPrefix = ImmutableList.<String>builder().addAll(fieldNamePrefix).add(parent.getFieldName()).build();
return pop(child.expand(push(state.withFieldNamePrefix(newPrefix))));
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class JoinedRecordPlanner method plan.
@Nonnull
public JoinedRecordPlan plan(@Nonnull JoinedRecordType.JoinConstituent joinConstituent) {
PendingType pendingType = findPendingType(joinConstituent);
bindAndRemove(pendingType);
while (!pendingTypes.isEmpty()) {
if (pendingTypes.size() == 1) {
pendingType = pendingTypes.get(0);
} else {
pendingType = pendingTypes.stream().filter(PendingType::allJoinsBound).findFirst().orElseGet(() -> pendingTypes.stream().max(Comparator.comparing(PendingType::countJoinsBound)).orElseThrow(() -> new RecordCoreException("did not find any pending types")));
}
queries.add(queryPlanner.plan(buildQuery(pendingType)));
bindAndRemove(pendingType);
}
if (!pendingJoins.isEmpty()) {
// pendingJoins are removed by buildQuery as both sides become bound, so the plan must be incomplete.
throw new RecordCoreException("did not perform all joins");
}
return new JoinedRecordPlan(joinedRecordType, joinedTypes, queries);
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class FDBRecordStore method getSnapshotRecordCount.
@Override
public CompletableFuture<Long> getSnapshotRecordCount(@Nonnull KeyExpression key, @Nonnull Key.Evaluated value, @Nonnull IndexQueryabilityFilter indexQueryabilityFilter) {
if (getRecordMetaData().getRecordCountKey() != null) {
if (key.getColumnSize() != value.size()) {
throw recordCoreException("key and value are not the same size");
}
final ReadTransaction tr = context.readTransaction(true);
final Tuple subkey = Tuple.from(RECORD_COUNT_KEY).addAll(value.toTupleAppropriateList());
if (getRecordMetaData().getRecordCountKey().equals(key)) {
return tr.get(getSubspace().pack(subkey)).thenApply(FDBRecordStore::decodeRecordCount);
} else if (key.isPrefixKey(getRecordMetaData().getRecordCountKey())) {
AsyncIterable<KeyValue> kvs = tr.getRange(getSubspace().range(Tuple.from(RECORD_COUNT_KEY)));
return MoreAsyncUtil.reduce(getExecutor(), kvs.iterator(), 0L, (count, kv) -> count + decodeRecordCount(kv.getValue()));
}
}
return evaluateAggregateFunction(Collections.emptyList(), IndexFunctionHelper.count(key), TupleRange.allOf(value.toTuple()), IsolationLevel.SNAPSHOT, indexQueryabilityFilter).thenApply(tuple -> tuple.getLong(0));
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class FDBRecordStore method deserializeRecord.
private <M extends Message> CompletableFuture<FDBStoredRecord<M>> deserializeRecord(@Nonnull RecordSerializer<M> typedSerializer, @Nonnull final FDBRawRecord rawRecord, @Nonnull final RecordMetaData metaData, @Nonnull final Optional<CompletableFuture<FDBRecordVersion>> versionFutureOptional) {
final Tuple primaryKey = rawRecord.getPrimaryKey();
final byte[] serialized = rawRecord.getRawRecord();
try {
final M protoRecord = typedSerializer.deserialize(metaData, primaryKey, rawRecord.getRawRecord(), getTimer());
final RecordType recordType = metaData.getRecordTypeForDescriptor(protoRecord.getDescriptorForType());
countKeysAndValues(FDBStoreTimer.Counts.LOAD_RECORD_KEY, FDBStoreTimer.Counts.LOAD_RECORD_KEY_BYTES, FDBStoreTimer.Counts.LOAD_RECORD_VALUE_BYTES, rawRecord);
final FDBStoredRecordBuilder<M> recordBuilder = FDBStoredRecord.newBuilder(protoRecord).setPrimaryKey(primaryKey).setRecordType(recordType).setSize(rawRecord);
if (rawRecord.hasVersion()) {
// In the current format version, the version should be read along with the version,
// so this should be hit the majority of the time.
recordBuilder.setVersion(rawRecord.getVersion());
return CompletableFuture.completedFuture(recordBuilder.build());
} else if (versionFutureOptional.isPresent()) {
// another read (which has hopefully happened in parallel with the main record read in the background).
return versionFutureOptional.get().thenApply(version -> {
recordBuilder.setVersion(version);
return recordBuilder.build();
});
} else {
// this will return an FDBStoredRecord where the version is unset.
return CompletableFuture.completedFuture(recordBuilder.build());
}
} catch (Exception ex) {
final LoggableException ex2 = new RecordCoreException("Failed to deserialize record", ex);
ex2.addLogInfo(subspaceProvider.logKey(), subspaceProvider.toString(context), LogMessageKeys.PRIMARY_KEY, primaryKey, LogMessageKeys.META_DATA_VERSION, metaData.getVersion());
if (LOGGER.isDebugEnabled()) {
ex2.addLogInfo("serialized", ByteArrayUtil2.loggable(serialized));
}
if (LOGGER.isTraceEnabled()) {
ex2.addLogInfo("descriptor", metaData.getUnionDescriptor().getFile().toProto());
}
throw ex2;
}
}
Aggregations