-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8393690
Showing
288 changed files
with
28,892 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,29 @@ | ||
|
||
doc/*.vsdx | ||
doc/*.~vsdx | ||
|
||
working/*.un~ | ||
|
||
*.o | ||
bin/aurora* | ||
*.swp | ||
bin/compile_proto | ||
.DS_Store | ||
|
||
bin/ | ||
|
||
*.log.* | ||
|
||
work/aurora*.INFO | ||
work/aurora*.WARNING | ||
work/aurora*.ERROR | ||
work/aurora*.FATAL | ||
|
||
work/*/aurora.INFO | ||
work/*/aurora.WARNING | ||
work/*/aurora.ERROR | ||
work/*/aurora.FATAL | ||
|
||
work/*/raft.binlog.* | ||
x64 | ||
doc/~$grpc-issue.xlsx |
This file contains 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,37 @@ | ||
cmake_minimum_required(VERSION 3.3) | ||
project(Aurora) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
option(GLOG_INC_DIR,"Use include" ON) | ||
|
||
message("project src:" ${PROJECT_SOURCE_DIR}) | ||
|
||
file(GLOB_RECURSE ALL_SRC ${PROJECT_SOURCE_DIR}/src *.cc) | ||
|
||
foreach(ARG ${ALL_SRC}) | ||
message("one source:${ARG}") | ||
endforeach() | ||
|
||
list(FILTER ALL_SRC EXCLUDE REGEX .*trivial_lock_deque.cc) | ||
list(FILTER ALL_SRC EXCLUDE REGEX .*trivial_lock_hash.cc) | ||
list(FILTER ALL_SRC EXCLUDE REGEX .*trivial_lock_list.cc) | ||
list(FILTER ALL_SRC EXCLUDE REGEX .*trivial_lock_queue.cc) | ||
|
||
set(MAIN_SRC ${ALL_SRC}) | ||
set(TEST_SRC ${ALL_SRC}) | ||
list(FILTER MAIN_SRC EXCLUDE REGEX .*gtest_main.cc) | ||
list(FILTER TEST_SRC EXCLUDE REGEX .*[/\\]main.cc) | ||
|
||
message("main src found:" ${MAIN_SRC}) | ||
message("test src found:" ${TEST_SRC}) | ||
|
||
# add the executable | ||
add_executable(aurora ${ALL_SRC}) | ||
add_executable(aurora_test ${ALL_SRC}) | ||
|
||
|
||
target_include_directories(aurora PUBLIC "${PROJECT_SOURCE_DIR}/src") | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,169 @@ | ||
|
||
BUILD_TYPE=debug | ||
|
||
CXX = g++ | ||
CXXFLAGS = -std=c++17 -D_RAFT_UNIT_TEST_ | ||
|
||
ifeq ($(BUILD_TYPE),debug) | ||
CXXFLAGS += -g3 | ||
else | ||
ifneq ($(BUILD_TYPE),release) | ||
$(error input 'BUILD_TYPE' parameter can be either 'debug' or 'release') | ||
endif | ||
CXXFLAGS += -O3 | ||
endif | ||
|
||
SRCDIR = src | ||
BINDIR = bin | ||
OBJDIR = $(BINDIR)/$(BUILD_TYPE)/object | ||
|
||
THIRD_PARTY_DIR=./third_party | ||
|
||
INC = -I./src \ | ||
-I./src/protocol \ | ||
-I$(THIRD_PARTY_DIR)/glog/src \ | ||
-I$(THIRD_PARTY_DIR)/gflags/build-dir/include \ | ||
-I$(THIRD_PARTY_DIR)/boost_1_68_0 \ | ||
-I$(THIRD_PARTY_DIR)/googletest/googletest/include\ | ||
-I$(THIRD_PARTY_DIR)/grpc/include\ | ||
|
||
LIB = /usr/local/lib/libglog.a \ | ||
/usr/local/lib/libgflags.a \ | ||
/usr/local/lib/libgtest.a \ | ||
/usr/local/lib/libgflags_nothreads.a \ | ||
/usr/local/lib/libboost_filesystem.a \ | ||
/usr/local/lib/libboost_system.a \ | ||
/usr/local/lib/libboost_thread.a \ | ||
/usr/local/lib/libprotobuf.a \ | ||
/usr/local/lib/libgrpc++.a \ | ||
/usr/local/lib/libgrpc.a \ | ||
/usr/local/lib/libgrpc++_reflection.a \ | ||
/usr/local/lib/libtcmalloc.a \ | ||
-lz -ldl -lpthread \ | ||
|
||
UNAME_S := $(shell uname -s) | ||
ifeq ($(UNAME_S),Linux) | ||
LIB += -latomic | ||
endif | ||
|
||
PROTOS_PATH = ./src/protocol | ||
|
||
vpath %.proto $(PROTOS_PATH) | ||
|
||
PROTO_FLAG=$(BINDIR)/compile_proto | ||
MAIN_PROGRAM=$(BINDIR)/$(BUILD_TYPE)/aurora | ||
MAIN_TEST=$(BINDIR)/$(BUILD_TYPE)/aurora_test | ||
|
||
-include prepare $(PROTO_FLAG) | ||
|
||
.PHONY: all | ||
all: system-check $(MAIN_PROGRAM) $(MAIN_TEST) | ||
|
||
.PHONY: prepare | ||
prepare: | ||
mkdir -p $(OBJDIR) | ||
|
||
ALL_SRC_FILES=$(wildcard src/*.cc src/*/*.cc) | ||
TPL_CC_FILES=%src/tools/lock_free_deque.cc %src/tools/lock_free_hash.cc \ | ||
%src/tools/trivial_lock_double_list.cc %src/tools/lock_free_queue.cc \ | ||
%src/tools/lock_free_queue.cc %src/tools/lock_free_single_list.cc \ | ||
%src/common/request_base.cc %src/client/client_framework.cc \ | ||
%src/follower/follower_request.cc %src/leader/connection_pool.cc \ | ||
%src/leader/client_pool.cc %src/leader/leader_request.cc \ | ||
%src/service/ownership_delegator.cc %src/candidate/candidate_request.cc \ | ||
%src/tools/data_structure_base.cc %src/tools/lock_free_unordered_single_list.cc \ | ||
%src/tools/trivial_lock_list_base.cc %src/tools/lock_free_single_list.cc\ | ||
%src/tools/trivial_lock_single_list.cc %src/tools/lock_free_hash_specific.cc\ | ||
%src/common/react_group.cc \ | ||
|
||
COMPILE_SRC_FILES = $(filter-out $(TPL_CC_FILES), $(ALL_SRC_FILES) ) | ||
|
||
OBJ = $(patsubst %.cc, $(OBJDIR)/%.o, $(COMPILE_SRC_FILES)) | ||
|
||
EXE_MAIN_OBJ=%/main.o | ||
UTEST_MAIN_OBJ=%gtest_main.o | ||
EXE_OBJ = $(filter-out $(UTEST_MAIN_OBJ), $(OBJ) ) | ||
UTEST_OBJ = $(filter-out $(EXE_MAIN_OBJ), $(OBJ) ) | ||
|
||
.PHONY:test | ||
test:$(PROTO_FLAG) | ||
@echo "all:" $(ALL_SRC_FILES) | ||
@echo "src:" $(COMPILE_SRC_FILES) | ||
@echo "object:" $(OBJ) | ||
|
||
$(OBJDIR)/%.o: %.cc | ||
@mkdir -p $(OBJDIR)/$(dir $<) | ||
$(CXX) $(CXXFLAGS) $(INC) -c $< -o $@ | ||
|
||
$(MAIN_PROGRAM): $(EXE_OBJ) | ||
$(CXX) $(CXXFLAGS) $^ $(LIB) -o $@ | ||
|
||
$(MAIN_TEST): $(UTEST_OBJ) | ||
$(CXX) $(CXXFLAGS) $^ $(LIB) -o $@ | ||
|
||
PROTOC = protoc | ||
GRPC_CPP_PLUGIN = grpc_cpp_plugin | ||
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` | ||
|
||
$(PROTO_FLAG): $(PROTOS_PATH)/raft.proto | ||
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=$(PROTOS_PATH) $< | ||
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=$(PROTOS_PATH) --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< | ||
touch $@ | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(OBJDIR) $(PROTOS_PATH)/*.h $(PROTOS_PATH)/*.cc $(PROTO_FLAG) $(MAIN_PROGRAM) $(MAIN_TEST) | ||
|
||
|
||
# The following is to test your system and ensure a smoother experience. | ||
# They are by no means necessary to actually compile a grpc-enabled software. | ||
|
||
PROTOC_CMD = which $(PROTOC) | ||
PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3 | ||
PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN) | ||
HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false) | ||
ifeq ($(HAS_PROTOC),true) | ||
HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) | ||
endif | ||
HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false) | ||
|
||
SYSTEM_OK = false | ||
ifeq ($(HAS_VALID_PROTOC),true) | ||
ifeq ($(HAS_PLUGIN),true) | ||
SYSTEM_OK = true | ||
endif | ||
endif | ||
|
||
system-check: | ||
ifneq ($(HAS_VALID_PROTOC),true) | ||
@echo " DEPENDENCY ERROR" | ||
@echo | ||
@echo "You don't have protoc 3.0.0 installed in your path." | ||
@echo "Please install Google protocol buffers 3.0.0 and its compiler." | ||
@echo "You can find it here:" | ||
@echo | ||
@echo " https://github.com/google/protobuf/releases/tag/v3.0.0" | ||
@echo | ||
@echo "Here is what I get when trying to evaluate your version of protoc:" | ||
@echo | ||
-$(PROTOC) --version | ||
@echo | ||
@echo | ||
endif | ||
ifneq ($(HAS_PLUGIN),true) | ||
@echo " DEPENDENCY ERROR" | ||
@echo | ||
@echo "You don't have the grpc c++ protobuf plugin installed in your path." | ||
@echo "Please install grpc. You can find it here:" | ||
@echo | ||
@echo " https://github.com/grpc/grpc" | ||
@echo | ||
@echo "Here is what I get when trying to detect if you have the plugin:" | ||
@echo | ||
-which $(GRPC_CPP_PLUGIN) | ||
@echo | ||
@echo | ||
endif | ||
ifneq ($(SYSTEM_OK),true) | ||
@false | ||
endif |
This file contains 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,148 @@ | ||
|
||
![logo](doc/images/logo/transparent-black-v2.png) | ||
|
||
<!-- PROJECT SHIELDS --> | ||
![AUR license](https://img.shields.io/aur/license/aurora.svg) | ||
|
||
<!-- TABLE OF CONTENTS --> | ||
## Table of Contents | ||
|
||
* [About the Project](#about-the-project) | ||
* [Getting Started](#getting-started) | ||
* [Prerequisites](#prerequisites) | ||
* [Building](#building) | ||
* [Usage](#usage) | ||
* [Contributing](#contributing) | ||
* [License](#license) | ||
* [Contact](#contact) | ||
* [Donation](#donation) | ||
|
||
<!-- ABOUT THE PROJECT --> | ||
## About The Project | ||
|
||
**Aurora is a [Raft](https://raft.github.io) based K-V database**. The basics of the current architecture is : | ||
|
||
![sys_arch](doc/images/system_architecture.png) | ||
|
||
*Note : The name `Aurora` **has nothing to do with** neither [Apache Aurora](http://aurora.apache.org/) nor [Amazon aurora](https://aws.amazon.com/rds/aurora/).* | ||
|
||
It's inspired by the [raft protocol](https://raft.github.io) which often being known as a contrast of another widely known protocol : `paxos`. Aurora comes along with all of raft dominant features supported: | ||
* **Log Replication**: A two phase commit data replication solution. | ||
* **Leader Election** : A majority & term based failover solution. | ||
* **Membership Change**: A smart approach dealing with cluster topology changing. | ||
|
||
Besides the consensus protocol, it also comes with a local storage subsystem whose idea is inspired and being the same with [leveldb](https://github.com/google/leveldb) : to enhance blind writing operation throughput. | ||
|
||
Last but not least, it's implemented by using the modern cpp(11/14/17) which may contributes to the popularization of the new lanaguage standards. After all, newer is probably better. | ||
|
||
<!-- GETTING STARTED --> | ||
## Getting Started | ||
|
||
Project root directory explanation: | ||
* src : source code. | ||
* doc : documents. | ||
* bin : binaries & objects after successfully building. | ||
* working : running directory of aurora. | ||
* third_party : the third party dependencies. | ||
|
||
Aurora has some basic components you need to firstly building before running. | ||
|
||
### Prerequisites | ||
|
||
* [protobuf](https://github.com/protocolbuffers/protobuf). >=3.0.0. | ||
* [grpc](https://github.com/grpc/grpc). >=1.8.x. | ||
* [boost](https://www.boost.org/). >=1.64.0. | ||
* [glog](https://github.com/google/glog). >=0.3.3. | ||
* [gflags](https://github.com/gflags/gflags). >=2.2.0. | ||
* [gtest](https://github.com/google/googletest). >=1.7.0. | ||
* [gperftools](https://github.com/gperftools/gperftools). >=7.0. | ||
|
||
Create a `third_party` directory and build the above dependencies under that. | ||
|
||
*Note: How to build the dependencies is beyond the scope and you may need consulting the documents for each of them. Making sure the headers and libraries are correctly installed on your system. That maybe boring but can't get around.* | ||
|
||
After successfully built all the above dependencies, your working directory should looks something like this: | ||
``` | ||
|-- src | ||
|-- doc | ||
|-- bin | ||
|-- working | ||
|-- third_party | ||
|-- boost_1_68_0 | ||
|-- protobuf | ||
|-- grpc | ||
|-- glog | ||
|-- gflags | ||
|-- googletest | ||
``` | ||
|
||
### Building | ||
Now, you are ready to compile aurora itself. | ||
|
||
* unix & linux & osx: | ||
```console | ||
cd aurora && make -j4 | ||
``` | ||
|
||
> Note: some gcc versions(like gcc (GCC) 8.3.1) don't fully support std::atomic, thus you might need to install `libatomic` manually. | ||
* windows: | ||
see [building under windows](doc/windows.md) | ||
|
||
<!-- USAGE EXAMPLES --> | ||
## Usage | ||
|
||
First , take a look at the configure files: | ||
* `election.config` : inner usage for election. | ||
* `membership-change.config` : inner usage for membership change. | ||
* `topology.config` : setup a cluster: | ||
* `leader` :leader node. | ||
* `followers` :follower nodes. | ||
* `candidates` :follower nodes. | ||
* all nodes are with format : `xx.xx.xx.xx:port`,like `192.168.0.100`. | ||
|
||
*Only `topology.config` is intending to be controlled by users, the others are either managed by the system or for debugging purpose.* | ||
|
||
Second, after finish configuring `topology.config`, you can start a node by : | ||
* running command under *nix: | ||
|
||
```console | ||
cd aurora/working/ | ||
nohup ../bin/aurora > aurora.log 2>&1 & | ||
``` | ||
|
||
* runing command under windows: | ||
|
||
```console | ||
cd aurora\working\ | ||
..\aurora\working\aurora.exe | ||
``` | ||
|
||
|
||
|
||
<!-- CONTRIBUTING --> | ||
## Contributing | ||
It is strongly recommended to read the [developer guide](doc/developer_guide.md) for details. | ||
|
||
<!-- LICENSE --> | ||
## License | ||
Distributed under the **GPLv3** License. See the [license file](LICENSE) for more information. | ||
|
||
<!-- CONTACT --> | ||
## Contact | ||
Arthur - [email protected] | ||
|
||
|
||
## Donation | ||
This project consumed a lot time away from the author, and if you think it helps, don't hesitate to show your generosity :moneybag: :moneybag: :moneybag: | ||
|
||
* paypal: [paypal.me link](paypal.me/arthurCoo) | ||
* wechat: | ||
|
||
![wechat-pay](doc/images/pay_wechat.png) | ||
|
||
* alipay: | ||
|
||
![alipay](doc/images/pay_alipay.png) | ||
|
||
|
This file contains 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,3 @@ | ||
* | ||
*/ | ||
!.gitignore |
Oops, something went wrong.