Skip to content
Merged
Show file tree
Hide file tree
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 Feb 24, 2023
b14834b
HDDS-8028: Remove duplicate files
swamirishi Feb 24, 2023
68b98c4
HDDS-8028: Add doc
swamirishi Feb 24, 2023
3e9db6e
HDDS-8028: Link Compresion Libraries while building Rocksdb
swamirishi Feb 26, 2023
68550ff
HDDS-8028: Add SSTDumptool Iterator
swamirishi Feb 27, 2023
1c68ddc
HDDS-8028: Fix dependency lib build
swamirishi Mar 1, 2023
189cf30
HDDS-8028: Fix checkstyle issue
swamirishi Mar 1, 2023
e8af6a0
HDDS-8028: Fix build script
swamirishi Mar 1, 2023
7d28b65
HDDS-8028: Fix build script
swamirishi Mar 1, 2023
1a9ba91
HDDS-8028: Fix build script
swamirishi Mar 1, 2023
9f4e4fd
HDDS-8028: Fix build script
swamirishi Mar 1, 2023
10bf033
HDDS-8028: Reduce number of threads
swamirishi Mar 1, 2023
485f623
HDDS-8028: Add cxx flag
swamirishi Mar 1, 2023
b6a9e4c
HDDS-8028: Add cxx flag
swamirishi Mar 1, 2023
873a031
HDDS-8028: fix phase
swamirishi Mar 1, 2023
584b4d7
HDDS-8028: fix javah
swamirishi Mar 1, 2023
004d26e
HDDS-8028: fix rockstool compile
swamirishi Mar 1, 2023
db9e3a4
HDDS-8028: fix rockstool compile
swamirishi Mar 1, 2023
ef8f58d
HDDS-8028: Increase github ci timeout
swamirishi Mar 2, 2023
6ee8984
HDDS-8028: Fix Java JNI Compilation for java 11
swamirishi Mar 2, 2023
3974a69
HDDS-8028: Fix Java JNI Compilation for java 11
swamirishi Mar 2, 2023
246820a
HDDS-8028: Fix Java JNI Compilation for java 11
swamirishi Mar 2, 2023
f192cba
HDDS-8028: Fix Java JNI Compilation for java 11
swamirishi Mar 2, 2023
b4e2735
HDDS-8028: Add Jni for creating pipe between sst dump output & iterator
swamirishi Mar 4, 2023
4f7f75b
HDDS-8028: Fix Checkstyle Issues
swamirishi Mar 4, 2023
35558b5
HDDS-8028: Add Maven Profile
swamirishi Mar 4, 2023
4038205
HDDS-8028: Add Rocksdb Patch file
swamirishi Mar 4, 2023
1d1111c
HDDS-8028: Add docs
swamirishi Mar 4, 2023
6effac6
HDDS-8028: Address review comments
swamirishi Mar 4, 2023
02ccdc8
HDDS-8028: Add additional line
swamirishi Mar 4, 2023
77ef6c2
HDDS-8028: Add license
swamirishi Mar 4, 2023
d42c6b2
HDDS-8028: Add rocks-native-jar to jar report
swamirishi Mar 4, 2023
4d27783
HDDS-8028: Revert import order change
swamirishi Mar 4, 2023
ada8e92
HDDS-8028: Remove last \n character from value
swamirishi Mar 4, 2023
32abb5b
HDDS-8028: Remove main function
swamirishi Mar 4, 2023
2e04b1a
HDDS-8028: Fix checkstyle issue
swamirishi Mar 4, 2023
b232abc
Merge remote-tracking branch 'apache/master' into HDDS-8028
swamirishi Mar 8, 2023
88c9b4a
HDDS-8028: Change name
swamirishi Mar 8, 2023
f626084
HDDS-8028: Address review comments
swamirishi Mar 8, 2023
7cd5c52
HDDS-8028: Use const variable in Pipe closing
swamirishi Mar 8, 2023
18c3afa
HDDS-8028: Fix checkstyle issues
swamirishi Mar 8, 2023
07aec35
HDDS-8028: Fix javadoc
swamirishi Mar 8, 2023
0c49383
HDDS-8028: Fix javadoc
swamirishi Mar 8, 2023
16dadc5
HDDS-8028: Fix exception handling & garbage collection
swamirishi Mar 9, 2023
1a42d5c
HDDS-8028: Remove unused import
swamirishi Mar 9, 2023
ba5de3a
HDDS-8028: Fix exception handling
swamirishi Mar 9, 2023
23d3735
HDDS-8028: Fix checkstyle
swamirishi Mar 9, 2023
fc6993b
HDDS-8028: Fix checkstyle
swamirishi Mar 9, 2023
9250a4d
HDDS-8028: Address review comments
swamirishi Mar 10, 2023
80019b9
HDDS-8028: Address review comments
swamirishi Mar 10, 2023
dbc3117
HDDS-8028: Address review comments
swamirishi Mar 10, 2023
db3300d
HDDS-8028: Address review comments
swamirishi Mar 10, 2023
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
6 changes: 6 additions & 0 deletions hadoop-hdds/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<module>config</module>
<module>test-utils</module>
<module>erasurecode</module>
<module>rocks-native</module>
</modules>

<repositories>
Expand Down Expand Up @@ -248,6 +249,11 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ozone</groupId>
<artifactId>hdds-rocks-native</artifactId>
<version>${hdds.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down
421 changes: 421 additions & 0 deletions hadoop-hdds/rocks-native/pom.xml

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions hadoop-hdds/rocks-native/src/CMakeLists.txt
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})
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";
}
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() {
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) {
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)
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();
}
}
}
}
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)));
}
}
Loading