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

Refactor JNI library #1402

Merged
merged 7 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 3 additions & 2 deletions .linters/cpp/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ if [ $# -eq 0 ];then
echo "You have unstaged changes, please stage or stash them first."
exit 1
fi
CHECK_FILES=$(git diff --name-only --diff-filter=ACMRTUXB HEAD | egrep '.*\.cpp$|.*\.h$|.*\.inl$' | grep -v 'com_vesoft_client_NativeClient.h')
CHECK_FILES=$(git diff --name-only --diff-filter=ACMRTUXB HEAD | egrep '.*\.cpp$|.*\.h$|.*\.inl$' | grep -v 'com_vesoft_client_NativeClient.h' | grep -v 'com_vesoft_nebula_NebulaCodec.h')
else
CHECK_FILES=$(find $@ -not \( -path src/CMakeFiles -prune \) \
-not \( -path src/interface/gen-cpp2 -prune \) \
-name "*.[h]" -o -name "*.cpp" -o -name '*.inl' \
| grep -v 'GraphScanner.*' | grep -v 'GraphParser.*' \
| grep -v 'com_vesoft_client_NativeClient.h')
| grep -v 'com_vesoft_client_NativeClient.h' \
| grep -v 'com_vesoft_nebula_NebulaCodec.h')
fi

# No changes on interested files
Expand Down
11 changes: 1 addition & 10 deletions src/common/base/Cord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

#include "base/Base.h"
#include "base/Cord.h"
#include "base/Logging.h"

namespace nebula {

Expand Down Expand Up @@ -225,15 +225,6 @@ Cord& Cord::operator<<(const char* value) {
return write(value, strlen(value));
}


Cord& Cord::operator<<(const folly::StringPiece value) {
return write(value.begin(), value.size());
}

Cord& Cord::operator<<(const folly::ByteRange value) {
return write(reinterpret_cast<const char*>(value.begin()), value.size());
}

Cord& Cord::operator<<(const Cord& rhs) {
char* next = rhs.head_;
while (next != rhs.tail_) {
Expand Down
6 changes: 3 additions & 3 deletions src/common/base/Cord.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#ifndef COMMON_BASE_CORD_H_
#define COMMON_BASE_CORD_H_

#include "base/Base.h"
#include <stdlib.h>
#include <functional>
#include <string>

namespace nebula {

Expand Down Expand Up @@ -53,8 +55,6 @@ class Cord {

Cord& operator<<(const std::string& value);
Cord& operator<<(const char* value);
Cord& operator<<(const folly::StringPiece value);
Cord& operator<<(const folly::ByteRange value);

Cord& operator<<(const Cord& rhs);

Expand Down
2 changes: 2 additions & 0 deletions src/common/base/ThriftTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef COMMON_BASE_THRIFTTYPES_H_
#define COMMON_BASE_THRIFTTYPES_H_

#include <cstdint>

namespace nebula {

// Raft related types
Expand Down
5 changes: 3 additions & 2 deletions src/common/base/test/CordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TEST(Cord, byteStream) {
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
Cord cord2;

cord2 << folly::ByteRange(bytes, sizeof(bytes));
cord2.write(reinterpret_cast<const char*>(&bytes[0]), sizeof(bytes));
std::string str = cord2.str();

EXPECT_EQ(sizeof(bytes), str.size());
Expand Down Expand Up @@ -187,7 +187,8 @@ TEST(Cord, stringStream) {

Cord cord;

cord << str1 << str2 << folly::StringPiece(str3);
cord << str1 << str2;
cord.write(str3.data(), str3.size());

EXPECT_EQ(str1.size() + strlen(str2) + str3.size(), cord.size());
EXPECT_EQ(str1.size() + strlen(str2) + str3.size(), cord.str().size());
Expand Down
2 changes: 1 addition & 1 deletion src/dataman/RowWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ RowWriter& RowWriter::operator<<(folly::StringPiece v) noexcept {
switch (type->get_type()) {
case SupportedType::STRING: {
writeInt(v.size());
cord_ << v;
cord_.write(v.data(), v.size());
break;
}
default: {
Expand Down
2 changes: 1 addition & 1 deletion src/dataman/RowWriter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RowWriter::writeInt(T v) {
uint8_t buf[10];
size_t len = folly::encodeVarint(v, buf);
DCHECK_GT(len, 0UL);
cord_ << folly::ByteRange(buf, len);
cord_.write(reinterpret_cast<const char*>(&buf[0]), len);
}

} // namespace nebula
Expand Down
58 changes: 58 additions & 0 deletions src/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) 2019 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
#
# The build can be controlled by defining following variables on the
# <cmake> command line
#
# CMAKE_C_COMPILER -- Specify the compiler for C language
# CMAKE_CXX_COMPILER -- Specify the compiler for C++ language
#
# NEBULA_HOME -- Specify the root directory for nebula project
# NEBULA_THIRDPARTY_ROOT -- Specify the third-party root dir.
# ENABLE_TESTING -- Build unit test
#
cmake_minimum_required(VERSION 3.0.0)

project("Nebula Graph codec" C CXX)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(ENABLE_TESTING "Whether to compile unit test ON or OFF" OFF)

message(STATUS "CMAKE_CURRENT_BINARY_DIR:" ${CMAKE_CURRENT_BINARY_DIR})
message(STATUS "CMAKE_CURRENT_SOURCE_DIR:" ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "NEBULA_HOME:" ${NEBULA_HOME})
message(STATUS "NEBULA_THIRDPARTY_ROOT:" ${NEBULA_THIRDPARTY_ROOT})

# locate jni header
include_directories($ENV{JAVA_HOME}/include
$ENV{JAVA_HOME}/include/linux)
include_directories(AFTER ${NEBULA_HOME}/src)
include_directories(AFTER ${NEBULA_HOME}/src/common)
include_directories(AFTER ${NEBULA_HOME}/src/jni/src)

include_directories(SYSTEM ${NEBULA_THIRDPARTY_ROOT}/include)
link_directories(
${NEBULA_THIRDPARTY_ROOT}/lib
${NEBULA_THIRDPARTY_ROOT}/lib64
)

if (ENABLE_TESTING)
enable_testing()
endif()

if (!CMAKE_CXX_COMPILER)
message(FATAL_ERROR "No C++ compiler found")
endif()

add_compile_options(-fPIC)
add_compile_options(-Wall)
add_compile_options(-Werror)
add_compile_options(-Wunused-parameter)


add_subdirectory(src)

22 changes: 22 additions & 0 deletions src/jni/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Nebula JNI codec library
It supports encode/decode data in nebula graph.


# How to build

## Build requirements
To build this project, you must have:
* Access to the Internet
* make
* cmake 3.0.0+
* GCC 6.0+
* glog


## Steps
* mkdir build && cd build
* cmake .. -DNEBULA_HOME=${nebula project root dir} -DNEBULA_THIRDPARTY_ROOT=${dependencies root dir}
* make
* cd ../java && mvn clean package

You could find the jni java package nebula-utils-1.0.0-beta.jar under java/target dir
Loading