-
Notifications
You must be signed in to change notification settings - Fork 587
HDDS-8028. JNI for RocksDB SST Dump tool #4315
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
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
c097f35
HDDS-8028: JNI for RocksDB SST Dump tool
swamirishi b14834b
HDDS-8028: Remove duplicate files
swamirishi 68b98c4
HDDS-8028: Add doc
swamirishi 3e9db6e
HDDS-8028: Link Compresion Libraries while building Rocksdb
swamirishi 68550ff
HDDS-8028: Add SSTDumptool Iterator
swamirishi 1c68ddc
HDDS-8028: Fix dependency lib build
swamirishi 189cf30
HDDS-8028: Fix checkstyle issue
swamirishi e8af6a0
HDDS-8028: Fix build script
swamirishi 7d28b65
HDDS-8028: Fix build script
swamirishi 1a9ba91
HDDS-8028: Fix build script
swamirishi 9f4e4fd
HDDS-8028: Fix build script
swamirishi 10bf033
HDDS-8028: Reduce number of threads
swamirishi 485f623
HDDS-8028: Add cxx flag
swamirishi b6a9e4c
HDDS-8028: Add cxx flag
swamirishi 873a031
HDDS-8028: fix phase
swamirishi 584b4d7
HDDS-8028: fix javah
swamirishi 004d26e
HDDS-8028: fix rockstool compile
swamirishi db9e3a4
HDDS-8028: fix rockstool compile
swamirishi ef8f58d
HDDS-8028: Increase github ci timeout
swamirishi 6ee8984
HDDS-8028: Fix Java JNI Compilation for java 11
swamirishi 3974a69
HDDS-8028: Fix Java JNI Compilation for java 11
swamirishi 246820a
HDDS-8028: Fix Java JNI Compilation for java 11
swamirishi f192cba
HDDS-8028: Fix Java JNI Compilation for java 11
swamirishi b4e2735
HDDS-8028: Add Jni for creating pipe between sst dump output & iterator
swamirishi 4f7f75b
HDDS-8028: Fix Checkstyle Issues
swamirishi 35558b5
HDDS-8028: Add Maven Profile
swamirishi 4038205
HDDS-8028: Add Rocksdb Patch file
swamirishi 1d1111c
HDDS-8028: Add docs
swamirishi 6effac6
HDDS-8028: Address review comments
swamirishi 02ccdc8
HDDS-8028: Add additional line
swamirishi 77ef6c2
HDDS-8028: Add license
swamirishi d42c6b2
HDDS-8028: Add rocks-native-jar to jar report
swamirishi 4d27783
HDDS-8028: Revert import order change
swamirishi ada8e92
HDDS-8028: Remove last \n character from value
swamirishi 32abb5b
HDDS-8028: Remove main function
swamirishi 2e04b1a
HDDS-8028: Fix checkstyle issue
swamirishi b232abc
Merge remote-tracking branch 'apache/master' into HDDS-8028
swamirishi 88c9b4a
HDDS-8028: Change name
swamirishi f626084
HDDS-8028: Address review comments
swamirishi 7cd5c52
HDDS-8028: Use const variable in Pipe closing
swamirishi 18c3afa
HDDS-8028: Fix checkstyle issues
swamirishi 07aec35
HDDS-8028: Fix javadoc
swamirishi 0c49383
HDDS-8028: Fix javadoc
swamirishi 16dadc5
HDDS-8028: Fix exception handling & garbage collection
swamirishi 1a42d5c
HDDS-8028: Remove unused import
swamirishi ba5de3a
HDDS-8028: Fix exception handling
swamirishi 23d3735
HDDS-8028: Fix checkstyle
swamirishi fc6993b
HDDS-8028: Fix checkstyle
swamirishi 9250a4d
HDDS-8028: Address review comments
swamirishi 80019b9
HDDS-8028: Address review comments
swamirishi dbc3117
HDDS-8028: Address review comments
swamirishi db3300d
HDDS-8028: Address review comments
swamirishi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| # | ||
| # CMake configuration. | ||
| # | ||
|
|
||
| cmake_minimum_required(VERSION 2.8) | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") | ||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") | ||
| project(ozone_native) | ||
| set(CMAKE_BUILD_TYPE Release) | ||
| find_package(JNI REQUIRED) | ||
| include_directories(${JNI_INCLUDE_DIRS}) | ||
| set(CMAKE_CXX_STANDARD ${CMAKE_STANDARDS}) | ||
|
|
||
| set(linked_libraries "") | ||
| if(NOT GENERATED_JAVAH) | ||
| message(FATAL_ERROR "You must set the CMake variable GENERATED_JAVAH") | ||
| endif() | ||
| include_directories(${GENERATED_JAVAH}) | ||
| if(${SST_DUMP_INCLUDE}) | ||
| include_directories(${ROCKSDB_HEADERS}) | ||
| set(SOURCE_FILES ${NATIVE_DIR}/SSTDumpTool.cpp ${NATIVE_DIR}/PipeInputStream.cpp ${NATIVE_DIR}/Pipe.h ${NATIVE_DIR}/Pipe.cpp ${NATIVE_DIR}/cplusplus_to_java_convert.h) | ||
| ADD_LIBRARY(rocksdb STATIC IMPORTED) | ||
| set_target_properties( | ||
| rocksdb | ||
| PROPERTIES | ||
| IMPORTED_LOCATION ${ROCKSDB_LIB}/librocksdb_debug.a) | ||
| ADD_LIBRARY(rocks_tools STATIC IMPORTED) | ||
| set_target_properties( | ||
| rocks_tools | ||
| PROPERTIES | ||
| IMPORTED_LOCATION ${ROCKSDB_LIB}/librocksdb_tools_debug.a) | ||
| ADD_LIBRARY(bz2 STATIC IMPORTED) | ||
| set_target_properties( | ||
| bz2 | ||
| PROPERTIES | ||
| IMPORTED_LOCATION ${BZIP2_LIB}/libbz2.a) | ||
| ADD_LIBRARY(zlib STATIC IMPORTED) | ||
| set_target_properties( | ||
| zlib | ||
| PROPERTIES | ||
| IMPORTED_LOCATION ${ZLIB_LIB}/libz.a) | ||
| ADD_LIBRARY(lz4 STATIC IMPORTED) | ||
| set_target_properties( | ||
| lz4 | ||
| PROPERTIES | ||
| IMPORTED_LOCATION ${LZ4_LIB}/liblz4.a) | ||
| ADD_LIBRARY(snappy STATIC IMPORTED) | ||
| set_target_properties( | ||
| snappy | ||
| PROPERTIES | ||
| IMPORTED_LOCATION ${SNAPPY_LIB}/libsnappy.a) | ||
| ADD_LIBRARY(zstd STATIC IMPORTED) | ||
| set_target_properties( | ||
| zstd | ||
| PROPERTIES | ||
| IMPORTED_LOCATION ${ZSTD_LIB}/libzstd.a) | ||
| set(linked_libraries ${linked_libraries} bz2 zlib rocks_tools rocksdb lz4 snappy zstd) | ||
| endif() | ||
| add_library(ozone_rocksdb_tools SHARED ${SOURCE_FILES}) | ||
| target_link_libraries(ozone_rocksdb_tools ${linked_libraries}) |
31 changes: 31 additions & 0 deletions
31
hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/NativeConstants.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * 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.hdds.utils; | ||
|
|
||
| /** | ||
| * Native Constants. | ||
| */ | ||
| public final class NativeConstants { | ||
|
|
||
| private NativeConstants() { | ||
|
|
||
| } | ||
| public static final String ROCKS_TOOLS_NATIVE_LIBRARY_NAME | ||
| = "ozone_rocksdb_tools"; | ||
| } |
150 changes: 150 additions & 0 deletions
150
hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/NativeLibraryLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* | ||
| * 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.hdds.utils; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.StandardCopyOption; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| /** | ||
| * Class to load Native Libraries. | ||
| */ | ||
| public class NativeLibraryLoader { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(NativeLibraryLoader.class); | ||
| private static final String OS = System.getProperty("os.name").toLowerCase(); | ||
| private Map<String, Boolean> librariesLoaded; | ||
| private static volatile NativeLibraryLoader instance; | ||
|
|
||
| public NativeLibraryLoader(final Map<String, Boolean> librariesLoaded) { | ||
| this.librariesLoaded = librariesLoaded; | ||
| } | ||
|
|
||
| private static synchronized void initNewInstance() { | ||
| if (instance == null) { | ||
| instance = new NativeLibraryLoader(new ConcurrentHashMap<>()); | ||
| } | ||
| } | ||
|
|
||
| public static NativeLibraryLoader getInstance() { | ||
| if (instance == null) { | ||
| initNewInstance(); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| public static String getJniLibraryFileName(String libraryName) { | ||
| return appendLibOsSuffix("lib" + libraryName); | ||
| } | ||
|
|
||
| public static boolean isMac() { | ||
smengcl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return OS.startsWith("mac"); | ||
| } | ||
|
|
||
| public static boolean isWindows() { | ||
| return OS.startsWith("win"); | ||
| } | ||
|
|
||
| public static boolean isLinux() { | ||
| return OS.startsWith("linux"); | ||
| } | ||
|
|
||
| private static String getLibOsSuffix() { | ||
| if (isMac()) { | ||
| return ".dylib"; | ||
| } else if (isWindows()) { | ||
| return ".dll"; | ||
| } else if (isLinux()) { | ||
| return ".so"; | ||
| } | ||
| throw new UnsatisfiedLinkError(String.format("Unsupported OS %s", OS)); | ||
| } | ||
|
|
||
| private static String appendLibOsSuffix(String libraryFileName) { | ||
smengcl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return libraryFileName + getLibOsSuffix(); | ||
| } | ||
|
|
||
| public static boolean isLibraryLoaded(final String libraryName) { | ||
| return getInstance().librariesLoaded | ||
| .getOrDefault(libraryName, false); | ||
| } | ||
|
|
||
| public synchronized boolean loadLibrary(final String libraryName) { | ||
| if (isLibraryLoaded(libraryName)) { | ||
| return true; | ||
| } | ||
| boolean loaded = false; | ||
| try { | ||
| loaded = false; | ||
| try { | ||
| System.loadLibrary(libraryName); | ||
| loaded = true; | ||
| } catch (Throwable e) { | ||
|
|
||
| } | ||
| if (!loaded) { | ||
| Optional<File> file = copyResourceFromJarToTemp(libraryName); | ||
| if (file.isPresent()) { | ||
| System.load(file.get().getAbsolutePath()); | ||
| loaded = true; | ||
| } | ||
| } | ||
| } catch (Throwable e) { | ||
| LOG.warn("Unable to load library: {}", libraryName, e); | ||
| } | ||
| this.librariesLoaded.put(libraryName, loaded); | ||
| return isLibraryLoaded(libraryName); | ||
| } | ||
|
|
||
| private Optional<File> copyResourceFromJarToTemp(final String libraryName) | ||
smengcl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| throws IOException { | ||
| final String libraryFileName = getJniLibraryFileName(libraryName); | ||
| InputStream is = null; | ||
| try { | ||
| is = getClass().getClassLoader().getResourceAsStream(libraryFileName); | ||
| if (is == null) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| // create a temporary file to copy the library to | ||
| final File temp = File.createTempFile(libraryName, getLibOsSuffix()); | ||
| if (!temp.exists()) { | ||
| return Optional.empty(); | ||
| } else { | ||
| temp.deleteOnExit(); | ||
| } | ||
|
|
||
| Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING); | ||
| return Optional.ofNullable(temp); | ||
| } finally { | ||
| if (is != null) { | ||
| is.close(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
smengcl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
30 changes: 30 additions & 0 deletions
30
...ks-native/src/main/java/org/apache/hadoop/hdds/utils/NativeLibraryNotLoadedException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * 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.hdds.utils; | ||
|
|
||
| /** | ||
| Exception when native library not loaded. | ||
| */ | ||
| public class NativeLibraryNotLoadedException extends Exception { | ||
| public NativeLibraryNotLoadedException(String libraryName) { | ||
| super(String.format("Unable to load library %s from both " + | ||
| "java.library.path & resource file %s from jar.", libraryName, | ||
| NativeLibraryLoader.getJniLibraryFileName(libraryName))); | ||
| } | ||
| } | ||
smengcl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.