Skip to content
Open
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/build
local_install
*.pb.cc
*.pb.h
*.o
Makefile
/.lib
/lib
/.sbin
/.vscode
16 changes: 6 additions & 10 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
[submodule "third_party/gtest"]
path = third_party/gtest
url = https://github.com/google/googletest
branch = release-1.6.0
[submodule "third_party/gflags"]
path = third_party/gflags
url = https://github.com/gflags/gflags
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://github.com/google/protobuf
[submodule "third_party/glog"]
path = third_party/glog
url = https://github.com/google/glog
[submodule "third_party/leveldb"]
path = third_party/leveldb
url = https://github.com/google/leveldb
[submodule "third_party/gmock"]
path = third_party/gmock
url = https://github.com/google/googlemock
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
[submodule "third_party/grpc"]
path = third_party/grpc
url = https://github.com/grpc/grpc.git
105 changes: 105 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
cmake_minimum_required(VERSION 3.12)
project(phxpaxos)

option(PHXPAXOS_BUILD_TOOLS "build tools" OFF)
option(PHXPAXOS_BUILD_UT "build ut" OFF)
option(PHXPAXOS_BUILD_TEST "build test" OFF)
option(PHXPAXOS_BUILD_BENCHMARK "build benchmark" OFF)
option(PHXPAXOS_BUILD_PLUGIN "build plugin" OFF)
option(PHXPAXOS_BUILD_SAMPLE_ECHO "build sample phxecho" OFF)
option(PHXPAXOS_BUILD_SAMPLE_ELECTION "build sample phxelection" OFF)
option(PHXPAXOS_BUILD_SAMPLE_KV "build sample phxkv" OFF)
option(PHXPAXOS_INSTALL "create target to install phxpaxos library and headers" ON)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# Release - Adds the -O3 -DNDEBUG flags to the compiler
# Debug - Adds the -g flag
# MinSizeRel - Adds -Os -DNDEBUG
# RelWithDebInfo - Adds -O2 -g -DNDEBUG flags
message("Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_compile_options(-Wall -Werror -Wno-unused-local-typedefs -Wno-unused-variable)
add_compile_options(-Wl,--no-as-needed)
add_compile_options(-std=c++11)

# for find_package in CONFIG mode to find <PackageName>Config.cmake and <lower-case-package-name>-config.cmake
list(APPEND CMAKE_PREFIX_PATH
"${PROJECT_SOURCE_DIR}/third_party/local_install/abseil/lib64/cmake/absl"
"${PROJECT_SOURCE_DIR}/third_party/local_install/grpc/lib/cmake/grpc"
)

# for find_library find_path find_program
list(APPEND CMAKE_PREFIX_PATH
"${PROJECT_SOURCE_DIR}/third_party/local_install/gflags"
"${PROJECT_SOURCE_DIR}/third_party/local_install/glog"
"${PROJECT_SOURCE_DIR}/third_party/local_install/gmock"
"${PROJECT_SOURCE_DIR}/third_party/local_install/leveldb"
"${PROJECT_SOURCE_DIR}/third_party/local_install/protobuf"
"${PROJECT_SOURCE_DIR}/third_party/local_install/grpc"
)

# for find_package in MODULE mode to find Find<PackageName>.cmake
list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake)


find_package(Leveldb MODULE REQUIRED)
find_package(Protobuf MODULE REQUIRED)

add_subdirectory(src/algorithm)
add_subdirectory(src/checkpoint)
add_subdirectory(src/comm)
add_subdirectory(src/communicate)
add_subdirectory(src/config)
add_subdirectory(src/logstorage)
add_subdirectory(src/master)
add_subdirectory(src/node)
add_subdirectory(src/sm-base)
add_subdirectory(src/utils)

if(PHXPAXOS_BUILD_TOOLS)
add_subdirectory(src/tools)
endif()

if(PHXPAXOS_BUILD_UT)
find_package(Gtest MODULE REQUIRED)
find_package(Gmock MODULE REQUIRED)
add_subdirectory(src/ut)
endif()

if(PHXPAXOS_BUILD_TEST)
add_subdirectory(src/test)
endif()

if(PHXPAXOS_BUILD_BENCHMARK)
add_subdirectory(src/benchmark)
endif()

if(PHXPAXOS_BUILD_PLUGIN
OR PHXPAXOS_BUILD_SAMPLE_ECHO
OR PHXPAXOS_BUILD_SAMPLE_ELECTION
OR PHXPAXOS_BUILD_SAMPLE_KV)
find_package(Gflags MODULE REQUIRED)
find_package(Glog MODULE REQUIRED)
add_subdirectory(plugin)
endif()

if(PHXPAXOS_BUILD_SAMPLE_ECHO)
add_subdirectory(sample/phxecho)
endif()

if(PHXPAXOS_BUILD_SAMPLE_ELECTION)
add_subdirectory(sample/phxelection)
endif()

if(PHXPAXOS_BUILD_SAMPLE_KV)
find_package(absl CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
include(${PROJECT_SOURCE_DIR}/cmake/gRPCHelper.cmake)
add_subdirectory(sample/phxkv)
endif()
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,23 @@ Following is a dependency relationship tablet of all directories.
| sample/phxkv | Executable program | libphxpaxos.a,libphxpaxos_plugin.a | grpc |
| src/ut | Unit tests | None | gtest,gmock |

We only need 2 third party libs: Protobuf and Leveldb while compiling PhxPaxos library(target is libphxpaoxs.a).But we need GLOG and GRPC while compiling other directories. All these third party libs should be prepared and palced in our `third_party` directory before PhxPaxos compilation. You can `git clone` them by adding `--recurse-submodules` on just download and link them.
We only need 2 third party libs: Protobuf and Leveldb while compiling PhxPaxos library(target is libphxpaoxs.a).But we need GLOG and GRPC while compiling other directories. All these third party libs should be prepared and palced in our `third_party` directory before PhxPaxos compilation. You can `git clone` them by adding `--recurse-submodules` on just download and link them. For already cloned repos, use `git submodule update --init --recursive`.

Then switch to the `third_party` directory, execute `autoinstall.sh` to compile deps. The script `autoinstall.sh` will compile all deps and install them to `third_party/local_install` directory.

```Bash
cd third_party
./autoinstall.sh
```

### Compilation Enviroment
* Linux
* GCC-4.8 or above

### Compilation and Installation

#### AutoTools

###### How to Complie libphxpaxos.a.

Execute following shell commands in root directory of PhxPaxos
Expand All @@ -123,6 +132,19 @@ make
make install
```

#### CMake

Execute following shell commands in root directory of PhxPaxos.
```
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
make install
```

See CMakeLists.txt in project root directory for all building options.

# How to Wrap Your Own Code Around PhxPaxos.
### First choose a single node service.
We will show you this by a PhxEcho service in our `sample` directory, Echo is a common test functions while writing an RPC service. We will wrap this service's code around PhxPaxos to make Echo into a multi-node service.
Expand Down
27 changes: 26 additions & 1 deletion README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,24 @@
| src/ut | 单元测试 | 无 | gtest,gmock |

编译我们的Phxpaxo(libphxpaxos.a)类库,只需要protobuf和leveldb两个第三方库;而编译其他目录则需要glog和grpc这两个库。
在编译前,需要先准备好这些第三方库,放在我们的third_party目录,可以直接放置,也可以通过软链的形式,也可以git clone时加上--recursive参数获取third_party目录下所有的submodule。
在编译前,需要先准备好这些第三方库,放在我们的third_party目录,可以在`git clone`时加上`--recurse-submodules`参数获取third_party目录下所有的submodule。
如果已经clone,可以在phxpaxos根目录执行 `git submodule update --init --recursive`来获取third_party下所有依赖。

确认`third_party`下所有submodule(以及submodule的submodule)都已准备完成后,进入`third_party`下,执行`autoinstall.sh`脚本,编译安装依赖。该脚本会逐一编译所有的依赖,并将其安装到`third_party/local_install`目录下。

```Bash
cd third_party
./autoinstall.sh
```

### 编译环境
* Linux。
* GCC-4.8及以上版本。

### 编译安装方法

#### AutoTools

###### 编译libphxpaxos.a

在PhxPaxos根目录下
Expand All @@ -128,6 +139,20 @@ make
make install
```

#### CMake

在PhxPaxos根目录下
```Bash
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
make install
```

其他的编译选项,可参见项目根目录的 CMakeLists.txt 文件。


# 如何嵌入PhxPaxos到自己的代码
### 选择一个单机服务
我们选用sample目录里面的PhxEcho来说明PhxPaxos的使用方法。Echo是我们编写RPC服务的常见测试函数,
Expand Down
21 changes: 21 additions & 0 deletions cmake/FindGflags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
find_path(GFLAGS_INCLUDE_DIR
NAMES gflags/gflags.h
PATHS "${CMAKE_PREFIX_PATH}/include"
)
mark_as_advanced(GFLAGS_INCLUDE_DIR)

find_library(GFLAGS_LIBRARY
NAMES gflags
PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64"
)
mark_as_advanced(GFLAGS_LIBRARY)

add_library(gflags STATIC IMPORTED)
set_target_properties(gflags PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${GFLAGS_INCLUDE_DIR}
IMPORTED_LOCATION ${GFLAGS_LIBRARY}
)

include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(gflags DEFAULT_MSG
GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR)
21 changes: 21 additions & 0 deletions cmake/FindGlog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
find_path(GLOG_INCLUDE_DIR
NAMES glog/logging.h
PATHS "${CMAKE_PREFIX_PATH}/include"
)
mark_as_advanced(GLOG_INCLUDE_DIR)

find_library(GLOG_LIBRARY
NAMES glog
PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64"
)
mark_as_advanced(GLOG_LIBRARY)

add_library(glog STATIC IMPORTED)
set_target_properties(glog PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${GLOG_INCLUDE_DIR}
IMPORTED_LOCATION ${GLOG_LIBRARY}
)

include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(glog DEFAULT_MSG
GLOG_LIBRARY GLOG_INCLUDE_DIR)
21 changes: 21 additions & 0 deletions cmake/FindGmock.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
find_path(GMOCK_INCLUDE_DIR
NAMES gmock/gmock.h
PATHS "${CMAKE_PREFIX_PATH}/include"
)
mark_as_advanced(GMOCK_INCLUDE_DIR)

find_library(GMOCK_LIBRARY
NAMES gmock
PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64"
)
mark_as_advanced(GMOCK_LIBRARY)

add_library(gmock STATIC IMPORTED)
set_target_properties(gmock PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${GMOCK_INCLUDE_DIR}
IMPORTED_LOCATION ${GMOCK_LIBRARY}
)

include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(gmock DEFAULT_MSG
GMOCK_LIBRARY GMOCK_INCLUDE_DIR)
21 changes: 21 additions & 0 deletions cmake/FindGtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
find_path(GTEST_INCLUDE_DIR
NAMES gtest/gtest.h
PATHS "${CMAKE_PREFIX_PATH}/include"
)
mark_as_advanced(GTEST_INCLUDE_DIR)

find_library(GTEST_LIBRARY
NAMES gtest
PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64"
)
mark_as_advanced(GTEST_LIBRARY)

add_library(gtest STATIC IMPORTED)
set_target_properties(gtest PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR}
IMPORTED_LOCATION ${GTEST_LIBRARY}
)

include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(gtest DEFAULT_MSG
GTEST_LIBRARY GTEST_INCLUDE_DIR)
21 changes: 21 additions & 0 deletions cmake/FindLeveldb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
find_path(LEVELDB_INCLUDE_DIR
NAMES leveldb/db.h
PATHS "${CMAKE_PREFIX_PATH}/include"
)
mark_as_advanced(LEVELDB_INCLUDE_DIR)

find_library(LEVELDB_LIBRARY
NAMES leveldb
PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64"
)
mark_as_advanced(LEVELDB_LIBRARY)

add_library(leveldb STATIC IMPORTED)
set_target_properties(leveldb PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${LEVELDB_INCLUDE_DIR}
IMPORTED_LOCATION ${LEVELDB_LIBRARY}
)

include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(leveldb DEFAULT_MSG
LEVELDB_LIBRARY LEVELDB_INCLUDE_DIR)
Loading