Skip to content

Commit 58205df

Browse files
authored
Change DataInKeySpacePath to contain a KeySpacePath instead of ResolvedKeySpacePath (#3716)
It was unnecessary to have the ResolvedKeySpacePath, and we want to be able to import into a different cluster, where the resolved values are different from the exported data. This means that DataInKeySpacePath has a few more fields, but makes it more versatile going forward. This also changes `exportAllData` to use `mapPipelined` to resolve the path, so that `DataInKeySpacePath` does not contain a future. This is in support of #3573
1 parent 80307d2 commit 58205df

File tree

8 files changed

+98
-429
lines changed

8 files changed

+98
-429
lines changed

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
import com.apple.foundationdb.annotation.API;
2525
import com.apple.foundationdb.record.RecordCoreArgumentException;
2626
import com.apple.foundationdb.record.logging.LogMessageKeys;
27-
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext;
28-
import com.apple.foundationdb.tuple.ByteArrayUtil2;
27+
import com.apple.foundationdb.tuple.Tuple;
2928

3029
import javax.annotation.Nonnull;
31-
import java.util.concurrent.CompletableFuture;
30+
import javax.annotation.Nullable;
3231

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

3938
@Nonnull
40-
private final CompletableFuture<ResolvedKeySpacePath> resolvedPath;
39+
private final KeySpacePath path;
40+
@Nullable
41+
private final Tuple remainder;
4142
@Nonnull
4243
private final byte[] value;
4344

44-
public DataInKeySpacePath(KeySpacePath path, KeyValue rawKeyValue, FDBRecordContext context) {
45-
this.resolvedPath = path.toResolvedPathAsync(context, rawKeyValue.getKey());
46-
this.value = rawKeyValue.getValue();
47-
if (this.value == null) {
45+
public DataInKeySpacePath(@Nonnull final KeySpacePath path, @Nullable final Tuple remainder,
46+
@Nullable final byte[] value) {
47+
this.path = path;
48+
this.remainder = remainder;
49+
if (value == null) {
4850
throw new RecordCoreArgumentException("Value cannot be null")
49-
.addLogInfo(LogMessageKeys.KEY, ByteArrayUtil2.loggable(rawKeyValue.getKey()));
51+
.addLogInfo(LogMessageKeys.KEY, path);
5052
}
51-
}
52-
53-
public CompletableFuture<ResolvedKeySpacePath> getResolvedPath() {
54-
return resolvedPath;
53+
this.value = value;
5554
}
5655

5756
public byte[] getValue() {
5857
return this.value;
5958
}
59+
60+
@Nonnull
61+
public KeySpacePath getPath() {
62+
return path;
63+
}
64+
65+
@Nullable
66+
public Tuple getRemainder() {
67+
return remainder;
68+
}
69+
6070
}

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpace.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ public KeySpacePath path(@Nonnull String name, @Nullable Object value) {
189189
* <p>
190190
* If entries remained in the tuple beyond the leaf directory, then {@link ResolvedKeySpacePath#getRemainder()} can be
191191
* used to fetch the remaining portion.
192-
* See also {@link KeySpacePath#toResolvedPathAsync(FDBRecordContext, byte[])} if you need to resolve and you
193-
* know that it is part of a given path.
194192
* </p>
195193
* @param context context used, if needed, for any database operations
196194
* @param key the tuple to be decoded

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpacePath.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,6 @@ default Tuple toTuple(@Nonnull FDBRecordContext context) {
157157
@Nonnull
158158
CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBRecordContext context);
159159

160-
/**
161-
* Given a tuple from an FDB key, attempts to determine what sub-path through this directory the tuple
162-
* represents, returning a <code>ResolvedKeySpacePath</code> representing the leaf-most directory in the path.
163-
* <p>
164-
* If entries remained in the tuple beyond the leaf directory, then {@link ResolvedKeySpacePath#getRemainder()}
165-
* can be used to fetch the remaining portion.
166-
* See also {@link KeySpace#resolveFromKeyAsync(FDBRecordContext, Tuple)} if you need to resolve from the root.
167-
* </p>
168-
* @param context context used, if needed, for any database operations
169-
* @param key a raw key from the database
170-
* @return the {@link ResolvedKeySpacePath} corresponding to that key, with a potential remainder.
171-
* @throws com.apple.foundationdb.record.RecordCoreArgumentException if the key provided is not part of this path
172-
*/
173-
@API(API.Status.EXPERIMENTAL)
174-
@Nonnull
175-
default CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBRecordContext context, byte[] key) {
176-
throw new UnsupportedOperationException("toResolvedPathAsync is not supported");
177-
}
178-
179160
/**
180161
* Resolves the path into a {@link ResolvedKeySpacePath}, a form the retains all of the information about
181162
* the path itself along with the value to which each path entry is resolved.

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpacePathImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.apple.foundationdb.tuple.ByteArrayUtil;
3535
import com.apple.foundationdb.tuple.Tuple;
3636
import com.apple.foundationdb.tuple.TupleHelpers;
37+
import com.google.common.annotations.VisibleForTesting;
3738
import com.google.common.collect.Lists;
3839

3940
import javax.annotation.Nonnull;
@@ -181,8 +182,8 @@ public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBR
181182
}
182183

183184
@Nonnull
184-
@Override
185-
public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull final FDBRecordContext context, final byte[] key) {
185+
@VisibleForTesting
186+
CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull final FDBRecordContext context, final byte[] key) {
186187
final Tuple keyTuple = Tuple.fromBytes(key);
187188
return toResolvedPathAsync(context).thenCompose(resolvedPath -> {
188189
// Now use the resolved path to find the child for the key
@@ -308,7 +309,11 @@ public RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext
308309
.setScanProperties(scanProperties)
309310
.build()),
310311
context.getExecutor())
311-
.map(keyValue -> new DataInKeySpacePath(this, keyValue, context));
312+
.mapPipelined(keyValue ->
313+
toResolvedPathAsync(context, keyValue.getKey())
314+
.thenApply(resolvedKey ->
315+
new DataInKeySpacePath(resolvedKey.toPath(), resolvedKey.getRemainder(), keyValue.getValue())),
316+
1);
312317
}
313318

314319
/**

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpacePathWrapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBR
175175
return inner.toResolvedPathAsync(context);
176176
}
177177

178-
@Nonnull
179-
@Override
180-
public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull final FDBRecordContext context, final byte[] key) {
181-
return inner.toResolvedPathAsync(context, key);
182-
}
183-
184178
@Override
185179
public boolean equals(Object obj) {
186180
return inner.equals(obj);

0 commit comments

Comments
 (0)