psalagnac commented on code in PR #5410:
URL: https://github.com/apache/solr/pull/5410#discussion_r4768653789


##########
solr/core/src/test/org/apache/solr/core/MMapAdviseByContextTest.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.solr.core;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.LockFactory;
+import org.apache.lucene.store.MMapDirectory;
+import org.apache.lucene.store.ReadAdvice;
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.DirectoryFactory.DirContext;
+import org.junit.Test;
+
+public class MMapAdviseByContextTest extends SolrTestCase {

Review Comment:
   This test class should be simply named `MMapDirectoryFactoryTest`.



##########
solr/core/src/test/org/apache/solr/core/MMapAdviseByContextTest.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.solr.core;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.LockFactory;
+import org.apache.lucene.store.MMapDirectory;
+import org.apache.lucene.store.ReadAdvice;
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.DirectoryFactory.DirContext;
+import org.junit.Test;
+
+public class MMapAdviseByContextTest extends SolrTestCase {
+
+  @Test
+  public void testMMapFactoryDefaultDoesNotSetAdviseByContext() throws 
Exception {
+    Path path = createTempDir();
+    AtomicReference<RecordingMMapDirectory> created = new AtomicReference<>();
+    try (MMapDirectoryFactory df =
+        new MMapDirectoryFactory() {
+          @Override
+          protected Directory create(String p, LockFactory lockFactory) throws 
IOException {
+            RecordingMMapDirectory mapDirectory =
+                new RecordingMMapDirectory(Path.of(p), lockFactory);
+            created.set(mapDirectory);
+            configure(mapDirectory);
+            return mapDirectory;
+          }
+        }) {
+      df.init(new NamedList<>());
+      assertFalse(df.adviseByContext);
+      Directory dir =
+          df.get(path.toString(), DirContext.DEFAULT, 
DirectoryFactory.LOCK_TYPE_SINGLE);
+      try {
+        assertNull(created.get().applied);
+      } finally {
+        df.release(dir);
+      }
+    }
+  }
+
+  @Test
+  public void testMMapFactoryAdviseByContext() throws Exception {
+    Path path = createTempDir();
+    NamedList<Object> args = new NamedList<>();
+    args.add("adviseByContext", true);
+    AtomicReference<RecordingMMapDirectory> created = new AtomicReference<>();
+    try (MMapDirectoryFactory df =
+        new MMapDirectoryFactory() {
+          @Override
+          protected Directory create(String p, LockFactory lockFactory) throws 
IOException {
+            RecordingMMapDirectory mapDirectory =
+                new RecordingMMapDirectory(Path.of(p), lockFactory);
+            created.set(mapDirectory);
+            configure(mapDirectory);
+            return mapDirectory;
+          }
+        }) {
+      df.init(args);
+      assertTrue(df.adviseByContext);
+      Directory dir =
+          df.get(path.toString(), DirContext.DEFAULT, 
DirectoryFactory.LOCK_TYPE_SINGLE);
+      try {
+        assertSame(MMapDirectory.ADVISE_BY_CONTEXT, created.get().applied);
+      } finally {
+        df.release(dir);
+      }
+    }
+  }
+
+  private static final class RecordingMMapDirectory extends MMapDirectory {
+    BiFunction<String, IOContext, Optional<ReadAdvice>> applied;

Review Comment:
   This is a very vague name. Could be `recordedToReadAdvice` or similar, so it 
is self explanatory.



##########
solr/solr-ref-guide/modules/configuration-guide/pages/index-location-format.adoc:
##########
@@ -47,9 +47,13 @@ You can force a particular implementation and/or 
configuration options by specif
 <directoryFactory name="DirectoryFactory"
                   class="solr.MMapDirectoryFactory">
   <bool name="preload">true</bool>
+  <bool name="adviseByContext">true</bool>
 </directoryFactory>
 ----
 
+`adviseByContext` (default `false`) is an `solr.MMapDirectoryFactory` option.

Review Comment:
   We try to keep links to Javadoc when the documentation has references to 
code.
   Please do the same here.
   
   You can see examples of this in other doc pages. Constants 
{solr-core-javadocs} and {lucene-javadocs} can be used for the links.



##########
solr/core/src/test/org/apache/solr/core/MMapAdviseByContextTest.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.solr.core;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.LockFactory;
+import org.apache.lucene.store.MMapDirectory;
+import org.apache.lucene.store.ReadAdvice;
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.DirectoryFactory.DirContext;
+import org.junit.Test;
+
+public class MMapAdviseByContextTest extends SolrTestCase {
+
+  @Test
+  public void testMMapFactoryDefaultDoesNotSetAdviseByContext() throws 
Exception {
+    Path path = createTempDir();
+    AtomicReference<RecordingMMapDirectory> created = new AtomicReference<>();

Review Comment:
   This dataflow is complex for no good reason.
   Instead of this `AtomicReference`, you can directly use the result of 
`df.get()` call. Since we control the factory, that's fine to cast the result 
into the expected testing type.



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