diff --git a/CMakeLists.txt b/CMakeLists.txt index 7af5f73..2a9fffc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,7 +181,6 @@ INCLUDE(cmake/brpc.cmake) INCLUDE(cmake/rocksdb.cmake) INCLUDE(cmake/braft.cmake) INCLUDE(cmake/rediscache.cmake) -INCLUDE(cmake/jemalloc.cmake) SET(PROTO_OUTPUT_DIR "${CMAKE_BINARY_DIR}/generated_pb") FILE(MAKE_DIRECTORY "${PROTO_OUTPUT_DIR}") diff --git a/cmake/jemalloc.cmake b/cmake/jemalloc.cmake deleted file mode 100644 index 4c002d8..0000000 --- a/cmake/jemalloc.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) 2024-present, Qihoo, Inc. 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. - -if(CMAKE_SYSTEM_NAME MATCHES "Linux") - ExternalProject_Add(jemalloc - DEPENDS - URL - https://github.com/jemalloc/jemalloc/archive/refs/tags/5.3.0.tar.gz - URL_HASH - MD5=594dd8e0a1e8c1ef8a1b210a1a5aff5b - DOWNLOAD_NO_PROGRESS - 1 - UPDATE_COMMAND - "" - LOG_CONFIGURE - 1 - LOG_BUILD - 1 - LOG_INSTALL - 1 - CONFIGURE_COMMAND - /autogen.sh --prefix=${LIB_INSTALL_PREFIX} - BUILD_IN_SOURCE - 1 - BUILD_COMMAND - make -j${CPU_CORE} - BUILD_ALWAYS - 1 - INSTALL_COMMAND - make install - ) - - set(JEMALLOC_LIBRARY ${LIB_INSTALL_DIR}/libjemalloc.a) - set(JEMALLOC_INCLUDE_DIR ${LIB_INCLUDE_DIR}) - set(LIBJEMALLOC_NAME jemalloc) - set(JEMALLOC_ON ON) -else() - set(JEMALLOC_ON OFF) -endif() \ No newline at end of file diff --git a/cmake/rediscache.cmake b/cmake/rediscache.cmake index 9be3c6e..44ddffb 100644 --- a/cmake/rediscache.cmake +++ b/cmake/rediscache.cmake @@ -1,10 +1,5 @@ -# Copyright (c) 2024-present, Qihoo, Inc. 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. - -SET(REDISCACHE_SOURCES_DIR "${LIB_INSTALL_PREFIX}" CACHE PATH "rediscache source directory." FORCE) -SET(REDISCACHE_INSTALL_DIR "${LIB_INSTALL_PREFIX}" CACHE PATH "rediscache install directory." FORCE) +SET(REDISCACHE_SOURCES_DIR "${LIB_INSTALL_PREFIX}" CACHE PATH "rediscache source directory.") +SET(REDISCACHE_INSTALL_DIR "${LIB_INSTALL_PREFIX}" CACHE PATH "rediscache install directory.") SET(REDISCACHE_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "rediscache include directory." FORCE) SET(REDISCACHE_LIBRARIES "${LIB_INSTALL_DIR}/librediscache.a" CACHE FILEPATH "rediscache library." FORCE) diff --git a/src/base_cmd.cc b/src/base_cmd.cc index 2b71b56..9e8f69b 100644 --- a/src/base_cmd.cc +++ b/src/base_cmd.cc @@ -15,8 +15,8 @@ #include "common.h" #include "config.h" -#include "log.h" #include "kiwi.h" +#include "log.h" #include "praft/praft.h" namespace kiwi { @@ -96,10 +96,6 @@ bool BaseCmd::IsNeedReadCache() const { return HasFlag(kCmdFlagsReadCache); } bool BaseCmd::IsNeedUpdateCache() const { return HasFlag(kCmdFlagsUpdateCache); } bool BaseCmd::IsNeedCacheDo(PClient* client) const { - if (g_config.tmp_cache_disable_flag.load()) { - return false; - } - if (HasFlag(kCmdFlagsKv)) { if (!g_config.cache_string.load()) { return false; diff --git a/src/base_cmd.h b/src/base_cmd.h index 9aeabc1..5b76964 100644 --- a/src/base_cmd.h +++ b/src/base_cmd.h @@ -299,6 +299,9 @@ class BaseCmd : public std::enable_shared_from_this { uint32_t cmd_id_ = 0; uint32_t acl_category_ = 0; + // save db operation status which will be used in cache operation + storage::Status s_; + private: // The function to be executed first before executing `DoCmd` // What needs to be done at present are: extract the key in the command and fill it into the context diff --git a/src/cache/CMakeLists.txt b/src/cache/CMakeLists.txt index c29d767..774e3cc 100644 --- a/src/cache/CMakeLists.txt +++ b/src/cache/CMakeLists.txt @@ -1,8 +1,3 @@ -# Copyright (c) 2024-present, Qihoo, Inc. 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. - FILE(GLOB PCACHE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cc" diff --git a/src/cache/config.h b/src/cache/config.h index 158364d..03aa11a 100644 --- a/src/cache/config.h +++ b/src/cache/config.h @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #pragma once #include diff --git a/src/cache/hash.cc b/src/cache/hash.cc index 6679cbc..e25e5c5 100644 --- a/src/cache/hash.cc +++ b/src/cache/hash.cc @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #include "pstd_defer.h" #include "redisCache.h" diff --git a/src/cache/list.cc b/src/cache/list.cc index fb148db..0aa0747 100644 --- a/src/cache/list.cc +++ b/src/cache/list.cc @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #include "pstd_defer.h" #include "redisCache.h" diff --git a/src/cache/redisCache.cc b/src/cache/redisCache.cc index 8d80dd6..8e322a8 100644 --- a/src/cache/redisCache.cc +++ b/src/cache/redisCache.cc @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #include "cache/redisCache.h" #include "pstd/pstd_defer.h" #include "pstd/pstd_string.h" diff --git a/src/cache/redisCache.h b/src/cache/redisCache.h index 274244a..ec2f771 100644 --- a/src/cache/redisCache.h +++ b/src/cache/redisCache.h @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #pragma once #include diff --git a/src/cache/set.cc b/src/cache/set.cc index caf2bf1..32b93a8 100644 --- a/src/cache/set.cc +++ b/src/cache/set.cc @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #include "pstd_defer.h" #include "redisCache.h" diff --git a/src/cache/string.cc b/src/cache/string.cc index 34337a9..8b2ddd1 100644 --- a/src/cache/string.cc +++ b/src/cache/string.cc @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #include #include "pstd/pstd_defer.h" diff --git a/src/cache/zset.cc b/src/cache/zset.cc index a3e7da9..fa46b56 100644 --- a/src/cache/zset.cc +++ b/src/cache/zset.cc @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #include "pstd/pstd_defer.h" #include "redisCache.h" diff --git a/src/cache_define.h b/src/cache_define.h index 0a691b4..f9f5283 100644 --- a/src/cache_define.h +++ b/src/cache_define.h @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #pragma once namespace kiwi { diff --git a/src/cmd_admin.h b/src/cmd_admin.h index 81a672b..002ed93 100644 --- a/src/cmd_admin.h +++ b/src/cmd_admin.h @@ -37,7 +37,7 @@ class CmdConfig : public BaseCmdGroup { private: // std::vector subCmd_; - void DoCmd(PClient* client) override{}; + void DoCmd(PClient* client) override {}; }; class CmdConfigGet : public BaseCmd { @@ -178,7 +178,7 @@ class CmdDebug : public BaseCmdGroup { bool DoInitial(PClient* client) override { return true; }; private: - void DoCmd(PClient* client) override{}; + void DoCmd(PClient* client) override {}; }; class CmdDebugHelp : public BaseCmd { diff --git a/src/cmd_hash.h b/src/cmd_hash.h index c0c17d4..f25e3e5 100644 --- a/src/cmd_hash.h +++ b/src/cmd_hash.h @@ -26,7 +26,6 @@ class HSetCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class HGetCmd : public BaseCmd { @@ -41,7 +40,6 @@ class HGetCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class HDelCmd : public BaseCmd { @@ -55,7 +53,7 @@ class HDelCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - rocksdb::Status s_; + int32_t deleted_ = 0; }; @@ -70,7 +68,6 @@ class HMSetCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - rocksdb::Status s_; }; class HMGetCmd : public BaseCmd { @@ -85,7 +82,6 @@ class HMGetCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - rocksdb::Status s_; }; class HGetAllCmd : public BaseCmd { @@ -100,7 +96,6 @@ class HGetAllCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - rocksdb::Status s_; }; class HKeysCmd : public BaseCmd { @@ -115,7 +110,6 @@ class HKeysCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - rocksdb::Status s_; }; class HLenCmd : public BaseCmd { @@ -130,7 +124,6 @@ class HLenCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - rocksdb::Status s_; }; class HStrLenCmd : public BaseCmd { @@ -145,7 +138,6 @@ class HStrLenCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class HScanCmd : public BaseCmd { @@ -174,7 +166,6 @@ class HValsCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class HIncrbyFloatCmd : public BaseCmd { @@ -188,7 +179,6 @@ class HIncrbyFloatCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class HSetNXCmd : public BaseCmd { @@ -202,7 +192,6 @@ class HSetNXCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class HIncrbyCmd : public BaseCmd { @@ -216,7 +205,7 @@ class HIncrbyCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; + int64_t int_by_ = 0; }; @@ -244,7 +233,6 @@ class HExistsCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - rocksdb::Status s_; }; } // namespace kiwi diff --git a/src/cmd_keys.h b/src/cmd_keys.h index cb0c479..28d312e 100644 --- a/src/cmd_keys.h +++ b/src/cmd_keys.h @@ -22,7 +22,6 @@ class DelCmd : public BaseCmd { bool DoInitial(PClient* client) override; private: - rocksdb::Status s_; void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; @@ -65,7 +64,7 @@ class ExpireCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - rocksdb::Status s_; + int64_t sec_ = 0; }; @@ -94,7 +93,6 @@ class PExpireCmd : public BaseCmd { void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; int64_t msec_ = 0; - rocksdb::Status s_; }; class ExpireatCmd : public BaseCmd { @@ -105,7 +103,6 @@ class ExpireatCmd : public BaseCmd { bool DoInitial(PClient* client) override; private: - rocksdb::Status s_; int64_t time_stamp_ = 0; void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; @@ -120,7 +117,6 @@ class PExpireatCmd : public BaseCmd { bool DoInitial(PClient* client) override; private: - rocksdb::Status s_; int64_t time_stamp_ms_ = 0; void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; @@ -136,7 +132,7 @@ class PersistCmd : public BaseCmd { private: void DoCmd(PClient* client) override; - rocksdb::Status s_; + void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; }; diff --git a/src/cmd_kv.cc b/src/cmd_kv.cc index 72673a5..9909412 100644 --- a/src/cmd_kv.cc +++ b/src/cmd_kv.cc @@ -918,8 +918,6 @@ bool SetRangeCmd::DoInitial(PClient* client) { } void SetRangeCmd::DoCmd(PClient* client) { - - int32_t ret = 0; s_ = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->Setrange(client->Key(), offset_, client->argv_[3], &ret); diff --git a/src/cmd_kv.h b/src/cmd_kv.h index 7b1e855..63eb7c8 100644 --- a/src/cmd_kv.h +++ b/src/cmd_kv.h @@ -23,7 +23,7 @@ class GetCmd : public BaseCmd { private: std::string value_; - rocksdb::Status s_; + int64_t ttl_ = 0; void DoCmd(PClient *client) override; @@ -50,7 +50,6 @@ class SetCmd : public BaseCmd { std::string target_; int64_t sec_ = 0; SetCmd::SetCondition condition_{kNONE}; - rocksdb::Status s_; }; class BitOpCmd : public BaseCmd { @@ -82,7 +81,7 @@ class StrlenCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - rocksdb::Status s_; + int64_t sec_ = 0; std::string value_; }; @@ -95,7 +94,6 @@ class SetExCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - storage::Status s_; int64_t sec_ = 0; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; @@ -111,7 +109,7 @@ class PSetExCmd : public BaseCmd { private: int64_t msec_ = 0; - storage::Status s_; + void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; @@ -136,7 +134,6 @@ class AppendCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - storage::Status s_; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; @@ -150,7 +147,6 @@ class GetSetCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - storage::Status s_; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; @@ -164,7 +160,6 @@ class MGetCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - storage::Status s_; std::vector db_value_status_array_; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; @@ -181,7 +176,7 @@ class MSetCmd : public BaseCmd { private: std::vector kvs_; - storage::Status s_; + void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; @@ -206,7 +201,6 @@ class DecrCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - storage::Status s_; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; @@ -220,7 +214,6 @@ class IncrCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - rocksdb::Status s_; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; @@ -234,7 +227,6 @@ class IncrbyCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - rocksdb::Status s_; int64_t by_ = 0; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; @@ -249,7 +241,7 @@ class DecrbyCmd : public BaseCmd { private: int64_t by_ = 0; - storage::Status s_; + void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; @@ -285,7 +277,6 @@ class IncrbyFloatCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - storage::Status s_; std::string value_; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; @@ -302,7 +293,7 @@ class GetRangeCmd : public BaseCmd { private: int64_t start_ = 0; int64_t end_ = 0; - storage::Status s_; + std::string value_; int64_t sec_ = 0; void DoCmd(PClient *client) override; @@ -319,7 +310,6 @@ class SetRangeCmd : public BaseCmd { bool DoInitial(PClient *client) override; private: - storage::Status s_; int64_t offset_ = 0; void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; diff --git a/src/cmd_list.cc b/src/cmd_list.cc index 75e4f9f..1e36b60 100644 --- a/src/cmd_list.cc +++ b/src/cmd_list.cc @@ -545,4 +545,3 @@ void LLenCmd::DoUpdateCache(PClient* client) { } } } // namespace kiwi - diff --git a/src/cmd_list.h b/src/cmd_list.h index de0c9bc..23c0cb0 100644 --- a/src/cmd_list.h +++ b/src/cmd_list.h @@ -22,7 +22,6 @@ class LPushCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; }; class RPushCmd : public BaseCmd { @@ -36,7 +35,6 @@ class RPushCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; }; class RPopCmd : public BaseCmd { @@ -50,7 +48,6 @@ class RPopCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; }; class LRangeCmd : public BaseCmd { public: @@ -66,7 +63,6 @@ class LRangeCmd : public BaseCmd { void ReadCache(PClient* client) override; int64_t start_index_ = 0; int64_t end_index_ = 0; - storage::Status s_; }; class LRemCmd : public BaseCmd { @@ -80,7 +76,7 @@ class LRemCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; + int64_t freq_ = 0; }; @@ -95,7 +91,7 @@ class LTrimCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; + int64_t start_index_ = 0; int64_t end_index_ = 0; }; @@ -111,7 +107,7 @@ class LSetCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; + int64_t index_ = 0; }; @@ -127,7 +123,6 @@ class LInsertCmd : public BaseCmd { void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; storage ::BeforeOrAfter before_or_after_; - storage::Status s_; }; class LPushxCmd : public BaseCmd { @@ -141,7 +136,6 @@ class LPushxCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; }; class RPushxCmd : public BaseCmd { @@ -155,7 +149,6 @@ class RPushxCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; }; class RPoplpushCmd : public BaseCmd { @@ -185,7 +178,6 @@ class LPopCmd : public BaseCmd { void DoCmd(PClient* client) override; void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; - storage::Status s_; }; class LIndexCmd : public BaseCmd { @@ -201,7 +193,6 @@ class LIndexCmd : public BaseCmd { void DoUpdateCache(PClient* client) override; void ReadCache(PClient* client) override; int64_t index_ = 0; - storage::Status s_; }; class LLenCmd : public BaseCmd { @@ -216,6 +207,5 @@ class LLenCmd : public BaseCmd { void DoThroughDB(PClient* client) override; void DoUpdateCache(PClient* client) override; void ReadCache(PClient* client) override; - storage::Status s_; }; } // namespace kiwi diff --git a/src/cmd_set.h b/src/cmd_set.h index b27f0a2..e64200d 100644 --- a/src/cmd_set.h +++ b/src/cmd_set.h @@ -25,7 +25,6 @@ class SIsMemberCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class SAddCmd : public BaseCmd { @@ -39,7 +38,6 @@ class SAddCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class SUnionStoreCmd : public BaseCmd { @@ -53,7 +51,6 @@ class SUnionStoreCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class SRemCmd : public BaseCmd { @@ -67,7 +64,7 @@ class SRemCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; + int32_t deleted_num = 0; }; @@ -104,7 +101,6 @@ class SInterStoreCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class SCardCmd : public BaseCmd { @@ -119,7 +115,6 @@ class SCardCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class SMoveCmd : public BaseCmd { @@ -133,7 +128,6 @@ class SMoveCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class SRandMemberCmd : public BaseCmd { @@ -149,7 +143,6 @@ class SRandMemberCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class SPopCmd : public BaseCmd { @@ -163,7 +156,7 @@ class SPopCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; + std::vector deleted_members_; }; @@ -179,7 +172,6 @@ class SMembersCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class SDiffCmd : public BaseCmd { @@ -204,7 +196,6 @@ class SDiffstoreCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class SScanCmd : public BaseCmd { diff --git a/src/cmd_thread_pool_worker.cc b/src/cmd_thread_pool_worker.cc index 63361ba..4191b15 100644 --- a/src/cmd_thread_pool_worker.cc +++ b/src/cmd_thread_pool_worker.cc @@ -10,8 +10,8 @@ #include "cmd_thread_pool_worker.h" #include "client.h" #include "env.h" -#include "log.h" #include "kiwi.h" +#include "log.h" namespace kiwi { diff --git a/src/cmd_zset.h b/src/cmd_zset.h index adddf46..46243e5 100644 --- a/src/cmd_zset.h +++ b/src/cmd_zset.h @@ -25,7 +25,6 @@ class ZAddCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class ZPopMinCmd : public BaseCmd { @@ -39,7 +38,6 @@ class ZPopMinCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class ZPopMaxCmd : public BaseCmd { @@ -53,7 +51,6 @@ class ZPopMaxCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class ZsetUIstoreParentCmd : public BaseCmd { @@ -81,7 +78,6 @@ class ZInterstoreCmd : public ZsetUIstoreParentCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class ZUnionstoreCmd : public ZsetUIstoreParentCmd { @@ -95,7 +91,6 @@ class ZUnionstoreCmd : public ZsetUIstoreParentCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; class ZRevrangeCmd : public BaseCmd { @@ -124,7 +119,7 @@ class ZRangebyscoreCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; + double min_score_ = 0, max_score_ = 0; bool left_close_ = true, right_close_ = true, with_scores_ = false; int64_t offset_ = 0, count_ = -1; @@ -141,7 +136,7 @@ class ZRemrangebyrankCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; + int32_t start_ = 0; int32_t end_ = 0; }; @@ -161,7 +156,7 @@ class ZRevrangebyscoreCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; + double min_score_ = 0, max_score_ = 0; bool left_close_ = true, right_close_ = true, with_scores_ = false; int64_t offset_ = 0, count_ = -1; @@ -179,7 +174,6 @@ class ZCardCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class ZRangeCmd : public BaseCmd { @@ -205,7 +199,6 @@ class ZScoreCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class ZRangebylexCmd : public BaseCmd { @@ -220,7 +213,7 @@ class ZRangebylexCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; + std::string min_member_, max_member_; bool left_close_ = true, right_close_ = true; int64_t offset_ = 0, count_ = -1; @@ -238,7 +231,7 @@ class ZRevrangebylexCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; + std::string min_member_, max_member_; bool left_close_ = true, right_close_ = true; int64_t offset_ = 0, count_ = -1; @@ -256,7 +249,6 @@ class ZRankCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class ZRevrankCmd : public BaseCmd { @@ -271,7 +263,6 @@ class ZRevrankCmd : public BaseCmd { void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; void ReadCache(PClient *client) override; - storage::Status s_; }; class ZRemCmd : public BaseCmd { @@ -285,7 +276,7 @@ class ZRemCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; + int32_t deleted_ = 0; }; @@ -300,7 +291,7 @@ class ZIncrbyCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; + double by_ = .0f; double score_ = .0f; }; @@ -316,7 +307,6 @@ class ZRemrangebyscoreCmd : public BaseCmd { void DoCmd(PClient *client) override; void DoThroughDB(PClient *client) override; void DoUpdateCache(PClient *client) override; - storage::Status s_; }; } // namespace kiwi diff --git a/src/config.h b/src/config.h index 77a3437..a70e251 100644 --- a/src/config.h +++ b/src/config.h @@ -11,13 +11,13 @@ #pragma once #include +#include +#include +#include #include #include #include #include -#include -#include -#include #include #include #include @@ -336,7 +336,6 @@ class PConfig { // cache std::vector cache_type_all; - std::atomic_bool tmp_cache_disable_flag = false; std::atomic_uint64_t cache_maxmemory = 10737418240; std::atomic_int cache_num = 5; std::atomic_int cache_mode = 1; diff --git a/src/config_parser.h b/src/config_parser.h index fe6c13c..83ecb9e 100644 --- a/src/config_parser.h +++ b/src/config_parser.h @@ -3,7 +3,6 @@ * Declared a set of functions for parsing configuration data * as required. * - * Copyright (c) 2023-present, Qihoo, Inc. All rights reserved. * * src/config_parser.h * diff --git a/src/db.h b/src/db.h index 09c8cc5..07a300c 100644 --- a/src/db.h +++ b/src/db.h @@ -18,7 +18,6 @@ #include "pstd/noncopyable.h" #include "storage/storage.h" - namespace kiwi { class DB { public: diff --git a/src/kiwi.cc b/src/kiwi.cc index 71439ba..3f551ce 100644 --- a/src/kiwi.cc +++ b/src/kiwi.cc @@ -201,7 +201,7 @@ bool KiwiDB::Init() { PREPL.SetMasterAddr(g_config.master_ip.ToString().c_str(), g_config.master_port.load()); } - event_server_ =std::make_unique>>(num); + event_server_ = std::make_unique>>(num); event_server_->SetRwSeparation(true); diff --git a/src/kiwi.h b/src/kiwi.h index 2502425..4284a1d 100644 --- a/src/kiwi.h +++ b/src/kiwi.h @@ -58,9 +58,7 @@ class KiwiDB final { event_server_->SendPacket(client, std::move(msg)); } - inline void CloseConnection(const std::shared_ptr& client) { - event_server_->CloseConnection(client); - } + inline void CloseConnection(const std::shared_ptr& client) { event_server_->CloseConnection(client); } void TCPConnect( const net::SocketAddr& addr, diff --git a/src/net/base_event.h b/src/net/base_event.h index 32d82be..72368ae 100644 --- a/src/net/base_event.h +++ b/src/net/base_event.h @@ -45,7 +45,7 @@ class BaseEvent : public std::enable_shared_from_this { const static int EVENT_HUB; BaseEvent(const std::shared_ptr &listen, int8_t mode, int8_t type) - : listen_(listen), mode_(mode), type_(type){}; + : listen_(listen), mode_(mode), type_(type) {}; virtual ~BaseEvent() = default; diff --git a/src/net/base_socket.h b/src/net/base_socket.h index 875ff31..b12811e 100644 --- a/src/net/base_socket.h +++ b/src/net/base_socket.h @@ -34,7 +34,7 @@ class BaseSocket : public NetEvent { ~BaseSocket() override = default; - void OnError() override{}; + void OnError() override {}; void Close() override; diff --git a/src/net/callback_function.h b/src/net/callback_function.h index 57bf086..458e4bb 100644 --- a/src/net/callback_function.h +++ b/src/net/callback_function.h @@ -35,8 +35,7 @@ concept HasSetFdFunction = requires(T t, uint64_t id, int8_t index) { { (*t).GetConnId() } -> std::same_as; // GetFd return type is int { (*t).SetThreadIndex(index) } -> std::same_as; // SetThreadIndex return type is void { (*t).GetThreadIndex() } -> std::same_as; // GetThreadIndex return type is int8_t -} -|| std::is_class_v; // If T is an ordinary class, the member function is called directly +} || std::is_class_v; // If T is an ordinary class, the member function is called directly template requires HasSetFdFunction diff --git a/src/net/client_socket.h b/src/net/client_socket.h index 04916f9..2a3f0d2 100644 --- a/src/net/client_socket.h +++ b/src/net/client_socket.h @@ -13,7 +13,7 @@ namespace net { class ClientSocket : public StreamSocket { public: - explicit ClientSocket(const SocketAddr& addr) : StreamSocket(0, SOCKET_TCP), addr_(addr){}; + explicit ClientSocket(const SocketAddr& addr) : StreamSocket(0, SOCKET_TCP), addr_(addr) {}; ~ClientSocket() override = default; diff --git a/src/net/epoll_event.h b/src/net/epoll_event.h index bc00c27..529dd99 100644 --- a/src/net/epoll_event.h +++ b/src/net/epoll_event.h @@ -23,7 +23,7 @@ namespace net { class EpollEvent : public BaseEvent { public: explicit EpollEvent(const std::shared_ptr &listen, int8_t mode) - : BaseEvent(listen, mode, BaseEvent::EVENT_TYPE_EPOLL){}; + : BaseEvent(listen, mode, BaseEvent::EVENT_TYPE_EPOLL) {}; ~EpollEvent() override { Close(); } diff --git a/src/net/event_server.h b/src/net/event_server.h index 6eafd18..dbaafb5 100644 --- a/src/net/event_server.h +++ b/src/net/event_server.h @@ -104,7 +104,8 @@ class EventServer final { }; template -requires HasSetFdFunction std::pair EventServer::StartServer(int64_t interval) { +requires HasSetFdFunction +std::pair EventServer::StartServer(int64_t interval) { if (threadNum_ <= 0) { return std::pair(false, "thread num must be greater than 0"); } @@ -143,7 +144,8 @@ requires HasSetFdFunction std::pair EventServer::StartS } template -requires HasSetFdFunction std::pair EventServer::StartClientServer() { +requires HasSetFdFunction +std::pair EventServer::StartClientServer() { if (threadNum_ <= 0) { return std::pair(false, "thread num must be greater than 0"); } diff --git a/src/net/io_thread.h b/src/net/io_thread.h index 0deaefc..f306559 100644 --- a/src/net/io_thread.h +++ b/src/net/io_thread.h @@ -16,7 +16,7 @@ namespace net { class IOThread { public: - explicit IOThread(const std::shared_ptr &event) : baseEvent_(event){}; + explicit IOThread(const std::shared_ptr &event) : baseEvent_(event) {}; ~IOThread() = default; diff --git a/src/net/kqueue_event.h b/src/net/kqueue_event.h index 0a31be5..086dd01 100644 --- a/src/net/kqueue_event.h +++ b/src/net/kqueue_event.h @@ -24,7 +24,7 @@ namespace net { class KqueueEvent : public BaseEvent { public: explicit KqueueEvent(std::shared_ptr listen, int8_t mode) - : BaseEvent(std::move(listen), mode, BaseEvent::EVENT_TYPE_KQUEUE){}; + : BaseEvent(std::move(listen), mode, BaseEvent::EVENT_TYPE_KQUEUE) {}; ~KqueueEvent() override { Close(); } diff --git a/src/net/thread_manager.h b/src/net/thread_manager.h index a7c819e..c202ab4 100644 --- a/src/net/thread_manager.h +++ b/src/net/thread_manager.h @@ -114,7 +114,10 @@ class ThreadManager { }; template -requires HasSetFdFunction ThreadManager::~ThreadManager() { Stop(); } +requires HasSetFdFunction +ThreadManager::~ThreadManager() { + Stop(); +} template requires HasSetFdFunction @@ -201,7 +204,9 @@ void ThreadManager::OnNetEventClose(uint64_t connId, std::string &&err) { template requires HasSetFdFunction -void ThreadManager::CloseConnection(uint64_t connId) { OnNetEventClose(connId, ""); } +void ThreadManager::CloseConnection(uint64_t connId) { + OnNetEventClose(connId, ""); +} template requires HasSetFdFunction @@ -326,8 +331,8 @@ bool ThreadManager::CreateWriteThread() { } template -requires HasSetFdFunction uint64_t ThreadManager::DoTCPConnect(T &t, int fd, - const std::shared_ptr &conn) { +requires HasSetFdFunction +uint64_t ThreadManager::DoTCPConnect(T &t, int fd, const std::shared_ptr &conn) { auto connId = getConnId(); if constexpr (IsPointer_v) { t->SetConnId(connId); diff --git a/src/pcache.cc b/src/pcache.cc index 17842e8..032a770 100644 --- a/src/pcache.cc +++ b/src/pcache.cc @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #include #include #include @@ -27,7 +22,7 @@ PCache::PCache(int zset_cache_start_direction, int zset_cache_field_num_per_key) zset_cache_start_direction_(zset_cache_start_direction), zset_cache_field_num_per_key_(EXTEND_CACHE_SIZE(zset_cache_field_num_per_key)) { cache_load_thread_ = std::make_unique(zset_cache_start_direction_, zset_cache_field_num_per_key_); - cache_load_thread_->StartThread(); + // cache_load_thread_->StartThread(); } PCache::~PCache() { diff --git a/src/pcache.h b/src/pcache.h index f8f27df..6bcc47b 100644 --- a/src/pcache.h +++ b/src/pcache.h @@ -1,8 +1,3 @@ -// Copyright (c) 2024-present, Qihoo, Inc. 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. - #pragma once #include diff --git a/src/pcache_load_thread.cc b/src/pcache_load_thread.cc index 292405f..622ff88 100644 --- a/src/pcache_load_thread.cc +++ b/src/pcache_load_thread.cc @@ -1,10 +1,3 @@ -/* - * Copyright (c) 2024-present, Qihoo, Inc. 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. - */ - #include "pcache_load_thread.h" #include "config.h" #include "pcache.h" @@ -21,7 +14,8 @@ PCacheLoadThread::PCacheLoadThread(int zset_cache_start_direction, int zset_cach waitting_load_keys_num_(0), zset_cache_start_direction_(zset_cache_start_direction), zset_cache_field_num_per_key_(zset_cache_field_num_per_key) { - set_thread_name("PCacheLoadThread"); + // set_thread_name("PCacheLoadThread"); + thread_ = std::thread([this]() { this->ThreadMain(); }); } PCacheLoadThread::~PCacheLoadThread() { @@ -31,7 +25,7 @@ PCacheLoadThread::~PCacheLoadThread() { loadkeys_cond_.notify_all(); } - StopThread(); + // StopThread(); } void PCacheLoadThread::Push(const char key_type, std::string& key, PClient* client) { @@ -164,7 +158,7 @@ bool PCacheLoadThread::LoadKey(const char key_type, std::string& key, PClient* c } } -void* PCacheLoadThread::ThreadMain() { +void PCacheLoadThread::ThreadMain() { INFO("PCacheLoadThread::ThreadMain Start"); while (!should_exit_) { @@ -177,7 +171,7 @@ void* PCacheLoadThread::ThreadMain() { } if (should_exit_) { - return nullptr; + return; } for (int i = 0; i < CACHE_LOAD_NUM_ONE_TIME; ++i) { @@ -197,6 +191,6 @@ void* PCacheLoadThread::ThreadMain() { } } - return nullptr; + return; } } // namespace kiwi diff --git a/src/pcache_load_thread.h b/src/pcache_load_thread.h index e86b904..012c160 100644 --- a/src/pcache_load_thread.h +++ b/src/pcache_load_thread.h @@ -1,27 +1,21 @@ -/* - * Copyright (c) 2024-present, Qihoo, Inc. 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. - */ - #pragma once #include #include +#include #include #include #include "client.h" #include "pcache.h" -#include "thread.h" +// #include "thread.h" namespace kiwi { -class PCacheLoadThread : public Thread { +class PCacheLoadThread { public: PCacheLoadThread(int zset_cache_start_direction, int zset_cache_field_num_per_key); - ~PCacheLoadThread() override; + ~PCacheLoadThread(); uint64_t AsyncLoadKeysNum(void) { return async_load_keys_num_; } uint32_t WaittingLoadKeysNum(void) { return waitting_load_keys_num_; } @@ -34,7 +28,7 @@ class PCacheLoadThread : public Thread { bool LoadSet(std::string& key, PClient* client); bool LoadZset(std::string& key, PClient* client); bool LoadKey(const char key_type, std::string& key, PClient* client); - virtual void* ThreadMain() override; + void ThreadMain(); private: std::atomic_bool should_exit_; @@ -51,5 +45,7 @@ class PCacheLoadThread : public Thread { // currently only take effects to zset int zset_cache_start_direction_; int zset_cache_field_num_per_key_; + + std::thread thread_; }; } // namespace kiwi diff --git a/src/pstd/memory_file.h b/src/pstd/memory_file.h index 6c906b2..a59a812 100644 --- a/src/pstd/memory_file.h +++ b/src/pstd/memory_file.h @@ -106,7 +106,7 @@ class OutputMemoryFile { * Initialize some private value. */ OutputMemoryFile(); - + /*------------------------ * ~OutputMemoryFile() * Close file and free the memory. @@ -131,7 +131,7 @@ class OutputMemoryFile { * Close file and end the mapping relation. */ void Close(); - + /*------------------------ * Sync() * Synchronize memory content to disk. @@ -140,7 +140,7 @@ class OutputMemoryFile { /*------------------------ * Truncate(std::size_t size) - * Adjust the file block size to the specified bytes + * Adjust the file block size to the specified bytes * and rebuild the mapping relationship. */ void Truncate(std::size_t size); @@ -149,14 +149,14 @@ class OutputMemoryFile { * TruncateTailZero() * Equal to Truncate(0), if process terminated abnormally, * erase the trash data. - */ + */ void TruncateTailZero(); /*------------------------ * Write(const void* data, std::size_t len) - * Write the content of the specified length into the buffer + * Write the content of the specified length into the buffer * and adjust the offset. - */ + */ void Write(const void* data, std::size_t len); // Write data to file buffer and adjust the offset. @@ -197,7 +197,7 @@ class OutputMemoryFile { // fd int file_ = -1; - + // The file content buffer char* pMemory_ = nullptr; diff --git a/src/replication.cc b/src/replication.cc index 28b5a6d..0356f40 100644 --- a/src/replication.cc +++ b/src/replication.cc @@ -13,8 +13,8 @@ #include "client.h" #include "config.h" -#include "log.h" #include "kiwi.h" +#include "log.h" #include "pstd/pstd_string.h" #include "replication.h" @@ -189,8 +189,7 @@ void PReplication::Cron() { INFO("Try connect to master IP:{} port:{}", masterInfo_.addr.GetIP(), masterInfo_.addr.GetPort()); - auto on_new_conn = [](uint64_t connID, std::shared_ptr& client, - const net::SocketAddr& addr) { + auto on_new_conn = [](uint64_t connID, std::shared_ptr& client, const net::SocketAddr& addr) { INFO("Connect to master IP:{} port:{}", addr.GetIP(), addr.GetPort()); if (g_kiwi) { g_kiwi->OnNewConnection(connID, client, addr); diff --git a/src/storage/src/base_data_value_format.h b/src/storage/src/base_data_value_format.h index 2bb7d76..26d6a97 100644 --- a/src/storage/src/base_data_value_format.h +++ b/src/storage/src/base_data_value_format.h @@ -97,7 +97,7 @@ class ParsedBaseDataValue : public ParsedInternalValue { } protected: - virtual void SetVersionToValue() override{}; + virtual void SetVersionToValue() override {}; private: const size_t kBaseDataValueSuffixLength = kSuffixReserveLength + kTimestampLength; diff --git a/src/storage/src/storage.cc b/src/storage/src/storage.cc index 8d6f5e2..266cab2 100644 --- a/src/storage/src/storage.cc +++ b/src/storage/src/storage.cc @@ -12,8 +12,8 @@ #include "binlog.pb.h" #include "config.h" -#include "pstd/log.h" #include "pstd/kiwi_slot.h" +#include "pstd/log.h" #include "pstd/pstd_string.h" #include "rocksdb/utilities/checkpoint.h" #include "scope_snapshot.h" diff --git a/src/thread.cc b/src/thread.cc deleted file mode 100644 index e07362e..0000000 --- a/src/thread.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2024-present, Qihoo, Inc. 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. - */ - -#include "thread.h" - -namespace kiwi { - -Thread::Thread() : should_stop_(false) {} - -Thread::~Thread() = default; - -void* Thread::RunThread(void* arg) { - auto thread = reinterpret_cast(arg); - thread->ThreadMain(); - return nullptr; -} - -int Thread::StartThread() { - if (!should_stop() && is_running()) { - return 0; - } - std::lock_guard l(running_mu_); - should_stop_ = false; - if (!running_) { - running_ = true; - return pthread_create(&thread_id_, nullptr, RunThread, this); - } - return 0; -} - -int Thread::StopThread() { - if (should_stop() && !is_running()) { - return 0; - } - std::lock_guard l(running_mu_); - should_stop_ = true; - if (running_) { - running_ = false; - return pthread_join(thread_id_, nullptr); - } - return 0; -} - -int Thread::JoinThread() { return pthread_join(thread_id_, nullptr); } - -} // namespace kiwi diff --git a/src/thread.h b/src/thread.h deleted file mode 100644 index 76c2c98..0000000 --- a/src/thread.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2024-present, Qihoo, Inc. 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. - */ - -#pragma once - -#include -#include -#include - -#include "pstd/noncopyable.h" -#include "pstd/pstd_mutex.h" - -namespace kiwi { - -class Thread : public pstd::noncopyable { - public: - Thread(); - virtual ~Thread(); - - virtual int StartThread(); - virtual int StopThread(); - int JoinThread(); - - bool should_stop() { return should_stop_.load(); } - - void set_should_stop() { should_stop_.store(true); } - - bool is_running() { return running_.load(); } - - pthread_t thread_id() const { return thread_id_; } - - std::string thread_name() const { return thread_name_; } - - void set_thread_name(const std::string& name) { thread_name_ = name; } - - protected: - std::atomic_bool should_stop_; - void set_is_running(bool is_running) { - std::lock_guard l(running_mu_); - running_ = is_running; - } - - private: - static void* RunThread(void* arg); - virtual void* ThreadMain() = 0; - - pstd::Mutex running_mu_; - std::atomic_bool running_ = false; - pthread_t thread_id_{}; - std::string thread_name_; -}; -} // namespace kiwi