Skip to content

Commit 8e813ed

Browse files
committed
Some minor cleanup after I looked through the code
1 parent f1e436a commit 8e813ed

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,16 +568,14 @@ default List<ResolvedKeySpacePath> listSubdirectory(@Nonnull FDBRecordContext co
568568
String toString(@Nonnull Tuple tuple);
569569

570570
/**
571-
* Export all data stored under this KeySpacePath and return it in a RecordCursor.
572-
* This method scans all keys that have this path as a prefix and returns the key-value pairs.
573-
* Supports continuation to resume scanning from a previous position.
571+
* Exports all data stored under this {@code KeySpacePath} and returns it in a {@link RecordCursor}.
574572
*
575573
* @param context the transaction context in which to perform the data export
576-
* @param continuation optional continuation from a previous export operation, or null to start from the beginning
574+
* @param continuation continuation from a previous export operation, or null to start from the beginning
577575
* @param scanProperties properties controlling how the scan should be performed
578-
* @return a RecordCursor that iterates over all KeyValue pairs under this path
576+
* @return a {link RecordCursor} that provides all the data under this path
579577
*/
580-
@API(API.Status.UNSTABLE)
578+
@API(API.Status.EXPERIMENTAL)
581579
@Nonnull
582580
RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext context,
583581
@Nullable byte[] continuation,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ static EnvironmentKeySpace setupSampleData(@Nonnull final FDBDatabase database)
9393
DataPath dataUser2App1 = app1User2.dataStore();
9494

9595
// Store data records with additional tuple elements after the KeySpacePath
96-
tr.set(dataUser1App1.toTuple(context).add("record1").pack(), Tuple.from("user100_app1_data1").pack());
97-
tr.set(dataUser1App1.toTuple(context).add("record2").add(0).pack(), Tuple.from("user100_app1_data2_0").pack());
98-
tr.set(dataUser1App1.toTuple(context).add("record2").add(1).pack(), Tuple.from("user100_app1_data2_1").pack());
99-
tr.set(metaUser1App1.toTuple(context).add("config1").pack(), Tuple.from("user100_app1_meta1").pack());
100-
tr.set(dataUser1App2.toTuple(context).add("record3").pack(), Tuple.from("user100_app2_data3").pack());
101-
tr.set(dataUser2App1.toTuple(context).add("record4").pack(), Tuple.from("user200_app1_data4").pack());
96+
tr.set(dataUser1App1.toSubspace(context).pack(Tuple.from("record1")), Tuple.from("user100_app1_data1").pack());
97+
tr.set(dataUser1App1.toSubspace(context).pack(Tuple.from("record2", 0)), Tuple.from("user100_app1_data2_0").pack());
98+
tr.set(dataUser1App1.toSubspace(context).pack(Tuple.from("record2", 1)), Tuple.from("user100_app1_data2_1").pack());
99+
tr.set(metaUser1App1.toSubspace(context).pack(Tuple.from("config1")), Tuple.from("user100_app1_meta1").pack());
100+
tr.set(dataUser1App2.toSubspace(context).pack(Tuple.from("record3")), Tuple.from("user100_app2_data3").pack());
101+
tr.set(dataUser2App1.toSubspace(context).pack(Tuple.from("record4")), Tuple.from("user200_app1_data4").pack());
102102

103103
context.commit();
104104
}

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext;
3232
import com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType;
3333
import com.apple.foundationdb.record.test.FDBDatabaseExtension;
34+
import com.apple.foundationdb.subspace.Subspace;
3435
import com.apple.foundationdb.tuple.Tuple;
3536
import com.apple.test.Tags;
3637
import org.assertj.core.api.Assertions;
@@ -56,8 +57,7 @@
5657
import static org.junit.jupiter.api.Assertions.assertTrue;
5758

5859
/**
59-
* Tests for the new KeySpacePath data export feature that fetches all data stored under a KeySpacePath
60-
* and returns it in a {@code RecordCursor<KeyValue>}.
60+
* Tests for {@link KeySpacePath#exportAllData}.
6161
*/
6262
@Tag(Tags.RequiresFDB)
6363
class KeySpacePathDataExportTest {
@@ -79,13 +79,11 @@ void exportAllDataFromSimplePath() {
7979

8080
// Add data at different levels
8181
for (int i = 0; i < 5; i++) {
82-
Tuple key = basePath.add("level1", (long) i).toTuple(context);
83-
tr.set(key.pack(), Tuple.from("value" + i).pack());
82+
final Subspace subspace = basePath.add("level1", (long)i).toSubspace(context);
8483

8584
// Add some sub-data under each key
8685
for (int j = 0; j < 3; j++) {
87-
Tuple subKey = key.add("sub" + j);
88-
tr.set(subKey.pack(), Tuple.from("subvalue" + i + "_" + j).pack());
86+
tr.set(subspace.pack("sub" + j), Tuple.from("subvalue" + i + "_" + j).pack());
8987
}
9088
}
9189
context.commit();
@@ -96,8 +94,8 @@ void exportAllDataFromSimplePath() {
9694
KeySpacePath rootPath = root.path("root");
9795
final List<KeyValue> allData = exportAllData(rootPath, context);
9896

99-
// Should have 5 main entries + 15 sub-entries = 20 total
100-
assertEquals(20, allData.size());
97+
// Should have 15 sub-entries = 20 total
98+
assertEquals(15, allData.size());
10199

102100
// Verify the data is sorted by key
103101
for (int i = 1; i < allData.size(); i++) {
@@ -126,8 +124,8 @@ void exportAllDataFromSpecificSubPath() {
126124

127125
// Add data for each user
128126
for (int i = 0; i < 4; i++) {
129-
Tuple key = dataPath.toTuple(context).add("record" + i);
130-
tr.set(key.pack(), Tuple.from("user" + userId + "_data" + i).pack());
127+
byte[] key = dataPath.toSubspace(context).pack("record" + i);
128+
tr.set(key, Tuple.from("user" + userId + "_data" + i).pack());
131129
}
132130
}
133131
context.commit();
@@ -168,10 +166,10 @@ void exportAllDataWithDirectoryLayer() {
168166
String[] services = {"auth", "storage", "compute"};
169167
for (String service : services) {
170168
KeySpacePath servicePath = basePath.add("service", service);
171-
Tuple serviceKey = servicePath.toTuple(context);
169+
Subspace serviceKey = servicePath.toSubspace(context);
172170

173171
for (int i = 0; i < 2; i++) {
174-
tr.set(serviceKey.add("config" + i).pack(),
172+
tr.set(serviceKey.pack("config" + i),
175173
Tuple.from(service + "_config_" + i).pack());
176174
}
177175
}
@@ -263,11 +261,11 @@ void exportAllDataWithConstantValues() {
263261
Transaction tr = context.ensureActive();
264262

265263
KeySpacePath dataPath = root.path("app").add("version").add("data");
266-
Tuple baseKey = dataPath.toTuple(context);
264+
Subspace baseKey = dataPath.toSubspace(context);
267265

268266
// Add multiple records under the constant path
269267
for (int i = 0; i < 4; i++) {
270-
tr.set(baseKey.add("record" + i).pack(),
268+
tr.set(baseKey.pack("record" + i),
271269
Tuple.from("constant_path_data_" + i).pack());
272270
}
273271
context.commit();
@@ -333,10 +331,10 @@ void exportAllDataWithDeepNestedStructure() {
333331
.add("member", memberId)
334332
.add("data");
335333

336-
Tuple key = memberPath.toTuple(context);
337-
tr.set(key.add("profile").pack(),
334+
Subspace key = memberPath.toSubspace(context);
335+
tr.set(key.pack("profile"),
338336
Tuple.from(dept + "_team" + team + "_member" + member).pack());
339-
tr.set(key.add("settings").pack(),
337+
tr.set(key.pack("settings"),
340338
Tuple.from("settings_" + member).pack());
341339
}
342340
}

0 commit comments

Comments
 (0)