Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8f4922e
Add tests for a KeySpacePath export method to export all the data wit…
ScottDugas Aug 27, 2025
f79e912
Add continuation tests
ScottDugas Aug 27, 2025
80cbad2
Fix checkstyle
ScottDugas Sep 3, 2025
1959c73
Reduce duplication in KeySpacePathDataExportTest and remove exportAll…
ScottDugas Sep 3, 2025
9f7c8f2
Implement KeySpacePath.exportAllData, and update the tests to make it…
ScottDugas Sep 3, 2025
5cadd88
Remove usage of asyncToSync in exportAllData
ScottDugas Sep 3, 2025
6b975d7
Add initial implementation of a class for resolved path & value
ScottDugas Sep 3, 2025
ed9702b
Validate remainder in more places
ScottDugas Sep 3, 2025
0820b97
Cleanup some of the assertions
ScottDugas Sep 3, 2025
0750e00
Change exportAllData to return DataInKeySpacePath instead of raw data
ScottDugas Sep 3, 2025
a6572f1
Move EnvironmentKeySpace out into its own file, move wrappers into it
ScottDugas Sep 4, 2025
439ea52
Add tests of KeySPacePathWrapper.exportAllData
ScottDugas Sep 4, 2025
d9b92ab
Cleanup style of test
ScottDugas Sep 4, 2025
cc2420e
Fix bug when exporting at the leaf node
ScottDugas Sep 4, 2025
e2da4ea
Reduce repetitive tests, and repetitive code for assertions
ScottDugas Sep 4, 2025
5a24630
Dleete some more redundant tests
ScottDugas Sep 4, 2025
f1e436a
Some minor test cleanup
ScottDugas Sep 4, 2025
039f53d
Merge branch 'main' into keyspacepath-export
ScottDugas Oct 17, 2025
5e310ea
Fix test that doesn't account for remainder
ScottDugas Oct 17, 2025
2a5da68
Add unit tests of withRemainder
ScottDugas Oct 20, 2025
9207a3e
Test reverse continuations
ScottDugas Oct 20, 2025
c43d878
Remove DataInKeySpacePath.getRawKeyValue
ScottDugas Oct 20, 2025
56c3f0e
Test continuation behavior while exporting a single key
ScottDugas Oct 20, 2025
60ad1d1
Move code for resolving a key to KeySpacePath and add tests
ScottDugas Oct 21, 2025
fc517e9
Add path checks & negative tests
ScottDugas Oct 21, 2025
4f5737d
Use TupleHelpers.isPrefix
ScottDugas Oct 21, 2025
714a42a
Default implementations for backwards compatibility
ScottDugas Oct 21, 2025
118cad7
Resolve from different depths
ScottDugas Oct 21, 2025
a36a55e
Use assertArrayEquals for byte[]
ScottDugas Oct 21, 2025
1ac438c
Test new default methods
ScottDugas Oct 21, 2025
5595a93
Some cleanup
ScottDugas Oct 21, 2025
1a58550
Respond to PR #3566 comments from @ohadzeliger
ScottDugas Oct 23, 2025
f7f2da2
Mark DataInKeySpacePath as EXPERIMENTAL
ScottDugas Oct 24, 2025
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
@@ -0,0 +1,76 @@
/*
* DataInKeySpacePath.java
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2015-2025 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import com.apple.foundationdb.KeyValue;
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext;
import com.apple.foundationdb.tuple.Tuple;
import com.apple.foundationdb.tuple.TupleHelpers;

import java.util.concurrent.CompletableFuture;

/**
* Class representing a {@link KeyValue} pair within in {@link KeySpacePath}.
*/
public class DataInKeySpacePath {

final CompletableFuture<ResolvedKeySpacePath> resolvedPath;
final KeyValue rawKeyValue;

public DataInKeySpacePath(KeySpacePath path, KeyValue rawKeyValue, FDBRecordContext context) {
this.rawKeyValue = rawKeyValue;

// Convert the raw key to a Tuple and resolve it starting from the provided path
Tuple keyTuple = Tuple.fromBytes(rawKeyValue.getKey());

// First resolve the provided path to get its resolved form
this.resolvedPath = path.toResolvedPathAsync(context).thenCompose(resolvedPath -> {
// Now use the resolved path to find the child for the key
// We need to figure out how much of the key corresponds to the resolved path
Tuple pathTuple = resolvedPath.toTuple();
int pathLength = pathTuple.size();

// The remaining part of the key should be resolved from the resolved path's directory
if (keyTuple.size() > pathLength) {
// There's more in the key than just the path, so resolve the rest
if (resolvedPath.getDirectory().getSubdirectories().isEmpty()) {
return CompletableFuture.completedFuture(
new ResolvedKeySpacePath(resolvedPath.getParent(), resolvedPath.toPath(),
resolvedPath.getResolvedPathValue(),
TupleHelpers.subTuple(keyTuple, pathTuple.size(), keyTuple.size())));
} else {
return resolvedPath.getDirectory().findChildForKey(context, resolvedPath, keyTuple, keyTuple.size(), pathLength);
}
} else {
// The key exactly matches the path
return CompletableFuture.completedFuture(resolvedPath);
}
});
}

public CompletableFuture<ResolvedKeySpacePath> getResolvedPath() {
return resolvedPath;
}

public KeyValue getRawKeyValue() {
return rawKeyValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,20 @@ default List<ResolvedKeySpacePath> listSubdirectory(@Nonnull FDBRecordContext co
*/
@API(API.Status.UNSTABLE)
String toString(@Nonnull Tuple tuple);

/**
* Export all data stored under this KeySpacePath and return it in a RecordCursor.
* This method scans all keys that have this path as a prefix and returns the key-value pairs.
* Supports continuation to resume scanning from a previous position.
*
* @param context the transaction context in which to perform the data export
* @param continuation optional continuation from a previous export operation, or null to start from the beginning
* @param scanProperties properties controlling how the scan should be performed
* @return a RecordCursor that iterates over all KeyValue pairs under this path
*/
@API(API.Status.UNSTABLE)
@Nonnull
RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext context,
@Nullable byte[] continuation,
@Nonnull ScanProperties scanProperties);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
import com.apple.foundationdb.record.RecordCursor;
import com.apple.foundationdb.record.ScanProperties;
import com.apple.foundationdb.record.ValueRange;
import com.apple.foundationdb.record.cursors.LazyCursor;
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext;
import com.apple.foundationdb.record.provider.foundationdb.KeyValueCursor;
import com.apple.foundationdb.subspace.Subspace;
import com.apple.foundationdb.tuple.ByteArrayUtil;
import com.apple.foundationdb.tuple.Tuple;
import com.google.common.collect.Lists;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
Expand Down Expand Up @@ -337,6 +341,21 @@ public String toString() {
return toString(null);
}

@Nonnull
@Override
public RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext context,
@Nullable byte[] continuation,
@Nonnull ScanProperties scanProperties) {
return new LazyCursor<>(toTupleAsync(context)
.thenApply(tuple -> KeyValueCursor.Builder.withSubspace(new Subspace(tuple))
.setContext(context)
.setContinuation(continuation)
.setScanProperties(scanProperties)
.build()),
context.getExecutor())
.map(keyValue -> new DataInKeySpacePath(this, keyValue, context));
}

/**
* Returns this path properly wrapped in whatever implementation the directory the path is contained in dictates.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,12 @@ public String toString() {
public String toString(@Nonnull Tuple t) {
return inner.toString(t);
}

@Nonnull
@Override
public RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext context,
@Nullable byte[] continuation,
@Nonnull ScanProperties scanProperties) {
return inner.exportAllData(context, continuation, scanProperties);
}
}
Loading
Loading