Skip to content

Commit

Permalink
style: some keywords begins with 'k' (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks authored Jan 13, 2025
2 parents 81bef3a + d14f52f commit c9ceb4a
Show file tree
Hide file tree
Showing 134 changed files with 1,084 additions and 927 deletions.
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Checks: '
# - { key: readability-identifier-naming.VariableCase, value: lower_case }

WarningsAsErrors: '*'
# HeaderFilterRegex: '(|/src|/src/net|/src/pstd|/src/storage)/include'
# HeaderFilterRegex: '/src/(net|storage|pstd)/include'
# HeaderFilterRegex: '(|/src|/src/net|/src/std|/src/storage)/include'
# HeaderFilterRegex: '/src/(net|storage|std)/include'

#### Disabled checks and why: #####
#
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/pikiwidb.yml → .github/workflows/kiwidb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "unstable" ]
pull_request:
branches: [ "unstable" ]
branches: [ "*" ]

env:
BUILD_DIR: cmake-build-release
Expand All @@ -19,6 +19,20 @@ jobs:
- name: Build
run: bash ./etc/script/ci/build.sh

- name: Add LLVM apt repository
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt update
- name: Install clang-format-18
run: |
sudo apt install -y clang-format-18
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 200
- name: Verify clang-format version
run: clang-format --version

- name: Check Format
working-directory: ${{ github.workspace }}/build
run: make check-format
Expand Down Expand Up @@ -94,7 +108,7 @@ jobs:
- uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get install -y ccache
run: sudo apt install -y ccache

- name: Configure ccache
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ download/
CMakeFiles/
CMakeCache.txt

# clang-format
temp.txt

# Precompiled Headers
*.gch
*.pch
Expand Down
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ ENDIF()
SET(LIB ${LIB} CACHE INTERNAL "libs which should be linked for executable target")

INCLUDE(ExternalProject)
INCLUDE(cmake/precommit.cmake)
INCLUDE(cmake/findTools.cmake)
INCLUDE(cmake/openssl.cmake)
INCLUDE(cmake/gflags.cmake)
Expand All @@ -204,9 +205,9 @@ FILE(MAKE_DIRECTORY "${PROTO_OUTPUT_DIR}")

#INCLUDE(cmake/protogen.cmake)

ADD_SUBDIRECTORY(src/pstd)
ADD_SUBDIRECTORY(src/std)
ADD_SUBDIRECTORY(src/net)
ADD_SUBDIRECTORY(src/praft)
ADD_SUBDIRECTORY(src/raft)
ADD_SUBDIRECTORY(src/storage)
ADD_SUBDIRECTORY(src/resp)

Expand All @@ -222,6 +223,15 @@ FOREACH(IGNORE_FILE ${CLANG_FORMAT_IGNORE_FILES})
FILE(APPEND ${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt "${IGNORE_FILE}\n")
ENDFOREACH()

# install git hooks when configure
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E make_directory ${GIT_HOOKS_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${HOOKS_SOURCE_DIR}/precommit.sh
${GIT_HOOKS_DIR}/pre-commit
COMMAND ${CMAKE_COMMAND} -E chmod 755 ${GIT_HOOKS_DIR}/pre-commit
)

STRING(CONCAT FORMAT_DIRS "${PROJECT_SOURCE_DIR}/src,")
ADD_CUSTOM_TARGET(format
COMMAND ${BUILD_SUPPORT_DIR}/run_clang_format.py
Expand Down
19 changes: 19 additions & 0 deletions cmake/precommit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2025-present, Arana/Kiwi Community. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.


# define hooks source and target path
SET(HOOKS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/etc/script")
set(GIT_HOOKS_DIR "${CMAKE_SOURCE_DIR}/.git/hooks")

# # ensure pre-commit hook is installed
# ADD_CUSTOM_TARGET(install_git_hooks
# COMMAND ${CMAKE_COMMAND} -E make_directory ${GIT_HOOKS_DIR}
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# ${HOOKS_SOURCE_DIR}/precommit.sh
# ${GIT_HOOKS_DIR}/pre-commit
# COMMAND ${CMAKE_COMMAND} -E chmod 755 ${GIT_HOOKS_DIR}/pre-commit
# COMMENT "Installing git hooks..."
# )
2 changes: 2 additions & 0 deletions etc/script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ while true; do
--kiwi)
MAKE_FLAGS="${MAKE_FLAGS} kiwi"
;;

-h|--help)
show_help
;;
Expand Down Expand Up @@ -133,3 +134,4 @@ while true; do
done

build

61 changes: 61 additions & 0 deletions etc/script/check_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Check if clang-format is installed
if ! command -v clang-format &> /dev/null; then
echo "Error: clang-format is not installed"
echo "Please install clang-format first"
exit 1
fi

# Set color output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Counters
error_count=0
checked_count=0

# Check file
check_file() {
local file=$1
# Create a temporary file with formatted content
clang-format $file > temp.txt

# Compare the original file with the formatted file
if ! diff -u "$file" temp.txt > /dev/null; then
echo -e "${RED}Needs formatting: $file${NC}"
# Show specific differences
diff -u "$file" temp.txt | grep -E "^[\+\-]" | head -n 10
echo "..."
((error_count++))
else
echo -e "${GREEN}Correctly formatted: $file${NC}"
fi
((checked_count++))

# Clean up temporary file
rm temp.txt
}

# Main function
main() {
echo "Starting code format check..."

# Find all C/C++ source files
while IFS= read -r -d '' file; do
check_file "$file"
done < <(find ./src -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" -o -name "*.cc" \) -print0)

# Output summary
echo "----------------------------------------"
echo "Check completed!"
echo "Total files checked: $checked_count"
echo "Files needing formatting: $error_count"

# Return non-zero if there are errors
[ "$error_count" -gt 0 ] && exit 1 || exit 0
}

# Run the main function
main
31 changes: 31 additions & 0 deletions etc/script/precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Path to the check_format.sh script
SCRIPT_PATH="etc/script/check_format.sh"

# Check if the script exists
if [ ! -f "$SCRIPT_PATH" ]; then
echo "Error: $SCRIPT_PATH not found!"
exit 1
fi

# Make sure the script is executable
chmod +x "$SCRIPT_PATH"

# Run the script on all staged files
#STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(cpp|cc|h|hpp|c)$')

# if [ -n "$STAGED_FILES" ]; then
# for file in $STAGED_FILES; do
# "$SCRIPT_PATH" "$file"
# if [ $? -ne 0 ]; then
# echo "Commit aborted due to formatting issues."
# exit 1
# fi
# done
# fi

sh $SCRIPT_PATH

exit 0 # Path to the check_format.sh script

24 changes: 14 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

AUX_SOURCE_DIRECTORY(. kiwi_SRC)
AUX_SOURCE_DIRECTORY(. KIWI_SRC)

ADD_EXECUTABLE(kiwi ${kiwi_SRC})
ADD_EXECUTABLE(kiwi ${KIWI_SRC})

IF (CMAKE_BUILD_TYPE STREQUAL "Release")
# get current date and time and git commit id
Expand All @@ -16,8 +16,8 @@ IF (CMAKE_BUILD_TYPE STREQUAL "Release")
MESSAGE(STATUS "Git commit id: ${GIT_COMMIT_ID}")

TARGET_COMPILE_DEFINITIONS(kiwi
PRIVATE Kkiwi_GIT_COMMIT_ID="${GIT_COMMIT_HASH}"
PRIVATE Kkiwi_BUILD_DATE="${BUILD_DATE}"
PRIVATE Kkiwi_GIT_COMMIT_ID="${GIT_COMMIT_ID}"
PRIVATE Kkiwi_BUILD_DATE="${BUILD_TIMESTAMP}"
)
ENDIF ()

Expand All @@ -26,7 +26,7 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/)

TARGET_INCLUDE_DIRECTORIES(kiwi
PRIVATE ${PROJECT_SOURCE_DIR}/src
PRIVATE ${PROJECT_SOURCE_DIR}/src/pstd
PRIVATE ${PROJECT_SOURCE_DIR}/src/std
PRIVATE ${PROJECT_SOURCE_DIR}/src/net
PRIVATE ${PROJECT_SOURCE_DIR}/src/storage/include
PRIVATE ${rocksdb_SOURCE_DIR}/
Expand All @@ -45,11 +45,15 @@ ADD_DEPENDENCIES(kiwi
zlib
rocksdb
protobuf
pstd
kstd
braft
brpc
storage
resp
leveldb
raft
raft_pb
binlog_pb
)

TARGET_LINK_LIBRARIES(kiwi
Expand All @@ -63,7 +67,7 @@ TARGET_LINK_LIBRARIES(kiwi
storage
gflags
spdlog
pstd
kstd
braft
brpc
ssl
Expand All @@ -72,11 +76,11 @@ TARGET_LINK_LIBRARIES(kiwi
protobuf
leveldb
z
praft
praft_pb
raft
raft_pb
binlog_pb
resp
"${LIB}"
)

SET_TARGET_PROPERTIES(kiwi PROPERTIES LINKER_LANGUAGE CXX)
SET_TARGET_PROPERTIES(kiwi PROPERTIES LINKER_LANGUAGE CXX)
16 changes: 8 additions & 8 deletions src/base_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

#include "fmt/core.h"

#include "praft/praft.h"
#include "raft/raft.h"

#include "common.h"
#include "config.h"
#include "kiwi.h"
#include "log.h"
#include "praft/praft.h"
#include "raft/raft.h"

namespace kiwi {

Expand All @@ -43,12 +43,12 @@ void BaseCmd::Execute(PClient* client) {

// read consistency (lease read) / write redirection
if (g_config.use_raft && (HasFlag(kCmdFlagsReadonly) || HasFlag(kCmdFlagsWrite))) {
if (!PRAFT.IsInitialized()) {
return client->SetRes(CmdRes::kErrOther, "PRAFT is not initialized");
if (!RAFT_INST.IsInitialized()) {
return client->SetRes(CmdRes::kErrOther, "RAFT_INST is not initialized");
}

if (!PRAFT.IsLeader()) {
auto leader_addr = PRAFT.GetLeaderAddress();
if (!RAFT_INST.IsLeader()) {
auto leader_addr = RAFT_INST.GetLeaderAddress();
if (leader_addr.empty()) {
return client->SetRes(CmdRes::kErrOther, std::string("-CLUSTERDOWN No Raft leader"));
}
Expand All @@ -59,11 +59,11 @@ void BaseCmd::Execute(PClient* client) {

auto dbIndex = client->GetCurrentDB();
if (!HasFlag(kCmdFlagsExclusive)) {
PSTORE.GetBackend(dbIndex)->LockShared();
STORE_INST.GetBackend(dbIndex)->LockShared();
}
DEFER {
if (!HasFlag(kCmdFlagsExclusive)) {
PSTORE.GetBackend(dbIndex)->UnLockShared();
STORE_INST.GetBackend(dbIndex)->UnLockShared();
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#include "config.h"
#include "env.h"
#include "kiwi.h"
#include "praft/praft.h"
#include "pstd/log.h"
#include "pstd/pstd_string.h"
#include "raft/raft.h"
#include "slow_log.h"
#include "std/log.h"
#include "std/std_string.h"

namespace kiwi {

Expand Down Expand Up @@ -119,7 +119,7 @@ int PClient::HandlePacket(std::string&& data) {
if (isPeerMaster()) {
if (isClusterCmdTarget()) {
// Proccees the packet at one turn.
int len = PRAFT.ProcessClusterCmdResponse(this, start, bytes); // @todo
int len = RAFT_INST.ProcessClusterCmdResponse(this, start, bytes); // @todo
if (len > 0) {
return len;
}
Expand Down Expand Up @@ -244,7 +244,7 @@ void PClient::OnConnect() {
}

if (isClusterCmdTarget()) {
PRAFT.SendNodeRequest(this);
RAFT_INST.SendNodeRequest(this);
}
} else {
if (g_config.password.empty()) {
Expand Down Expand Up @@ -304,7 +304,7 @@ bool PClient::isPeerMaster() const {
}

bool PClient::isClusterCmdTarget() const {
return PRAFT.GetClusterCmdCtx().GetPeerIp() == PeerIP() && PRAFT.GetClusterCmdCtx().GetPort() == PeerPort();
return RAFT_INST.GetClusterCmdCtx().GetPeerIp() == PeerIP() && RAFT_INST.GetClusterCmdCtx().GetPort() == PeerPort();
}

uint64_t PClient::GetUniqueID() const { return GetConnId(); }
Expand Down
3 changes: 2 additions & 1 deletion src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class PClient : public std::enable_shared_from_this<PClient> {

// If T is of type string, then the contents of string must be numbers
template <typename T>
requires(std::integral<T> || std::same_as<T, std::string>) void AppendArrayLen(T value) {
requires(std::integral<T> || std::same_as<T, std::string>)
void AppendArrayLen(T value) {
AppendStringRaw(fmt::format("*{}\r\n", value));
}

Expand Down
Loading

0 comments on commit c9ceb4a

Please sign in to comment.