Search in sources :

Example 6 with API

use of com.apple.foundationdb.annotation.API in project fdb-record-layer by FoundationDB.

the class FDBMetaDataStore method updateRecordsAsync.

/**
 * Update the meta-data records descriptor asynchronously.
 * This adds any new record types to the meta-data and replaces all of the current descriptors with the new descriptors.
 *
 * <p>
 *  It is important to note that if a local file descriptor is set using {@link #setLocalFileDescriptor(Descriptors.FileDescriptor)},
 *  the local file descriptor must be at least as evolved as the records descriptor passed to this method.
 *  Otherwise, {@code updateRecordsAsync} will fail.
 * </p>
 *
 * <p>
 * If the given file descriptor is missing a union message, this method will add one before updating the meta-data.
 * The generated union descriptor is constructed by adding any non-{@code NESTED} types in the file descriptor to the
 * union descriptor from the currently stored meta-data. A new field is not added if a field of the given type already
 * exists, and the order of any existing fields is preserved. Note that types are identified by name, so renaming
 * top-level message types may result in validation errors when trying to update the record descriptor.
 * </p>
 *
 * @param recordsDescriptor the new recordsDescriptor
 * @return a future that completes when the records descriptor is updated
 */
@Nonnull
@API(API.Status.MAINTAINED)
public CompletableFuture<Void> updateRecordsAsync(@Nonnull Descriptors.FileDescriptor recordsDescriptor) {
    return loadCurrentProto().thenCompose(metaDataProto -> {
        // Update the records without using its local file descriptor. Let saveAndSetCurrent use the local file descriptor when saving the meta-data.
        RecordMetaDataBuilder recordMetaDataBuilder = createMetaDataBuilder(metaDataProto, false);
        // If union is missing, first add a default union.
        recordMetaDataBuilder.updateRecords(MetaDataProtoEditor.addDefaultUnionIfMissing(recordsDescriptor, recordMetaDataBuilder.getUnionDescriptor()));
        return saveAndSetCurrent(recordMetaDataBuilder.getRecordMetaData().toProto());
    });
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Nonnull(javax.annotation.Nonnull) API(com.apple.foundationdb.annotation.API)

Example 7 with API

use of com.apple.foundationdb.annotation.API in project fdb-record-layer by FoundationDB.

the class RecordMetaDataBuilder method addJoinedRecordType.

/**
 * Add a new joined record type.
 * @param name the name of the new record type
 * @return a new uninitialized joined record type
 */
@Nonnull
@API(API.Status.EXPERIMENTAL)
public JoinedRecordTypeBuilder addJoinedRecordType(@Nonnull String name) {
    if (recordTypes.containsKey(name)) {
        throw new MetaDataException("There is already a record type named " + name);
    }
    if (syntheticRecordTypes.containsKey(name)) {
        throw new MetaDataException("There is already a synthetic record type named " + name);
    }
    JoinedRecordTypeBuilder recordType = new JoinedRecordTypeBuilder(name, getNextRecordTypeKey(), this);
    syntheticRecordTypes.put(name, recordType);
    return recordType;
}
Also used : JoinedRecordTypeBuilder(com.apple.foundationdb.record.metadata.JoinedRecordTypeBuilder) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Nonnull(javax.annotation.Nonnull) API(com.apple.foundationdb.annotation.API)

Example 8 with API

use of com.apple.foundationdb.annotation.API in project fdb-record-layer by FoundationDB.

the class FDBRecordStore method loadSyntheticRecord.

/**
 * Load a {@link FDBSyntheticRecord synthetic record} by loading its stored constituent records and synthesizing it from them.
 * @param primaryKey the primary key of the synthetic record, which includes the primary keys of the constituents
 * @return a future which completes to the synthesized record
 */
@Nonnull
@API(API.Status.EXPERIMENTAL)
public CompletableFuture<FDBSyntheticRecord> loadSyntheticRecord(@Nonnull Tuple primaryKey) {
    SyntheticRecordType<?> syntheticRecordType = getRecordMetaData().getSyntheticRecordTypeFromRecordTypeKey(primaryKey.get(0));
    int nconstituents = syntheticRecordType.getConstituents().size();
    if (nconstituents != primaryKey.size() - 1) {
        throw recordCoreException("Primary key does not have correct number of nested keys: " + primaryKey);
    }
    final Map<String, FDBStoredRecord<? extends Message>> constituents = new ConcurrentHashMap<>(nconstituents);
    final CompletableFuture<?>[] futures = new CompletableFuture<?>[nconstituents];
    for (int i = 0; i < nconstituents; i++) {
        final SyntheticRecordType.Constituent constituent = syntheticRecordType.getConstituents().get(i);
        final Tuple constituentKey = primaryKey.getNestedTuple(i + 1);
        if (constituentKey == null) {
            futures[i] = AsyncUtil.DONE;
        } else {
            futures[i] = loadRecordAsync(constituentKey).thenApply(rec -> {
                if (rec == null) {
                    throw new RecordDoesNotExistException("constituent record not found: " + constituent.getName());
                }
                constituents.put(constituent.getName(), rec);
                return null;
            });
        }
    }
    return CompletableFuture.allOf(futures).thenApply(vignore -> FDBSyntheticRecord.of(syntheticRecordType, constituents));
}
Also used : LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) UnaryOperator(java.util.function.UnaryOperator) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) RecordSerializer(com.apple.foundationdb.record.provider.common.RecordSerializer) Subspace(com.apple.foundationdb.subspace.Subspace) MutationType(com.apple.foundationdb.MutationType) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) Map(java.util.Map) RecordIndexUniquenessViolation(com.apple.foundationdb.record.RecordIndexUniquenessViolation) QueryToKeyMatcher(com.apple.foundationdb.record.query.QueryToKeyMatcher) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Query(com.apple.foundationdb.record.query.expressions.Query) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) Set(java.util.Set) TupleRange(com.apple.foundationdb.record.TupleRange) KeySpacePath(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePath) ByteOrder(java.nio.ByteOrder) SyntheticRecordType(com.apple.foundationdb.record.metadata.SyntheticRecordType) RecordMetaDataProvider(com.apple.foundationdb.record.RecordMetaDataProvider) RecordStoreState(com.apple.foundationdb.record.RecordStoreState) TupleHelpers(com.apple.foundationdb.tuple.TupleHelpers) API(com.apple.foundationdb.annotation.API) FunctionNames(com.apple.foundationdb.record.FunctionNames) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) IndexAggregateFunction(com.apple.foundationdb.record.metadata.IndexAggregateFunction) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) RangeSet(com.apple.foundationdb.async.RangeSet) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) Supplier(java.util.function.Supplier) FormerIndex(com.apple.foundationdb.record.metadata.FormerIndex) ArrayList(java.util.ArrayList) ByteScanLimiter(com.apple.foundationdb.record.ByteScanLimiter) ParameterRelationshipGraph(com.apple.foundationdb.record.query.ParameterRelationshipGraph) LoggableException(com.apple.foundationdb.util.LoggableException) CloseableAsyncIterator(com.apple.foundationdb.async.CloseableAsyncIterator) IndexRecordFunction(com.apple.foundationdb.record.metadata.IndexRecordFunction) Nullable(javax.annotation.Nullable) ByteArrayUtil2(com.apple.foundationdb.tuple.ByteArrayUtil2) IsolationLevel(com.apple.foundationdb.record.IsolationLevel) CursorLimitManager(com.apple.foundationdb.record.cursors.CursorLimitManager) ExecuteState(com.apple.foundationdb.record.ExecuteState) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordType(com.apple.foundationdb.record.metadata.RecordType) Index(com.apple.foundationdb.record.metadata.Index) DynamicMessageRecordSerializer(com.apple.foundationdb.record.provider.common.DynamicMessageRecordSerializer) SyntheticRecordPlanner(com.apple.foundationdb.record.query.plan.synthetic.SyntheticRecordPlanner) IndexEntry(com.apple.foundationdb.record.IndexEntry) LoggerFactory(org.slf4j.LoggerFactory) RecordCoreStorageException(com.apple.foundationdb.record.RecordCoreStorageException) ByteBuffer(java.nio.ByteBuffer) RecordQueryPlanner(com.apple.foundationdb.record.query.plan.RecordQueryPlanner) Transaction(com.apple.foundationdb.Transaction) Tuple(com.apple.foundationdb.tuple.Tuple) Range(com.apple.foundationdb.Range) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) PipelineOperation(com.apple.foundationdb.record.PipelineOperation) RecordMetaDataProto(com.apple.foundationdb.record.RecordMetaDataProto) ByteArrayUtil(com.apple.foundationdb.tuple.ByteArrayUtil) KeyValue(com.apple.foundationdb.KeyValue) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IndexQueryabilityFilter(com.apple.foundationdb.record.query.IndexQueryabilityFilter) AndComponent(com.apple.foundationdb.record.query.expressions.AndComponent) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) List(java.util.List) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) AggregateFunctionNotSupportedException(com.apple.foundationdb.record.AggregateFunctionNotSupportedException) RecordTypeKeyComparison(com.apple.foundationdb.record.query.expressions.RecordTypeKeyComparison) IndexTypes(com.apple.foundationdb.record.metadata.IndexTypes) Optional(java.util.Optional) MutableRecordStoreState(com.apple.foundationdb.record.MutableRecordStoreState) RecordTypeOrBuilder(com.apple.foundationdb.record.metadata.RecordTypeOrBuilder) SyntheticRecordFromStoredRecordPlan(com.apple.foundationdb.record.query.plan.synthetic.SyntheticRecordFromStoredRecordPlan) SpotBugsSuppressWarnings(com.apple.foundationdb.annotation.SpotBugsSuppressWarnings) Descriptors(com.google.protobuf.Descriptors) AsyncIterator(com.apple.foundationdb.async.AsyncIterator) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) CursorStreamingMode(com.apple.foundationdb.record.CursorStreamingMode) Key(com.apple.foundationdb.record.metadata.Key) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) EndpointType(com.apple.foundationdb.record.EndpointType) ScanProperties(com.apple.foundationdb.record.ScanProperties) Suppliers(com.google.common.base.Suppliers) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) EmptyKeyExpression(com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression) MoreAsyncUtil(com.apple.foundationdb.async.MoreAsyncUtil) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) IndexState(com.apple.foundationdb.record.IndexState) StoreRecordFunction(com.apple.foundationdb.record.metadata.StoreRecordFunction) ReadTransaction(com.apple.foundationdb.ReadTransaction) AsyncIterable(com.apple.foundationdb.async.AsyncIterable) FDBRecordStoreStateCache(com.apple.foundationdb.record.provider.foundationdb.storestate.FDBRecordStoreStateCache) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Message(com.google.protobuf.Message) SyntheticRecordType(com.apple.foundationdb.record.metadata.SyntheticRecordType) ByteString(com.google.protobuf.ByteString) CompletableFuture(java.util.concurrent.CompletableFuture) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Tuple(com.apple.foundationdb.tuple.Tuple) Nonnull(javax.annotation.Nonnull) API(com.apple.foundationdb.annotation.API)

Aggregations

API (com.apple.foundationdb.annotation.API)8 Nonnull (javax.annotation.Nonnull)7 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)4 RecordType (com.apple.foundationdb.record.metadata.RecordType)4 SyntheticRecordType (com.apple.foundationdb.record.metadata.SyntheticRecordType)4 KeyValue (com.apple.foundationdb.KeyValue)3 MutationType (com.apple.foundationdb.MutationType)3 Range (com.apple.foundationdb.Range)3 ReadTransaction (com.apple.foundationdb.ReadTransaction)3 Transaction (com.apple.foundationdb.Transaction)3 SpotBugsSuppressWarnings (com.apple.foundationdb.annotation.SpotBugsSuppressWarnings)3 AsyncIterable (com.apple.foundationdb.async.AsyncIterable)3 AsyncIterator (com.apple.foundationdb.async.AsyncIterator)3 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)3 CloseableAsyncIterator (com.apple.foundationdb.async.CloseableAsyncIterator)3 MoreAsyncUtil (com.apple.foundationdb.async.MoreAsyncUtil)3 RangeSet (com.apple.foundationdb.async.RangeSet)3 AggregateFunctionNotSupportedException (com.apple.foundationdb.record.AggregateFunctionNotSupportedException)3 ByteScanLimiter (com.apple.foundationdb.record.ByteScanLimiter)3 CursorStreamingMode (com.apple.foundationdb.record.CursorStreamingMode)3