mlbiscoc commented on code in PR #4935:
URL: https://github.com/apache/solr/pull/4935#discussion_r4761567408


##########
solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java:
##########
@@ -42,14 +51,96 @@
  * behavior.
  *
  * <p>File based DirectoryFactory implementations generally extend this class.
+ *
+ * <p>The following parameters are supported:
+ *
+ * <ul>
+ *   <li>preload -- Which index files to load into the OS page cache when they 
are opened:
+ *       <ul>
+ *         <li>{@code ALL_FILES} or {@code true} -- all files.
+ *         <li>{@code false}, or not set -- no files.
+ *         <li>Comma separated alphanumeric file extensions, such as {@code 
vex,vec} -- only files
+ *             whose name ends with a listed extension. The leading {@code .} 
is optional.
+ *       </ul>
+ *       Values are matched case-insensitively. Any other value logs a warning 
and preloads no
+ *       files.
+ * </ul>
+ *
+ * <p>This parameter only applies when the underlying directory is an {@link 
MMapDirectory}, which
+ * is what {@link FSDirectory#open} selects on most platforms.
  */
 public class StandardDirectoryFactory extends CachingDirectoryFactory {
 
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
+  static final String PRELOAD_ALL_FILES = "ALL_FILES";
+  private static final Pattern PRELOAD_EXTENSION = 
Pattern.compile("\\.?[a-z0-9]+");
+
+  private BiPredicate<String, IOContext> preloadPredicate = 
MMapDirectory.NO_FILES;
+
+  @Override
+  public void init(NamedList<?> args) {
+    super.init(args);
+    SolrParams params = args.toSolrParams();
+    preloadPredicate = parsePreload(params.get("preload"));
+  }
+
+  private static BiPredicate<String, IOContext> parsePreload(String value) {
+    if (value == null) {
+      return MMapDirectory.NO_FILES;
+    }
+    String trimmed = value.trim();
+    if (trimmed.equalsIgnoreCase(PRELOAD_ALL_FILES) || 
trimmed.equalsIgnoreCase("true")) {
+      return MMapDirectory.ALL_FILES;
+    }
+    if (trimmed.equalsIgnoreCase("false")) {
+      return MMapDirectory.NO_FILES;
+    }
+    Set<String> extensions = new HashSet<>();
+    for (String extension : trimmed.toLowerCase(Locale.ROOT).split(",")) {
+      extension = extension.trim();
+      if (extension.isEmpty()) {
+        continue;
+      }
+      if (!PRELOAD_EXTENSION.matcher(extension).matches()) {
+        log.warn(
+            "Invalid preload value '{}': expected {}, true, false, or comma 
separated alphanumeric file extensions. No files will be preloaded",
+            value,
+            PRELOAD_ALL_FILES);
+        return MMapDirectory.NO_FILES;
+      }
+      extensions.add(extension.startsWith(".") ? extension : "." + extension);
+    }
+    if (extensions.isEmpty()) {
+      log.warn(
+          "No file extensions found in preload value '{}', so no files will be 
preloaded", value);
+      return MMapDirectory.NO_FILES;
+    }
+    log.info("Preloading index files with extensions: {}", extensions);

Review Comment:
   This will run per core I beleive on startup? This is over logging then.



##########
solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java:
##########
@@ -42,14 +51,96 @@
  * behavior.
  *
  * <p>File based DirectoryFactory implementations generally extend this class.
+ *
+ * <p>The following parameters are supported:
+ *
+ * <ul>
+ *   <li>preload -- Which index files to load into the OS page cache when they 
are opened:
+ *       <ul>
+ *         <li>{@code ALL_FILES} or {@code true} -- all files.
+ *         <li>{@code false}, or not set -- no files.
+ *         <li>Comma separated alphanumeric file extensions, such as {@code 
vex,vec} -- only files
+ *             whose name ends with a listed extension. The leading {@code .} 
is optional.
+ *       </ul>
+ *       Values are matched case-insensitively. Any other value logs a warning 
and preloads no
+ *       files.
+ * </ul>
+ *
+ * <p>This parameter only applies when the underlying directory is an {@link 
MMapDirectory}, which
+ * is what {@link FSDirectory#open} selects on most platforms.
  */
 public class StandardDirectoryFactory extends CachingDirectoryFactory {
 
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
+  static final String PRELOAD_ALL_FILES = "ALL_FILES";
+  private static final Pattern PRELOAD_EXTENSION = 
Pattern.compile("\\.?[a-z0-9]+");
+
+  private BiPredicate<String, IOContext> preloadPredicate = 
MMapDirectory.NO_FILES;
+
+  @Override
+  public void init(NamedList<?> args) {
+    super.init(args);
+    SolrParams params = args.toSolrParams();
+    preloadPredicate = parsePreload(params.get("preload"));
+  }
+
+  private static BiPredicate<String, IOContext> parsePreload(String value) {
+    if (value == null) {
+      return MMapDirectory.NO_FILES;
+    }
+    String trimmed = value.trim();
+    if (trimmed.equalsIgnoreCase(PRELOAD_ALL_FILES) || 
trimmed.equalsIgnoreCase("true")) {

Review Comment:
   This looks backwards-compat breaking now when it used `params.getBool` which 
under the hood was checking the value with 
[parseBool](https://github.com/apache/solr/blob/f9b9fce3b8e4603578f5ce0a0326f6b2b59e4a33/solr/solrj/src/java/org/apache/solr/common/util/StrUtils.java#L267)
 which accepted `on`/`yes`/`off`/`no` and throws on anything else.



##########
solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java:
##########
@@ -42,14 +51,96 @@
  * behavior.
  *
  * <p>File based DirectoryFactory implementations generally extend this class.
+ *
+ * <p>The following parameters are supported:
+ *
+ * <ul>
+ *   <li>preload -- Which index files to load into the OS page cache when they 
are opened:
+ *       <ul>
+ *         <li>{@code ALL_FILES} or {@code true} -- all files.
+ *         <li>{@code false}, or not set -- no files.
+ *         <li>Comma separated alphanumeric file extensions, such as {@code 
vex,vec} -- only files
+ *             whose name ends with a listed extension. The leading {@code .} 
is optional.
+ *       </ul>
+ *       Values are matched case-insensitively. Any other value logs a warning 
and preloads no
+ *       files.
+ * </ul>
+ *
+ * <p>This parameter only applies when the underlying directory is an {@link 
MMapDirectory}, which
+ * is what {@link FSDirectory#open} selects on most platforms.
  */
 public class StandardDirectoryFactory extends CachingDirectoryFactory {
 
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
+  static final String PRELOAD_ALL_FILES = "ALL_FILES";
+  private static final Pattern PRELOAD_EXTENSION = 
Pattern.compile("\\.?[a-z0-9]+");
+
+  private BiPredicate<String, IOContext> preloadPredicate = 
MMapDirectory.NO_FILES;
+
+  @Override
+  public void init(NamedList<?> args) {
+    super.init(args);
+    SolrParams params = args.toSolrParams();
+    preloadPredicate = parsePreload(params.get("preload"));
+  }
+
+  private static BiPredicate<String, IOContext> parsePreload(String value) {
+    if (value == null) {
+      return MMapDirectory.NO_FILES;
+    }
+    String trimmed = value.trim();
+    if (trimmed.equalsIgnoreCase(PRELOAD_ALL_FILES) || 
trimmed.equalsIgnoreCase("true")) {
+      return MMapDirectory.ALL_FILES;
+    }
+    if (trimmed.equalsIgnoreCase("false")) {
+      return MMapDirectory.NO_FILES;
+    }
+    Set<String> extensions = new HashSet<>();
+    for (String extension : trimmed.toLowerCase(Locale.ROOT).split(",")) {
+      extension = extension.trim();
+      if (extension.isEmpty()) {
+        continue;
+      }
+      if (!PRELOAD_EXTENSION.matcher(extension).matches()) {
+        log.warn(
+            "Invalid preload value '{}': expected {}, true, false, or comma 
separated alphanumeric file extensions. No files will be preloaded",
+            value,
+            PRELOAD_ALL_FILES);
+        return MMapDirectory.NO_FILES;

Review Comment:
   I think this is deserving of being an error at minimum or potentially even 
throwing here so it is loud. Someone preloads for performance gain. If they 
miss this warning from a typo in `preload` and rolls this out, the symptom is 
slower cold queries noticed too late.



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

Reply via email to