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