diff --git a/.github/workflows/import_braft.yml b/.github/workflows/import_braft.yml index 1d890bd3e..91f6b24a8 100644 --- a/.github/workflows/import_braft.yml +++ b/.github/workflows/import_braft.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - name: Build - run: bash ci/build.sh + run: bash ./etc/script/ci/build.sh - name: Check Format working-directory: ${{ github.workspace }}/build @@ -27,12 +27,12 @@ jobs: - uses: actions/checkout@v4 - name: Build --verbose - env: + env: CPLUS_INCLUDE_PATH: /opt/homebrew/include run: | brew install autoconf brew install go - sh build.sh + bash ./etc/script/build.sh - name: Run Go E2E Tests working-directory: ${{ github.workspace }}/build-release @@ -50,7 +50,7 @@ jobs: - name: Build run: | - bash build.sh --verbose + bash ./etc/script/build.sh --verbos - name: Run Go E2E Tests working-directory: ${{ github.workspace }}/build-release diff --git a/.github/workflows/pikiwidb.yml b/.github/workflows/pikiwidb.yml index c9187b4fc..dcc4f84f2 100644 --- a/.github/workflows/pikiwidb.yml +++ b/.github/workflows/pikiwidb.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - name: Build - run: bash ci/build.sh + run: bash ./etc/script/ci/build.sh - name: Check Format working-directory: ${{ github.workspace }}/build @@ -30,7 +30,7 @@ jobs: run: | brew install autoconf brew install go - sh build.sh --verbose + bash ./etc/script/build.sh --verbose - name: GTest working-directory: ${{ github.workspace }}/build-release @@ -56,7 +56,7 @@ jobs: - name: Build run: | - bash build.sh --verbose + bash ./etc/script/build.sh --verbose - name: GTest working-directory: ${{ github.workspace }}/build-release @@ -71,4 +71,4 @@ jobs: cd ../tests go mod tidy go test -timeout 15m --ginkgo.v - sh print_log.sh \ No newline at end of file + sh print_log.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0401ae5c4..2863a35c3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,7 +35,7 @@ jobs: - name: Build run: | - bash build.sh + bash ./etc/script/build.sh - name: Calculate checksum and rename binary working-directory: ${{ github.workspace }}/bin diff --git a/.gitignore b/.gitignore index c0e2b905a..cc9a5c681 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,14 @@ *.obj *pb.cc *pb.h -build -cmake-build-debug -cmake-build-release +deps-debug/ +deps-release/ +cmake-build-debug/ +cmake-build-release/ +cmake-build-release-release/ +build/ +build-debug/ +build-release/ # Precompiled Headers *.gch diff --git a/README.md b/README.md index 0574fe07c..74f16d926 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A C++20 implementation of Redis Server, use RocksDB for persist storage.(not inc ## Requirements * C++20 -* Linux or OS X +* Linux or OS X or FreeBSD ## compile @@ -28,14 +28,14 @@ scl enable devtoolset-11 bash Execute this command to start compiling Pikiwidb: ```bash -./build.sh +sh ./etc/script/build.sh ``` Pikiwidb is compiled by default in release mode, which does not support debugging. If debugging is needed, compile in debug mode. ```bash -./clear.sh -./build.sh --debug +sh ./etc/script/build.sh --clear +sh ./etc/script/build.sh --debug ``` ## Support module for write your own extensions diff --git a/README_CN.md b/README_CN.md index 34ec2431f..c9cea497d 100644 --- a/README_CN.md +++ b/README_CN.md @@ -7,7 +7,7 @@ C++20 实现的增强版 Redis 服务器,使用 RocksDB 作为持久化存储引 ## 环境需求 * C++20、CMake -* Linux 或 MAC OS +* Linux 或 MAC OS 或 FreeBSD ## 编译 @@ -28,14 +28,14 @@ scl enable devtoolset-11 bash 执行以下命令开始编译 PikiwiDB: ```bash -./build.sh +sh ./etc/script/build.sh ``` PikiwiDB 默认以 release 模式编译,不支持调试。如果需要调试,请以 debug 模式编译。 ```bash -./clear.sh -./build.sh --debug +sh ./etc/script/build.sh --clear +sh ./etc/script/build.sh --debug ``` ## 与 Redis 完全兼容 diff --git a/build.sh b/build.sh deleted file mode 100755 index 644a5df64..000000000 --- a/build.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash - -#color code -C_RED="\033[31m" -C_GREEN="\033[32m" - -C_END="\033[0m" - -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} - -BUILD_TYPE=Release -VERBOSE=0 -CMAKE_FLAGS="" -MAKE_FLAGS="" -PREFIX="cmake-build" - -ARGS=`getopt -a -o h -l help,debug,verbose,prefix: -- "$@"` -function show_help() { - echo " - -h --help show help - --debug compile with debug - --verbose compile with verbose - --prefix compile output path - " - exit 0 -} - -eval set -- "${ARGS}" -while true -do - case "$1" in - -h|--help) - show_help - ;; - --debug) - BUILD_TYPE=debug - ;; - --verbose) - CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" - MAKE_FLAGS="${MAKE_FLAGS} VERBOSE=1" - ;; - --prefix) - PREFIX=$2 - shift - ;; - --) - shift - break - ;; - esac -shift -done - -if [ ! -f "/proc/cpuinfo" ];then - CPU_CORE=$(sysctl -n hw.ncpu) -else - CPU_CORE=$(cat /proc/cpuinfo| grep "processor"| wc -l) -fi -if [ ${CPU_CORE} -eq 0 ]; then - CPU_CORE=1 -fi - -echo "cpu core ${CPU_CORE}" - -echo "BUILD_TYPE:" $BUILD_TYPE -echo "CMAKE_FLAGS:" $CMAKE_FLAGS -echo "MAKE_FLAGS:" $MAKE_FLAGS - -if [ "${BUILD_TYPE}" == "Release" ]; then - PREFIX="${PREFIX}-release" -else - PREFIX="${PREFIX}-debug" -fi - -cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${CMAKE_FLAGS} -S . -B ${PREFIX} -cmake --build ${PREFIX} -- ${MAKE_FLAGS} -j ${CPU_CORE} - -if [ $? -eq 0 ]; then - echo -e "pikiwidb compile complete, output file ${C_GREEN} ${BUILD_DIR}/pikiwidb ${C_END}" -else - echo -e "${C_RED} pikiwidb compile fail ${C_END}" - exit 1 -fi diff --git a/clear.sh b/clear.sh deleted file mode 100755 index c936f446e..000000000 --- a/clear.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# ****************************************************** -# DESC : -# AUTHOR : Alex Stocks -# VERSION : 1.0 -# LICENCE : Apache License 2.0 -# EMAIL : alexstocks@foxmail.com -# MOD : 2023-07-31 17:03 -# FILE : clear.sh -# ****************************************************** - -rm -rf ./build-release -rm -rf ./build-debug -rm -rf ./bin diff --git a/cmake/rocksdb.cmake b/cmake/rocksdb.cmake index 05212875b..aa5571776 100644 --- a/cmake/rocksdb.cmake +++ b/cmake/rocksdb.cmake @@ -11,7 +11,10 @@ ExternalProject_Add( extern_rocksdb ${EXTERNAL_PROJECT_LOG_ARGS} GIT_REPOSITORY https://github.com/facebook/rocksdb.git - GIT_TAG v8.3.3 + GIT_TAG v9.4.0 + URL https://github.com/facebook/rocksdb/archive/refs/tags/v9.4.0.tar.gz + URL_HASH MD5=ce19cb3e2b6db927ef88cbf25c42097e + DOWNLOAD_NO_PROGRESS 1 DEPENDS gflags snappy diff --git a/pikiwidb.conf b/etc/conf/pikiwidb.conf similarity index 100% rename from pikiwidb.conf rename to etc/conf/pikiwidb.conf diff --git a/etc/script/build.sh b/etc/script/build.sh new file mode 100755 index 000000000..510575505 --- /dev/null +++ b/etc/script/build.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +#color code +C_RED="\033[31m" +C_GREEN="\033[32m" + +C_END="\033[0m" + +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} + +BUILD_TYPE=Release +VERBOSE=0 +CMAKE_FLAGS="" +MAKE_FLAGS="" +PREFIX="cmake-build" + +PWD=`pwd` +PROJECT_HOME="${PWD}/" +CONF="${PROJECT_HOME}/etc/conf/pikiwidb.conf" + +function build() { + if [ ! -f "/proc/cpuinfo" ];then + CPU_CORE=$(sysctl -n hw.ncpu) + else + CPU_CORE=$(cat /proc/cpuinfo| grep "processor"| wc -l) + fi + if [ ${CPU_CORE} -eq 0 ]; then + CPU_CORE=1 + fi + + echo "cpu core ${CPU_CORE}" + + echo "BUILD_TYPE:" $BUILD_TYPE + echo "CMAKE_FLAGS:" $CMAKE_FLAGS + echo "MAKE_FLAGS:" $MAKE_FLAGS + + if [ "${BUILD_TYPE}" == "Release" ]; then + PREFIX="${PREFIX}-release" + else + PREFIX="${PREFIX}-debug" + fi + + cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${CMAKE_FLAGS} -S . -B ${PREFIX} + cmake --build ${PREFIX} -- ${MAKE_FLAGS} -j ${CPU_CORE} + + if [ $? -eq 0 ]; then + # echo -e "pikiwidb compile complete, output file ${C_GREEN} ${PREFIX}/bin/pikiwidb ${C_END}" + echo -e "pikiwidb compile complete, output file ${C_GREEN} ./bin/pikiwidb ${C_END}" + else + echo -e "${C_RED} pikiwidb compile fail ${C_END}" + exit 1 + fi +} + +# ":?" makes sure the bash var is not empty. +function clear() { + rm -rf ${PROJECT_HOME:?}/deps-debug + rm -rf ${PROJECT_HOME:?}/deps-release + rm -rf ${PROJECT_HOME:?}/cmake-build-debug + rm -rf ${PROJECT_HOME:?}/cmake-build-release + rm -rf ${PROJECT_HOME:?}/cmake-build-release-release + rm -rf ${PROJECT_HOME:?}/build + rm -rf ${PROJECT_HOME:?}/build-release + rm -rf ${PROJECT_HOME:?}/build-debug + rm -rf ${PROJECT_HOME:?}/bin + exit 0 +} + +function show_help() { + echo " + sh $0 --debug compile with debug + sh $0 --clear clear compilation directory + sh $0 -h|--help show help + sh $0 --prefix compile output path + sh $0 --verbose compile with verbose + " + exit 0 +} + +# ARGS=`getopt -a -o h -l help,debug,verbose,prefix: -- "$@"` +# Convert the parsed arguments into an array +# eval set -- "$ARGS" + +while true; do + # echo "hello first arg $1" + case "$1" in + -c|--clear) + clear + shift ;; + + --debug) + BUILD_TYPE=debug + ;; + + -h|--help) + show_help + ;; + + --prefix) + if [[ -n $2 ]]; then + PREFIX=$2 + else + echo "you should provide a value for --prefix as output path" + exit 0 + fi + shift;; + + --verbose) + CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" + MAKE_FLAGS="${MAKE_FLAGS} VERBOSE=1" + ;; + + --) + shift + break;; + + *) + break;; + esac + shift +done + +build diff --git a/ci/build.sh b/etc/script/ci/build.sh similarity index 100% rename from ci/build.sh rename to etc/script/ci/build.sh diff --git a/pikiwidbtests.sh b/etc/script/pikiwidbtests.sh similarity index 95% rename from pikiwidbtests.sh rename to etc/script/pikiwidbtests.sh index d5b691935..e51305c65 100755 --- a/pikiwidbtests.sh +++ b/etc/script/pikiwidbtests.sh @@ -30,7 +30,7 @@ function setup_pikiwidb_bin { exit 1 fi cp $PIKIWIDB_BIN src/redis-server - cp ./pikiwidb.conf tests/assets/default.conf + cp ./etc/conf/pikiwidb.conf tests/assets/default.conf } diff --git a/save_load.sh b/etc/script/save_load.sh similarity index 60% rename from save_load.sh rename to etc/script/save_load.sh index 09f36c260..a45170dc9 100755 --- a/save_load.sh +++ b/etc/script/save_load.sh @@ -3,8 +3,13 @@ killall -9 pikiwidb mkdir leader follower1 -cd leader && ulimit -n 99999 && rm -fr * && ../bin/pikiwidb ../pikiwidb.conf --port 7777 & -cd follower1 && ulimit -n 99999 && rm -fr * && ../bin/pikiwidb ../pikiwidb.conf --port 8888 & + +PWD=`pwd` +PROJECT_HOME="${PWD}/../" +BIN="${PROJECT_HOME}/bin/pikiwidb" +CONF="${PROJECT_HOME}/etc/conf/pikiwidb.conf" +cd leader && ulimit -n 99999 && rm -fr * && ${BIN} ${CONF} --port 7777 & +cd follower1 && ulimit -n 99999 && rm -fr * && ${BIN} ${CONF} --port 8888 & sleep 5 redis-cli -p 7777 raft.cluster init diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8f4fc743..a2ae9ba5f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,8 @@ IF (CMAKE_BUILD_TYPE STREQUAL "Release") TARGET_COMPILE_DEFINITIONS(pikiwidb PRIVATE KPIKIWIDB_BUILD_DATE="${BUILD_TIMESTAMP}" KPIKIWIDB_GIT_COMMIT_ID="${GIT_COMMIT_ID}") ENDIF () -SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +# SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin/) +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/) TARGET_INCLUDE_DIRECTORIES(pikiwidb PRIVATE ${PROJECT_SOURCE_DIR}/src diff --git a/src/pikiwidb.cc b/src/pikiwidb.cc index a5ba33804..1b26ca1c0 100644 --- a/src/pikiwidb.cc +++ b/src/pikiwidb.cc @@ -225,7 +225,7 @@ static int InitLimit() { limit.rlim_cur = maxfiles; limit.rlim_max = maxfiles; if (setrlimit(RLIMIT_NOFILE, &limit) != -1) { - WARN("your 'limit -n ' of {} is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to ", + WARN("your 'limit -n' of {} is not enough for PikiwiDB to start. PikiwiDB has successfully reconfig it to {}", old_limit, limit.rlim_cur); } else { ERROR( @@ -235,6 +235,7 @@ static int InitLimit() { return -1; } } + return 0; } diff --git a/tests/README.md b/tests/README.md index 96abac0bf..7f3b97ec2 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,4 +1,4 @@ ### PikiwiDB test -* 在 PikiwiDB 目录下执行 `./pikatests.sh geo` 测试PikiwiDB GEO命令 -* 如果是`unit/type`接口, 例如 SET, 执行 `./pikiwidbtests.sh type/set` 测试PikiwiDB SET命令 \ No newline at end of file +* 在 PikiwiDB 目录下执行 `sh ./etc/script/pikatests.sh geo` 测试PikiwiDB GEO命令 +* 如果是`unit/type`接口, 例如 SET, 执行 `./etc/script/pikiwidbtests.sh type/set` 测试PikiwiDB SET命令 \ No newline at end of file diff --git a/tests/util/pikiwidb.go b/tests/util/pikiwidb.go index 6c84178a3..962563dc9 100644 --- a/tests/util/pikiwidb.go +++ b/tests/util/pikiwidb.go @@ -50,11 +50,11 @@ func GetConfPath(copy bool, t int64) string { nPath string ) if len(rPath) != 0 && copy { - nPath = path.Join(rPath, fmt.Sprintf("pikiwidb_%d.conf", t)) + nPath = path.Join(rPath, fmt.Sprintf("etc/conf/pikiwidb_%d.conf", t)) return nPath } if len(rPath) != 0 { - cPath = path.Join(rPath, "pikiwidb.conf") + cPath = path.Join(rPath, "etc/conf/pikiwidb.conf") return cPath } return rPath