forked from OpenAtomFoundation/pikiwidb-raft
-
Notifications
You must be signed in to change notification settings - Fork 0
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 7c9b671
Showing
119 changed files
with
21,583 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,112 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 3.14) | ||
PROJECT(PikiwiDB) | ||
|
||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -g -D'GIT_COMMIT_ID=\"${GIT_COMMIT_ID}\"'") | ||
|
||
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: | ||
IF (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") | ||
CMAKE_POLICY(SET CMP0135 NEW) | ||
ENDIF () | ||
|
||
SET(CMAKE_CXX_STANDARD 20) | ||
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
ENABLE_TESTING() | ||
|
||
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
# using Clang | ||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0") | ||
MESSAGE(FATAL_ERROR "Clang version must be greater than 10.0") | ||
ENDIF () | ||
ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
# using GCC | ||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0") | ||
MESSAGE(FATAL_ERROR "GCC G++ version must be greater than 10.0") | ||
ENDIF () | ||
ENDIF () | ||
|
||
|
||
############# You should enable sanitizer if you are developing pika ############# | ||
# Uncomment the following two lines to enable AddressSanitizer to detect memory leaks and other memory-related bugs. | ||
# SET(CMAKE_BUILD_TYPE "Debug") | ||
# SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -O0 -fno-omit-frame-pointer -fno-optimize-sibling-calls") | ||
|
||
# [Notice] AddressSanitizer and ThreadSanitizer can not be enabled at the same time. | ||
|
||
# Uncomment the following two lines to enable ThreadSanitizer to detect data race and other thread-related issue. | ||
# SET(CMAKE_BUILD_TYPE "Debug") | ||
# SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread -O0 -fno-omit-frame-pointer -fno-optimize-sibling-calls") | ||
|
||
EXECUTE_PROCESS(COMMAND uname -p OUTPUT_VARIABLE HOST_ARCH) | ||
STRING(TOLOWER ${HOST_ARCH} HOST_ARCH) | ||
|
||
IF (NOT CMAKE_BUILD_TYPE) | ||
SET(CMAKE_BUILD_TYPE RELEASE) | ||
ENDIF () | ||
|
||
# NOTE !!! CMAKE_BUILD_TYPE is case-sensitive | ||
STRING(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE) | ||
|
||
IF (${BUILD_TYPE} STREQUAL DEBUG) | ||
SET(LIB_BUILD_TYPE DEBUG) | ||
ELSEIF (${BUILD_TYPE} STREQUAL MINSIZEREL) | ||
SET(LIB_BUILD_TYPE MINSIZEREL) | ||
ELSEIF (${BUILD_TYPE} STREQUAL RELWITHDEBINFO) | ||
SET(LIB_BUILD_TYPE RELWITHDEBINFO) | ||
ELSE () | ||
SET(LIB_BUILD_TYPE RELEASE) | ||
SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") | ||
ENDIF () | ||
|
||
IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") | ||
SET(CMAKE_CXX_FLAGS "-pthread") | ||
ADD_DEFINITIONS(-DOS_MACOSX) | ||
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux") | ||
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
SET(CMAKE_EXE_LINKER_FLAGS "-stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi ${CMAKE_EXE_LINKER_FLAGS}") | ||
SET(CMAKE_CXX_FLAGS "-stdlib=libc++ -pthread ${CMAKE_CXX_FLAGS}") | ||
ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") | ||
SET(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl") | ||
ENDIF () | ||
ADD_DEFINITIONS(-DOS_LINUX) | ||
ELSE () | ||
MESSAGE(FATAL_ERROR "only support linux or macOS") | ||
ENDIF () | ||
|
||
IF (HOST_ARCH MATCHES "x86_64" OR HOST_ARCH MATCHES "i386") | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse4.2") | ||
ELSEIF (HOST_ARCH MATCHES "arm") | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc+crypto -moutline-atomics") | ||
ENDIF () | ||
|
||
SET(EP_BASE_SUFFIX "buildtrees") | ||
SET_PROPERTY(DIRECTORY PROPERTY EP_BASE ${CMAKE_CURRENT_SOURCE_DIR}/${EP_BASE_SUFFIX}) | ||
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/") | ||
SET(STAGED_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/deps) | ||
SET(CMAKE_UTILS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/utils) | ||
SET(INSTALL_INCLUDEDIR ${STAGED_INSTALL_PREFIX}/include) | ||
SET(INSTALL_LIBDIR ${STAGED_INSTALL_PREFIX}/lib) | ||
SET(INSTALL_LIBDIR_64 ${STAGED_INSTALL_PREFIX}/lib64) | ||
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${STAGED_INSTALL_PREFIX}) | ||
|
||
MESSAGE(STATUS "${PROJECT_NAME} staged install: ${STAGED_INSTALL_PREFIX}") | ||
MESSAGE(STATUS "Current platform: ${OS_VERSION} ") | ||
CMAKE_HOST_SYSTEM_INFORMATION(RESULT CPU_CORE QUERY NUMBER_OF_LOGICAL_CORES) | ||
MESSAGE(STATUS "CPU core ${CPU_CORE}") | ||
|
||
|
||
INCLUDE(FetchContent) | ||
#include(cmake/CmakeLists.txt) | ||
|
||
include(cmake/findTools.cmake) | ||
include(cmake/leveldb.cmake) | ||
include(cmake/libevent.cmake) | ||
include(cmake/llhttp.cmake) | ||
include(cmake/spdlog.cmake) | ||
include(cmake/fmt.cmake) | ||
|
||
|
||
ADD_SUBDIRECTORY(src/std) | ||
ADD_SUBDIRECTORY(src/net) | ||
ADD_SUBDIRECTORY(src) | ||
|
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,13 @@ | ||
Copyright (c) 2015-2023, Qihoo360 | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,79 @@ | ||
# PikiwiDB | ||
|
||
[Click me switch to English](README.en.md) | ||
|
||
C++11实现的增强版Redis服务器,使用Leveldb作为持久化存储引擎。(集群支持尚正在计划中) | ||
|
||
## 环境需求 | ||
* C++11、CMake | ||
* Linux 或 MAC OS | ||
|
||
## 与Redis完全兼容 | ||
你可以用redis的各种工具来测试PikiwiDB,比如官方的redis-cli, redis-benchmark。 | ||
|
||
PikiwiDB可以和redis之间进行复制,可以读取redis的rdb文件或aof文件。当然,PikiwiDB生成的aof或rdb文件也可以被redis读取。 | ||
|
||
你还可以用redis-sentinel来实现PikiwiDB的高可用! | ||
|
||
总之,PikiwiDB与Redis完全兼容。 | ||
|
||
## 高性能 | ||
- PikiwiDB性能大约比Redis3.2高出20%(使用redis-benchmark测试pipeline请求,比如设置-P=50或更高) | ||
- PikiwiDB的高性能有一部分得益于独立的网络线程处理IO,因此和redis比占了便宜。但PikiwiDB逻辑仍然是单线程的。 | ||
- 另一部分得益于C++ STL的高效率(CLANG的表现比GCC更好)。 | ||
- 在测试前,你要确保std::list的size()是O(1)复杂度,这才遵循C++11的标准。否则list相关命令不可测。 | ||
|
||
运行下面这个命令,试试和redis比一比~ | ||
```bash | ||
./redis-benchmark -q -n 1000000 -P 50 -c 50 | ||
``` | ||
|
||
## 编写扩展模块 | ||
PikiwiDB支持动态库模块,可以在运行时添加新命令。 | ||
我添加了三个命令(ldel, skeys, hgets)作为演示。 | ||
|
||
## 支持冷数据淘汰 | ||
是的,在内存受限的情况下,你可以让PikiwiDB根据简单的LRU算法淘汰一些key以释放内存。 | ||
|
||
## 主从复制,事务,RDB/AOF持久化,慢日志,发布订阅 | ||
这些特性PikiwiDB都有:-) | ||
|
||
## 持久化:内存不再是上限 | ||
Leveldb可以配置为PikiwiDB的持久化存储引擎,可以存储更多的数据。 | ||
|
||
|
||
## 命令列表 | ||
#### 展示PikiwiDB支持的所有命令 | ||
- cmdlist | ||
|
||
#### key commands | ||
- type exists del expire pexpire expireat pexpireat ttl pttl persist move keys randomkey rename renamenx scan sort | ||
|
||
#### server commands | ||
- select dbsize bgsave save lastsave flushdb flushall client debug shutdown bgrewriteaof ping echo info monitor auth | ||
|
||
#### string commands | ||
- set get getrange setrange getset append bitcount bitop getbit setbit incr incrby incrbyfloat decr decrby mget mset msetnx setnx setex psetex strlen | ||
|
||
#### list commands | ||
- lpush rpush lpushx rpushx lpop rpop lindex llen lset ltrim lrange linsert lrem rpoplpush blpop brpop brpoplpush | ||
|
||
#### hash commands | ||
- hget hmget hgetall hset hsetnx hmset hlen hexists hkeys hvals hdel hincrby hincrbyfloat hscan hstrlen | ||
|
||
#### set commands | ||
- sadd scard srem sismember smembers sdiff sdiffstore sinter sinterstore sunion sunionstore smove spop srandmember sscan | ||
|
||
#### sorted set commands | ||
- zadd zcard zrank zrevrank zrem zincrby zscore zrange zrevrange zrangebyscore zrevrangebyscore zremrangebyrank zremrangebyscore | ||
|
||
#### pubsub commands | ||
- subscribe unsubscribe publish psubscribe punsubscribe pubsub | ||
|
||
#### multi commands | ||
- watch unwatch multi exec discard | ||
|
||
#### replication commands | ||
- sync slaveof | ||
|
||
|
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,18 @@ | ||
#!/bin/bash | ||
|
||
BUILD_TIME=$(git log -1 --format=%ai) | ||
BUILD_TIME=${BUILD_TIME: 0: 10} | ||
|
||
COMMIT_ID=$(git rev-parse HEAD) | ||
SHORT_COMMIT_ID=${COMMIT_ID: 0: 8} | ||
|
||
if [ -z "$SHORT_COMMIT_ID" ]; then | ||
echo "no git commit id" | ||
SHORT_COMMIT_ID="pikiwidb" | ||
fi | ||
|
||
echo "BUILD_TIME:" $BUILD_TIME | ||
echo "COMMIT_ID:" $SHORT_COMMIT_ID | ||
|
||
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build | ||
cmake --build build -- -j 32 |
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,18 @@ | ||
#!/usr/bin/env bash | ||
# ****************************************************** | ||
# DESC : | ||
# AUTHOR : Alex Stocks | ||
# VERSION : 1.0 | ||
# LICENCE : Apache License 2.0 | ||
# EMAIL : [email protected] | ||
# MOD : 2023-07-31 17:03 | ||
# FILE : clear.sh | ||
# ****************************************************** | ||
|
||
rm -rf ./cmake-build-debug | ||
rm -rf ./deps | ||
rm -rf ./buildtrees | ||
rm -rf ./build | ||
rm -rf ./bin | ||
rm -rf ./dbsync | ||
|
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,41 @@ | ||
FIND_PROGRAM(AUTOCONF autoconf PATHS /usr/bin /usr/local/bin) | ||
|
||
IF(${AUTOCONF} MATCHES AUTOCONF-NOTFOUND) | ||
MESSAGE(FATAL_ERROR "not find autoconf on localhost") | ||
ENDIF() | ||
|
||
#set(CLANG_SEARCH_PATH "/usr/local/bin" "/usr/bin" "/usr/local/opt/llvm/bin" | ||
# "/usr/local/opt/llvm@12/bin") | ||
FIND_PROGRAM(CLANG_TIDY_BIN | ||
NAMES clang-tidy clang-tidy-12 | ||
HINTS ${CLANG_SEARCH_PATH}) | ||
IF("${CLANG_TIDY_BIN}" STREQUAL "CLANG_TIDY_BIN-NOTFOUND") | ||
MESSAGE(WARNING "couldn't find clang-tidy.") | ||
ELSE() | ||
MESSAGE(STATUS "found clang-tidy at ${CLANG_TIDY_BIN}") | ||
ENDIF() | ||
|
||
FIND_PROGRAM(CLANG_APPLY_REPLACEMENTS_BIN | ||
NAMES clang-apply-replacements clang-apply-replacements-12 | ||
HINTS ${CLANG_SEARCH_PATH}) | ||
|
||
IF("${CLANG_APPLY_REPLACEMENTS_BIN}" STREQUAL "CLANG_APPLY_REPLACEMENTS_BIN-NOTFOUND") | ||
MESSAGE(WARNING "couldn't find clang-apply-replacements.") | ||
ELSE() | ||
MESSAGE(STATUS "found clang-apply-replacements at ${CLANG_APPLY_REPLACEMENTS_BIN}") | ||
ENDIF() | ||
|
||
OPTION(WITH_COMMAND_DOCS "build with command docs support" OFF) | ||
IF(WITH_COMMAND_DOCS) | ||
ADD_DEFINITIONS(-DWITH_COMMAND_DOCS) | ||
ENDIF() | ||
|
||
IF(${CMAKE_BUILD_TYPE} MATCHES "RELEASE") | ||
MESSAGE(STATUS "make RELEASE version") | ||
ADD_DEFINITIONS(-DBUILD_RELEASE) | ||
SET(BuildType "Release") | ||
ELSE() | ||
MESSAGE(STATUS "make DEBUG version") | ||
ADD_DEFINITIONS(-DBUILD_DEBUG) | ||
SET(BuildType "Debug") | ||
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,8 @@ | ||
# fmt | ||
FETCHCONTENT_DECLARE( | ||
fmt | ||
GIT_REPOSITORY https://github.com/fmtlib/fmt.git | ||
GIT_TAG 10.1.0 | ||
) | ||
FETCHCONTENT_MAKEAVAILABLE(fmt) | ||
|
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,9 @@ | ||
FETCHCONTENT_DECLARE( | ||
leveldb | ||
GIT_REPOSITORY https://github.com/google/leveldb.git | ||
GIT_TAG main | ||
) | ||
SET(LEVELDB_BUILD_TESTS OFF CACHE BOOL "" FORCE) | ||
SET(LEVELDB_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE) | ||
SET(LEVELDB_INSTALL OFF CACHE BOOL "" FORCE) | ||
FETCHCONTENT_MAKEAVAILABLE(leveldb) |
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,16 @@ | ||
|
||
# libevent | ||
FETCHCONTENT_DECLARE( | ||
libevent | ||
GIT_REPOSITORY https://github.com/libevent/libevent.git | ||
GIT_TAG release-2.1.12-stable | ||
) | ||
|
||
SET(EVENT__DISABLE_THREAD_SUPPORT ON CACHE BOOL "" FORCE) | ||
SET(EVENT__DISABLE_OPENSSL ON CACHE BOOL "" FORCE) | ||
SET(EVENT__DISABLE_BENCHMz`ARK ON CACHE BOOL "" FORCE) | ||
SET(EVENT__DISABLE_TESTS ON CACHE BOOL "" FORCE) | ||
SET(EVENT__DISABLE_REGRESS ON CACHE BOOL "" FORCE) | ||
SET(EVENT__DISABLE_SAMPLES ON CACHE BOOL "" FORCE) | ||
SET(EVENT__LIBRARY_TYPE STATIC CACHE STRING "" FORCE) | ||
FETCHCONTENT_MAKEAVAILABLE(libevent) |
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,19 @@ | ||
# nodejs/llhttp | ||
FETCHCONTENT_DECLARE( | ||
llhttp | ||
URL https://github.com/nodejs/llhttp/archive/refs/tags/release/v6.0.5.tar.gz | ||
URL_HASH MD5=7ec6829c56642cce27e3d8e06504ddca | ||
DOWNLOAD_NO_PROGRESS 1 | ||
UPDATE_COMMAND "" | ||
LOG_CONFIGURE 1 | ||
LOG_BUILD 1 | ||
LOG_INSTALL 1 | ||
BUILD_ALWAYS 1 | ||
CMAKE_ARGS | ||
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX} | ||
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} | ||
-DBUILD_STATIC_LIBS=ON | ||
-DBUILD_SHARED_LIBS=OFF | ||
BUILD_COMMAND make -j${CPU_CORE} | ||
) | ||
FETCHCONTENT_MAKEAVAILABLE(llhttp) |
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,7 @@ | ||
# spdlog | ||
FETCHCONTENT_DECLARE( | ||
spdlog | ||
GIT_REPOSITORY https://github.com/gabime/spdlog.git | ||
GIT_TAG v1.12.0 | ||
) | ||
FETCHCONTENT_MAKEAVAILABLE(spdlog) |
Oops, something went wrong.