magibney commented on code in PR #13570:
URL: https://github.com/apache/lucene/pull/13570#discussion_r1681711345
##########
lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java:
##########
@@ -83,6 +86,19 @@ public class MMapDirectory extends FSDirectory {
*/
public static final BiPredicate<String, IOContext> NO_FILES = (filename,
context) -> false;
+ /** Argument for {@link #setGroupingFunction(Function)} that configures no
grouping. */
+ public static final Function<String, Optional<String>> NO_GROUPING =
filename -> Optional.empty();
+
+ /** Argument for {@link #setGroupingFunction(Function)} that configures
grouping by segment. */
+ public static final Function<String, Optional<String>> GROUP_BY_SEGMENT =
+ filename -> {
+ String segmentName = IndexFileNames.parseSegmentName(filename);
+ if (filename.length() == segmentName.length()) {
+ return Optional.empty();
+ }
+ return Optional.of(segmentName);
+ };
Review Comment:
I think Uwe had floated the idea of doing extra validation that we're
actually getting a segment name -- e.g. something like:
```java
String segmentPrefix = IndexFileNames.parseSegmentName(filename);
int segmentPrefixLength = segmentPrefix.length();
if (segmentPrefixLength > 1 && segmentPrefixLength != filename.length() &&
segmentName.charAt(0) == '_') {
String segmentName = segmentPrefix.substring(1);
try {
// try to parse a proper segment identifier
Long.parseLong(segmentName, Character.MAX_RADIX);
return Optional.of(segmentName);
} catch (NumberFormatException ex) {
// unable to parse as a segment identifier
}
}
return Optional.empty();
```
If we can account for all explicit exceptions (where we don't expect to be
able to parse a segment name) we could even throw `IllegalArgumentException`
here instead of returning `Optional.empty()`? (this would prevent grouping from
being used in cases where it should not be, by failing hard -- and could be a
good complement to ensuring `READ_ONCE` is used where appropriate).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]