Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11347. Add rocks_tools_native lib check in Ozone CLI checknative subcommand #7101

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import static org.apache.hadoop.hdds.utils.NativeConstants.ROCKS_TOOLS_NATIVE_LIBRARY_NAME;

/**
* Class to load Native Libraries.
*/
Expand Down Expand Up @@ -67,6 +69,10 @@ public static NativeLibraryLoader getInstance() {
return instance;
}

public static String getJniLibraryFileName() {
return appendLibOsSuffix("lib" + ROCKS_TOOLS_NATIVE_LIBRARY_NAME);
}

public static String getJniLibraryFileName(String libraryName) {
return appendLibOsSuffix("lib" + libraryName);
}
Expand Down Expand Up @@ -99,9 +105,12 @@ private static String appendLibOsSuffix(String libraryFileName) {
return libraryFileName + getLibOsSuffix();
}

public static boolean isLibraryLoaded() {
return isLibraryLoaded(ROCKS_TOOLS_NATIVE_LIBRARY_NAME);
}

public static boolean isLibraryLoaded(final String libraryName) {
return getInstance().librariesLoaded
.getOrDefault(libraryName, false);
return getInstance().librariesLoaded.getOrDefault(libraryName, false);
}

public synchronized boolean loadLibrary(final String libraryName, final List<String> dependentFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
package org.apache.hadoop.ozone.shell.checknative;

import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.utils.NativeLibraryLoader;
import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksObjectUtils;
import org.apache.hadoop.io.erasurecode.ErasureCodeNative;
import org.apache.hadoop.util.NativeCodeLoader;
import picocli.CommandLine;

import java.util.Collections;

import static org.apache.hadoop.hdds.utils.NativeConstants.ROCKS_TOOLS_NATIVE_LIBRARY_NAME;

/**
* CLI command to check if native libraries are loaded.
*/
Expand All @@ -36,12 +41,12 @@ public static void main(String[] argv) {

@Override
public Void call() throws Exception {
boolean nativeHadoopLoaded = NativeCodeLoader.isNativeCodeLoaded();
boolean nativeHadoopLoaded = org.apache.hadoop.util.NativeCodeLoader.isNativeCodeLoaded();
String hadoopLibraryName = "";
String isalDetail = "";
boolean isalLoaded = false;
if (nativeHadoopLoaded) {
hadoopLibraryName = NativeCodeLoader.getLibraryName();
hadoopLibraryName = org.apache.hadoop.util.NativeCodeLoader.getLibraryName();

isalDetail = ErasureCodeNative.getLoadingFailureReason();
if (isalDetail != null) {
Expand All @@ -50,12 +55,21 @@ public Void call() throws Exception {
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);

// Attempt to load the rocks-tools lib
boolean nativeRocksToolsLoaded = NativeLibraryLoader.getInstance().loadLibrary(
ROCKS_TOOLS_NATIVE_LIBRARY_NAME,
Collections.singletonList(ManagedRocksObjectUtils.getRocksDBLibFileName()));
String rocksToolsDetail = "";
if (nativeRocksToolsLoaded) {
rocksToolsDetail = NativeLibraryLoader.getJniLibraryFileName();
}
System.out.printf("rocks-tools: %b %s%n", nativeRocksToolsLoaded, rocksToolsDetail);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.ozone.checknative;

import org.apache.hadoop.ozone.shell.checknative.CheckNative;
import org.apache.ozone.test.tag.Native;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -27,6 +28,7 @@
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import static org.apache.hadoop.hdds.utils.NativeConstants.ROCKS_TOOLS_NATIVE_LIBRARY_NAME;
import static org.assertj.core.api.Assertions.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;

Expand Down Expand Up @@ -59,6 +61,22 @@ public void testCheckNativeNotLoaded() throws UnsupportedEncodingException {
assertThat(stdOut).contains("Native library checking:");
assertThat(stdOut).contains("hadoop: false");
assertThat(stdOut).contains("ISA-L: false");
assertThat(stdOut).contains("rocks-tools: false");
}

@Native(ROCKS_TOOLS_NATIVE_LIBRARY_NAME)
@Test
public void testCheckNativeRocksToolsLoaded() throws UnsupportedEncodingException {
outputStream.reset();
new CheckNative()
.run(new String[] {});
// trims multiple spaces
String stdOut = outputStream.toString(DEFAULT_ENCODING)
.replaceAll(" +", " ");
assertThat(stdOut).contains("Native library checking:");
assertThat(stdOut).contains("hadoop: false");
assertThat(stdOut).contains("ISA-L: false");
assertThat(stdOut).contains("rocks-tools: true");
}

@AfterEach
Expand Down