ChrisHegarty commented on code in PR #14482:
URL: https://github.com/apache/lucene/pull/14482#discussion_r2057896977
##########
lucene/core/src/java/org/apache/lucene/store/Directory.java:
##########
@@ -79,6 +83,31 @@ public abstract class Directory implements Closeable {
*/
public abstract long fileLength(String name) throws IOException;
+ protected void validateIOContext(IOContext context) {
+ Map<Class<? extends IOContext.FileOpenHint>, List<IOContext.FileOpenHint>>
hintClasses =
+
context.hints().stream().collect(Collectors.groupingBy(IOContext.FileOpenHint::getClass));
+
+ // there should only be one of FileType, FileData, DataAccess
+ List<IOContext.FileOpenHint> fileTypes =
+ hintClasses.getOrDefault(FileTypeHint.class, List.of());
+ if (fileTypes.size() > 1) {
+ throw new IllegalArgumentException("Multiple file type hints specified:
" + fileTypes);
+ }
+ List<IOContext.FileOpenHint> fileData =
hintClasses.getOrDefault(FileDataHint.class, List.of());
+ if (fileData.size() > 1) {
+ throw new IllegalArgumentException("Multiple file data hints specified:
" + fileData);
+ }
+ List<IOContext.FileOpenHint> dataAccess =
+ hintClasses.getOrDefault(DataAccessHint.class, List.of());
+ if (dataAccess.size() > 1) {
+ throw new IllegalArgumentException("Multiple data access hints
specified: " + dataAccess);
+ }
+ }
+
+ protected ReadAdvice toReadAdvice(IOContext context) {
Review Comment:
The final api position as I understand it, `IOContext` has no knowledge of
`ReadAdvice` ( `IOConext::withReadAdvice` and `IOContext::readAdvice` will be
removed ).
`ReadAdvice` is rather determined by the directory when given the
higher-level hints from the IOContext. For example, the `MMapDirectory`
implementation of openInput would do something like.
```java
public IndexInput openInput(String name, IOContext context) throws
IOException {
...
return PROVIDER.openInput(..., toReadAdvice(context), preload.test(name,
context),...);
}
```
... so it's somewhat akin to the the current preLoad model.
For a custom filter wrapper one would do:
```java
Directory dir = new FilterDirectory(mmapDirectory) {
@Override
public ReadAdvice toReadAdvice(IOContext context) {
if (someCondition) {
// enforce specific read advice instead of relying on hints
return ReadAdvice.NORMAL;
}
// hints to readAdvice
}
}
```
--
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]