jpountz commented on code in PR #14482:
URL: https://github.com/apache/lucene/pull/14482#discussion_r2054788526


##########
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:
   Do we need the ability to translate hints into a ReadAdvice on Directory, or 
should this be an implementation detail of MMapDirectory?



##########
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

Review Comment:
   For my understanding, since we require at most one file type, one file data 
and one data access, why not tracking these 3 things separately instead of 
folding them all into a set?



##########
lucene/core/src/java/org/apache/lucene/store/DataAccessHint.java:
##########
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.store;
+
+/** Hint on the data access pattern likely to be used */
+public enum DataAccessHint implements IOContext.FileOpenHint {
+  RANDOM,
+  SEQUENTIAL

Review Comment:
   Can you add javadocs to enum constants to help decide when each one should 
be used? E.g. postings do a mix of sequential reading and skipping, should they 
use RANDOM or SEQUENTIAL?



-- 
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

Reply via email to