Skip to content

Commit 714faf3

Browse files
committed
Respond to DataInKeySpacePath not having Resolved on main (after rebase)
1 parent f63ae18 commit 714faf3

File tree

4 files changed

+28
-35
lines changed

4 files changed

+28
-35
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ default RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext
417417
* or one of the sub-directories, if not the future will complete exceptionally with
418418
* {@link RecordCoreIllegalImportDataException}.
419419
* If there is any data already existing under this path, the new data will overwrite if the keys are the same.
420-
* This will use the logical value in the {@link DataInKeySpacePath#getResolvedPath()} to determine the key, rather
420+
* This will use the logical values in the {@link DataInKeySpacePath#getPath()} and
421+
* {@link DataInKeySpacePath#getRemainder()} to determine the key, rather
421422
* than the raw key, meaning that this will work even if the data was exported from a different cluster.
422423
* @param context the transaction context in which to save the data
423424
* @param dataToImport the data to be saved to the database

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,33 +322,32 @@ public CompletableFuture<Void> importData(@Nonnull FDBRecordContext context,
322322
@Nonnull Iterable<DataInKeySpacePath> dataToImport) {
323323
return toTupleAsync(context).thenCompose(targetTuple -> {
324324
List<CompletableFuture<Void>> importFutures = new ArrayList<>();
325-
325+
326326
for (DataInKeySpacePath dataItem : dataToImport) {
327-
CompletableFuture<Void> importFuture = dataItem.getResolvedPath().thenCompose(resolvedPath -> {
327+
CompletableFuture<Void> importFuture = dataItem.getPath().toTupleAsync(context).thenCompose(itemPathTuple -> {
328328
// Validate that this data belongs under this path
329-
Tuple itemTuple = resolvedPath.toTuple();
330-
if (!TupleHelpers.isPrefix(targetTuple, itemTuple)) {
329+
if (!TupleHelpers.isPrefix(targetTuple, itemPathTuple)) {
331330
throw new RecordCoreIllegalImportDataException(
332331
"Data item path does not belong under target path",
333-
"target", targetTuple, "item", itemTuple);
332+
"target", targetTuple, "item", itemPathTuple);
334333
}
335-
336-
// Reconstruct the key using logical values from the resolved path
337-
Tuple keyTuple = itemTuple;
338-
if (resolvedPath.getRemainder() != null) {
339-
keyTuple = keyTuple.addAll(resolvedPath.getRemainder());
334+
335+
// Reconstruct the key using the path and remainder
336+
Tuple keyTuple = itemPathTuple;
337+
if (dataItem.getRemainder() != null) {
338+
keyTuple = keyTuple.addAll(dataItem.getRemainder());
340339
}
341-
340+
342341
// Store the data
343342
byte[] keyBytes = keyTuple.pack();
344343
byte[] valueBytes = dataItem.getValue();
345344
context.ensureActive().set(keyBytes, valueBytes);
346-
345+
347346
return AsyncUtil.DONE;
348347
});
349348
importFutures.add(importFuture);
350349
}
351-
350+
352351
return AsyncUtil.whenAll(importFutures);
353352
});
354353
}

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpacePathDataExportTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ private static List<DataInKeySpacePath> exportAllData(final KeySpacePath pathToE
635635
final List<DataInKeySpacePath> reversed = pathToExport.exportAllData(context, null, ScanProperties.REVERSE_SCAN)
636636
.asList().join();
637637
Collections.reverse(reversed);
638-
assertDataInKeySpacePathEquals(asSingleExport, reversed);
638+
assertDataInKeySpacePathEquals(context, asSingleExport, reversed);
639639

640640
// Assert continuations work correctly
641641
final ScanProperties scanProperties = ScanProperties.FORWARD_SCAN.with(props -> props.setReturnedRowLimit(1));
@@ -655,11 +655,12 @@ private static List<DataInKeySpacePath> exportAllData(final KeySpacePath pathToE
655655
}
656656
}
657657

658-
assertDataInKeySpacePathEquals(asSingleExport, asContinuations);
658+
assertDataInKeySpacePathEquals(context, asSingleExport, asContinuations);
659659
return asSingleExport;
660660
}
661661

662-
private static void assertDataInKeySpacePathEquals(final List<DataInKeySpacePath> expectedList,
662+
private static void assertDataInKeySpacePathEquals(final FDBRecordContext context,
663+
final List<DataInKeySpacePath> expectedList,
663664
final List<DataInKeySpacePath> actualList) {
664665
assertThat(actualList).zipSatisfy(expectedList,
665666
(actual, other) -> {

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpacePathImportDataTest.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
package com.apple.foundationdb.record.provider.foundationdb.keyspace;
2222

23-
import com.apple.foundationdb.KeyValue;
2423
import com.apple.foundationdb.Transaction;
2524
import com.apple.foundationdb.record.ScanProperties;
2625
import com.apple.foundationdb.record.provider.foundationdb.FDBDatabase;
@@ -178,11 +177,8 @@ void importOverwriteExistingData() {
178177

179178
// Create import data with same key but different value
180179
List<DataInKeySpacePath> importData = new ArrayList<>();
181-
try (FDBRecordContext context = database.openContext()) {
182-
byte[] key = dataPath.toSubspace(context).pack(Tuple.from("record"));
183-
KeyValue kv = new KeyValue(key, Tuple.from("new_value").pack());
184-
importData.add(new DataInKeySpacePath(root.path("root"), kv, context));
185-
}
180+
importData.add(new DataInKeySpacePath(dataPath,
181+
Tuple.from("record"), Tuple.from("new_value").pack()));
186182

187183
// Verify we can re-import the data multiple times
188184
importData(database, root.path("root"), importData);
@@ -349,19 +345,15 @@ void importDataWithDuplicateKeys() {
349345

350346

351347
KeySpacePath dataPath = root.path("root").add("data", 1L);
352-
try (FDBRecordContext context = database.openContext()) {
353-
byte[] key = dataPath.toSubspace(context).pack(Tuple.from("item"));
354-
355-
// Create multiple DataInKeySpacePath objects with same key but different values
356-
List<DataInKeySpacePath> duplicateData = Arrays.asList(
357-
new DataInKeySpacePath(root.path("root"),
358-
new KeyValue(key, Tuple.from("first_value").pack()), context),
359-
new DataInKeySpacePath(root.path("root"),
360-
new KeyValue(key, Tuple.from("second_value").pack()), context),
361-
new DataInKeySpacePath(root.path("root"),
362-
new KeyValue(key, Tuple.from("final_value").pack()), context)
363-
);
364348

349+
// Create multiple DataInKeySpacePath objects with same key but different values
350+
List<DataInKeySpacePath> duplicateData = Arrays.asList(
351+
new DataInKeySpacePath(dataPath, Tuple.from("item"), Tuple.from("first_value").pack()),
352+
new DataInKeySpacePath(dataPath, Tuple.from("item"), Tuple.from("second_value").pack()),
353+
new DataInKeySpacePath(dataPath, Tuple.from("item"), Tuple.from("final_value").pack())
354+
);
355+
356+
try (FDBRecordContext context = database.openContext()) {
365357
root.path("root").importData(context, duplicateData).join();
366358
context.commit();
367359
}

0 commit comments

Comments
 (0)