This is an automated email from the ASF dual-hosted git repository.

ayushsaxena pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new b8f2dccf3e HDDS-9230. Add CLI command for checking native libs (#5238)
b8f2dccf3e is described below

commit b8f2dccf3e29fe06842f0205b10e5e33865868ab
Author: Maxim Myskov <[email protected]>
AuthorDate: Tue Sep 5 01:58:08 2023 +0300

    HDDS-9230. Add CLI command for checking native libs (#5238)
---
 hadoop-hdds/docs/content/feature/ErasureCoding.md  | 22 +++++++
 hadoop-ozone/dist/src/shell/ozone/ozone            |  5 ++
 .../ozone/shell/checknative/CheckNative.java       | 61 ++++++++++++++++++
 .../ozone/shell/checknative/package-info.java      | 22 +++++++
 .../hadoop/ozone/checknative/TestCheckNative.java  | 74 ++++++++++++++++++++++
 5 files changed, 184 insertions(+)

diff --git a/hadoop-hdds/docs/content/feature/ErasureCoding.md 
b/hadoop-hdds/docs/content/feature/ErasureCoding.md
index cced272125..77866762f6 100644
--- a/hadoop-hdds/docs/content/feature/ErasureCoding.md
+++ b/hadoop-hdds/docs/content/feature/ErasureCoding.md
@@ -210,3 +210,25 @@ ozone sh key put <Ozone Key Object Path> <Local File> 
--type EC --replication rs
 
 In the case bucket already has default EC Replication Config, there is no need 
of passing EC Replication Config while creating key.
 
+### Enable Intel ISA-L
+
+Intel Intelligent Storage Acceleration Library (ISA-L) is an open-source 
collection of optimized low-level functions used for
+storage applications. Enabling ISA-L allows significantly improve EC 
performance.
+
+#### Prerequisites
+
+To enable ISA-L you will also require Hadoop native libraries (libhadoop.so). 
+
+#### Installation
+Both libraries should be placed to the directory specified by the 
java.library.path property or set by  `LD_LIBRARY_PATH` environment variable.
+The default value of java.library.path depends on the OS and Java version. For 
example, on Linux with OpenJDK 8 it is 
`/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib`.
+
+#### Verification
+
+You can check if ISA-L is accessible to Ozone by running the following command:
+
+```shell
+ozone checknative
+```
+
+
diff --git a/hadoop-ozone/dist/src/shell/ozone/ozone 
b/hadoop-ozone/dist/src/shell/ozone/ozone
index 563df308e8..854ee462ee 100755
--- a/hadoop-ozone/dist/src/shell/ozone/ozone
+++ b/hadoop-ozone/dist/src/shell/ozone/ozone
@@ -59,6 +59,7 @@ function ozone_usage
   ozone_add_subcommand "dtutil" client "operations related to delegation 
tokens"
   ozone_add_subcommand "admin" client "Ozone admin tool"
   ozone_add_subcommand "debug" client "Ozone debug tool"
+  ozone_add_subcommand "checknative" client "checks if native libraries are 
loaded"
 
   ozone_generate_usage "${OZONE_SHELL_EXECNAME}" false
 }
@@ -230,6 +231,10 @@ function ozonecmd_case
       OZONE_CLASSNAME=org.apache.hadoop.ozone.debug.OzoneDebug
       OZONE_RUN_ARTIFACT_NAME="ozone-tools"
     ;;
+    checknative)
+        OZONE_CLASSNAME=org.apache.hadoop.ozone.shell.checknative.CheckNative
+        OZONE_RUN_ARTIFACT_NAME="ozone-tools"
+    ;;
     *)
       OZONE_CLASSNAME="${subcmd}"
       if ! ozone_validate_classname "${OZONE_CLASSNAME}"; then
diff --git 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java
 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java
new file mode 100644
index 0000000000..63b2b425c6
--- /dev/null
+++ 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java
@@ -0,0 +1,61 @@
+/*
+ * 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.hadoop.ozone.shell.checknative;
+
+import org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.hadoop.io.erasurecode.ErasureCodeNative;
+import org.apache.hadoop.util.NativeCodeLoader;
+import picocli.CommandLine;
+
+/**
+ * CLI command to check if native libraries are loaded.
+ */
[email protected](name = "ozone checknative",
+    description = "Checks if native libraries are loaded")
+public class CheckNative extends GenericCli {
+
+  public static void main(String[] argv) {
+    new CheckNative().run(argv);
+  }
+
+  @Override
+  public Void call() throws Exception {
+    boolean nativeHadoopLoaded = NativeCodeLoader.isNativeCodeLoaded();
+    String hadoopLibraryName = "";
+    String isalDetail = "";
+    boolean isalLoaded = false;
+    if (nativeHadoopLoaded) {
+      hadoopLibraryName = NativeCodeLoader.getLibraryName();
+
+      isalDetail = ErasureCodeNative.getLoadingFailureReason();
+      if (isalDetail != null) {
+        isalLoaded = false;
+      } else {
+        isalDetail = ErasureCodeNative.getLibraryName();
+        isalLoaded = true;
+      }
+
+    }
+    System.out.println("Native library checking:");
+    System.out.printf("hadoop:  %b %s%n", nativeHadoopLoaded,
+        hadoopLibraryName);
+    System.out.printf("ISA-L:   %b %s%n", isalLoaded, isalDetail);
+    return null;
+  }
+}
diff --git 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/package-info.java
 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/package-info.java
new file mode 100644
index 0000000000..ba46d6d471
--- /dev/null
+++ 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 for commands related to checking native libraries.
+ */
+package org.apache.hadoop.ozone.shell.checknative;
diff --git 
a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/checknative/TestCheckNative.java
 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/checknative/TestCheckNative.java
new file mode 100644
index 0000000000..0aff651367
--- /dev/null
+++ 
b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/checknative/TestCheckNative.java
@@ -0,0 +1,74 @@
+/*
+ * 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.hadoop.ozone.checknative;
+
+import org.apache.hadoop.ozone.shell.checknative.CheckNative;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for {@link CheckNative}.
+ */
+public class TestCheckNative {
+
+  private static PrintStream psBackup;
+  private static ByteArrayOutputStream outputStream;
+
+  private static final String DEFAULT_ENCODING = UTF_8.name();
+
+  @BeforeClass
+  public static void init() throws UnsupportedEncodingException {
+    psBackup = System.out;
+    outputStream = new ByteArrayOutputStream();
+    PrintStream psOut = new PrintStream(outputStream, false, DEFAULT_ENCODING);
+    System.setOut(psOut);
+  }
+
+  @Test
+  public void testCheckNativeNotLoaded() throws UnsupportedEncodingException {
+    outputStream.reset();
+    new CheckNative()
+        .run(new String[] {});
+    // trims multiple spaces
+    String stdOut = outputStream.toString(DEFAULT_ENCODING)
+        .replaceAll(" +", " ");
+    assertTrue(stdOut.contains("Native library checking:"));
+    assertTrue(stdOut.contains("hadoop: false"));
+    assertTrue(stdOut.contains("ISA-L: false"));
+  }
+
+  @After
+  public void setUp() {
+    outputStream.reset();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    System.setOut(psBackup);
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to