Skip to content

Commit ec075d2

Browse files
committed
Remove aspects of KeySpacePath for storing a resolved key
Shortly before ResolvedKeySpacePath was introduced, KeySpacePathImpl would store the resolved tuple and remainder in itself. The methods around this have been deprecated for years. More pressingly, what having this value means is that if you have a KeySpacePath that is generated from KeySpaceDirectorys and call toTuple or toSubspace it will resolve in the context that you provide, but if that KeySpacePath came from resolving a key then toTuple / toSubspace will contain the original directory-layer mappings, which could be problematic if the provided context is not on the same cluster.
1 parent e3c8903 commit ec075d2

File tree

6 files changed

+15
-339
lines changed

6 files changed

+15
-339
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ protected CompletableFuture<Optional<ResolvedKeySpacePath>> pathFromKey(@Nonnull
258258

259259
// Make sure that the path is constructed with the text-name from the directory layer.
260260
ResolvedKeySpacePath myPath = new ResolvedKeySpacePath(parent,
261-
KeySpacePathImpl.newPath(parentPath, this, directoryString,
262-
true, pathValue, remainder),
261+
KeySpacePathImpl.newPath(parentPath, this, directoryString),
263262
pathValue, remainder);
264263

265264
// We are finished if there are no more subdirectories or no more tuple to consume

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

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -180,55 +180,14 @@ public KeySpacePath path(@Nonnull String name) {
180180
@Nonnull
181181
public KeySpacePath path(@Nonnull String name, @Nullable Object value) {
182182
KeySpaceDirectory dir = root.getSubdirectory(name);
183-
return KeySpacePathImpl.newPath(null, dir, value, false, null, null);
184-
}
185-
186-
/**
187-
* Given a tuple from an FDB key, attempts to determine what path through this directory the tuple
188-
* represents, returning a <code>KeySpacePath</code> representing the leaf-most directory in the path.
189-
* If entries remained in the tuple beyond the leaf directory, then
190-
* {@link KeySpacePath#getRemainder()} can be used to fetch the remaining portion.
191-
*
192-
* @param context context used, if needed, for any database operations
193-
* @param key the tuple to be decoded
194-
* @return a path entry representing the leaf directory entry that corresponds to a value in the
195-
* provided tuple
196-
* @throws RecordCoreArgumentException if the tuple provided does not correspond to any path through
197-
* the directory structure at this point
198-
*
199-
* @deprecated use {@link #resolveFromKeyAsync(FDBRecordContext, Tuple)} instead
200-
*/
201-
@Deprecated
202-
@API(API.Status.DEPRECATED)
203-
@Nonnull
204-
public CompletableFuture<KeySpacePath> pathFromKeyAsync(@Nonnull FDBRecordContext context, @Nonnull Tuple key) {
205-
return root.findChildForKey(context, null, key, key.size(), 0).thenApply(ResolvedKeySpacePath::toPath);
206-
}
207-
208-
/**
209-
* Synchronous/blocking version of <code>pathFromKeyAsync</code>.
210-
*
211-
* @param context context used, if needed, for any database operations
212-
* @param key the tuple to be decoded
213-
* @return a path entry representing the leaf directory entry that corresponds to a value in the
214-
* provided tuple
215-
* @throws RecordCoreArgumentException if the tuple provided does not correspond to any path through
216-
* the directory structure at this point
217-
*
218-
* @deprecated use {@link #resolveFromKey(FDBRecordContext, Tuple)} instead
219-
*/
220-
@Deprecated
221-
@API(API.Status.DEPRECATED)
222-
@Nonnull
223-
public KeySpacePath pathFromKey(@Nonnull FDBRecordContext context, @Nonnull Tuple key) {
224-
return context.asyncToSync(FDBStoreTimer.Waits.WAIT_KEYSPACE_PATH_RESOLVE, pathFromKeyAsync(context, key));
183+
return KeySpacePathImpl.newPath(null, dir, value);
225184
}
226185

227186
/**
228187
* Given a tuple from an FDB key, attempts to determine what path through this directory the tuple
229188
* represents, returning a <code>ResolvedKeySpacePath</code> representing the leaf-most directory in the path.
230189
* <p>
231-
* If entries remained in the tuple beyond the leaf directory, then {@link KeySpacePath#getRemainder()} can be
190+
* If entries remained in the tuple beyond the leaf directory, then {@link ResolvedKeySpacePath#getRemainder()} can be
232191
* used to fetch the remaining portion.
233192
* See also {@link KeySpacePath#toResolvedPathAsync(FDBRecordContext, byte[])} if you need to resolve and you
234193
* know that it is part of a given path.

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class KeySpaceDirectory {
103103
* type may be stored in the directory, otherwise specifies a constant value that represents the
104104
* directory
105105
* @param wrapper if non-null, specifies a function that may be used to wrap any <code>KeySpacePath</code>
106-
* objects return from {@link KeySpace#pathFromKey(FDBRecordContext, Tuple)}
106+
* objects return from {@link KeySpace#resolveFromKeyAsync(FDBRecordContext, Tuple)}.
107107
*
108108
* @throws RecordCoreArgumentException if the provided value constant value is not valid for the
109109
* type of directory being created
@@ -130,7 +130,7 @@ public KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullab
130130
* @param name the name of the directory
131131
* @param keyType the data type of the values that may be contained within the directory
132132
* @param wrapper if non-null, specifies a function that may be used to wrap any <code>KeySpacePath</code>
133-
* objects returned from {@link KeySpace#pathFromKey(FDBRecordContext, Tuple)}
133+
* objects returned from {@link KeySpace#resolveFromKeyAsync(FDBRecordContext, Tuple)}
134134
*/
135135
public KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Function<KeySpacePath, KeySpacePath> wrapper) {
136136
this(name, keyType, keyType.getAnyValue(), wrapper);
@@ -213,14 +213,12 @@ protected CompletableFuture<Optional<ResolvedKeySpacePath>> pathFromKey(@Nonnull
213213
// Have we hit the leaf of the tree or run out of tuple to process?
214214
if (subdirs.isEmpty() || keyIndex + 1 == keySize) {
215215
final Tuple remainder = (keyIndex + 1 == key.size()) ? null : TupleHelpers.subTuple(key, keyIndex + 1, key.size());
216-
final KeySpacePath path = KeySpacePathImpl.newPath(parentPath, this, tupleValue,
217-
true, resolvedValue, remainder);
216+
final KeySpacePath path = KeySpacePathImpl.newPath(parentPath, this, tupleValue);
218217

219218
return CompletableFuture.completedFuture(
220219
Optional.of(new ResolvedKeySpacePath(parent, path, new PathValue(tupleValue), remainder)));
221220
} else {
222-
final KeySpacePath path = KeySpacePathImpl.newPath(parentPath, this, tupleValue,
223-
true, resolvedValue, null);
221+
final KeySpacePath path = KeySpacePathImpl.newPath(parentPath, this, tupleValue);
224222
return findChildForKey(context,
225223
new ResolvedKeySpacePath(parent, path, pathValue, null),
226224
key, keySize, keyIndex + 1).thenApply(Optional::of);

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

Lines changed: 2 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,6 @@ default int size() {
8080
@Nonnull
8181
KeySpacePath add(@Nonnull String dirName, @Nullable Object value);
8282

83-
/**
84-
* If this path was created via {@link KeySpace#pathFromKey(FDBRecordContext, Tuple)}, this returns
85-
* any remaining portion of the input tuple that was not used to construct the path.
86-
* @return the remaining portion of the original input tuple or <code>null</code>
87-
*
88-
* @deprecated use {@link KeySpace#resolveFromKey(FDBRecordContext, Tuple)} and
89-
* {@link ResolvedKeySpacePath#getRemainder()} instead
90-
*/
91-
@API(API.Status.DEPRECATED)
92-
@Deprecated
93-
@Nullable
94-
Tuple getRemainder();
95-
9683
/**
9784
* Returns the parent of this entry or null if this is the root of the path.
9885
* @return the parent keyspace path
@@ -129,39 +116,11 @@ default int size() {
129116
* by the directory layer for this path entry's value.
130117
*
131118
* @param context the context in which to resolve the value
132-
* @return future that will resolve to value to be store for this path element. Note that if the path
133-
* was produced via {@link KeySpace#pathFromKeyAsync(FDBRecordContext, Tuple)} or {@link #listAsync(FDBRecordContext, String, byte[], ScanProperties)},
134-
* then the future that is returned will have already been completed (i.e it is safe to retrieve the
135-
* value without blocking)
119+
* @return future that will resolve to value to be store for this path element.
136120
*/
137121
@Nonnull
138122
CompletableFuture<PathValue> resolveAsync(@Nonnull FDBRecordContext context);
139123

140-
/**
141-
* If this path was created via a call to <code>pathFromKey</code> or <code>listAsync</code> (or their blocking
142-
* variants), this method may be used to determine what the underlying value was physically stored in the key.
143-
*
144-
* @return the value that was stored for the path element
145-
* @throws IllegalStateException if this path element was not produced from one of the above method calls
146-
*
147-
* @deprecated use {@link KeySpace#resolveFromKey(FDBRecordContext, Tuple)} and
148-
* {@link ResolvedKeySpacePath#getResolvedPathValue()} instead
149-
*/
150-
@API(API.Status.DEPRECATED)
151-
@Deprecated
152-
@Nonnull
153-
PathValue getStoredValue();
154-
155-
/**
156-
* Whether it is legal to ask this key space path for the underlying value stored in the key.
157-
* @return true if it is legal to call {@link #getStoredValue()}.
158-
* @see #getStoredValue()
159-
* @deprecated use {@link KeySpace#resolveFromKey(FDBRecordContext, Tuple)} instead
160-
*/
161-
@API(API.Status.DEPRECATED)
162-
@Deprecated
163-
boolean hasStoredValue();
164-
165124
/**
166125
* Converts this path into a tuple. During this process the value that was provided for the directory, or
167126
* was resolved by the directory implementation, is validated to ensure that it is a valid type for the
@@ -202,7 +161,7 @@ default Tuple toTuple(@Nonnull FDBRecordContext context) {
202161
* Given a tuple from an FDB key, attempts to determine what sub-path through this directory the tuple
203162
* represents, returning a <code>ResolvedKeySpacePath</code> representing the leaf-most directory in the path.
204163
* <p>
205-
* If entries remained in the tuple beyond the leaf directory, then {@link KeySpacePath#getRemainder()}
164+
* If entries remained in the tuple beyond the leaf directory, then {@link ResolvedKeySpacePath#getRemainder()}
206165
* can be used to fetch the remaining portion.
207166
* See also {@link KeySpace#resolveFromKeyAsync(FDBRecordContext, Tuple)} if you need to resolve from the root.
208167
* </p>
@@ -302,139 +261,6 @@ default void deleteAllData(@Nonnull FDBRecordContext context) {
302261
context.asyncToSync(FDBStoreTimer.Waits.WAIT_KEYSPACE_CLEAR, deleteAllDataAsync(context));
303262
}
304263

305-
/**
306-
* For a given subdirectory from this path element, return a list of paths for all available keys in the FDB
307-
* keyspace for that directory. For example, given the tree:
308-
* <pre>
309-
* root
310-
* +- node
311-
* +- leaf
312-
* </pre>
313-
* Performing a <code>listAsync</code> from a given <code>node</code>, will result in a list of paths, one for
314-
* each <code>leaf</code> that is available within the <code>node</code>'s scope.
315-
*
316-
* <p>The listing is performed by reading the first key of the data type (and possibly constant value) for the
317-
* subdirectory and, if a key is found, skipping to the next available value after the first one that was found,
318-
* and so on, each time resulting in an additional <code>KeySpacePath</code> that is returned. In each case,
319-
* the returned <code>KeySpacePath</code> may contain a remainder (see {@link #getRemainder()}) of the portion
320-
* of the key tuple that was read.
321-
*
322-
* @param context the transaction in which to perform the listing
323-
* @param subdirName the name of the subdirectory that is to be listed
324-
* @param continuation an optional continuation from a previous list attempt
325-
* @param scanProperties details for how the scan should be performed
326-
* @return a list of fully qualified paths for each value contained within this directory
327-
* @throws NoSuchDirectoryException if the subdirectory name provided does not exist
328-
* @throws com.apple.foundationdb.record.RecordCoreException if a key found during the listing process did not correspond to
329-
* the directory tree
330-
*
331-
* @deprecated use {@link #listSubdirectoryAsync(FDBRecordContext, String, byte[], ScanProperties)} instead
332-
*/
333-
@API(API.Status.DEPRECATED)
334-
@Deprecated
335-
@Nonnull
336-
default RecordCursor<KeySpacePath> listAsync(@Nonnull FDBRecordContext context,
337-
@Nonnull String subdirName, @Nullable byte[] continuation,
338-
@Nonnull ScanProperties scanProperties) {
339-
return listAsync(context, subdirName, null, continuation, scanProperties);
340-
}
341-
342-
/**
343-
* For a given subdirectory from this path element, return a list of paths for all available keys in the FDB
344-
* keyspace for that directory. For example, given the tree:
345-
* <pre>
346-
* root
347-
* +- node
348-
* +- leaf
349-
* </pre>
350-
* Performing a <code>listAsync</code> from a given <code>node</code>, will result in a list of paths, one for
351-
* each <code>leaf</code> that is available within the <code>node</code>'s scope.
352-
*
353-
* <p>The listing is performed by reading the first key of the data type (and possibly constant value) for the
354-
* subdirectory and, if a key is found, skipping to the next available value after the first one that was found,
355-
* and so on, each time resulting in an additional <code>KeySpacePath</code> that is returned. In each case,
356-
* the returned <code>KeySpacePath</code> may contain a remainder (see {@link #getRemainder()}) of the portion
357-
* of the key tuple that was read.
358-
*
359-
* @param context the transaction in which to perform the listing
360-
* @param subdirName the name of the subdirectory that is to be listed
361-
* @param range the range of the subdirectory values to be listed. All will be listed if it is <code>null</code>.
362-
* If the directory is restricted to a specific constant value, it has to be <code>null</code>
363-
* @param continuation an optional continuation from a previous list attempt
364-
* @param scanProperties details for how the scan should be performed
365-
* @return a list of fully qualified paths for each value contained within this directory
366-
* @throws NoSuchDirectoryException if the subdirectory name provided does not exist
367-
* @throws com.apple.foundationdb.record.RecordCoreException if a key found during the listing process did not correspond to
368-
* the directory tree
369-
*
370-
* @deprecated use {@link #listSubdirectoryAsync(FDBRecordContext, String, ValueRange, byte[], ScanProperties)} instead
371-
*/
372-
@API(API.Status.DEPRECATED)
373-
@Deprecated
374-
@Nonnull
375-
RecordCursor<KeySpacePath> listAsync(@Nonnull FDBRecordContext context,
376-
@Nonnull String subdirName,
377-
@Nullable ValueRange<?> range,
378-
@Nullable byte[] continuation,
379-
@Nonnull ScanProperties scanProperties);
380-
381-
/**
382-
* Synchronous version of <code>listAsync</code>.
383-
*
384-
* @param context the transaction in which to perform the listing
385-
* @param subdirName the name of the subdirectory that is to be listed
386-
* @param scanProperties details for how the scan should be performed
387-
* @return a list of fully qualified paths for each value contained within this directory
388-
*
389-
* @deprecated use {@link #listSubdirectory(FDBRecordContext, String, ScanProperties)} instead
390-
*/
391-
@API(API.Status.DEPRECATED)
392-
@Deprecated
393-
@Nonnull
394-
default List<KeySpacePath> list(@Nonnull FDBRecordContext context, @Nonnull String subdirName,
395-
@Nonnull ScanProperties scanProperties) {
396-
return context.asyncToSync(FDBStoreTimer.Waits.WAIT_KEYSPACE_LIST, listAsync(context, subdirName, null, scanProperties).asList());
397-
}
398-
399-
/**
400-
* Synchronous version of <code>listAsync</code>.
401-
*
402-
* @param context the transaction in which to perform the listing
403-
* @param subdirName the name of the subdirectory that is to be listed
404-
* @param range the range of the subdirectory values to be listed. All will be listed if it is <code>null</code>.
405-
* If the directory is restricted to a specific constant value, it has to be <code>null</code>
406-
* @param continuation an optional continuation from a previous list attempt
407-
* @param scanProperties details for how the scan should be performed
408-
* @return a list of fully qualified paths for each value contained within this directory
409-
*
410-
* @deprecated use {@link #listSubdirectory(FDBRecordContext, String, ValueRange, byte[], ScanProperties)} instead
411-
*/
412-
@API(API.Status.DEPRECATED)
413-
@Deprecated
414-
@Nonnull
415-
default List<KeySpacePath> list(@Nonnull FDBRecordContext context, @Nonnull String subdirName,
416-
@Nullable ValueRange<?> range,
417-
@Nullable byte[] continuation,
418-
@Nonnull ScanProperties scanProperties) {
419-
return context.asyncToSync(FDBStoreTimer.Waits.WAIT_KEYSPACE_LIST, listAsync(context, subdirName, range, continuation, scanProperties).asList());
420-
}
421-
422-
/**
423-
* Synchronous version of <code>listAsync</code> that performs a forward, serializable scan.
424-
*
425-
* @param context the transaction in which to perform the listing
426-
* @param subdirName the name of the subdirectory that is to be listed
427-
* @return a list of fully qualified paths for each value contained within this directory
428-
*
429-
* @deprecated use {@link #listSubdirectory(FDBRecordContext, String)} instead
430-
*/
431-
@API(API.Status.DEPRECATED)
432-
@Deprecated
433-
@Nonnull
434-
default List<KeySpacePath> list(@Nonnull FDBRecordContext context, @Nonnull String subdirName) {
435-
return list(context, subdirName, ScanProperties.FORWARD_SCAN);
436-
}
437-
438264
/**
439265
* For a given subdirectory from this path element, return a list of paths for all available keys in the FDB
440266
* keyspace for that directory. For example, given the tree:

0 commit comments

Comments
 (0)