Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
import com.apple.foundationdb.annotation.API;
import com.apple.foundationdb.record.RecordCoreArgumentException;
import com.apple.foundationdb.record.logging.LogMessageKeys;
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext;
import com.apple.foundationdb.tuple.ByteArrayUtil2;
import com.apple.foundationdb.tuple.Tuple;

import javax.annotation.Nonnull;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nullable;

/**
* Class representing a {@link KeyValue} pair within in {@link KeySpacePath}.
Expand All @@ -37,24 +36,35 @@
public class DataInKeySpacePath {

@Nonnull
private final CompletableFuture<ResolvedKeySpacePath> resolvedPath;
private final KeySpacePath path;
@Nullable
private final Tuple remainder;
@Nonnull
private final byte[] value;

public DataInKeySpacePath(KeySpacePath path, KeyValue rawKeyValue, FDBRecordContext context) {
this.resolvedPath = path.toResolvedPathAsync(context, rawKeyValue.getKey());
this.value = rawKeyValue.getValue();
if (this.value == null) {
public DataInKeySpacePath(@Nonnull final KeySpacePath path, @Nullable final Tuple remainder,
@Nullable final byte[] value) {
this.path = path;
this.remainder = remainder;
if (value == null) {
throw new RecordCoreArgumentException("Value cannot be null")
.addLogInfo(LogMessageKeys.KEY, ByteArrayUtil2.loggable(rawKeyValue.getKey()));
.addLogInfo(LogMessageKeys.KEY, path);
}
}

public CompletableFuture<ResolvedKeySpacePath> getResolvedPath() {
return resolvedPath;
this.value = value;

Check warning on line 53 in fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/DataInKeySpacePath.java

View check run for this annotation

fdb.teamscale.io / Teamscale | Findings

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/DataInKeySpacePath.java#L53

Store a copy of `value` https://fdb.teamscale.io/findings/details/foundationdb-fdb-record-layer?t=FORK_MR%2F3716%2FScottDugas%2Fnon-resolved-data-in-keyspace%3AHEAD&id=070A7A05FB4C44121B9F0942728F357E
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copying the byte[] here and in getValue, I created an issue to convert it to ByteString: #3717

}

public byte[] getValue() {
return this.value;

Check warning on line 57 in fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/DataInKeySpacePath.java

View check run for this annotation

fdb.teamscale.io / Teamscale | Findings

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/DataInKeySpacePath.java#L57

Return a copy of `value` https://fdb.teamscale.io/findings/details/foundationdb-fdb-record-layer?t=FORK_MR%2F3716%2FScottDugas%2Fnon-resolved-data-in-keyspace%3AHEAD&id=28DE7718F7668214DBBA0276EDF01F54
}

@Nonnull
public KeySpacePath getPath() {
return path;
}

@Nullable
public Tuple getRemainder() {
return remainder;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ public KeySpacePath path(@Nonnull String name, @Nullable Object value) {
* <p>
* If entries remained in the tuple beyond the leaf directory, then {@link ResolvedKeySpacePath#getRemainder()} can be
* used to fetch the remaining portion.
* See also {@link KeySpacePath#toResolvedPathAsync(FDBRecordContext, byte[])} if you need to resolve and you
* know that it is part of a given path.
* </p>
* @param context context used, if needed, for any database operations
* @param key the tuple to be decoded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,6 @@ default Tuple toTuple(@Nonnull FDBRecordContext context) {
@Nonnull
CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBRecordContext context);

/**
* Given a tuple from an FDB key, attempts to determine what sub-path through this directory the tuple
* represents, returning a <code>ResolvedKeySpacePath</code> representing the leaf-most directory in the path.
* <p>
* If entries remained in the tuple beyond the leaf directory, then {@link ResolvedKeySpacePath#getRemainder()}
* can be used to fetch the remaining portion.
* See also {@link KeySpace#resolveFromKeyAsync(FDBRecordContext, Tuple)} if you need to resolve from the root.
* </p>
* @param context context used, if needed, for any database operations
* @param key a raw key from the database
* @return the {@link ResolvedKeySpacePath} corresponding to that key, with a potential remainder.
* @throws com.apple.foundationdb.record.RecordCoreArgumentException if the key provided is not part of this path
*/
@API(API.Status.EXPERIMENTAL)
@Nonnull
default CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBRecordContext context, byte[] key) {
throw new UnsupportedOperationException("toResolvedPathAsync is not supported");
}

/**
* Resolves the path into a {@link ResolvedKeySpacePath}, a form the retains all of the information about
* the path itself along with the value to which each path entry is resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.apple.foundationdb.tuple.ByteArrayUtil;
import com.apple.foundationdb.tuple.Tuple;
import com.apple.foundationdb.tuple.TupleHelpers;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -181,8 +182,8 @@ public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBR
}

@Nonnull
@Override
public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull final FDBRecordContext context, final byte[] key) {
@VisibleForTesting
CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull final FDBRecordContext context, final byte[] key) {
final Tuple keyTuple = Tuple.fromBytes(key);
return toResolvedPathAsync(context).thenCompose(resolvedPath -> {
// Now use the resolved path to find the child for the key
Expand Down Expand Up @@ -308,7 +309,11 @@ public RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext
.setScanProperties(scanProperties)
.build()),
context.getExecutor())
.map(keyValue -> new DataInKeySpacePath(this, keyValue, context));
.mapPipelined(keyValue ->
toResolvedPathAsync(context, keyValue.getKey())
.thenApply(resolvedKey ->
new DataInKeySpacePath(resolvedKey.toPath(), resolvedKey.getRemainder(), keyValue.getValue())),
1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBR
return inner.toResolvedPathAsync(context);
}

@Nonnull
@Override
public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull final FDBRecordContext context, final byte[] key) {
return inner.toResolvedPathAsync(context, key);
}

@Override
public boolean equals(Object obj) {
return inner.equals(obj);
Expand Down
Loading
Loading