Search in sources :

Example 56 with Subspace

use of com.apple.foundationdb.subspace.Subspace in project fdb-record-layer by FoundationDB.

the class RankIndexMaintainer method evaluateEqualRange.

private CompletableFuture<Tuple> evaluateEqualRange(@Nonnull TupleRange range, @Nonnull EvaluateEqualRange function) {
    Subspace rankSubspace = getSecondarySubspace();
    Tuple values = range.getLow();
    final int groupingCount = getGroupingCount();
    if (groupingCount > 0) {
        rankSubspace = rankSubspace.subspace(TupleHelpers.subTuple(values, 0, groupingCount));
        values = TupleHelpers.subTuple(values, groupingCount, values.size());
    }
    final RankedSet rankedSet = new RankedSetIndexHelper.InstrumentedRankedSet(state, rankSubspace, config);
    return function.apply(rankedSet, values);
}
Also used : Subspace(com.apple.foundationdb.subspace.Subspace) RankedSet(com.apple.foundationdb.async.RankedSet) Tuple(com.apple.foundationdb.tuple.Tuple)

Example 57 with Subspace

use of com.apple.foundationdb.subspace.Subspace in project fdb-record-layer by FoundationDB.

the class SplitHelper method clearPreviousSplitRecord.

private static void clearPreviousSplitRecord(@Nonnull final FDBRecordContext context, @Nonnull final Subspace subspace, @Nonnull final Tuple key, final boolean clearBasedOnPreviousSizeInfo, @Nullable FDBStoredSizes previousSizeInfo) {
    final Transaction tr = context.ensureActive();
    final Subspace keySplitSubspace = subspace.subspace(key);
    if (clearBasedOnPreviousSizeInfo) {
        if (previousSizeInfo != null) {
            if (previousSizeInfo.isSplit() || previousSizeInfo.isVersionedInline()) {
                // Record might be shorter than previous split.
                tr.clear(keySplitSubspace.range());
            } else {
                // Record was previously unsplit and had unsplit suffix because we are splitting long records.
                tr.clear(keySplitSubspace.pack(UNSPLIT_RECORD));
            }
        }
    } else {
        // Clears both unsplit and previous longer split.
        tr.clear(keySplitSubspace.range());
    }
    final byte[] versionKey = keySplitSubspace.pack(RECORD_VERSION);
    context.getLocalVersion(versionKey).ifPresent(localVersion -> context.removeVersionMutation(versionKey));
}
Also used : Transaction(com.apple.foundationdb.Transaction) ReadTransaction(com.apple.foundationdb.ReadTransaction) Subspace(com.apple.foundationdb.subspace.Subspace)

Example 58 with Subspace

use of com.apple.foundationdb.subspace.Subspace in project fdb-record-layer by FoundationDB.

the class SubspaceProviderByKeySpacePath method getSubspaceAsync.

@Nonnull
@Override
public CompletableFuture<Subspace> getSubspaceAsync(@Nonnull FDBRecordContext context) {
    CompletableFuture<Subspace> subspaceFuture;
    String clusterFile = context.getDatabase().getClusterFile();
    Optional<String> key = Optional.ofNullable(clusterFile);
    Subspace subspace = databases.get(key);
    if (subspace == null) {
        subspaceFuture = keySpacePath.toSubspaceAsync(context).whenComplete((s, e) -> {
            if (e == null) {
                this.databases.put(key, s);
            }
        });
    } else {
        subspaceFuture = CompletableFuture.completedFuture(subspace);
    }
    return subspaceFuture;
}
Also used : KeySpacePath(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePath) Tuple(com.apple.foundationdb.tuple.Tuple) LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) API(com.apple.foundationdb.annotation.API) Nonnull(javax.annotation.Nonnull) Subspace(com.apple.foundationdb.subspace.Subspace) Subspace(com.apple.foundationdb.subspace.Subspace) Nonnull(javax.annotation.Nonnull)

Example 59 with Subspace

use of com.apple.foundationdb.subspace.Subspace in project fdb-record-layer by FoundationDB.

the class SubspaceProviderByKeySpacePath method toString.

@Override
public String toString(@Nonnull FDBRecordContext context) {
    Optional<String> key = Optional.ofNullable(context.getDatabase().getClusterFile());
    Subspace subspace = databases.get(key);
    if (subspace != null) {
        return keySpacePath.toString(Tuple.fromBytes(subspace.pack()));
    } else {
        return toString();
    }
}
Also used : Subspace(com.apple.foundationdb.subspace.Subspace)

Example 60 with Subspace

use of com.apple.foundationdb.subspace.Subspace in project fdb-record-layer by FoundationDB.

the class SplitHelper method loadWithSplit.

/**
 * Load serialized byte array that may be split among several keys.
 * @param tr read transaction
 * @param context transaction context
 * @param subspace subspace containing serialized value
 * @param key key within subspace
 * @param splitLongRecords <code>true</code> if multiple keys should be used; if <code>false</code>, <code>serialized</code> must fit in a single key
 * @param missingUnsplitRecordSuffix if <code>splitLongRecords</code> is <code>false</code> and this is <code>true</code>, this will assume keys are missing a suffix for backwards compatibility reasons
 * @param sizeInfo optional size information to populate
 * @return the merged byte array
 */
public static CompletableFuture<FDBRawRecord> loadWithSplit(@Nonnull final ReadTransaction tr, @Nonnull final FDBRecordContext context, @Nonnull final Subspace subspace, @Nonnull final Tuple key, final boolean splitLongRecords, final boolean missingUnsplitRecordSuffix, @Nullable SizeInfo sizeInfo) {
    if (!splitLongRecords && missingUnsplitRecordSuffix) {
        return loadUnsplitLegacy(tr, context, subspace, key, sizeInfo);
    }
    // Even if long records are not split, then unless we are using the old format, it might be the case
    // that there is a record version associated with this key, hence the range read.
    // It is still better to do a range read in that case than two point reads (probably).
    final long startTime = System.nanoTime();
    final Subspace recordSubspace = subspace.subspace(key);
    // Note that recordSubspace.range() includes only keys that are a strict prefix of recordSubspace.pack(). This means
    // it excludes recordSubspace.pack() itself as well as any keys that are greater than or equal to recordSubspace.pack() + \xff.
    final AsyncIterable<KeyValue> rangeScan = tr.getRange(recordSubspace.range(), ReadTransaction.ROW_LIMIT_UNLIMITED, false, StreamingMode.WANT_ALL);
    final AsyncIterator<KeyValue> rangeIter = rangeScan.iterator();
    context.instrument(FDBStoreTimer.DetailEvents.GET_RECORD_RANGE_RAW_FIRST_CHUNK, rangeIter.onHasNext(), startTime);
    return new SingleKeyUnsplitter(context, key, recordSubspace, rangeIter, sizeInfo).run(context.getExecutor());
}
Also used : KeyValue(com.apple.foundationdb.KeyValue) Subspace(com.apple.foundationdb.subspace.Subspace)

Aggregations

Subspace (com.apple.foundationdb.subspace.Subspace)61 Nonnull (javax.annotation.Nonnull)33 Tuple (com.apple.foundationdb.tuple.Tuple)28 List (java.util.List)23 ArrayList (java.util.ArrayList)21 CompletableFuture (java.util.concurrent.CompletableFuture)21 Nullable (javax.annotation.Nullable)20 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)19 KeyValue (com.apple.foundationdb.KeyValue)18 Map (java.util.Map)18 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)17 API (com.apple.foundationdb.annotation.API)16 ScanProperties (com.apple.foundationdb.record.ScanProperties)15 Collections (java.util.Collections)15 Test (org.junit.jupiter.api.Test)15 Transaction (com.apple.foundationdb.Transaction)14 RecordCursor (com.apple.foundationdb.record.RecordCursor)14 TupleRange (com.apple.foundationdb.record.TupleRange)14 LogMessageKeys (com.apple.foundationdb.record.logging.LogMessageKeys)14 Message (com.google.protobuf.Message)14