jpountz commented on code in PR #14482: URL: https://github.com/apache/lucene/pull/14482#discussion_r2064548591
########## 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: I like that you're breaking the change in multiple PRs, but I'd like public APIs to be in an ok state at every stage, and I don't like the new `Directory#toReadAdvice` API. Could we make `SerialIOCountingDirectory` keep getting the read advice from the context for now (since it should always be set?), remove the `Directory#toReadAdvice` API, and later update https://github.com/apache/lucene/pull/14510 to somehow make `SerialIOCountingDirectory` use this implementation to compute the read advice? https://github.com/apache/lucene/pull/14510/files#diff-a320c032354752cddf187b571d2832ca7a0dcfee5a1f3bda19578e2559338f8bR107 -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org