[GitHub] [lucene-solr] uschindler commented on a change in pull request #1364: SOLR-14335: Lock Solr's memory to prevent swapping

2020-03-23 Thread GitBox
uschindler commented on a change in pull request #1364: SOLR-14335: Lock Solr's 
memory to prevent swapping
URL: https://github.com/apache/lucene-solr/pull/1364#discussion_r396331814
 
 

 ##
 File path: solr/bootstrap/src/java/org/apache/solr/bootstrap/NativeLibrary.java
 ##
 @@ -0,0 +1,139 @@
+/*
+ * 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.bootstrap;
+
+import com.sun.jna.LastErrorException;
+import org.eclipse.jetty.start.StartLog;
+
+import static org.apache.solr.bootstrap.NativeLibrary.OSType.*;
+
+public final class NativeLibrary {
+  public enum OSType {
+LINUX,
+MAC,
+WINDOWS,
+AIX,
+OTHER;
+  }
+
+  public static final OSType osType;
+
+  private static final int MCL_CURRENT;
+
+  private static final int ENOMEM = 12;
+
+  private static final NativeLibraryWrapper wrappedLibrary;
+  private static boolean jnaLockable = false;
+
+  static {
+// detect the OS type the JVM is running on and then set the 
CLibraryWrapper
+// instance to a compatable implementation of CLibraryWrapper for that OS 
type
+osType = getOsType();
+switch (osType) {
+  case MAC:
+wrappedLibrary = new NativeLibraryDarwin();
+break;
+  case WINDOWS:
+wrappedLibrary = new NativeLibraryWindows();
+break;
+  case LINUX:
+  case AIX:
+  case OTHER:
+  default:
+wrappedLibrary = new NativeLibraryLinux();
+}
+
+if (System.getProperty("os.arch").toLowerCase().contains("ppc")) {
+  if (osType == LINUX) {
+MCL_CURRENT = 0x2000;
+  } else if (osType == AIX) {
+MCL_CURRENT = 0x100;
+  } else {
+MCL_CURRENT = 1;
+  }
+} else {
+  MCL_CURRENT = 1;
+}
+  }
+
+  private NativeLibrary() {
+  }
+
+  /**
+   * @return the detected OSType of the Operating System running the JVM using 
crude string matching
+   */
+  private static OSType getOsType() {
 
 Review comment:
   Ah right!


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] uschindler commented on a change in pull request #1364: SOLR-14335: Lock Solr's memory to prevent swapping

2020-03-23 Thread GitBox
uschindler commented on a change in pull request #1364: SOLR-14335: Lock Solr's 
memory to prevent swapping
URL: https://github.com/apache/lucene-solr/pull/1364#discussion_r396321964
 
 

 ##
 File path: solr/bootstrap/src/java/org/apache/solr/bootstrap/SolrBootstrap.java
 ##
 @@ -0,0 +1,51 @@
+/*
+ * 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.bootstrap;
+
+import org.eclipse.jetty.start.StartLog;
+
+/**
+ * Main class that will delegate to Jetty's Main class after doing some 
bootstrap actions.
+ * Everything that needs to be done before the Jetty application starts can go 
here.
+ */
+public class SolrBootstrap {
+  static {
+System.setProperty("jna.tmpdir", System.getProperty("solr.solr.home"));
+  }
+
+  public SolrBootstrap() {
+StartLog.info("Starting Solr...");
+  }
+
+  public static void main(String[] args) {
+SolrBootstrap solrBootstrap = new SolrBootstrap();
+solrBootstrap.memLockMaybe();
+org.eclipse.jetty.start.Main.main(args);
+  }
+
+  private void memLockMaybe() {
+if (Boolean.getBoolean("solr.memory.lock")) {
+  if (NativeLibrary.isAvailable()) {
+StartLog.info("Attempting to lock Solr's memory to prevent 
swapping...");
+NativeLibrary.tryMlockall();
+  } else {
+StartLog.debug("JNA not available, cannot lock memory");
 
 Review comment:
   This should also be "warn" has it is a bad idea to not tell the user that it 
does not work at all. If user wants to get rid of warning, he should disable 
the solr.memory.lock sysprop (resp. env var) from startfile.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] uschindler commented on a change in pull request #1364: SOLR-14335: Lock Solr's memory to prevent swapping

2020-03-23 Thread GitBox
uschindler commented on a change in pull request #1364: SOLR-14335: Lock Solr's 
memory to prevent swapping
URL: https://github.com/apache/lucene-solr/pull/1364#discussion_r396320238
 
 

 ##
 File path: solr/bootstrap/src/java/org/apache/solr/bootstrap/NativeLibrary.java
 ##
 @@ -0,0 +1,139 @@
+/*
+ * 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.bootstrap;
+
+import com.sun.jna.LastErrorException;
+import org.eclipse.jetty.start.StartLog;
+
+import static org.apache.solr.bootstrap.NativeLibrary.OSType.*;
+
+public final class NativeLibrary {
+  public enum OSType {
+LINUX,
+MAC,
+WINDOWS,
+AIX,
+OTHER;
+  }
+
+  public static final OSType osType;
+
+  private static final int MCL_CURRENT;
+
+  private static final int ENOMEM = 12;
+
+  private static final NativeLibraryWrapper wrappedLibrary;
+  private static boolean jnaLockable = false;
+
+  static {
+// detect the OS type the JVM is running on and then set the 
CLibraryWrapper
+// instance to a compatable implementation of CLibraryWrapper for that OS 
type
+osType = getOsType();
+switch (osType) {
+  case MAC:
+wrappedLibrary = new NativeLibraryDarwin();
+break;
+  case WINDOWS:
+wrappedLibrary = new NativeLibraryWindows();
+break;
+  case LINUX:
+  case AIX:
+  case OTHER:
+  default:
+wrappedLibrary = new NativeLibraryLinux();
+}
+
+if (System.getProperty("os.arch").toLowerCase().contains("ppc")) {
+  if (osType == LINUX) {
+MCL_CURRENT = 0x2000;
+  } else if (osType == AIX) {
+MCL_CURRENT = 0x100;
+  } else {
+MCL_CURRENT = 1;
+  }
+} else {
+  MCL_CURRENT = 1;
+}
+  }
+
+  private NativeLibrary() {
+  }
+
+  /**
+   * @return the detected OSType of the Operating System running the JVM using 
crude string matching
+   */
+  private static OSType getOsType() {
 
 Review comment:
   we already detect the OS type using `oal.util.Constants`. We should not 
duplicate code here.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org