From 83cad142f18c349aa7f80161195f1bd5062c2089 Mon Sep 17 00:00:00 2001 From: ForestLH <39085999+ForestLH@users.noreply.github.com> Date: Sat, 27 May 2023 15:30:47 +0800 Subject: [PATCH] feat: add clang-tidy for pika (#1515) * feature:add clang-tidy for pika There are several conflicting files left that need to be manually modified. See run_clang_tidy.py.And disabled some clang-tidy checks, eg, use int64_t instead of long or long long, variable naming. Signed-off-by: Hao Lee <1838249551@qq.com> * feature:WIP modified clang-tidy file Signed-off-by: Hao Lee <1838249551@qq.com> * feature:disable compile command clang-tidy check Signed-off-by: Hao Lee <1838249551@qq.com> * style:Make the code standard according to clang-tidy Signed-off-by: Hao Lee <1838249551@qq.com> * delete double std::move * auto* -> auto * using noncopyable * add space for override{} * add spaces * delete != 0 * format if-return * clear inheritage * format codes * format codes * delete == 0 * fix:fix build error Signed-off-by: Hao Lee <1838249551@qq.com> * style:disable check bool implicit convert in clang-tidy Signed-off-by: Hao Lee <1838249551@qq.com> * style:update code style Signed-off-by: Hao Lee <1838249551@qq.com> * delete '!= nullptr' * format if/while * fix ci failure * fix:build ci error Signed-off-by: Hao Lee <1838249551@qq.com> * style:The judgment statement should not be an assignment Signed-off-by: Hao Lee <1838249551@qq.com> * style:format codes remove redundant extern statement and use default Signed-off-by: Hao Lee <1838249551@qq.com> * style:format codes remove redundant extern g_pika_conf statement and correct if statement judgement instead of assignment Signed-off-by: Hao Lee <1838249551@qq.com> * format codes * format codes --------- Signed-off-by: Hao Lee <1838249551@qq.com> Co-authored-by: alexstocks Co-authored-by: Xin.Zh --- .clang-tidy | 118 + .github/workflows/pika.yml | 2 +- CMakeLists.txt | 37 + include/pika_admin.h | 292 +-- include/pika_auxiliary_thread.h | 4 +- include/pika_binlog.h | 43 +- include/pika_binlog_reader.h | 7 +- include/pika_binlog_transverter.h | 6 +- include/pika_bit.h | 68 +- include/pika_client_conn.h | 22 +- include/pika_command.h | 34 +- include/pika_conf.h | 26 +- include/pika_consensus.h | 79 +- include/pika_data_distribution.h | 10 +- include/pika_define.h | 106 +- include/pika_dispatch_thread.h | 4 +- include/pika_geo.h | 72 +- include/pika_geohash.h | 47 +- include/pika_geohash_helper.h | 16 +- include/pika_hash.h | 228 +- include/pika_hyperloglog.h | 38 +- include/pika_kv.h | 450 ++-- include/pika_list.h | 182 +- include/pika_meta.h | 15 +- include/pika_monitor_thread.h | 48 + include/pika_partition.h | 25 +- include/pika_pubsub.h | 62 +- include/pika_repl_bgworker.h | 2 +- include/pika_repl_client.h | 44 +- include/pika_repl_client_conn.h | 9 +- include/pika_repl_client_thread.h | 6 +- include/pika_repl_server.h | 5 +- include/pika_repl_server_conn.h | 6 +- include/pika_repl_server_thread.h | 6 +- include/pika_rm.h | 109 +- include/pika_rsync_service.h | 2 +- include/pika_server.h | 25 +- include/pika_set.h | 179 +- include/pika_slave_node.h | 12 +- include/pika_stable_log.h | 6 +- include/pika_statistic.h | 2 +- include/pika_table.h | 21 +- include/pika_zset.h | 316 +-- run_clang_tidy.py | 401 +++ src/net/include/backend_thread.h | 30 +- src/net/include/bg_thread.h | 8 +- src/net/include/client_thread.h | 20 +- src/net/include/http_conn.h | 49 +- src/net/include/net_cli.h | 26 +- src/net/include/net_conn.h | 16 +- src/net/include/net_pubsub.h | 23 +- src/net/include/net_thread.h | 13 +- src/net/include/pb_conn.h | 6 +- src/net/include/period_thread.h | 2 +- src/net/include/redis_cli.h | 2 +- src/net/include/redis_conn.h | 8 +- src/net/include/redis_parser.h | 16 +- src/net/include/server_thread.h | 10 +- src/net/include/simple_http_conn.h | 18 +- src/net/include/thread_pool.h | 16 +- src/net/src/backend_thread.cc | 30 +- src/net/src/client_thread.cc | 30 +- src/net/src/dispatch_thread.cc | 16 +- src/net/src/dispatch_thread.h | 25 +- src/net/src/holy_thread.cc | 20 +- src/net/src/holy_thread.h | 22 +- src/net/src/http_conn.cc | 39 +- src/net/src/net_cli.cc | 59 +- src/net/src/net_conn.cc | 19 +- src/net/src/net_epoll.cc | 22 +- src/net/src/net_epoll.h | 2 +- src/net/src/net_interfaces.cc | 14 +- src/net/src/net_item.h | 7 +- src/net/src/net_kqueue.cc | 16 +- src/net/src/net_kqueue.h | 2 +- src/net/src/net_multiplexer.cc | 2 +- src/net/src/net_pubsub.cc | 114 +- src/net/src/net_thread.cc | 8 +- src/net/src/pb_cli.cc | 19 +- src/net/src/pb_conn.cc | 2 +- src/net/src/redis_cli.cc | 110 +- src/net/src/redis_conn.cc | 23 +- src/net/src/redis_parser.cc | 55 +- src/net/src/server_socket.cc | 10 +- src/net/src/server_socket.h | 10 +- src/net/src/server_thread.cc | 35 +- src/net/src/simple_http_conn.cc | 25 +- src/net/src/thread_pool.cc | 12 +- src/net/src/worker_thread.cc | 28 +- src/net/src/worker_thread.h | 8 +- src/net/test/net_thread_test.cc | 2 +- src/pika.cc | 12 +- src/pika_admin.cc | 386 ++- src/pika_auxiliary_thread.cc | 5 +- src/pika_binlog.cc | 51 +- src/pika_binlog_reader.cc | 26 +- src/pika_binlog_transverter.cc | 22 +- src/pika_bit.cc | 48 +- src/pika_client_conn.cc | 45 +- src/pika_client_processor.cc | 8 +- src/pika_cmd_table_manager.cc | 7 +- src/pika_command.cc | 30 +- src/pika_conf.cc | 40 +- src/pika_consensus.cc | 74 +- src/pika_data_distribution.cc | 9 +- src/pika_dispatch_thread.cc | 3 +- src/pika_geo.cc | 102 +- src/pika_geohash.cc | 32 +- src/pika_geohash_helper.cc | 66 +- src/pika_hash.cc | 80 +- src/pika_kv.cc | 195 +- src/pika_list.cc | 29 +- src/pika_meta.cc | 18 +- src/pika_monitor_thread.cc | 193 ++ src/pika_partition.cc | 42 +- src/pika_pubsub.cc | 38 +- src/pika_repl_bgworker.cc | 18 +- src/pika_repl_client.cc | 28 +- src/pika_repl_client_conn.cc | 27 +- src/pika_repl_client_thread.cc | 2 +- src/pika_repl_server.cc | 7 +- src/pika_repl_server_conn.cc | 53 +- src/pika_repl_server_thread.cc | 3 +- src/pika_rm.cc | 64 +- src/pika_rsync_service.cc | 5 +- src/pika_server.cc | 135 +- src/pika_set.cc | 67 +- src/pika_slave_node.cc | 14 +- src/pika_stable_log.cc | 26 +- src/pika_statistic.cc | 6 +- src/pika_table.cc | 11 +- src/pika_zset.cc | 120 +- src/pstd/include/base_conf.h | 28 +- src/pstd/include/env.h | 46 +- src/pstd/include/lock_mgr.h | 10 +- src/pstd/include/mutex.h | 6 +- src/pstd/include/noncopyable.h | 23 + src/pstd/include/posix.h | 37 +- src/pstd/include/pstd_coding.h | 34 +- src/pstd/include/pstd_mutex.h | 24 +- src/pstd/include/pstd_slice.h | 16 +- src/pstd/include/pstd_status.h | 16 +- src/pstd/include/pstd_string.h | 10 +- src/pstd/include/random.h | 2 +- src/pstd/include/rsync.h | 7 +- src/pstd/include/scope_record_lock.h | 24 +- src/pstd/include/xdebug.h | 8 +- src/pstd/src/base_conf.cc | 151 +- src/pstd/src/env.cc | 119 +- src/pstd/src/lock_mgr.cc | 19 +- src/pstd/src/mutex_impl.cc | 14 +- src/pstd/src/posix.cc | 157 +- src/pstd/src/pstd_coding.cc | 22 +- src/pstd/src/pstd_hash.cc | 98 +- src/pstd/src/pstd_mutex.cc | 2 +- src/pstd/src/pstd_status.cc | 8 +- src/pstd/src/pstd_string.cc | 285 ++- src/pstd/src/rsync.cc | 5 +- src/pstd/src/scope_record_lock.cc | 9 +- src/pstd/src/testutil.cc | 6 +- src/pstd/tests/base_conf_test.cc | 4 +- src/pstd/tests/slash_coding_test.cc | 16 +- src/pstd/tests/slash_string_test.cc | 2 +- src/storage/include/storage/backupable.h | 10 +- src/storage/include/storage/db_checkpoint.h | 2 +- src/storage/include/storage/storage.h | 29 +- src/storage/src/backupable.cc | 8 +- src/storage/src/base_data_key_format.h | 10 +- src/storage/src/base_filter.h | 35 +- src/storage/src/base_meta_value_format.h | 22 +- src/storage/src/base_value_format.h | 8 +- src/storage/src/coding.h | 2 +- src/storage/src/custom_comparator.h | 24 +- src/storage/src/db_checkpoint.cc | 14 +- src/storage/src/lists_data_key_format.h | 4 +- src/storage/src/lists_filter.h | 14 +- src/storage/src/lists_meta_value_format.h | 26 +- src/storage/src/lru_cache.h | 30 +- src/storage/src/murmurhash.cc | 42 +- src/storage/src/murmurhash.h | 4 +- src/storage/src/options_helper.cc | 20 +- src/storage/src/redis.cc | 9 +- src/storage/src/redis.h | 2 +- src/storage/src/redis_hashes.cc | 52 +- src/storage/src/redis_hashes.h | 8 +- src/storage/src/redis_hyperloglog.cc | 10 +- src/storage/src/redis_hyperloglog.h | 4 +- src/storage/src/redis_lists.cc | 38 +- src/storage/src/redis_lists.h | 4 +- src/storage/src/redis_sets.cc | 57 +- src/storage/src/redis_sets.h | 6 +- src/storage/src/redis_strings.cc | 79 +- src/storage/src/redis_strings.h | 12 +- src/storage/src/redis_zsets.cc | 51 +- src/storage/src/redis_zsets.h | 14 +- src/storage/src/scope_record_lock.h | 2 + src/storage/src/scope_snapshot.h | 6 +- src/storage/src/storage.cc | 163 +- src/storage/src/storage_murmur3.h | 14 +- src/storage/src/strings_filter.h | 2 +- src/storage/src/strings_value_format.h | 4 +- src/storage/src/util.cc | 67 +- src/storage/src/zsets_data_key_format.h | 4 +- src/storage/src/zsets_filter.h | 4 +- src/storage/tests/hashes_test.cc | 23 +- src/storage/tests/hyperloglog_test.cc | 28 +- src/storage/tests/keys_test.cc | 2260 +++++++++-------- src/storage/tests/lists_filter_test.cc | 23 +- src/storage/tests/lists_test.cc | 53 +- src/storage/tests/options_test.cc | 6 +- src/storage/tests/sets_test.cc | 71 +- src/storage/tests/strings_filter_test.cc | 3 +- src/storage/tests/strings_test.cc | 18 +- src/storage/tests/zsets_test.cc | 87 +- tools/aof_to_pika/include/aof_sender.h | 10 +- tools/aof_to_pika/src/aof_info.cc | 15 +- tools/aof_to_pika/src/aof_lock.cc | 2 +- tools/aof_to_pika/src/aof_reader.cc | 31 +- tools/aof_to_pika/src/aof_sender.cc | 102 +- tools/benchmark_client/benchmark_client.cc | 12 +- tools/binlog_sender/binlog_consumer.cc | 10 +- tools/binlog_sender/binlog_sender.cc | 17 +- tools/binlog_sender/binlog_transverter.cc | 8 +- tools/binlog_sender/progress_thread.cc | 4 +- tools/binlog_sender/utils.cc | 16 +- .../manifest_generator/include/pika_binlog.h | 6 +- .../manifest_generator/manifest_generator.cc | 12 +- tools/manifest_generator/pika_binlog.cc | 21 +- .../pika_port_3/binlog_receiver_thread.cc | 2 +- .../pika_port_3/binlog_receiver_thread.h | 2 +- .../pika_port_3/binlog_transverter.cc | 8 +- tools/pika-port/pika_port_3/const.cc | 10 +- tools/pika-port/pika_port_3/main.cc | 21 +- tools/pika-port/pika_port_3/master_conn.cc | 11 +- tools/pika-port/pika_port_3/master_conn.h | 4 +- .../pika-port/pika_port_3/migrator_thread.cc | 46 +- tools/pika-port/pika_port_3/pika_binlog.cc | 25 +- tools/pika-port/pika_port_3/pika_binlog.h | 6 +- tools/pika-port/pika_port_3/pika_port.cc | 31 +- tools/pika-port/pika_port_3/pika_sender.cc | 17 +- tools/pika-port/pika_port_3/pika_sender.h | 2 +- tools/pika-port/pika_port_3/redis_sender.cc | 18 +- tools/pika-port/pika_port_3/trysync_thread.cc | 41 +- tools/pika-port/pika_port_3/trysync_thread.h | 2 +- tools/pika_to_txt/pika_to_txt.cc | 10 +- tools/pika_to_txt/scan_thread.cc | 6 +- tools/pika_to_txt/write_thread.cc | 8 +- tools/pika_to_txt/write_thread.h | 2 +- tools/rdb_to_pika/protocoltopika.cc | 5 +- tools/txt_to_pika/CMakeLists.txt | 3 +- tools/txt_to_pika/scan.cc | 6 +- tools/txt_to_pika/sender.cc | 19 +- tools/txt_to_pika/txt_to_pika.cc | 3 +- 253 files changed, 6309 insertions(+), 5349 deletions(-) create mode 100644 .clang-tidy create mode 100644 include/pika_monitor_thread.h create mode 100755 run_clang_tidy.py create mode 100644 src/pika_monitor_thread.cc create mode 100644 src/pstd/include/noncopyable.h diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..dd9e39d382 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,118 @@ +--- +Checks: ' + bugprone-*, + clang-analyzer-*, + google-*, + modernize-*, + performance-*, + portability-*, + readability-*, + -bugprone-easily-swappable-parameters, + -bugprone-implicit-widening-of-multiplication-result, + -bugprone-narrowing-conversions, + -bugprone-reserved-identifier, + -bugprone-signed-char-misuse, + -bugprone-suspicious-include, + -bugprone-unhandled-self-assignment, + -clang-analyzer-cplusplus.NewDelete, + -clang-analyzer-cplusplus.NewDeleteLeaks, + -clang-analyzer-security.insecureAPI.rand, + -clang-diagnostic-implicit-int-float-conversion, + -google-readability-avoid-underscore-in-googletest-name, + -modernize-avoid-c-arrays, + -modernize-use-nodiscard, + -readability-convert-member-functions-to-static, + -readability-identifier-length, + -readability-function-cognitive-complexity, + -readability-magic-numbers, + -readability-make-member-function-const, + -readability-qualified-auto, + -readability-redundant-access-specifiers, + -bugprone-exception-escape, + -modernize-use-trailing-return-type, + -readability-function-size, + -readability-else-after-return, + -bugprone-branch-clone, + -readability-use-anyofallof, + -google-default-arguments, + -clang-analyzer-cplusplus.InnerPointer, + -google-explicit-constructor, + -use_of_tag_name_without_tag, + -clang-analyzer-core.CallAndMessage, + -clang-analyzer-deadcode.DeadStores, + -google-runtime-int, + -clang-diagnostic-unused-command-line-argument, + -clang-diagnostic-ignored-optimization-argument, + -readability-implicit-bool-conversion, + ' +# CheckOptions: +# - { key: readability-identifier-naming.ClassCase, value: CamelCase } +# - { key: readability-identifier-naming.EnumCase, value: CamelCase } +# - { key: readability-identifier-naming.FunctionCase, value: CamelCase } +# - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } +# - { key: readability-identifier-naming.MemberCase, value: lower_case } +# - { key: readability-identifier-naming.MemberSuffix, value: _ } +# - { key: readability-identifier-naming.NamespaceCase, value: lower_case } +# - { key: readability-identifier-naming.StructCase, value: CamelCase } +# - { key: readability-identifier-naming.UnionCase, value: CamelCase } +# - { key: readability-identifier-naming.VariableCase, value: lower_case } + +WarningsAsErrors: '*' +# HeaderFilterRegex: '(|/src|/src/net|/src/pstd|/src/storage)/include' +# HeaderFilterRegex: '/src/(net|storage|pstd)/include' +AnalyzeTemporaryDtors: true + +#### Disabled checks and why: ##### +# +# -readability-convert-member-functions-to-static, +# This check started going off in the upgrade from clang-tidy-8 to clang-tidy-12. It is not always correct because +# we hide the reference implementation in another repository. +# -clang-analyzer-security.insecureAPI.rand, -clang-analyzer-security.insecureAPI.rand, -bugprone-unhandled-self-assignment, +# -bugprone-implicit-widening-of-multiplication-result +# These have not been investigated yet. +# -bugprone-reserved-identifier, +# Fails due to use of some __SHORT_FILE__ symbol, originating from very old code. +# -bugprone-suspicious-include, +# False positive due to GTest code. +# -bugprone-too-small-loop-variable, +# Complains about uint8_t or uint16_t when the limit on the loop is a container's .size() (size_t). +# We usually do this when we know the maximum size of the container though, so propose leaving disabled. +# -clang-analyzer-cplusplus.NewDelete, +# Seems to generate false positives. Suggest relying on ASAN and valgrind for memory stuff. +# -clang-analyzer-cplusplus.NewDeleteLeaks, +# Seems to generate false positives. Suggest relying on ASAN and valgrind for memory stuff. +# -modernize-use-nodiscard, +# New C++17 feature, slightly polarizing. Would clutter codebase. +# -modernize-avoid-c-arrays, +# Let's not deal with people doing ridiculous things to hack around this. If it bites them, it bites them. +# -bugprone-signed-char-misuse, -clang-diagnostic-implicit-int-float-conversion, -readability-make-member-function-const, +# -readability-qualified-auto, -readability-redundant-access-specifiers +# These were previously disabled for not being available in clang-tidy-8. They are now available on our clang-tidy-12, +# and potentially worth investigating/fixing. +# -bugprone-exception-escape +# Weird. No idea how to resolve. +# -bugprone-branch-clone, +# frequent misidentification +# -google-default-arguments +# Too many virtual functions in pika have default parameters, specifically void Do(std::shared_ptr partition = nullptr) +# -clang-analyzer-cplusplus.InnerPointer +# I don't know why this bug in the RocksDB library fails to suppress detection.So I have to disable this check. +#--google-explicit-constructor +# There are so many implicit convert in pika +#--use_of_tag_name_without_tag +# like class member is class , If there is no class tag, an error will be reported +# class A{ B b_; } -> error ; class A{ class B b_; } -> no error ; +#-clang-analyzer-core.CallAndMessage +# pika/src/storage/src/scope_record_lock.h +# Always detect a null pointer and call the TryLock method +# Called C++ object pointer is null [clang-analyzer-core.CallAndMessage,-warnings-as-errors] +# lock_mgr_->UnLock(key); +#-clang-analyzer-deadcode.DeadStores +# error detection in some places +#-google-runtime-int +# todo discussed, because there are so many of `long` and `long long` in pika, so disable for now +#-clang-diagnostic-unused-command-line-argument +# because there are to many compile command error in github ci, but no error in local environment +# See in build folder compile_commands.json +#-clang-diagnostic-ignored-optimization-argument +# The reason disabled this is same as above. \ No newline at end of file diff --git a/.github/workflows/pika.yml b/.github/workflows/pika.yml index fe3002e574..0543b19d48 100644 --- a/.github/workflows/pika.yml +++ b/.github/workflows/pika.yml @@ -101,4 +101,4 @@ jobs: run: | cd ${{github.workspace}}/build source /opt/rh/devtoolset-10/enable - ctest -C ${{env.BUILD_TYPE}} + ctest -C ${{env.BUILD_TYPE}} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index a60aeb6ae2..f178f3eb78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,26 @@ if (${AUTOCONF} MATCHES AUTOCONF-NOTFOUND) message(FATAL_ERROR "not find autoconf on localhost") endif() +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 () + + include(protogen.cmake) include(ExternalProject) @@ -750,3 +770,20 @@ target_link_libraries(${PROJECT_NAME} ${JEMALLOC_LIBRARY}) option(USE_SSL "Enable SSL support" OFF) +add_custom_target( + clang-tidy + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_clang_tidy.py + -clang-tidy-binary ${CLANG_TIDY_BIN} + -header-filter='${PROJECT_SOURCE_DIR}(/include|/tools|/src)/.*' + -p ${CMAKE_BINARY_DIR} + -quiet + ) + +add_custom_target(clang-tidy-fix + ${CMAKE_CURRENT_SOURCE_DIR}/run_clang_tidy.py + -clang-tidy-binary ${CLANG_TIDY_BIN} + -p ${CMAKE_BINARY_DIR} + -header-filter='${PROJECT_SOURCE_DIR}(/include|/tools|/src)/.*' + -clang-apply-replacements-binary ${CLANG_APPLY_REPLACEMENTS_BIN} + -fix +) \ No newline at end of file diff --git a/include/pika_admin.h b/include/pika_admin.h index da0776e59e..1ebdac6182 100644 --- a/include/pika_admin.h +++ b/include/pika_admin.h @@ -20,18 +20,18 @@ */ class SlaveofCmd : public Cmd { public: - SlaveofCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), is_none_(false) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SlaveofCmd(*this); } + SlaveofCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SlaveofCmd(*this); } private: std::string master_ip_; int64_t master_port_ = -1; bool is_none_ = false; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { is_none_ = false; master_ip_.clear(); master_port_ = 0; @@ -41,10 +41,10 @@ class SlaveofCmd : public Cmd { class DbSlaveofCmd : public Cmd { public: DbSlaveofCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new DbSlaveofCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new DbSlaveofCmd(*this); } private: std::string db_name_; @@ -53,8 +53,8 @@ class DbSlaveofCmd : public Cmd { bool have_offset_ = false; int64_t filenum_ = 0; int64_t offset_ = 0; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { db_name_.clear(); force_sync_ = false; is_none_ = false; @@ -65,41 +65,41 @@ class DbSlaveofCmd : public Cmd { class AuthCmd : public Cmd { public: AuthCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new AuthCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new AuthCmd(*this); } private: std::string pwd_; - virtual void DoInitial() override; + void DoInitial() override; }; class BgsaveCmd : public Cmd { public: BgsaveCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new BgsaveCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new BgsaveCmd(*this); } private: - virtual void DoInitial() override; - virtual void Clear() { bgsave_tables_.clear(); } + void DoInitial() override; + void Clear() override { bgsave_tables_.clear(); } std::set bgsave_tables_; }; class CompactCmd : public Cmd { public: CompactCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new CompactCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new CompactCmd(*this); } private: - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { struct_type_.clear(); compact_tables_.clear(); } @@ -109,85 +109,85 @@ class CompactCmd : public Cmd { class PurgelogstoCmd : public Cmd { public: - PurgelogstoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), num_(0) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PurgelogstoCmd(*this); } + PurgelogstoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PurgelogstoCmd(*this); } private: uint32_t num_ = 0; std::string table_; - virtual void DoInitial() override; + void DoInitial() override; }; class PingCmd : public Cmd { public: PingCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PingCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PingCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class SelectCmd : public Cmd { public: SelectCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SelectCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SelectCmd(*this); } private: - virtual void DoInitial() override; - virtual void Clear() { table_name_.clear(); } + void DoInitial() override; + void Clear() override { table_name_.clear(); } std::string table_name_; }; class FlushallCmd : public Cmd { public: FlushallCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new FlushallCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new FlushallCmd(*this); } private: - virtual void DoInitial() override; - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + void DoInitial() override; + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class FlushdbCmd : public Cmd { public: FlushdbCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new FlushdbCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new FlushdbCmd(*this); } private: std::string db_name_; - virtual void DoInitial() override; - virtual void Clear() { db_name_.clear(); } + void DoInitial() override; + void Clear() override { db_name_.clear(); } }; class ClientCmd : public Cmd { public: ClientCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); + void Do(std::shared_ptr partition = nullptr) override; const static std::string CLIENT_LIST_S; const static std::string CLIENT_KILL_S; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ClientCmd(*this); } + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ClientCmd(*this); } private: std::string operation_, info_; - virtual void DoInitial() override; + void DoInitial() override; }; class InfoCmd : public Cmd { @@ -208,11 +208,11 @@ class InfoCmd : public Cmd { kInfoDebug }; - InfoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), rescan_(false), off_(false) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new InfoCmd(*this); } + InfoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new InfoCmd(*this); } private: InfoSection info_section_; @@ -232,8 +232,8 @@ class InfoCmd : public Cmd { const static std::string kDataSection; const static std::string kDebugSection; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { rescan_ = false; off_ = false; keyspace_scan_tables_.clear(); @@ -254,26 +254,26 @@ class InfoCmd : public Cmd { class ShutdownCmd : public Cmd { public: ShutdownCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ShutdownCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ShutdownCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ConfigCmd : public Cmd { public: ConfigCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ConfigCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ConfigCmd(*this); } private: std::vector config_args_v_; - virtual void DoInitial() override; + void DoInitial() override; void ConfigGet(std::string& ret); void ConfigSet(std::string& ret); void ConfigRewrite(std::string& ret); @@ -283,92 +283,92 @@ class ConfigCmd : public Cmd { class MonitorCmd : public Cmd { public: MonitorCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new MonitorCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new MonitorCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class DbsizeCmd : public Cmd { public: DbsizeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new DbsizeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new DbsizeCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class TimeCmd : public Cmd { public: TimeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new TimeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new TimeCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class DelbackupCmd : public Cmd { public: DelbackupCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new DelbackupCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new DelbackupCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class EchoCmd : public Cmd { public: EchoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new EchoCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new EchoCmd(*this); } private: std::string body_; - virtual void DoInitial() override; + void DoInitial() override; }; class ScandbCmd : public Cmd { public: - ScandbCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), type_(storage::kAll) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ScandbCmd(*this); } + ScandbCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ScandbCmd(*this); } private: storage::DataType type_ = storage::kAll; - virtual void DoInitial() override; - virtual void Clear() { type_ = storage::kAll; } + void DoInitial() override; + void Clear() override { type_ = storage::kAll; } }; class SlowlogCmd : public Cmd { public: enum SlowlogCondition { kGET, kLEN, kRESET }; - SlowlogCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), condition_(kGET) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SlowlogCmd(*this); } + SlowlogCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SlowlogCmd(*this); } private: int64_t number_ = 10; SlowlogCmd::SlowlogCondition condition_ = kGET; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { number_ = 10; condition_ = kGET; } @@ -377,66 +377,66 @@ class SlowlogCmd : public Cmd { class PaddingCmd : public Cmd { public: PaddingCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PaddingCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PaddingCmd(*this); } private: - virtual void DoInitial(); - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + void DoInitial() override; + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class PKPatternMatchDelCmd : public Cmd { public: PKPatternMatchDelCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PKPatternMatchDelCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PKPatternMatchDelCmd(*this); } private: storage::DataType type_ = storage::kAll; std::string pattern_; - virtual void DoInitial() override; + void DoInitial() override; }; class DummyCmd : public Cmd { public: DummyCmd() : Cmd("", 0, 0) {} DummyCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new DummyCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new DummyCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class QuitCmd : public Cmd { public: QuitCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new QuitCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new QuitCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class HelloCmd : public Cmd { public: HelloCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HelloCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HelloCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; #endif // PIKA_ADMIN_H_ diff --git a/include/pika_auxiliary_thread.h b/include/pika_auxiliary_thread.h index 5802bca902..ab0fa6aea2 100644 --- a/include/pika_auxiliary_thread.h +++ b/include/pika_auxiliary_thread.h @@ -13,12 +13,12 @@ class PikaAuxiliaryThread : public net::Thread { public: PikaAuxiliaryThread() { set_thread_name("AuxiliaryThread"); } - virtual ~PikaAuxiliaryThread(); + ~PikaAuxiliaryThread() override; pstd::Mutex mu_; pstd::CondVar cv_; private: - virtual void* ThreadMain(); + void* ThreadMain() override; }; #endif diff --git a/include/pika_binlog.h b/include/pika_binlog.h index ecbc3d4ceb..bcc130d1b3 100644 --- a/include/pika_binlog.h +++ b/include/pika_binlog.h @@ -11,23 +11,22 @@ #include "pstd/include/env.h" #include "pstd/include/pstd_mutex.h" #include "pstd/include/pstd_status.h" +#include "pstd/include/noncopyable.h" #include "include/pika_define.h" -using pstd::Slice; -using pstd::Status; -std::string NewFileName(const std::string name, const uint32_t current); +std::string NewFileName(const std::string& name, uint32_t current); -class Version { +class Version final : public pstd::noncopyable { public: - Version(std::shared_ptr save); + Version(const std::shared_ptr& save); ~Version(); - Status Init(); + pstd::Status Init(); // RWLock should be held when access members. - Status StableSave(); + pstd::Status StableSave(); uint32_t pro_num_ = 0; uint64_t pro_offset_ = 0; @@ -38,35 +37,31 @@ class Version { void debug() { std::shared_lock l(rwlock_); - printf("Current pro_num %u pro_offset %lu\n", pro_num_, pro_offset_); + printf("Current pro_num %u pro_offset %llu\n", pro_num_, pro_offset_); } private: // shared with versionfile_ std::shared_ptr save_; - - // No copying allowed; - Version(const Version&); - void operator=(const Version&); }; -class Binlog { +class Binlog : public pstd::noncopyable { public: - Binlog(const std::string& Binlog_path, const int file_size = 100 * 1024 * 1024); + Binlog(std::string Binlog_path, int file_size = 100 * 1024 * 1024); ~Binlog(); void Lock() { mutex_.lock(); } void Unlock() { mutex_.unlock(); } - Status Put(const std::string& item); + pstd::Status Put(const std::string& item); - Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32_t* term = nullptr, uint64_t* logic_id = nullptr); + pstd::Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32_t* term = nullptr, uint64_t* logic_id = nullptr); /* * Set Producer pro_num and pro_offset with lock */ - Status SetProducerStatus(uint32_t filenum, uint64_t pro_offset, uint32_t term = 0, uint64_t index = 0); + pstd::Status SetProducerStatus(uint32_t pro_num, uint64_t pro_offset, uint32_t term = 0, uint64_t index = 0); // Need to hold Lock(); - Status Truncate(uint32_t pro_num, uint64_t pro_offset, uint64_t index); + pstd::Status Truncate(uint32_t pro_num, uint64_t pro_offset, uint64_t index); uint64_t file_size() { return file_size_; } @@ -89,17 +84,17 @@ class Binlog { void Close(); private: - Status Put(const char* item, int len); - static Status AppendPadding(pstd::WritableFile* file, uint64_t* len); + pstd::Status Put(const char* item, int len); + static pstd::Status AppendPadding(pstd::WritableFile* file, uint64_t* len); // pstd::WritableFile *queue() { return queue_; } void InitLogFile(); - Status EmitPhysicalRecord(RecordType t, const char* ptr, size_t n, int* temp_pro_offset); + pstd::Status EmitPhysicalRecord(RecordType t, const char* ptr, size_t n, int* temp_pro_offset); /* * Produce */ - Status Produce(const Slice& item, int* pro_offset); + pstd::Status Produce(const pstd::Slice& item, int* pro_offset); std::atomic opened_; @@ -125,10 +120,6 @@ class Binlog { std::atomic binlog_io_error_; // Not use // int32_t retry_; - - // No copying allowed - Binlog(const Binlog&); - void operator=(const Binlog&); }; #endif diff --git a/include/pika_binlog_reader.h b/include/pika_binlog_reader.h index a12e2dc0f4..9a9d41ad0d 100644 --- a/include/pika_binlog_reader.h +++ b/include/pika_binlog_reader.h @@ -24,16 +24,17 @@ class PikaBinlogReader { PikaBinlogReader(uint32_t cur_filenum, uint64_t cur_offset); PikaBinlogReader(); ~PikaBinlogReader() {}; + Status Get(std::string* scratch, uint32_t* filenum, uint64_t* offset); - int Seek(std::shared_ptr logger, uint32_t filenum, uint64_t offset); + int Seek(const std::shared_ptr& logger, uint32_t filenum, uint64_t offset); bool ReadToTheEnd(); void GetReaderStatus(uint32_t* cur_filenum, uint64_t* cur_offset); private: bool GetNext(uint64_t* size); - unsigned int ReadPhysicalRecord(pstd::Slice* redult, uint32_t* filenum, uint64_t* offset); + unsigned int ReadPhysicalRecord(pstd::Slice* result, uint32_t* filenum, uint64_t* offset); // Returns scratch binflog and corresponding offset - Status Consume(std::string* scratch, uint32_t* filenum, uint64_t* offset); + pstd::Status Consume(std::string* scratch, uint32_t* filenum, uint64_t* offset); std::shared_mutex rwlock_; uint32_t cur_filenum_ = 0; diff --git a/include/pika_binlog_transverter.h b/include/pika_binlog_transverter.h index 2231914a9e..d85d958667 100644 --- a/include/pika_binlog_transverter.h +++ b/include/pika_binlog_transverter.h @@ -7,7 +7,7 @@ #define PIKA_BINLOG_TRANSVERTER_H_ #include -#include +#include #include #include @@ -32,7 +32,7 @@ const int SPACE_STROE_PARAMETER_LENGTH = 5; class BinlogItem { public: - BinlogItem() : exec_time_(0), term_id_(0), logic_id_(0), filenum_(0), offset_(0), content_("") {} + BinlogItem() = default; friend class PikaBinlogTransverter; @@ -62,7 +62,7 @@ class BinlogItem { class PikaBinlogTransverter { public: - PikaBinlogTransverter(){}; + PikaBinlogTransverter()= default;; static std::string BinlogEncode(BinlogType type, uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset, const std::string& content, const std::vector& extends); diff --git a/include/pika_bit.h b/include/pika_bit.h index db91df3b86..8afa557167 100644 --- a/include/pika_bit.h +++ b/include/pika_bit.h @@ -17,90 +17,90 @@ class BitGetCmd : public Cmd { public: BitGetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new BitGetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new BitGetCmd(*this); } private: std::string key_; int64_t bit_offset_ = -1; - virtual void Clear() { + void Clear() override { key_ = ""; bit_offset_ = -1; } - virtual void DoInitial() override; + void DoInitial() override; }; class BitSetCmd : public Cmd { public: BitSetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new BitSetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new BitSetCmd(*this); } private: std::string key_; int64_t bit_offset_; int64_t on_; - virtual void Clear() { + void Clear() override { key_ = ""; bit_offset_ = -1; on_ = -1; } - virtual void DoInitial() override; + void DoInitial() override; }; class BitCountCmd : public Cmd { public: BitCountCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new BitCountCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new BitCountCmd(*this); } private: std::string key_; bool count_all_; int64_t start_offset_; int64_t end_offset_; - virtual void Clear() { + void Clear() override { key_ = ""; count_all_ = false; start_offset_ = -1; end_offset_ = -1; } - virtual void DoInitial() override; + void DoInitial() override; }; class BitPosCmd : public Cmd { public: BitPosCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new BitPosCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new BitPosCmd(*this); } private: std::string key_; @@ -109,7 +109,7 @@ class BitPosCmd : public Cmd { int64_t bit_val_; int64_t start_offset_; int64_t end_offset_; - virtual void Clear() { + void Clear() override { key_ = ""; pos_all_ = false; endoffset_set_ = false; @@ -117,26 +117,26 @@ class BitPosCmd : public Cmd { start_offset_ = -1; end_offset_ = -1; } - virtual void DoInitial() override; + void DoInitial() override; }; class BitOpCmd : public Cmd { public: BitOpCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new BitOpCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new BitOpCmd(*this); } private: std::string dest_key_; std::vector src_keys_; storage::BitOpType op_; - virtual void Clear() { + void Clear() override { dest_key_ = ""; src_keys_.clear(); op_ = storage::kBitOpDefault; } - virtual void DoInitial() override; + void DoInitial() override; }; #endif diff --git a/include/pika_client_conn.h b/include/pika_client_conn.h index 86d7934d28..c6245baae7 100644 --- a/include/pika_client_conn.h +++ b/include/pika_client_conn.h @@ -6,6 +6,8 @@ #ifndef PIKA_CLIENT_CONN_H_ #define PIKA_CLIENT_CONN_H_ +#include + #include "include/pika_command.h" class PikaClientConn : public net::RedisConn { @@ -26,8 +28,8 @@ class PikaClientConn : public net::RedisConn { class AuthStat { public: void Init(); - bool IsAuthed(const std::shared_ptr cmd_ptr); - bool ChecknUpdate(const std::string& arg); + bool IsAuthed(const std::shared_ptr& cmd_ptr); + bool ChecknUpdate(const std::string& message); private: enum StatType { @@ -38,22 +40,22 @@ class PikaClientConn : public net::RedisConn { StatType stat_; }; - PikaClientConn(int fd, std::string ip_port, net::Thread* server_thread, net::NetMultiplexer* mpx, - const net::HandleType& handle_type, int max_conn_rubf_size); - virtual ~PikaClientConn() {} + PikaClientConn(int fd, const std::string& ip_port, net::Thread* server_thread, net::NetMultiplexer* mpx, + const net::HandleType& handle_type, int max_conn_rbuf_size); + ~PikaClientConn() override = default; - virtual void ProcessRedisCmds(const std::vector& argvs, bool async, + void ProcessRedisCmds(const std::vector& argvs, bool async, std::string* response) override; void BatchExecRedisCmd(const std::vector& argvs); - int DealMessage(const net::RedisCmdArgsType& argv, std::string* response) { return 0; } + int DealMessage(const net::RedisCmdArgsType& argv, std::string* response) override { return 0; } static void DoBackgroundTask(void* arg); static void DoExecTask(void* arg); bool IsPubSub() { return is_pubsub_; } void SetIsPubSub(bool is_pubsub) { is_pubsub_ = is_pubsub; } void SetCurrentTable(const std::string& table_name) { current_table_ = table_name; } - void SetWriteCompleteCallback(WriteCompleteCallback cb) { write_completed_cb_ = cb; } + void SetWriteCompleteCallback(WriteCompleteCallback cb) { write_completed_cb_ = std::move(cb); } net::ServerThread* server_thread() { return server_thread_; } @@ -69,12 +71,12 @@ class PikaClientConn : public net::RedisConn { bool is_pubsub_ = false; std::shared_ptr DoCmd(const PikaCmdArgsType& argv, const std::string& opt, - std::shared_ptr resp_ptr); + const std::shared_ptr& resp_ptr); void ProcessSlowlog(const PikaCmdArgsType& argv, uint64_t start_us, uint64_t do_duration); void ProcessMonitor(const PikaCmdArgsType& argv); - void ExecRedisCmd(const PikaCmdArgsType& argv, std::shared_ptr resp_ptr); + void ExecRedisCmd(const PikaCmdArgsType& argv, const std::shared_ptr& resp_ptr); void TryWriteResp(); AuthStat auth_stat_; diff --git a/include/pika_command.h b/include/pika_command.h index 97f588ee41..6d9b7238bd 100644 --- a/include/pika_command.h +++ b/include/pika_command.h @@ -7,7 +7,9 @@ #define PIKA_COMMAND_H_ #include +#include #include + #include "net/include/net_conn.h" #include "net/include/redis_conn.h" #include "pstd/include/pstd_string.h" @@ -191,7 +193,7 @@ const std::string kCmdNamePSubscribe = "psubscribe"; const std::string kCmdNamePUnSubscribe = "punsubscribe"; const std::string kClusterPrefix = "pkcluster"; -typedef net::RedisCmdArgsType PikaCmdArgsType; +using PikaCmdArgsType = net::RedisCmdArgsType; static const int RAW_ARGS_LEN = 1024 * 1024; enum CmdFlagsMask { @@ -263,7 +265,7 @@ class CmdRes { kErrOther }; - CmdRes() : ret_(kNone) {} + CmdRes() = default; bool none() const { return ret_ == kNone && message_.empty(); } bool ok() const { return ret_ == kOk || ret_ == kNone; } @@ -353,7 +355,7 @@ class CmdRes { AppendContent(value); } void AppendStringRaw(const std::string& value) { message_.append(value); } - void SetRes(CmdRet _ret, const std::string content = "") { + void SetRes(CmdRet _ret, const std::string& content = "") { ret_ = _ret; if (!content.empty()) { message_ = content; @@ -369,7 +371,7 @@ class Cmd : public std::enable_shared_from_this { public: enum CmdStage { kNone, kBinlogStage, kExecuteStage }; struct HintKeys { - HintKeys() {} + HintKeys() = default; void Push(const std::string& key, int hint) { keys.push_back(key); hints.push_back(hint); @@ -379,17 +381,17 @@ class Cmd : public std::enable_shared_from_this { std::vector hints; }; struct ProcessArg { - ProcessArg() {} + ProcessArg() = default; ProcessArg(std::shared_ptr _partition, std::shared_ptr _sync_partition, HintKeys _hint_keys) - : partition(_partition), sync_partition(_sync_partition), hint_keys(_hint_keys) {} + : partition(std::move(_partition)), sync_partition(std::move(_sync_partition)), hint_keys(std::move(_hint_keys)) {} std::shared_ptr partition; std::shared_ptr sync_partition; HintKeys hint_keys; }; - Cmd(const std::string& name, int arity, uint16_t flag) - : name_(name), arity_(arity), flag_(flag), stage_(kNone), do_duration_(0) {} - virtual ~Cmd() {} + Cmd(std::string name, int arity, uint16_t flag) + : name_(std::move(name)), arity_(arity), flag_(flag) {} + virtual ~Cmd() = default; virtual std::vector current_key() const; virtual void Execute(); @@ -424,10 +426,10 @@ class Cmd : public std::enable_shared_from_this { virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset); - void SetConn(const std::shared_ptr conn); + void SetConn(const std::shared_ptr& conn); std::shared_ptr GetConn(); - void SetResp(const std::shared_ptr resp); + void SetResp(const std::shared_ptr& resp); std::shared_ptr GetResp(); void SetStage(CmdStage stage); @@ -435,12 +437,12 @@ class Cmd : public std::enable_shared_from_this { protected: // enable copy, used default copy // Cmd(const Cmd&); - void ProcessCommand(std::shared_ptr partition, std::shared_ptr sync_partition, + void ProcessCommand(const std::shared_ptr& partition, const std::shared_ptr& sync_partition, const HintKeys& hint_key = HintKeys()); - void InternalProcessCommand(std::shared_ptr partition, std::shared_ptr sync_partition, + void InternalProcessCommand(const std::shared_ptr& partition, const std::shared_ptr& sync_partition, const HintKeys& hint_key); - void DoCommand(std::shared_ptr partition, const HintKeys& hint_key); - void DoBinlog(std::shared_ptr partition); + void DoCommand(const std::shared_ptr& partition, const HintKeys& hint_key); + void DoBinlog(const std::shared_ptr& partition); bool CheckArg(int num) const; void LogCommand() const; @@ -464,7 +466,7 @@ class Cmd : public std::enable_shared_from_this { Cmd& operator=(const Cmd&); }; -typedef std::unordered_map> CmdTable; +using CmdTable = std::unordered_map>; // Method for Cmd Table void InitCmdTable(CmdTable* cmd_table); diff --git a/include/pika_conf.h b/include/pika_conf.h index 242072aba0..c7d9b26a73 100644 --- a/include/pika_conf.h +++ b/include/pika_conf.h @@ -26,7 +26,7 @@ class PikaConf : public pstd::BaseConf { public: PikaConf(const std::string& path); - ~PikaConf(){}; + ~PikaConf() override {} // Getter int port() { @@ -133,7 +133,7 @@ class PikaConf : public pstd::BaseConf { std::shared_lock l(rwlock_); return userpass_; } - const std::string suser_blacklist() { + std::string suser_blacklist() { std::shared_lock l(rwlock_); return pstd::StringConcat(user_blacklist_, COMMA); } @@ -313,7 +313,7 @@ class PikaConf : public pstd::BaseConf { std::lock_guard l(rwlock_); thread_pool_size_ = value; } - void SetSlaveof(const std::string value) { + void SetSlaveof(const std::string& value) { std::lock_guard l(rwlock_); TryPushDiffCommands("slaveof", value); slaveof_ = value; @@ -326,7 +326,7 @@ class PikaConf : public pstd::BaseConf { void SetWriteBinlog(const std::string& value) { std::lock_guard l(rwlock_); TryPushDiffCommands("write-binlog", value); - write_binlog_ = (value == "yes") ? true : false; + write_binlog_ = value == "yes"; } void SetMaxCacheStatisticKeys(const int value) { std::lock_guard l(rwlock_); @@ -405,7 +405,7 @@ class PikaConf : public pstd::BaseConf { } void SetSlowlogWriteErrorlog(const bool value) { std::lock_guard l(rwlock_); - TryPushDiffCommands("slowlog-write-errorlog", value == true ? "yes" : "no"); + TryPushDiffCommands("slowlog-write-errorlog", value ? "yes" : "no"); slowlog_write_errorlog_.store(value); } void SetSlowlogSlowerThan(const int value) { @@ -467,20 +467,20 @@ class PikaConf : public pstd::BaseConf { arena_block_size_ = value; } - Status TablePartitionsSanityCheck(const std::string& table_name, const std::set& partition_ids, + pstd::Status TablePartitionsSanityCheck(const std::string& table_name, const std::set& partition_ids, bool is_add); - Status AddTablePartitions(const std::string& table_name, const std::set& partition_ids); - Status RemoveTablePartitions(const std::string& table_name, const std::set& partition_ids); - Status AddTable(const std::string& table_name, uint32_t slot_num); - Status AddTableSanityCheck(const std::string& table_name); - Status DelTable(const std::string& table_name); - Status DelTableSanityCheck(const std::string& table_name); + pstd::Status AddTablePartitions(const std::string& table_name, const std::set& partition_ids); + pstd::Status RemoveTablePartitions(const std::string& table_name, const std::set& partition_ids); + pstd::Status AddTable(const std::string& table_name, uint32_t slot_num); + pstd::Status AddTableSanityCheck(const std::string& table_name); + pstd::Status DelTable(const std::string& table_name); + pstd::Status DelTableSanityCheck(const std::string& table_name); int Load(); int ConfigRewrite(); private: - Status InternalGetTargetTable(const std::string& table_name, uint32_t* const target); + pstd::Status InternalGetTargetTable(const std::string& table_name, uint32_t* target); int port_ = 0; std::string slaveof_; diff --git a/include/pika_consensus.h b/include/pika_consensus.h index bea3534cea..d7552f7985 100644 --- a/include/pika_consensus.h +++ b/include/pika_consensus.h @@ -5,6 +5,8 @@ #ifndef PIKA_CONSENSUS_H_ #define PIKA_CONSENSUS_H_ +#include + #include "include/pika_binlog_transverter.h" #include "include/pika_client_conn.h" #include "include/pika_define.h" @@ -12,16 +14,16 @@ #include "include/pika_stable_log.h" #include "pstd/include/env.h" -class Context final { +class Context : public pstd::noncopyable { public: - Context(const std::string path); + Context(std::string path); - Status Init(); + pstd::Status Init(); // RWLock should be held when access members. - Status StableSave(); + pstd::Status StableSave(); void PrepareUpdateAppliedIndex(const LogOffset& offset); void UpdateAppliedIndex(const LogOffset& offset); - void Reset(const LogOffset& applied_index); + void Reset(const LogOffset& offset); std::shared_mutex rwlock_; LogOffset applied_index_; @@ -38,9 +40,6 @@ class Context final { private: std::string path_; std::unique_ptr save_; - // No copying allowed; - Context(const Context&); - void operator=(const Context&); }; class SyncProgress { @@ -50,15 +49,15 @@ class SyncProgress { std::shared_ptr GetSlaveNode(const std::string& ip, int port); std::unordered_map> GetAllSlaveNodes(); std::unordered_map GetAllMatchIndex(); - Status AddSlaveNode(const std::string& ip, int port, const std::string& table_name, uint32_t partition_id, + pstd::Status AddSlaveNode(const std::string& ip, int port, const std::string& table_name, uint32_t partition_id, int session_id); - Status RemoveSlaveNode(const std::string& ip, int port); - Status Update(const std::string& ip, int port, const LogOffset& start, const LogOffset& end, + pstd::Status RemoveSlaveNode(const std::string& ip, int port); + pstd::Status Update(const std::string& ip, int port, const LogOffset& start, const LogOffset& end, LogOffset* committed_index); int SlaveSize(); private: - LogOffset InternalCalCommittedIndex(std::unordered_map match_index); + LogOffset InternalCalCommittedIndex(const std::unordered_map& match_index); std::shared_mutex rwlock_; std::unordered_map> slaves_; @@ -68,9 +67,9 @@ class SyncProgress { class MemLog { public: struct LogItem { - LogItem(LogOffset _offset, std::shared_ptr _cmd_ptr, std::shared_ptr _conn_ptr, + LogItem(const LogOffset& _offset, std::shared_ptr _cmd_ptr, std::shared_ptr _conn_ptr, std::shared_ptr _resp_ptr) - : offset(_offset), cmd_ptr(_cmd_ptr), conn_ptr(_conn_ptr), resp_ptr(_resp_ptr) {} + : offset(_offset), cmd_ptr(std::move(_cmd_ptr)), conn_ptr(std::move(_conn_ptr)), resp_ptr(std::move(_resp_ptr)) {} LogOffset offset; std::shared_ptr cmd_ptr; std::shared_ptr conn_ptr; @@ -84,9 +83,9 @@ class MemLog { logs_.push_back(item); last_offset_ = item.offset; } - Status PurgeLogs(const LogOffset& offset, std::vector* logs); - Status GetRangeLogs(int start, int end, std::vector* logs); - Status TruncateTo(const LogOffset& offset); + pstd::Status PurgeLogs(const LogOffset& offset, std::vector* logs); + pstd::Status GetRangeLogs(int start, int end, std::vector* logs); + pstd::Status TruncateTo(const LogOffset& offset); void Reset(const LogOffset& offset); @@ -115,24 +114,24 @@ class ConsensusCoordinator { // since it is invoked in constructor all locks not hold void Init(); // invoked by dbsync process - Status Reset(const LogOffset& offset); + pstd::Status Reset(const LogOffset& offset); - Status ProposeLog(std::shared_ptr cmd_ptr, std::shared_ptr conn_ptr, + pstd::Status ProposeLog(const std::shared_ptr& cmd_ptr, std::shared_ptr conn_ptr, std::shared_ptr resp_ptr); - Status UpdateSlave(const std::string& ip, int port, const LogOffset& start, const LogOffset& end); - Status AddSlaveNode(const std::string& ip, int port, int session_id); - Status RemoveSlaveNode(const std::string& ip, int port); + pstd::Status UpdateSlave(const std::string& ip, int port, const LogOffset& start, const LogOffset& end); + pstd::Status AddSlaveNode(const std::string& ip, int port, int session_id); + pstd::Status RemoveSlaveNode(const std::string& ip, int port); void UpdateTerm(uint32_t term); uint32_t term(); - Status CheckEnoughFollower(); + pstd::Status CheckEnoughFollower(); // invoked by follower - Status ProcessLeaderLog(std::shared_ptr cmd_ptr, const BinlogItem& attribute); - Status ProcessLocalUpdate(const LogOffset& leader_commit); + pstd::Status ProcessLeaderLog(const std::shared_ptr& cmd_ptr, const BinlogItem& attribute); + pstd::Status ProcessLocalUpdate(const LogOffset& leader_commit); // Negotiate - Status LeaderNegotiate(const LogOffset& f_last_offset, bool* reject, std::vector* hints); - Status FollowerNegotiate(const std::vector& hints, LogOffset* reply_offset); + pstd::Status LeaderNegotiate(const LogOffset& f_last_offset, bool* reject, std::vector* hints); + pstd::Status FollowerNegotiate(const std::vector& hints, LogOffset* reply_offset); SyncProgress& SyncPros() { return sync_pros_; } std::shared_ptr StableLogger() { return stable_logger_; } @@ -152,7 +151,7 @@ class ConsensusCoordinator { // redis parser cb struct CmdPtrArg { - CmdPtrArg(std::shared_ptr ptr) : cmd_ptr(ptr) {} + CmdPtrArg(std::shared_ptr ptr) : cmd_ptr(std::move(ptr)) {} std::shared_ptr cmd_ptr; }; static int InitCmd(net::RedisParser* parser, const net::RedisCmdArgsType& argv); @@ -181,27 +180,27 @@ class ConsensusCoordinator { } private: - Status ScheduleApplyLog(const LogOffset& committed_index); - Status ScheduleApplyFollowerLog(const LogOffset& committed_index); + pstd::Status ScheduleApplyLog(const LogOffset& committed_index); + pstd::Status ScheduleApplyFollowerLog(const LogOffset& committed_index); bool MatchConsensusLevel(); - Status TruncateTo(const LogOffset& offset); + pstd::Status TruncateTo(const LogOffset& offset); - Status InternalAppendLog(const BinlogItem& item, std::shared_ptr cmd_ptr, + pstd::Status InternalAppendLog(const BinlogItem& item, const std::shared_ptr& cmd_ptr, std::shared_ptr conn_ptr, std::shared_ptr resp_ptr); - Status InternalAppendBinlog(const BinlogItem& item, std::shared_ptr cmd_ptr, LogOffset* log_offset); + pstd::Status InternalAppendBinlog(const BinlogItem& item, const std::shared_ptr& cmd_ptr, LogOffset* log_offset); void InternalApply(const MemLog::LogItem& log); void InternalApplyFollower(const MemLog::LogItem& log); - bool InternalUpdateCommittedIndex(const LogOffset& slaves_committed_index, LogOffset* updated_committed_index); + bool InternalUpdateCommittedIndex(const LogOffset& slave_committed_index, LogOffset* updated_committed_index); - Status GetBinlogOffset(const BinlogOffset& start_offset, LogOffset* log_offset); - Status GetBinlogOffset(const BinlogOffset& start_offset, const BinlogOffset& end_offset, + pstd::Status GetBinlogOffset(const BinlogOffset& start_offset, LogOffset* log_offset); + pstd::Status GetBinlogOffset(const BinlogOffset& start_offset, const BinlogOffset& end_offset, std::vector* log_offset); - Status FindBinlogFileNum(const std::map binlogs, uint64_t target_index, uint32_t start_filenum, + pstd::Status FindBinlogFileNum(const std::map& binlogs, uint64_t target_index, uint32_t start_filenum, uint32_t* founded_filenum); - Status FindLogicOffsetBySearchingBinlog(const BinlogOffset& hint_offset, uint64_t target_index, + pstd::Status FindLogicOffsetBySearchingBinlog(const BinlogOffset& hint_offset, uint64_t target_index, LogOffset* found_offset); - Status FindLogicOffset(const BinlogOffset& start_offset, uint64_t target_index, LogOffset* found_offset); - Status GetLogsBefore(const BinlogOffset& start_offset, std::vector* hints); + pstd::Status FindLogicOffset(const BinlogOffset& start_offset, uint64_t target_index, LogOffset* found_offset); + pstd::Status GetLogsBefore(const BinlogOffset& start_offset, std::vector* hints); // keep members in this class works in order pstd::Mutex order_mu_; diff --git a/include/pika_data_distribution.h b/include/pika_data_distribution.h index a06416d3ab..abac62f11e 100644 --- a/include/pika_data_distribution.h +++ b/include/pika_data_distribution.h @@ -22,15 +22,15 @@ class PikaDataDistribution { class HashModulo : public PikaDataDistribution { public: - virtual ~HashModulo() = default; - virtual void Init(); - virtual uint32_t Distribute(const std::string& str, uint32_t partition_num); + ~HashModulo() override = default; + void Init() override; + uint32_t Distribute(const std::string& str, uint32_t partition_num) override; }; class Crc32 : public PikaDataDistribution { public: - virtual void Init(); - virtual uint32_t Distribute(const std::string& str, uint32_t partition_num); + void Init() override; + uint32_t Distribute(const std::string& str, uint32_t partition_num) override; private: void Crc32TableInit(uint32_t poly); diff --git a/include/pika_define.h b/include/pika_define.h index 4927ab87de..0fcb6f26d6 100644 --- a/include/pika_define.h +++ b/include/pika_define.h @@ -8,6 +8,7 @@ #include #include +#include #include "net/include/redis_cli.h" @@ -32,8 +33,8 @@ const std::string kPikaSecretFile = "rsync.secret"; const std::string kDefaultRsyncAuth = "default"; struct TableStruct { - TableStruct(const std::string& tn, const uint32_t pn, const std::set& pi) - : table_name(tn), partition_num(pn), partition_ids(pi) {} + TableStruct(std::string tn, const uint32_t pn, std::set pi) + : table_name(std::move(tn)), partition_num(pn), partition_ids(std::move(pi)) {} bool operator==(const TableStruct& table_struct) const { return table_name == table_struct.table_name && partition_num == table_struct.partition_num && @@ -48,7 +49,7 @@ struct WorkerCronTask { int task; std::string ip_port; }; -typedef WorkerCronTask MonitorCronTask; +using MonitorCronTask = WorkerCronTask; // task define #define TASK_KILL 0 #define TASK_KILLALL 1 @@ -86,9 +87,9 @@ enum SlotState { }; struct LogicOffset { - uint32_t term; - uint64_t index; - LogicOffset() : term(0), index(0) {} + uint32_t term{0}; + uint64_t index{0}; + LogicOffset() = default; LogicOffset(uint32_t _term, uint64_t _index) : term(_term), index(_index) {} LogicOffset(const LogicOffset& other) { term = other.term; @@ -101,9 +102,9 @@ struct LogicOffset { }; struct BinlogOffset { - uint32_t filenum; - uint64_t offset; - BinlogOffset() : filenum(0), offset(0) {} + uint32_t filenum{0}; + uint64_t offset{0}; + BinlogOffset() = default; BinlogOffset(uint32_t num, uint64_t off) : filenum(num), offset(off) {} BinlogOffset(const BinlogOffset& other) { filenum = other.filenum; @@ -111,41 +112,23 @@ struct BinlogOffset { } std::string ToString() const { return "filenum: " + std::to_string(filenum) + " offset: " + std::to_string(offset); } bool operator==(const BinlogOffset& other) const { - if (filenum == other.filenum && offset == other.offset) { - return true; - } - return false; + return filenum == other.filenum && offset == other.offset; } bool operator!=(const BinlogOffset& other) const { - if (filenum != other.filenum || offset != other.offset) { - return true; - } - return false; + return filenum != other.filenum || offset != other.offset; } bool operator>(const BinlogOffset& other) const { - if (filenum > other.filenum || (filenum == other.filenum && offset > other.offset)) { - return true; - } - return false; + return filenum > other.filenum || (filenum == other.filenum && offset > other.offset); } bool operator<(const BinlogOffset& other) const { - if (filenum < other.filenum || (filenum == other.filenum && offset < other.offset)) { - return true; - } - return false; + return filenum < other.filenum || (filenum == other.filenum && offset < other.offset); } bool operator<=(const BinlogOffset& other) const { - if (filenum < other.filenum || (filenum == other.filenum && offset <= other.offset)) { - return true; - } - return false; + return filenum < other.filenum || (filenum == other.filenum && offset <= other.offset); } bool operator>=(const BinlogOffset& other) const { - if (filenum > other.filenum || (filenum == other.filenum && offset >= other.offset)) { - return true; - } - return false; + return filenum > other.filenum || (filenum == other.filenum && offset >= other.offset); } }; @@ -154,8 +137,8 @@ struct LogOffset { b_offset = _log_offset.b_offset; l_offset = _log_offset.l_offset; } - LogOffset() : b_offset(), l_offset() {} - LogOffset(BinlogOffset _b_offset, LogicOffset _l_offset) : b_offset(_b_offset), l_offset(_l_offset) {} + LogOffset() = default; + LogOffset(const BinlogOffset& _b_offset, const LogicOffset& _l_offset) : b_offset(_b_offset), l_offset(_l_offset) {} bool operator<(const LogOffset& other) const { return b_offset < other.b_offset; } bool operator==(const LogOffset& other) const { return b_offset == other.b_offset; } bool operator<=(const LogOffset& other) const { return b_offset <= other.b_offset; } @@ -173,9 +156,9 @@ struct DBSyncArg { int port; std::string table_name; uint32_t partition_id; - DBSyncArg(PikaServer* const _p, const std::string& _ip, int _port, const std::string& _table_name, + DBSyncArg(PikaServer* const _p, std::string _ip, int _port, std::string _table_name, uint32_t _partition_id) - : p(_p), ip(_ip), port(_port), table_name(_table_name), partition_id(_partition_id) {} + : p(_p), ip(std::move(_ip)), port(_port), table_name(std::move(_table_name)), partition_id(_partition_id) {} }; // rm define @@ -200,7 +183,7 @@ const std::string BinlogSyncStateMsg[] = {"NotSync", "ReadFromCache", "ReadFromF struct BinlogChip { LogOffset offset_; std::string binlog_; - BinlogChip(LogOffset offset, std::string binlog) : offset_(offset), binlog_(binlog) {} + BinlogChip(const LogOffset& offset, std::string binlog) : offset_(offset), binlog_(std::move(binlog)) {} BinlogChip(const BinlogChip& binlog_chip) { offset_ = binlog_chip.offset_; binlog_ = binlog_chip.binlog_; @@ -208,16 +191,13 @@ struct BinlogChip { }; struct PartitionInfo { - PartitionInfo(const std::string& table_name, uint32_t partition_id) - : table_name_(table_name), partition_id_(partition_id) {} + PartitionInfo(std::string table_name, uint32_t partition_id) + : table_name_(std::move(table_name)), partition_id_(partition_id) {} - PartitionInfo() : partition_id_(0) {} + PartitionInfo() = default; bool operator==(const PartitionInfo& other) const { - if (table_name_ == other.table_name_ && partition_id_ == other.partition_id_) { - return true; - } - return false; + return table_name_ == other.table_name_ && partition_id_ == other.partition_id_; } bool operator<(const PartitionInfo& other) const { @@ -226,7 +206,7 @@ struct PartitionInfo { std::string ToString() const { return "(" + table_name_ + ":" + std::to_string(partition_id_) + ")"; } std::string table_name_; - uint32_t partition_id_; + uint32_t partition_id_{0}; }; struct hash_partition_info { @@ -237,9 +217,9 @@ struct hash_partition_info { class Node { public: - Node(const std::string& ip, int port) : ip_(ip), port_(port) {} + Node(std::string ip, int port) : ip_(std::move(ip)), port_(port) {} virtual ~Node() = default; - Node() : port_(0) {} + Node() = default; const std::string& Ip() const { return ip_; } int Port() const { return port_; } std::string ToString() const { return ip_ + ":" + std::to_string(port_); } @@ -251,34 +231,28 @@ class Node { class RmNode : public Node { public: - RmNode(const std::string& ip, int port, const PartitionInfo& partition_info) - : Node(ip, port), partition_info_(partition_info), session_id_(0), last_send_time_(0), last_recv_time_(0) {} + RmNode(const std::string& ip, int port, PartitionInfo partition_info) + : Node(ip, port), partition_info_(std::move(partition_info)) {} RmNode(const std::string& ip, int port, const std::string& table_name, uint32_t partition_id) : Node(ip, port), - partition_info_(table_name, partition_id), - session_id_(0), - last_send_time_(0), - last_recv_time_(0) {} + partition_info_(table_name, partition_id) + {} RmNode(const std::string& ip, int port, const std::string& table_name, uint32_t partition_id, int32_t session_id) : Node(ip, port), partition_info_(table_name, partition_id), - session_id_(session_id), - last_send_time_(0), - last_recv_time_(0) {} + session_id_(session_id) + {} RmNode(const std::string& table_name, uint32_t partition_id) - : Node(), partition_info_(table_name, partition_id), session_id_(0), last_send_time_(0), last_recv_time_(0) {} - RmNode() : Node(), partition_info_(), session_id_(0), last_send_time_(0), last_recv_time_(0) {} + : partition_info_(table_name, partition_id) {} + RmNode() = default; - virtual ~RmNode() = default; + ~RmNode() override = default; bool operator==(const RmNode& other) const { - if (partition_info_.table_name_ == other.TableName() && partition_info_.partition_id_ == other.PartitionId() && - Ip() == other.Ip() && Port() == other.Port()) { - return true; - } - return false; + return partition_info_.table_name_ == other.TableName() && partition_info_.partition_id_ == other.PartitionId() && + Ip() == other.Ip() && Port() == other.Port(); } const std::string& TableName() const { return partition_info_.table_name_; } @@ -313,7 +287,7 @@ struct WriteTask { struct RmNode rm_node_; struct BinlogChip binlog_chip_; LogOffset prev_offset_; - WriteTask(RmNode rm_node, BinlogChip binlog_chip, LogOffset prev_offset) + WriteTask(const RmNode& rm_node, const BinlogChip& binlog_chip, const LogOffset& prev_offset) : rm_node_(rm_node), binlog_chip_(binlog_chip), prev_offset_(prev_offset) {} }; diff --git a/include/pika_dispatch_thread.h b/include/pika_dispatch_thread.h index bbfa580b9b..14170bfe17 100644 --- a/include/pika_dispatch_thread.h +++ b/include/pika_dispatch_thread.h @@ -26,8 +26,8 @@ class PikaDispatchThread { class ClientConnFactory : public net::ConnFactory { public: explicit ClientConnFactory(int max_conn_rbuf_size) : max_conn_rbuf_size_(max_conn_rbuf_size) {} - virtual std::shared_ptr NewNetConn(int connfd, const std::string& ip_port, net::Thread* server_thread, - void* worker_specific_data, net::NetMultiplexer* net) const { + std::shared_ptr NewNetConn(int connfd, const std::string& ip_port, net::Thread* server_thread, + void* worker_specific_data, net::NetMultiplexer* net) const override { return std::make_shared(connfd, ip_port, server_thread, net, net::HandleType::kAsynchronous, max_conn_rbuf_size_); } diff --git a/include/pika_geo.h b/include/pika_geo.h index 2ce0c6eb13..055c1bfd25 100644 --- a/include/pika_geo.h +++ b/include/pika_geo.h @@ -51,91 +51,91 @@ struct GeoRange { class GeoAddCmd : public Cmd { public: GeoAddCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GeoAddCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GeoAddCmd(*this); } private: std::string key_; std::vector pos_; - virtual void DoInitial(); + void DoInitial() override; }; class GeoPosCmd : public Cmd { public: GeoPosCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GeoPosCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GeoPosCmd(*this); } private: std::string key_; std::vector members_; - virtual void DoInitial(); + void DoInitial() override; }; class GeoDistCmd : public Cmd { public: GeoDistCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GeoDistCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GeoDistCmd(*this); } private: std::string key_, first_pos_, second_pos_, unit_; - virtual void DoInitial(); + void DoInitial() override; }; class GeoHashCmd : public Cmd { public: GeoHashCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GeoHashCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GeoHashCmd(*this); } private: std::string key_; std::vector members_; - virtual void DoInitial(); + void DoInitial() override; }; class GeoRadiusCmd : public Cmd { public: GeoRadiusCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GeoRadiusCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GeoRadiusCmd(*this); } private: std::string key_; GeoRange range_; - virtual void DoInitial(); - virtual void Clear() { + void DoInitial() override; + void Clear() override { range_.withdist = false; range_.withcoord = false; range_.withhash = false; @@ -151,16 +151,16 @@ class GeoRadiusCmd : public Cmd { class GeoRadiusByMemberCmd : public Cmd { public: GeoRadiusByMemberCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GeoRadiusByMemberCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GeoRadiusByMemberCmd(*this); } private: std::string key_; GeoRange range_; - virtual void DoInitial(); - virtual void Clear() { + void DoInitial() override; + void Clear() override { range_.withdist = false; range_.withcoord = false; range_.withhash = false; diff --git a/include/pika_geohash.h b/include/pika_geohash.h index e706fcef3e..2971351f68 100644 --- a/include/pika_geohash.h +++ b/include/pika_geohash.h @@ -32,8 +32,8 @@ #ifndef PIKA_GEOHASH_H_ #define PIKA_GEOHASH_H_ -#include -#include +#include +#include #if defined(__cplusplus) extern "C" { @@ -41,17 +41,18 @@ extern "C" { #define HASHISZERO(r) (!(r).bits && !(r).step) #define RANGEISZERO(r) (!(r).max && !(r).min) -#define RANGEPISZERO(r) (r == nullptr || RANGEISZERO(*r)) +#define RANGEPISZERO(r) ((r) == nullptr || RANGEISZERO(*(r))) #define GEO_STEP_MAX 26 /* 26*2 = 52 bits. */ /* Limits from EPSG:900913 / EPSG:3785 / OSGEO:41001 */ -#define GEO_LAT_MIN -85.05112878 -#define GEO_LAT_MAX 85.05112878 -#define GEO_LONG_MIN -180 -#define GEO_LONG_MAX 180 +constexpr double GEO_LAT_MIN{-85.05112878}; +constexpr double GEO_LAT_MAX{85.05112878}; +constexpr int64_t GEO_LONG_MIN{-180}; +constexpr int64_t GEO_LONG_MAX{180}; -typedef enum { + +enum GeoDirection { GEOHASH_NORTH = 0, GEOHASH_EAST, GEOHASH_WEST, @@ -60,25 +61,25 @@ typedef enum { GEOHASH_SOUTH_EAST, GEOHASH_NORT_WEST, GEOHASH_NORT_EAST -} GeoDirection; +}; -typedef struct { +struct GeoHashBits { uint64_t bits; uint8_t step; -} GeoHashBits; +}; -typedef struct { +struct GeoHashRange { double min; double max; -} GeoHashRange; +}; -typedef struct { +struct GeoHashArea { GeoHashBits hash; GeoHashRange longitude; GeoHashRange latitude; -} GeoHashArea; +}; -typedef struct { +struct GeoHashNeighbors { GeoHashBits north; GeoHashBits east; GeoHashBits west; @@ -87,7 +88,7 @@ typedef struct { GeoHashBits south_east; GeoHashBits north_west; GeoHashBits south_west; -} GeoHashNeighbors; +}; /* * 0:success @@ -98,14 +99,14 @@ int geohashEncode(const GeoHashRange* long_range, const GeoHashRange* lat_range, uint8_t step, GeoHashBits* hash); int geohashEncodeType(double longitude, double latitude, uint8_t step, GeoHashBits* hash); int geohashEncodeWGS84(double longitude, double latitude, uint8_t step, GeoHashBits* hash); -int geohashDecode(const GeoHashRange long_range, const GeoHashRange lat_range, const GeoHashBits hash, +int geohashDecode(GeoHashRange long_range, GeoHashRange lat_range, GeoHashBits hash, GeoHashArea* area); -int geohashDecodeType(const GeoHashBits hash, GeoHashArea* area); -int geohashDecodeWGS84(const GeoHashBits hash, GeoHashArea* area); +int geohashDecodeType(GeoHashBits hash, GeoHashArea* area); +int geohashDecodeWGS84(GeoHashBits hash, GeoHashArea* area); int geohashDecodeAreaToLongLat(const GeoHashArea* area, double* xy); -int geohashDecodeToLongLatType(const GeoHashBits hash, double* xy); -int geohashDecodeToLongLatWGS84(const GeoHashBits hash, double* xy); -int geohashDecodeToLongLatMercator(const GeoHashBits hash, double* xy); +int geohashDecodeToLongLatType(GeoHashBits hash, double* xy); +int geohashDecodeToLongLatWGS84(GeoHashBits hash, double* xy); +int geohashDecodeToLongLatMercator(GeoHashBits hash, double* xy); void geohashNeighbors(const GeoHashBits* hash, GeoHashNeighbors* neighbors); #if defined(__cplusplus) diff --git a/include/pika_geohash_helper.h b/include/pika_geohash_helper.h index dec4471839..8478ea60ac 100644 --- a/include/pika_geohash_helper.h +++ b/include/pika_geohash_helper.h @@ -34,18 +34,18 @@ #include "include/pika_geohash.h" -#define GZERO(s) s.bits = s.step = 0; -#define GISZERO(s) (!s.bits && !s.step) -#define GISNOTZERO(s) (s.bits || s.step) +#define GZERO(s) s.bits = (s).step = 0; +#define GISZERO(s) (!(s).bits && !(s).step) +#define GISNOTZERO(s) ((s).bits || (s).step) -typedef uint64_t GeoHashFix52Bits; -typedef uint64_t GeoHashVarBits; +using GeoHashFix52Bits = uint64_t; +using GeoHashVarBits = uint64_t; -typedef struct { +struct GeoHashRadius { GeoHashBits hash; GeoHashArea area; GeoHashNeighbors neighbors; -} GeoHashRadius; +}; int GeoHashBitsComparator(const GeoHashBits* a, const GeoHashBits* b); uint8_t geohashEstimateStepsByRadius(double range_meters, double lat); @@ -53,7 +53,7 @@ int geohashBoundingBox(double longitude, double latitude, double radius_meters, GeoHashRadius geohashGetAreasByRadius(double longitude, double latitude, double radius_meters); GeoHashRadius geohashGetAreasByRadiusWGS84(double longitude, double latitude, double radius_meters); GeoHashRadius geohashGetAreasByRadiusMercator(double longitude, double latitude, double radius_meters); -GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits hash); +GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits& hash); double geohashGetDistance(double lon1d, double lat1d, double lon2d, double lat2d); int geohashGetDistanceIfInRadius(double x1, double y1, double x2, double y2, double radius, double* distance); int geohashGetDistanceIfInRadiusWGS84(double x1, double y1, double x2, double y2, double radius, double* distance); diff --git a/include/pika_hash.h b/include/pika_hash.h index 292fce1d82..48f6025de9 100644 --- a/include/pika_hash.h +++ b/include/pika_hash.h @@ -17,277 +17,277 @@ class HDelCmd : public Cmd { public: HDelCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HDelCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HDelCmd(*this); } private: std::string key_; std::vector fields_; - virtual void DoInitial() override; + void DoInitial() override; }; class HGetCmd : public Cmd { public: HGetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HGetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HGetCmd(*this); } private: std::string key_, field_; - virtual void DoInitial() override; + void DoInitial() override; }; class HGetallCmd : public Cmd { public: HGetallCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HGetallCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HGetallCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class HSetCmd : public Cmd { public: HSetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HSetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HSetCmd(*this); } private: std::string key_, field_, value_; - virtual void DoInitial() override; + void DoInitial() override; }; class HExistsCmd : public Cmd { public: HExistsCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HExistsCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HExistsCmd(*this); } private: std::string key_, field_; - virtual void DoInitial() override; + void DoInitial() override; }; class HIncrbyCmd : public Cmd { public: HIncrbyCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HIncrbyCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HIncrbyCmd(*this); } private: std::string key_, field_; int64_t by_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class HIncrbyfloatCmd : public Cmd { public: HIncrbyfloatCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HIncrbyfloatCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HIncrbyfloatCmd(*this); } private: std::string key_, field_, by_; - virtual void DoInitial() override; + void DoInitial() override; }; class HKeysCmd : public Cmd { public: HKeysCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HKeysCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HKeysCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class HLenCmd : public Cmd { public: HLenCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HLenCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HLenCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class HMgetCmd : public Cmd { public: HMgetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HMgetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HMgetCmd(*this); } private: std::string key_; std::vector fields_; - virtual void DoInitial() override; + void DoInitial() override; }; class HMsetCmd : public Cmd { public: HMsetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HMsetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HMsetCmd(*this); } private: std::string key_; std::vector fvs_; - virtual void DoInitial() override; + void DoInitial() override; }; class HSetnxCmd : public Cmd { public: HSetnxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HSetnxCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HSetnxCmd(*this); } private: std::string key_, field_, value_; - virtual void DoInitial() override; + void DoInitial() override; }; class HStrlenCmd : public Cmd { public: HStrlenCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HStrlenCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HStrlenCmd(*this); } private: std::string key_, field_; - virtual void DoInitial() override; + void DoInitial() override; }; class HValsCmd : public Cmd { public: HValsCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HValsCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HValsCmd(*this); } private: std::string key_, field_; - virtual void DoInitial() override; + void DoInitial() override; }; class HScanCmd : public Cmd { public: HScanCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*"), count_(10) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HScanCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HScanCmd(*this); } private: std::string key_, pattern_; int64_t cursor_, count_; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { pattern_ = "*"; count_ = 10; } @@ -296,21 +296,21 @@ class HScanCmd : public Cmd { class HScanxCmd : public Cmd { public: HScanxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*"), count_(10) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new HScanxCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new HScanxCmd(*this); } private: std::string key_, start_field_, pattern_; int64_t count_; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { pattern_ = "*"; count_ = 10; } @@ -319,16 +319,16 @@ class HScanxCmd : public Cmd { class PKHScanRangeCmd : public Cmd { public: PKHScanRangeCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), pattern_("*"), limit_(10) {} - virtual std::vector current_key() const { + : Cmd(name, arity, flag), pattern_("*") {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PKHScanRangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PKHScanRangeCmd(*this); } private: std::string key_; @@ -336,8 +336,8 @@ class PKHScanRangeCmd : public Cmd { std::string field_end_; std::string pattern_; int64_t limit_ = 10; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { pattern_ = "*"; limit_ = 10; } @@ -346,16 +346,16 @@ class PKHScanRangeCmd : public Cmd { class PKHRScanRangeCmd : public Cmd { public: PKHRScanRangeCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), pattern_("*"), limit_(10) {} - virtual std::vector current_key() const { + : Cmd(name, arity, flag), pattern_("*") {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PKHRScanRangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PKHRScanRangeCmd(*this); } private: std::string key_; @@ -363,8 +363,8 @@ class PKHRScanRangeCmd : public Cmd { std::string field_end_; std::string pattern_ = "*"; int64_t limit_ = 10; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { pattern_ = "*"; limit_ = 10; } diff --git a/include/pika_hyperloglog.h b/include/pika_hyperloglog.h index d6ca344a59..54ae14f25b 100644 --- a/include/pika_hyperloglog.h +++ b/include/pika_hyperloglog.h @@ -15,49 +15,49 @@ class PfAddCmd : public Cmd { public: PfAddCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PfAddCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PfAddCmd(*this); } private: std::string key_; std::vector values_; - virtual void DoInitial() override; - virtual void Clear() { values_.clear(); } + void DoInitial() override; + void Clear() override { values_.clear(); } }; class PfCountCmd : public Cmd { public: PfCountCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PfCountCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PfCountCmd(*this); } private: std::vector keys_; - virtual void DoInitial() override; - virtual void Clear() { keys_.clear(); } + void DoInitial() override; + void Clear() override { keys_.clear(); } }; class PfMergeCmd : public Cmd { public: PfMergeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PfMergeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PfMergeCmd(*this); } private: std::vector keys_; - virtual void DoInitial() override; - virtual void Clear() { keys_.clear(); } + void DoInitial() override; + void Clear() override { keys_.clear(); } }; #endif diff --git a/include/pika_kv.h b/include/pika_kv.h index b5c57c5746..15b00dc992 100644 --- a/include/pika_kv.h +++ b/include/pika_kv.h @@ -17,16 +17,16 @@ class SetCmd : public Cmd { public: enum SetCondition { kNONE, kNX, kXX, kVX, kEXORPX }; - SetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), sec_(0), condition_(kNONE){}; - virtual std::vector current_key() const { + SetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), condition_(kNONE){}; + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SetCmd(*this); } private: std::string key_; @@ -35,573 +35,573 @@ class SetCmd : public Cmd { int32_t success_ = 0; int64_t sec_ = 0; SetCmd::SetCondition condition_; - virtual void DoInitial() override; - virtual void Clear() override { + void DoInitial() override; + void Clear() override { sec_ = 0; success_ = 0; condition_ = kNONE; } - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class GetCmd : public Cmd { public: GetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GetCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class DelCmd : public Cmd { public: - DelCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), split_res_(0){}; - virtual void Do(std::shared_ptr partition = nullptr); - virtual std::vector current_key() const { return keys_; } - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys); - virtual void Merge(); - virtual Cmd* Clone() override { return new DelCmd(*this); } + DelCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}; + void Do(std::shared_ptr partition = nullptr) override; + std::vector current_key() const override { return keys_; } + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override; + void Merge() override; + Cmd* Clone() override { return new DelCmd(*this); } private: std::vector keys_; int64_t split_res_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class IncrCmd : public Cmd { public: IncrCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new IncrCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new IncrCmd(*this); } private: std::string key_; int64_t new_value_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class IncrbyCmd : public Cmd { public: IncrbyCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new IncrbyCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new IncrbyCmd(*this); } private: std::string key_; int64_t by_ = 0, new_value_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class IncrbyfloatCmd : public Cmd { public: IncrbyfloatCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new IncrbyfloatCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new IncrbyfloatCmd(*this); } private: std::string key_, value_, new_value_; double by_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class DecrCmd : public Cmd { public: DecrCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new DecrCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new DecrCmd(*this); } private: std::string key_; int64_t new_value_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class DecrbyCmd : public Cmd { public: DecrbyCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new DecrbyCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new DecrbyCmd(*this); } private: std::string key_; int64_t by_ = 0, new_value_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class GetsetCmd : public Cmd { public: GetsetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GetsetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GetsetCmd(*this); } private: std::string key_; std::string new_value_; - virtual void DoInitial() override; + void DoInitial() override; }; class AppendCmd : public Cmd { public: AppendCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new AppendCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new AppendCmd(*this); } private: std::string key_; std::string value_; - virtual void DoInitial() override; + void DoInitial() override; }; class MgetCmd : public Cmd { public: MgetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual void Do(std::shared_ptr partition = nullptr); - virtual std::vector current_key() const { return keys_; } - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys); - virtual void Merge(); - virtual Cmd* Clone() override { return new MgetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + std::vector current_key() const override { return keys_; } + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override; + void Merge() override; + Cmd* Clone() override { return new MgetCmd(*this); } private: std::vector keys_; std::vector split_res_; - virtual void DoInitial() override; + void DoInitial() override; }; class KeysCmd : public Cmd { public: KeysCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), type_(storage::DataType::kAll) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new KeysCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new KeysCmd(*this); } private: std::string pattern_; storage::DataType type_; - virtual void DoInitial() override; - virtual void Clear() { type_ = storage::DataType::kAll; } + void DoInitial() override; + void Clear() override { type_ = storage::DataType::kAll; } }; class SetnxCmd : public Cmd { public: SetnxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SetnxCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SetnxCmd(*this); } private: std::string key_; std::string value_; int32_t success_ = 0; - virtual void DoInitial() override; - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + void DoInitial() override; + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class SetexCmd : public Cmd { public: SetexCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SetexCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SetexCmd(*this); } private: std::string key_; int64_t sec_ = 0; std::string value_; - virtual void DoInitial() override; - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + void DoInitial() override; + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class PsetexCmd : public Cmd { public: PsetexCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PsetexCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PsetexCmd(*this); } private: std::string key_; int64_t usec_ = 0; std::string value_; - virtual void DoInitial() override; - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + void DoInitial() override; + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class DelvxCmd : public Cmd { public: DelvxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new DelvxCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new DelvxCmd(*this); } private: std::string key_; std::string value_; int32_t success_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class MsetCmd : public Cmd { public: MsetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual std::vector current_key() const { + void Do(std::shared_ptr partition = nullptr) override; + std::vector current_key() const override { std::vector res; for (auto& kv : kvs_) { res.push_back(kv.key); } return res; } - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys); - virtual void Merge(); - virtual Cmd* Clone() override { return new MsetCmd(*this); } + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override; + void Merge() override; + Cmd* Clone() override { return new MsetCmd(*this); } private: std::vector kvs_; - virtual void DoInitial() override; + void DoInitial() override; }; class MsetnxCmd : public Cmd { public: MsetnxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new MsetnxCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new MsetnxCmd(*this); } private: std::vector kvs_; int32_t success_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class GetrangeCmd : public Cmd { public: GetrangeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new GetrangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new GetrangeCmd(*this); } private: std::string key_; int64_t start_ = 0; int64_t end_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class SetrangeCmd : public Cmd { public: SetrangeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SetrangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SetrangeCmd(*this); } private: std::string key_; int64_t offset_ = 0; std::string value_; - virtual void DoInitial() override; + void DoInitial() override; }; class StrlenCmd : public Cmd { public: StrlenCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new StrlenCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new StrlenCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class ExistsCmd : public Cmd { public: - ExistsCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), split_res_(0) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual std::vector current_key() const { return keys_; } - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys); - virtual void Merge(); - virtual Cmd* Clone() override { return new ExistsCmd(*this); } + ExistsCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} + void Do(std::shared_ptr partition = nullptr) override; + std::vector current_key() const override { return keys_; } + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override; + void Merge() override; + Cmd* Clone() override { return new ExistsCmd(*this); } private: std::vector keys_; int64_t split_res_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class ExpireCmd : public Cmd { public: ExpireCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ExpireCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ExpireCmd(*this); } private: std::string key_; int64_t sec_ = 0; - virtual void DoInitial() override; - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + void DoInitial() override; + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class PexpireCmd : public Cmd { public: PexpireCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PexpireCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PexpireCmd(*this); } private: std::string key_; int64_t msec_ = 0; - virtual void DoInitial() override; - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + void DoInitial() override; + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class ExpireatCmd : public Cmd { public: ExpireatCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ExpireatCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ExpireatCmd(*this); } private: std::string key_; int64_t time_stamp_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class PexpireatCmd : public Cmd { public: PexpireatCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PexpireatCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PexpireatCmd(*this); } private: std::string key_; int64_t time_stamp_ms_ = 0; - virtual void DoInitial() override; - virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, + void DoInitial() override; + std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) override; }; class TtlCmd : public Cmd { public: TtlCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new TtlCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new TtlCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class PttlCmd : public Cmd { public: PttlCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PttlCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PttlCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class PersistCmd : public Cmd { public: PersistCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PersistCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PersistCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class TypeCmd : public Cmd { public: TypeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new TypeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new TypeCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class ScanCmd : public Cmd { public: - ScanCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*"), count_(10) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ScanCmd(*this); } + ScanCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*") {} + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ScanCmd(*this); } private: int64_t cursor_ = 0; std::string pattern_ = "*"; int64_t count_ = 10; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { pattern_ = "*"; count_ = 10; } @@ -609,19 +609,19 @@ class ScanCmd : public Cmd { class ScanxCmd : public Cmd { public: - ScanxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*"), count_(10) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ScanxCmd(*this); } + ScanxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*") {} + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ScanxCmd(*this); } private: storage::DataType type_; std::string start_key_; std::string pattern_ = "*"; int64_t count_ = 10; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { pattern_ = "*"; count_ = 10; } @@ -629,38 +629,38 @@ class ScanxCmd : public Cmd { class PKSetexAtCmd : public Cmd { public: - PKSetexAtCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), time_stamp_(0) {} - virtual std::vector current_key() const { + PKSetexAtCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PKSetexAtCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PKSetexAtCmd(*this); } private: std::string key_; std::string value_; int64_t time_stamp_ = 0; - virtual void DoInitial() override; - virtual void Clear() { time_stamp_ = 0; } + void DoInitial() override; + void Clear() override { time_stamp_ = 0; } }; class PKScanRangeCmd : public Cmd { public: PKScanRangeCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), pattern_("*"), limit_(10), string_with_value(false) {} + : Cmd(name, arity, flag), pattern_("*") {} std::vector current_key() const override { std::vector res; res.push_back(key_start_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PKScanRangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PKScanRangeCmd(*this); } private: storage::DataType type_; @@ -669,8 +669,8 @@ class PKScanRangeCmd : public Cmd { std::string pattern_ = "*"; int64_t limit_ = 10; bool string_with_value = false; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { pattern_ = "*"; limit_ = 10; string_with_value = false; @@ -680,16 +680,16 @@ class PKScanRangeCmd : public Cmd { class PKRScanRangeCmd : public Cmd { public: PKRScanRangeCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), pattern_("*"), limit_(10), string_with_value(false) {} + : Cmd(name, arity, flag), pattern_("*") {} std::vector current_key() const override { std::vector res; res.push_back(key_start_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PKRScanRangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PKRScanRangeCmd(*this); } private: storage::DataType type_ = storage::kAll; @@ -699,7 +699,7 @@ class PKRScanRangeCmd : public Cmd { int64_t limit_ = 10; bool string_with_value = false; void DoInitial() override; - virtual void Clear() { + void Clear() override { pattern_ = "*"; limit_ = 10; string_with_value = false; diff --git a/include/pika_list.h b/include/pika_list.h index f249b6a5c9..765047051f 100644 --- a/include/pika_list.h +++ b/include/pika_list.h @@ -16,216 +16,216 @@ */ class LIndexCmd : public Cmd { public: - LIndexCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), index_(0){}; - virtual std::vector current_key() const { + LIndexCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}; + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LIndexCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LIndexCmd(*this); } private: std::string key_; int64_t index_ = 0; - virtual void DoInitial() override; - virtual void Clear() { index_ = 0; } + void DoInitial() override; + void Clear() override { index_ = 0; } }; class LInsertCmd : public Cmd { public: LInsertCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), dir_(storage::After){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LInsertCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LInsertCmd(*this); } private: std::string key_; storage::BeforeOrAfter dir_; std::string pivot_; std::string value_; - virtual void DoInitial() override; + void DoInitial() override; }; class LLenCmd : public Cmd { public: LLenCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LLenCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LLenCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class LPopCmd : public Cmd { public: LPopCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LPopCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LPopCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class LPushCmd : public Cmd { public: LPushCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LPushCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LPushCmd(*this); } private: std::string key_; std::vector values_; - virtual void DoInitial() override; - virtual void Clear() { values_.clear(); } + void DoInitial() override; + void Clear() override { values_.clear(); } }; class LPushxCmd : public Cmd { public: LPushxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LPushxCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LPushxCmd(*this); } private: std::string key_; std::string value_; - virtual void DoInitial() override; + void DoInitial() override; }; class LRangeCmd : public Cmd { public: - LRangeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), left_(0), right_(0){}; - virtual std::vector current_key() const { + LRangeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}; + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LRangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LRangeCmd(*this); } private: std::string key_; int64_t left_ = 0; int64_t right_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class LRemCmd : public Cmd { public: - LRemCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), count_(0){}; - virtual std::vector current_key() const { + LRemCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}; + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LRemCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LRemCmd(*this); } private: std::string key_; int64_t count_ = 0; std::string value_; - virtual void DoInitial() override; + void DoInitial() override; }; class LSetCmd : public Cmd { public: - LSetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), index_(0){}; - virtual std::vector current_key() const { + LSetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}; + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LSetCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LSetCmd(*this); } private: std::string key_; int64_t index_ = 0; std::string value_; - virtual void DoInitial() override; + void DoInitial() override; }; class LTrimCmd : public Cmd { public: - LTrimCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), start_(0), stop_(0){}; - virtual std::vector current_key() const { + LTrimCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}; + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new LTrimCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new LTrimCmd(*this); } private: std::string key_; int64_t start_ = 0; int64_t stop_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class RPopCmd : public Cmd { public: RPopCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new RPopCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new RPopCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class RPopLPushCmd : public Cmd { @@ -236,53 +236,53 @@ class RPopLPushCmd : public Cmd { res.push_back(source_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new RPopLPushCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new RPopLPushCmd(*this); } private: std::string source_; std::string receiver_; - virtual void DoInitial() override; + void DoInitial() override; }; class RPushCmd : public Cmd { public: RPushCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new RPushCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new RPushCmd(*this); } private: std::string key_; std::vector values_; - virtual void DoInitial() override; - virtual void Clear() { values_.clear(); } + void DoInitial() override; + void Clear() override { values_.clear(); } }; class RPushxCmd : public Cmd { public: RPushxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){}; - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new RPushxCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new RPushxCmd(*this); } private: std::string key_; std::string value_; - virtual void DoInitial() override; + void DoInitial() override; }; #endif diff --git a/include/pika_meta.h b/include/pika_meta.h index 5288062db2..252d527e62 100644 --- a/include/pika_meta.h +++ b/include/pika_meta.h @@ -7,30 +7,27 @@ #define PIKA_META #include + #include "pstd/include/env.h" #include "pstd/include/pstd_mutex.h" #include "include/pika_define.h" -using pstd::Status; -class PikaMeta { +class PikaMeta : public pstd::noncopyable { public: - PikaMeta(); - ~PikaMeta(); + PikaMeta() = default; + ~PikaMeta() = default; void SetPath(const std::string& path); - Status StableSave(const std::vector& table_structs); - Status ParseMeta(std::vector* const table_structs); + pstd::Status StableSave(const std::vector& table_structs); + pstd::Status ParseMeta(std::vector* table_structs); private: std::shared_mutex rwlock_; std::string local_meta_path_; - // No copying allowed; - PikaMeta(const PikaMeta&); - void operator=(const PikaMeta&); }; #endif diff --git a/include/pika_monitor_thread.h b/include/pika_monitor_thread.h new file mode 100644 index 0000000000..42bab74783 --- /dev/null +++ b/include/pika_monitor_thread.h @@ -0,0 +1,48 @@ +// Copyright (c) 2015-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. + +#ifndef PIKA_MONITOR_THREAD_H_ +#define PIKA_MONITOR_THREAD_H_ + +#include +#include +#include +#include + +#include "net/include/net_thread.h" +#include "pstd/include/pstd_mutex.h" + +#include "include/pika_client_conn.h" +#include "include/pika_define.h" + +class PikaMonitorThread : public net::Thread { + public: + PikaMonitorThread(); + ~PikaMonitorThread() override; + + void AddMonitorClient(const std::shared_ptr& client_ptr); + void AddMonitorMessage(const std::string& monitor_message); + int32_t ThreadClientList(std::vector* client = nullptr); + bool ThreadClientKill(const std::string& ip_port = "all"); + bool HasMonitorClients(); + + private: + void AddCronTask(const MonitorCronTask& task); + bool FindClient(const std::string& ip_port); + net::WriteStatus SendMessage(int32_t fd, std::string& message); + void RemoveMonitorClient(const std::string& ip_port); + + std::atomic has_monitor_clients_; + pstd::Mutex monitor_mutex_protector_; + pstd::CondVar monitor_cond_; + + std::list monitor_clients_; + std::deque monitor_messages_; + std::queue cron_tasks_; + + void* ThreadMain() override; + void RemoveMonitorClient(int32_t client_fd); +}; +#endif diff --git a/include/pika_partition.h b/include/pika_partition.h index f3896f0f86..27e7c9c584 100644 --- a/include/pika_partition.h +++ b/include/pika_partition.h @@ -7,7 +7,9 @@ #define PIKA_PARTITION_H_ #include + #include "pstd/include/scope_record_lock.h" + #include "storage/backupable.h" #include "storage/storage.h" @@ -24,12 +26,10 @@ struct KeyScanInfo { int32_t duration = -3; std::vector key_infos; // the order is strings, hashes, lists, zsets, sets bool key_scaning_ = false; - KeyScanInfo() - : start_time(0), + KeyScanInfo() : s_start_time("0"), - duration(-3), - key_infos({{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}), - key_scaning_(false) {} + key_infos({{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}) + {} }; struct BgSaveInfo { @@ -38,7 +38,7 @@ struct BgSaveInfo { std::string s_start_time; std::string path; LogOffset offset; - BgSaveInfo() : bgsaving(false), offset() {} + BgSaveInfo() = default; void Clear() { bgsaving = false; path.clear(); @@ -82,9 +82,15 @@ class Partition : public std::enable_shared_from_this { bool FlushSubDB(const std::string& db_name); // key scan info use - Status GetKeyNum(std::vector* key_info); + pstd::Status GetKeyNum(std::vector* key_info); KeyScanInfo GetKeyScanInfo(); + /* + * No allowed copy and copy assign + */ + Partition(const Partition&) = delete; + void operator=(const Partition&) = delete; + private: std::string table_name_; uint32_t partition_id_ = 0; @@ -122,11 +128,6 @@ class Partition : public std::enable_shared_from_this { // key scan info use void InitKeyScan(); - /* - * No allowed copy and copy assign - */ - Partition(const Partition&); - void operator=(const Partition&); }; #endif diff --git a/include/pika_pubsub.h b/include/pika_pubsub.h index 41b4a0ff2f..2cc206adeb 100644 --- a/include/pika_pubsub.h +++ b/include/pika_pubsub.h @@ -14,78 +14,78 @@ class PublishCmd : public Cmd { public: PublishCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PublishCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PublishCmd(*this); } private: std::string channel_; std::string msg_; - virtual void DoInitial() override; + void DoInitial() override; }; class SubscribeCmd : public Cmd { public: SubscribeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SubscribeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SubscribeCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class UnSubscribeCmd : public Cmd { public: UnSubscribeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new UnSubscribeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new UnSubscribeCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class PUnSubscribeCmd : public Cmd { public: PUnSubscribeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PUnSubscribeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PUnSubscribeCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class PSubscribeCmd : public Cmd { public: PSubscribeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PSubscribeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PSubscribeCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class PubSubCmd : public Cmd { public: PubSubCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr) override; - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new PubSubCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new PubSubCmd(*this); } private: std::string subcommand_; std::vector arguments_; - virtual void DoInitial() override; - virtual void Clear() { arguments_.clear(); } + void DoInitial() override; + void Clear() override { arguments_.clear(); } }; #endif // INCLUDE_PIKA_PUBSUB_H_ diff --git a/include/pika_repl_bgworker.h b/include/pika_repl_bgworker.h index 6417802ebb..cc7bbde561 100644 --- a/include/pika_repl_bgworker.h +++ b/include/pika_repl_bgworker.h @@ -37,7 +37,7 @@ class PikaReplBgWorker { private: net::BGThread bg_thread_; static int HandleWriteBinlog(net::RedisParser* parser, const net::RedisCmdArgsType& argv); - static void ParseBinlogOffset(const InnerMessage::BinlogOffset pb_offset, LogOffset* offset); + static void ParseBinlogOffset(const InnerMessage::BinlogOffset& pb_offset, LogOffset* offset); }; #endif // PIKA_REPL_BGWROKER_H_ diff --git a/include/pika_repl_client.h b/include/pika_repl_client.h index d47d3205cf..9a2f9a70b9 100644 --- a/include/pika_repl_client.h +++ b/include/pika_repl_client.h @@ -8,6 +8,7 @@ #include #include +#include #include "net/include/client_thread.h" #include "net/include/net_conn.h" @@ -23,13 +24,12 @@ #include "net/include/thread_pool.h" #include "pika_inner_message.pb.h" -using pstd::Status; struct ReplClientTaskArg { std::shared_ptr res; std::shared_ptr conn; ReplClientTaskArg(std::shared_ptr _res, std::shared_ptr _conn) - : res(_res), conn(_conn) {} + : res(std::move(_res)), conn(std::move(_conn)) {} }; struct ReplClientWriteBinlogTaskArg { @@ -37,9 +37,10 @@ struct ReplClientWriteBinlogTaskArg { std::shared_ptr conn; void* res_private_data; PikaReplBgWorker* worker; - ReplClientWriteBinlogTaskArg(const std::shared_ptr _res, - std::shared_ptr _conn, void* _res_private_data, PikaReplBgWorker* _worker) - : res(_res), conn(_conn), res_private_data(_res_private_data), worker(_worker) {} + ReplClientWriteBinlogTaskArg(const std::shared_ptr& _res, + const std::shared_ptr& _conn, + void* _res_private_data, PikaReplBgWorker* _worker) + : res(std::move(_res)), conn(std::move(_conn)), res_private_data(_res_private_data), worker(_worker) {} }; struct ReplClientWriteDBTaskArg { @@ -47,10 +48,13 @@ struct ReplClientWriteDBTaskArg { LogOffset offset; std::string table_name; uint32_t partition_id; - ReplClientWriteDBTaskArg(const std::shared_ptr _cmd_ptr, const LogOffset _offset, const std::string _table_name, + ReplClientWriteDBTaskArg(std::shared_ptr _cmd_ptr, const LogOffset& _offset, std::string _table_name, uint32_t _partition_id) - : cmd_ptr(_cmd_ptr), offset(_offset), table_name(_table_name), partition_id(_partition_id) {} - ~ReplClientWriteDBTaskArg() {} + : cmd_ptr(std::move(_cmd_ptr)), + offset(_offset), + table_name(std::move(_table_name)), + partition_id(_partition_id) {} + ~ReplClientWriteDBTaskArg() = default; }; class PikaReplClient { @@ -61,28 +65,28 @@ class PikaReplClient { int Start(); int Stop(); - pstd::Status Write(const std::string& ip, const int port, const std::string& msg); - pstd::Status Close(const std::string& ip, const int port); + pstd::Status Write(const std::string& ip, int port, const std::string& msg); + pstd::Status Close(const std::string& ip, int port); void Schedule(net::TaskFunc func, void* arg); - void ScheduleWriteBinlogTask(std::string table_partition, const std::shared_ptr res, - std::shared_ptr conn, void* req_private_data); - void ScheduleWriteDBTask(const std::shared_ptr cmd_ptr, const LogOffset& offset, const std::string& table_name, + void ScheduleWriteBinlogTask(const std::string& table_partition, const std::shared_ptr& res, + std::shared_ptr conn, void* res_private_data); + void ScheduleWriteDBTask(const std::shared_ptr& cmd_ptr, const LogOffset& offset, const std::string& table_name, uint32_t partition_id); - Status SendMetaSync(); - Status SendPartitionDBSync(const std::string& ip, uint32_t port, const std::string& table_name, uint32_t partition_id, + pstd::Status SendMetaSync(); + pstd::Status SendPartitionDBSync(const std::string& ip, uint32_t port, const std::string& table_name, uint32_t partition_id, const BinlogOffset& boffset, const std::string& local_ip); - Status SendPartitionTrySync(const std::string& ip, uint32_t port, const std::string& table_name, + pstd::Status SendPartitionTrySync(const std::string& ip, uint32_t port, const std::string& table_name, uint32_t partition_id, const BinlogOffset& boffset, const std::string& local_ip); - Status SendPartitionBinlogSync(const std::string& ip, uint32_t port, const std::string& table_name, + pstd::Status SendPartitionBinlogSync(const std::string& ip, uint32_t port, const std::string& table_name, uint32_t partition_id, const LogOffset& ack_start, const LogOffset& ack_end, - const std::string& local_ip, bool is_frist_send); - Status SendRemoveSlaveNode(const std::string& ip, uint32_t port, const std::string& table_name, uint32_t partition_id, + const std::string& local_ip, bool is_first_send); + pstd::Status SendRemoveSlaveNode(const std::string& ip, uint32_t port, const std::string& table_name, uint32_t partition_id, const std::string& local_ip); private: - size_t GetHashIndex(std::string key, bool upper_half); + size_t GetHashIndex(const std::string& key, bool upper_half); void UpdateNextAvail() { next_avail_ = (next_avail_ + 1) % bg_workers_.size(); } std::unique_ptr client_thread_; diff --git a/include/pika_repl_client_conn.h b/include/pika_repl_client_conn.h index 0c45fb861a..5d8fa7b1cd 100644 --- a/include/pika_repl_client_conn.h +++ b/include/pika_repl_client_conn.h @@ -9,6 +9,7 @@ #include "net/include/pb_conn.h" #include +#include #include "include/pika_conf.h" #include "pika_inner_message.pb.h" @@ -20,14 +21,14 @@ class PikaReplClientConn : public net::PbConn { public: PikaReplClientConn(int fd, const std::string& ip_port, net::Thread* thread, void* worker_specific_data, net::NetMultiplexer* mpx); - virtual ~PikaReplClientConn() = default; + ~PikaReplClientConn() override = default; static void HandleMetaSyncResponse(void* arg); static void HandleDBSyncResponse(void* arg); static void HandleTrySyncResponse(void* arg); static void HandleRemoveSlaveNodeResponse(void* arg); - static Status TrySyncConsensusCheck(const InnerMessage::ConsensusMeta& consensus_meta, + static pstd::Status TrySyncConsensusCheck(const InnerMessage::ConsensusMeta& consensus_meta, const std::shared_ptr& partition, const std::shared_ptr& slave_partition); static bool IsTableStructConsistent(const std::vector& current_tables, @@ -36,13 +37,13 @@ class PikaReplClientConn : public net::PbConn { private: // dispatch binlog by its table_name + partition - void DispatchBinlogRes(const std::shared_ptr response); + void DispatchBinlogRes(const std::shared_ptr& response); struct ReplRespArg { std::shared_ptr resp; std::shared_ptr conn; ReplRespArg(std::shared_ptr _resp, std::shared_ptr _conn) - : resp(_resp), conn(_conn) {} + : resp(std::move(_resp)), conn(std::move(_conn)) {} }; }; diff --git a/include/pika_repl_client_thread.h b/include/pika_repl_client_thread.h index 94c0ea029f..92c29ee0a2 100644 --- a/include/pika_repl_client_thread.h +++ b/include/pika_repl_client_thread.h @@ -17,13 +17,13 @@ class PikaReplClientThread : public net::ClientThread { public: PikaReplClientThread(int cron_interval, int keepalive_timeout); - virtual ~PikaReplClientThread() = default; + ~PikaReplClientThread() override = default; int Start(); private: class ReplClientConnFactory : public net::ConnFactory { public: - virtual std::shared_ptr NewNetConn(int connfd, const std::string& ip_port, net::Thread* thread, + std::shared_ptr NewNetConn(int connfd, const std::string& ip_port, net::Thread* thread, void* worker_specific_data, net::NetMultiplexer* net) const override { return std::static_pointer_cast( @@ -45,7 +45,7 @@ class PikaReplClientThread : public net::ClientThread { } int CreateWorkerSpecificData(void** data) const override { return 0; } int DeleteWorkerSpecificData(void* data) const override { return 0; } - void DestConnectFailedHandle(std::string ip_port, std::string reason) const override {} + void DestConnectFailedHandle(const std::string& ip_port, const std::string& reason) const override {} }; ReplClientConnFactory conn_factory_; diff --git a/include/pika_repl_server.h b/include/pika_repl_server.h index 5e743dea30..68daf1ee4d 100644 --- a/include/pika_repl_server.h +++ b/include/pika_repl_server.h @@ -9,6 +9,7 @@ #include "net/include/thread_pool.h" #include +#include #include #include "include/pika_command.h" @@ -19,7 +20,7 @@ struct ReplServerTaskArg { std::shared_ptr req; std::shared_ptr conn; ReplServerTaskArg(std::shared_ptr _req, std::shared_ptr _conn) - : req(_req), conn(_conn) {} + : req(std::move(_req)), conn(std::move(_conn)) {} }; class PikaReplServer { @@ -33,7 +34,7 @@ class PikaReplServer { pstd::Status SendSlaveBinlogChips(const std::string& ip, int port, const std::vector& tasks); void BuildBinlogOffset(const LogOffset& offset, InnerMessage::BinlogOffset* boffset); void BuildBinlogSyncResp(const std::vector& tasks, InnerMessage::InnerResponse* resp); - pstd::Status Write(const std::string& ip, const int port, const std::string& msg); + pstd::Status Write(const std::string& ip, int port, const std::string& msg); void Schedule(net::TaskFunc func, void* arg); void UpdateClientConnMap(const std::string& ip_port, int fd); diff --git a/include/pika_repl_server_conn.h b/include/pika_repl_server_conn.h index 178ea1d991..671f0aabc1 100644 --- a/include/pika_repl_server_conn.h +++ b/include/pika_repl_server_conn.h @@ -18,9 +18,9 @@ class SyncMasterPartition; class PikaReplServerConn : public net::PbConn { public: - PikaReplServerConn(int fd, std::string ip_port, net::Thread* thread, void* worker_specific_data, + PikaReplServerConn(int fd, const std::string& ip_port, net::Thread* thread, void* worker_specific_data, net::NetMultiplexer* mpx); - virtual ~PikaReplServerConn(); + ~PikaReplServerConn() override; static void HandleMetaSyncRequest(void* arg); static void HandleTrySyncRequest(void* arg); @@ -43,7 +43,7 @@ class PikaReplServerConn : public net::PbConn { static void HandleBinlogSyncRequest(void* arg); static void HandleRemoveSlaveNodeRequest(void* arg); - int DealMessage(); + int DealMessage() override; }; #endif // INCLUDE_PIKA_REPL_SERVER_CONN_H_ diff --git a/include/pika_repl_server_thread.h b/include/pika_repl_server_thread.h index c7c51aaa20..013dd869a0 100644 --- a/include/pika_repl_server_thread.h +++ b/include/pika_repl_server_thread.h @@ -13,7 +13,7 @@ class PikaReplServerThread : public net::HolyThread { public: PikaReplServerThread(const std::set& ips, int port, int cron_interval); - virtual ~PikaReplServerThread() = default; + ~PikaReplServerThread() override = default; int ListenPort(); @@ -25,7 +25,7 @@ class PikaReplServerThread : public net::HolyThread { public: explicit ReplServerConnFactory(PikaReplServerThread* binlog_receiver) : binlog_receiver_(binlog_receiver) {} - virtual std::shared_ptr NewNetConn(int connfd, const std::string& ip_port, net::Thread* thread, + std::shared_ptr NewNetConn(int connfd, const std::string& ip_port, net::Thread* thread, void* worker_specific_data, net::NetMultiplexer* net) const override { return std::static_pointer_cast( @@ -38,7 +38,7 @@ class PikaReplServerThread : public net::HolyThread { class ReplServerHandle : public net::ServerHandle { public: - virtual void FdClosedHandle(int fd, const std::string& ip_port) const override; + void FdClosedHandle(int fd, const std::string& ip_port) const override; }; ReplServerConnFactory conn_factory_; diff --git a/include/pika_rm.h b/include/pika_rm.h index 42b431393a..a7d77fb711 100644 --- a/include/pika_rm.h +++ b/include/pika_rm.h @@ -29,7 +29,6 @@ #define kSendKeepAliveTimeout (2 * 1000000) #define kRecvKeepAliveTimeout (20 * 1000000) -using pstd::Status; class SyncPartition { public: @@ -47,36 +46,36 @@ class SyncPartition { class SyncMasterPartition : public SyncPartition { public: SyncMasterPartition(const std::string& table_name, uint32_t partition_id); - Status AddSlaveNode(const std::string& ip, int port, int session_id); - Status RemoveSlaveNode(const std::string& ip, int port); + pstd::Status AddSlaveNode(const std::string& ip, int port, int session_id); + pstd::Status RemoveSlaveNode(const std::string& ip, int port); - Status ActivateSlaveBinlogSync(const std::string& ip, int port, const LogOffset& offset); - Status ActivateSlaveDbSync(const std::string& ip, int port); + pstd::Status ActivateSlaveBinlogSync(const std::string& ip, int port, const LogOffset& offset); + pstd::Status ActivateSlaveDbSync(const std::string& ip, int port); - Status SyncBinlogToWq(const std::string& ip, int port); + pstd::Status SyncBinlogToWq(const std::string& ip, int port); - Status GetSlaveSyncBinlogInfo(const std::string& ip, int port, BinlogOffset* sent_offset, BinlogOffset* acked_offset); - Status GetSlaveState(const std::string& ip, int port, SlaveState* const slave_state); + pstd::Status GetSlaveSyncBinlogInfo(const std::string& ip, int port, BinlogOffset* sent_offset, BinlogOffset* acked_offset); + pstd::Status GetSlaveState(const std::string& ip, int port, SlaveState* slave_state); - Status SetLastSendTime(const std::string& ip, int port, uint64_t time); - Status GetLastSendTime(const std::string& ip, int port, uint64_t* time); + pstd::Status SetLastSendTime(const std::string& ip, int port, uint64_t time); + pstd::Status GetLastSendTime(const std::string& ip, int port, uint64_t* time); - Status SetLastRecvTime(const std::string& ip, int port, uint64_t time); - Status GetLastRecvTime(const std::string& ip, int port, uint64_t* time); + pstd::Status SetLastRecvTime(const std::string& ip, int port, uint64_t time); + pstd::Status GetLastRecvTime(const std::string& ip, int port, uint64_t* time); - Status GetSafetyPurgeBinlog(std::string* safety_purge); + pstd::Status GetSafetyPurgeBinlog(std::string* safety_purge); bool BinlogCloudPurge(uint32_t index); - Status WakeUpSlaveBinlogSync(); - Status CheckSyncTimeout(uint64_t now); + pstd::Status WakeUpSlaveBinlogSync(); + pstd::Status CheckSyncTimeout(uint64_t now); int GetNumberOfSlaveNode(); bool CheckSlaveNodeExist(const std::string& ip, int port); - Status GetSlaveNodeSession(const std::string& ip, int port, int32_t* session); + pstd::Status GetSlaveNodeSession(const std::string& ip, int port, int32_t* session); void GetValidSlaveNames(std::vector* slavenames); // display use - Status GetInfo(std::string* info); + pstd::Status GetInfo(std::string* info); // debug use std::string ToStringStatus(); @@ -85,21 +84,21 @@ class SyncMasterPartition : public SyncPartition { int session_id); // consensus use - Status ConsensusUpdateSlave(const std::string& ip, int port, const LogOffset& start, const LogOffset& end); - Status ConsensusProposeLog(std::shared_ptr cmd_ptr, std::shared_ptr conn_ptr, + pstd::Status ConsensusUpdateSlave(const std::string& ip, int port, const LogOffset& start, const LogOffset& end); + pstd::Status ConsensusProposeLog(const std::shared_ptr& cmd_ptr, std::shared_ptr conn_ptr, std::shared_ptr resp_ptr); - Status ConsensusSanityCheck(); - Status ConsensusProcessLeaderLog(std::shared_ptr cmd_ptr, const BinlogItem& attribute); - Status ConsensusProcessLocalUpdate(const LogOffset& leader_commit); + pstd::Status ConsensusSanityCheck(); + pstd::Status ConsensusProcessLeaderLog(const std::shared_ptr& cmd_ptr, const BinlogItem& attribute); + pstd::Status ConsensusProcessLocalUpdate(const LogOffset& leader_commit); LogOffset ConsensusCommittedIndex(); LogOffset ConsensusLastIndex(); uint32_t ConsensusTerm(); void ConsensusUpdateTerm(uint32_t term); - Status ConsensusUpdateAppliedIndex(const LogOffset& offset); + pstd::Status ConsensusUpdateAppliedIndex(const LogOffset& offset); LogOffset ConsensusAppliedIndex(); - Status ConsensusLeaderNegotiate(const LogOffset& f_last_offset, bool* reject, std::vector* hints); - Status ConsensusFollowerNegotiate(const std::vector& hints, LogOffset* reply_offset); - Status ConsensusReset(LogOffset applied_offset); + pstd::Status ConsensusLeaderNegotiate(const LogOffset& f_last_offset, bool* reject, std::vector* hints); + pstd::Status ConsensusFollowerNegotiate(const std::vector& hints, LogOffset* reply_offset); + pstd::Status ConsensusReset(const LogOffset& applied_offset); void CommitPreviousLogs(const uint32_t& term); std::shared_ptr StableLogger() { return coordinator_.StableLogger(); } @@ -114,7 +113,7 @@ class SyncMasterPartition : public SyncPartition { private: bool CheckReadBinlogFromCache(); // invoker need to hold slave_mu_ - Status ReadBinlogFileToWq(const std::shared_ptr& slave_ptr); + pstd::Status ReadBinlogFileToWq(const std::shared_ptr& slave_ptr); std::shared_ptr GetSlaveNode(const std::string& ip, int port); std::unordered_map> GetAllSlaveNodes(); @@ -138,10 +137,10 @@ class SyncSlavePartition : public SyncPartition { void SetReplState(const ReplState& repl_state); ReplState State(); - Status CheckSyncTimeout(uint64_t now); + pstd::Status CheckSyncTimeout(uint64_t now); // For display - Status GetInfo(std::string* info); + pstd::Status GetInfo(std::string* info); // For debug std::string ToStringStatus(); @@ -176,26 +175,26 @@ class PikaReplicaManager { bool CheckMasterSyncFinished(); - Status AddSyncPartitionSanityCheck(const std::set& p_infos); - Status AddSyncPartition(const std::set& p_infos); - Status RemoveSyncPartitionSanityCheck(const std::set& p_infos); - Status RemoveSyncPartition(const std::set& p_infos); - Status ActivateSyncSlavePartition(const RmNode& node, const ReplState& repl_state); - Status DeactivateSyncSlavePartition(const PartitionInfo& p_info); - Status SyncTableSanityCheck(const std::string& table_name); - Status DelSyncTable(const std::string& table_name); + pstd::Status AddSyncPartitionSanityCheck(const std::set& p_infos); + pstd::Status AddSyncPartition(const std::set& p_infos); + pstd::Status RemoveSyncPartitionSanityCheck(const std::set& p_infos); + pstd::Status RemoveSyncPartition(const std::set& p_infos); + pstd::Status ActivateSyncSlavePartition(const RmNode& node, const ReplState& repl_state); + pstd::Status DeactivateSyncSlavePartition(const PartitionInfo& p_info); + pstd::Status SyncTableSanityCheck(const std::string& table_name); + pstd::Status DelSyncTable(const std::string& table_name); // For Pika Repl Client Thread - Status SendMetaSyncRequest(); - Status SendRemoveSlaveNodeRequest(const std::string& table, uint32_t partition_id); - Status SendPartitionTrySyncRequest(const std::string& table_name, size_t partition_id); - Status SendPartitionDBSyncRequest(const std::string& table_name, size_t partition_id); - Status SendPartitionBinlogSyncAckRequest(const std::string& table, uint32_t partition_id, const LogOffset& ack_start, + pstd::Status SendMetaSyncRequest(); + pstd::Status SendRemoveSlaveNodeRequest(const std::string& table, uint32_t partition_id); + pstd::Status SendPartitionTrySyncRequest(const std::string& table_name, size_t partition_id); + pstd::Status SendPartitionDBSyncRequest(const std::string& table_name, size_t partition_id); + pstd::Status SendPartitionBinlogSyncAckRequest(const std::string& table, uint32_t partition_id, const LogOffset& ack_start, const LogOffset& ack_end, bool is_first_send = false); - Status CloseReplClientConn(const std::string& ip, int32_t port); + pstd::Status CloseReplClientConn(const std::string& ip, int32_t port); // For Pika Repl Server Thread - Status SendSlaveBinlogChipsRequest(const std::string& ip, int port, const std::vector& tasks); + pstd::Status SendSlaveBinlogChipsRequest(const std::string& ip, int port, const std::vector& tasks); // For SyncMasterPartition std::shared_ptr GetSyncMasterPartitionByName(const PartitionInfo& p_info); @@ -203,28 +202,28 @@ class PikaReplicaManager { // For SyncSlavePartition std::shared_ptr GetSyncSlavePartitionByName(const PartitionInfo& p_info); - Status RunSyncSlavePartitionStateMachine(); + pstd::Status RunSyncSlavePartitionStateMachine(); - Status CheckSyncTimeout(uint64_t now); + pstd::Status CheckSyncTimeout(uint64_t now); // To check partition info // For pkcluster info command - Status GetPartitionInfo(const std::string& table, uint32_t partition_id, std::string* info); + pstd::Status GetPartitionInfo(const std::string& table, uint32_t partition_id, std::string* info); void FindCompleteReplica(std::vector* replica); void FindCommonMaster(std::string* master); - Status CheckPartitionRole(const std::string& table, uint32_t partition_id, int* role); + pstd::Status CheckPartitionRole(const std::string& table, uint32_t partition_id, int* role); void RmStatus(std::string* debug_info); - static bool CheckSlavePartitionState(const std::string& ip, const int port); + static bool CheckSlavePartitionState(const std::string& ip, int port); - Status LostConnection(const std::string& ip, int port); + pstd::Status LostConnection(const std::string& ip, int port); // Update binlog win and try to send next binlog - Status UpdateSyncBinlogStatus(const RmNode& slave, const LogOffset& offset_start, const LogOffset& offset_end); + pstd::Status UpdateSyncBinlogStatus(const RmNode& slave, const LogOffset& offset_start, const LogOffset& offset_end); - Status WakeUpBinlogSync(); + pstd::Status WakeUpBinlogSync(); // write_queue related void ProduceWriteQueue(const std::string& ip, int port, uint32_t partition_id, const std::vector& tasks); @@ -235,9 +234,9 @@ class PikaReplicaManager { void ScheduleReplServerBGTask(net::TaskFunc func, void* arg); void ScheduleReplClientBGTask(net::TaskFunc func, void* arg); void ScheduleWriteBinlogTask(const std::string& table_partition, - const std::shared_ptr res, + const std::shared_ptr& res, std::shared_ptr conn, void* res_private_data); - void ScheduleWriteDBTask(const std::shared_ptr cmd_ptr, const LogOffset& offset, const std::string& table_name, + void ScheduleWriteDBTask(const std::shared_ptr& cmd_ptr, const LogOffset& offset, const std::string& table_name, uint32_t partition_id); void ReplServerRemoveClientConn(int fd); @@ -245,7 +244,7 @@ class PikaReplicaManager { private: void InitPartition(); - Status SelectLocalIp(const std::string& remote_ip, const int remote_port, std::string* const local_ip); + pstd::Status SelectLocalIp(const std::string& remote_ip, int remote_port, std::string* local_ip); std::shared_mutex partitions_rw_; std::unordered_map, hash_partition_info> sync_master_partitions_; diff --git a/include/pika_rsync_service.h b/include/pika_rsync_service.h index 8ab976f897..a5c2bdf1e7 100644 --- a/include/pika_rsync_service.h +++ b/include/pika_rsync_service.h @@ -10,7 +10,7 @@ class PikaRsyncService { public: - PikaRsyncService(const std::string& raw_path, const int port); + PikaRsyncService(const std::string& raw_path, int port); ~PikaRsyncService(); int StartRsync(); bool CheckRsyncAlive(); diff --git a/include/pika_server.h b/include/pika_server.h index d9c965b50f..3154bbed01 100644 --- a/include/pika_server.h +++ b/include/pika_server.h @@ -37,8 +37,7 @@ #include "include/pika_statistic.h" #include "include/pika_table.h" -using pstd::Slice; -using pstd::Status; + /* static std::set MultiKvCommands {kCmdNameDel, @@ -127,7 +126,7 @@ enum TaskType { kBgSave, }; -class PikaServer { +class PikaServer : public pstd::noncopyable { public: PikaServer(); ~PikaServer(); @@ -161,8 +160,8 @@ class PikaServer { * Table use */ void InitTableStruct(); - Status AddTableStruct(std::string table_name, uint32_t num); - Status DelTableStruct(std::string table_name); + pstd::Status AddTableStruct(const std::string& table_name, uint32_t num); + pstd::Status DelTableStruct(const std::string& table_name); std::shared_ptr GetTable(const std::string& table_name); std::set GetTablePartitionIds(const std::string& table_name); bool IsBgSaving(); @@ -172,7 +171,7 @@ class PikaServer { bool IsTablePartitionExist(const std::string& table_name, uint32_t partition_id); bool IsCommandSupport(const std::string& command); bool IsTableBinlogIoError(const std::string& table_name); - Status DoSameThingSpecificTable(const TaskType& type, const std::set& tables = {}); + pstd::Status DoSameThingSpecificTable(const TaskType& type, const std::set& tables = {}); /* * Partition use @@ -180,11 +179,11 @@ class PikaServer { void PreparePartitionTrySync(); void PartitionSetMaxCacheStatisticKeys(uint32_t max_cache_statistic_keys); void PartitionSetSmallCompactionThreshold(uint32_t small_compaction_threshold); - bool GetTablePartitionBinlogOffset(const std::string& table_name, uint32_t partition_id, BinlogOffset* const boffset); + bool GetTablePartitionBinlogOffset(const std::string& table_name, uint32_t partition_id, BinlogOffset* boffset); std::shared_ptr GetPartitionByDbName(const std::string& db_name); std::shared_ptr GetTablePartitionById(const std::string& table_name, uint32_t partition_id); std::shared_ptr GetTablePartitionByKey(const std::string& table_name, const std::string& key); - Status DoSameThingEveryPartition(const TaskType& type); + pstd::Status DoSameThingEveryPartition(const TaskType& type); /* * Master use @@ -298,7 +297,7 @@ class PikaServer { */ int SendToPeer(); void SignalAuxiliary(); - Status TriggerSendBinlogSync(); + pstd::Status TriggerSendBinlogSync(); /* * PubSub used @@ -306,14 +305,14 @@ class PikaServer { int PubSubNumPat(); int Publish(const std::string& channel, const std::string& msg); void EnablePublish(int fd); - int UnSubscribe(std::shared_ptr conn, const std::vector& channels, const bool pattern, + int UnSubscribe(const std::shared_ptr& conn, const std::vector& channels, bool pattern, std::vector>* result); - void Subscribe(std::shared_ptr conn, const std::vector& channels, const bool pattern, + void Subscribe(const std::shared_ptr& conn, const std::vector& channels, bool pattern, std::vector>* result); void PubSubChannels(const std::string& pattern, std::vector* result); void PubSubNumSub(const std::vector& channels, std::vector>* result); - Status GetCmdRouting(std::vector& redis_cmds, std::vector* dst, bool* all_local); + pstd::Status GetCmdRouting(std::vector& redis_cmds, std::vector* dst, bool* all_local); // info debug use void ServerStatus(std::string* info); @@ -441,8 +440,6 @@ class PikaServer { */ Statistic statistic_; - PikaServer(PikaServer& ps); - void operator=(const PikaServer& ps); }; #endif diff --git a/include/pika_set.h b/include/pika_set.h index 340b634a05..94c2e6fc75 100644 --- a/include/pika_set.h +++ b/include/pika_set.h @@ -1,4 +1,4 @@ -// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved. + // Copyright (c) 2015-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. @@ -15,95 +15,96 @@ class SAddCmd : public Cmd { public: SAddCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SAddCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SAddCmd(*this); } private: std::string key_; std::vector members_; - virtual void DoInitial() override; + void DoInitial() override; }; class SPopCmd : public Cmd { public: SPopCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SPopCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SPopCmd(*this); } private: std::string key_; int64_t count_; - virtual void DoInitial() override; + void DoInitial() override; }; class SCardCmd : public Cmd { public: SCardCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SCardCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SCardCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class SMembersCmd : public Cmd { public: SMembersCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SMembersCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SMembersCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class SScanCmd : public Cmd { public: - SScanCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*"), count_(10) {} - virtual std::vector current_key() const { + SScanCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*") {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SScanCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SScanCmd(*this); } private: std::string key_, pattern_ = "*"; - int64_t cursor_ = 0, count_ = 10; - virtual void DoInitial() override; - virtual void Clear() { + int64_t cursor_ = 0; + int64_t count_ = 10; + void DoInitial() override; + void Clear() override { pattern_ = "*"; count_ = 10; } @@ -112,153 +113,153 @@ class SScanCmd : public Cmd { class SRemCmd : public Cmd { public: SRemCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SRemCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SRemCmd(*this); } private: std::string key_; std::vector members_; - virtual void DoInitial() override; + void DoInitial() override; }; class SUnionCmd : public Cmd { public: SUnionCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SUnionCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SUnionCmd(*this); } private: std::vector keys_; - virtual void DoInitial() override; + void DoInitial() override; }; class SUnionstoreCmd : public Cmd { public: SUnionstoreCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SUnionstoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SUnionstoreCmd(*this); } private: std::string dest_key_; std::vector keys_; - virtual void DoInitial() override; + void DoInitial() override; }; class SInterCmd : public Cmd { public: SInterCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SInterCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SInterCmd(*this); } private: std::vector keys_; - virtual void DoInitial() override; + void DoInitial() override; }; class SInterstoreCmd : public Cmd { public: SInterstoreCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SInterstoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SInterstoreCmd(*this); } private: std::string dest_key_; std::vector keys_; - virtual void DoInitial() override; + void DoInitial() override; }; class SIsmemberCmd : public Cmd { public: SIsmemberCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SIsmemberCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SIsmemberCmd(*this); } private: std::string key_, member_; - virtual void DoInitial() override; + void DoInitial() override; }; class SDiffCmd : public Cmd { public: SDiffCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SDiffCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SDiffCmd(*this); } private: std::vector keys_; - virtual void DoInitial() override; + void DoInitial() override; }; class SDiffstoreCmd : public Cmd { public: SDiffstoreCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SDiffstoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SDiffstoreCmd(*this); } private: std::string dest_key_; std::vector keys_; - virtual void DoInitial() override; + void DoInitial() override; }; class SMoveCmd : public Cmd { public: SMoveCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SMoveCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SMoveCmd(*this); } private: std::string src_key_, dest_key_, member_; - virtual void DoInitial() override; + void DoInitial() override; }; class SRandmemberCmd : public Cmd { public: - SRandmemberCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), count_(1) {} - virtual std::vector current_key() const { + SRandmemberCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new SRandmemberCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new SRandmemberCmd(*this); } private: std::string key_; int64_t count_ = 1; bool reply_arr = false; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { count_ = 1; reply_arr = false; } diff --git a/include/pika_slave_node.h b/include/pika_slave_node.h index 37a2844b82..3953a070c3 100644 --- a/include/pika_slave_node.h +++ b/include/pika_slave_node.h @@ -21,15 +21,15 @@ struct SyncWinItem { offset_.b_offset.offset == other.offset_.b_offset.offset; } explicit SyncWinItem(const LogOffset& offset, std::size_t binlog_size = 0) - : offset_(offset), binlog_size_(binlog_size), acked_(false) {} + : offset_(offset), binlog_size_(binlog_size) {} std::string ToString() const { - return offset_.ToString() + " binglog size: " + std::to_string(binlog_size_) + " acked: " + std::to_string(acked_); + return offset_.ToString() + " binglog size: " + std::to_string(binlog_size_) + " acked: " + std::to_string(static_cast(acked_)); } }; class SyncWindow { public: - SyncWindow() : total_size_(0) {} + SyncWindow() = default; void Push(const SyncWinItem& item); bool Update(const SyncWinItem& start_item, const SyncWinItem& end_item, LogOffset* acked_offset); int Remaining(); @@ -60,7 +60,7 @@ class SyncWindow { class SlaveNode : public RmNode { public: SlaveNode(const std::string& ip, int port, const std::string& table_name, uint32_t partition_id, int session_id); - ~SlaveNode(); + ~SlaveNode() override; void Lock() { slave_mu.lock(); } void Unlock() { slave_mu.unlock(); } SlaveState slave_state; @@ -73,8 +73,8 @@ class SlaveNode : public RmNode { std::string ToStringStatus(); std::shared_ptr binlog_reader; - Status InitBinlogFileReader(const std::shared_ptr& binlog, const BinlogOffset& offset); - Status Update(const LogOffset& start, const LogOffset& end, LogOffset* updated_offset); + pstd::Status InitBinlogFileReader(const std::shared_ptr& binlog, const BinlogOffset& offset); + pstd::Status Update(const LogOffset& start, const LogOffset& end, LogOffset* updated_offset); pstd::Mutex slave_mu; }; diff --git a/include/pika_stable_log.h b/include/pika_stable_log.h index 3bba4be933..746ea2300b 100644 --- a/include/pika_stable_log.h +++ b/include/pika_stable_log.h @@ -13,7 +13,7 @@ class StableLog : public std::enable_shared_from_this { public: - StableLog(const std::string table_name, uint32_t partition_id, const std::string& log_path); + StableLog(std::string table_name, uint32_t partition_id, std::string log_path); ~StableLog(); std::shared_ptr Logger() { return stable_logger_; } void Leave(); @@ -26,13 +26,13 @@ class StableLog : public std::enable_shared_from_this { return first_offset_; } // Need to hold binlog lock - Status TruncateTo(const LogOffset& offset); + pstd::Status TruncateTo(const LogOffset& offset); // Purgelogs use bool PurgeStableLogs(uint32_t to = 0, bool manual = false); void ClearPurge(); bool GetBinlogFiles(std::map* binlogs); - Status PurgeFileAfter(uint32_t filenum); + pstd::Status PurgeFileAfter(uint32_t filenum); private: void Close(); diff --git a/include/pika_statistic.h b/include/pika_statistic.h index 90275d786d..37bb2111e2 100644 --- a/include/pika_statistic.h +++ b/include/pika_statistic.h @@ -15,7 +15,7 @@ class QpsStatistic { public: QpsStatistic(); QpsStatistic(const QpsStatistic& other); - ~QpsStatistic(); + ~QpsStatistic() = default; void IncreaseQueryNum(bool is_write); diff --git a/include/pika_table.h b/include/pika_table.h index deadf22b2f..3deb19276a 100644 --- a/include/pika_table.h +++ b/include/pika_table.h @@ -7,14 +7,15 @@ #define PIKA_TABLE_H_ #include + #include "storage/storage.h" #include "include/pika_command.h" #include "include/pika_partition.h" -class Table : public std::enable_shared_from_this
{ +class Table : public std::enable_shared_from_this
, public pstd::noncopyable { public: - Table(const std::string& table_name, uint32_t partition_num, const std::string& db_path, const std::string& log_path); + Table(std::string table_name, uint32_t partition_num, const std::string& db_path, const std::string& log_path); virtual ~Table(); friend class Cmd; @@ -33,8 +34,8 @@ class Table : public std::enable_shared_from_this
{ void GetAllPartitions(std::set& partition_ids); // Dynamic change partition - Status AddPartitions(const std::set& partition_ids); - Status RemovePartitions(const std::set& partition_ids); + pstd::Status AddPartitions(const std::set& partition_ids); + pstd::Status RemovePartitions(const std::set& partition_ids); // KeyScan use; void KeyScan(); @@ -43,7 +44,7 @@ class Table : public std::enable_shared_from_this
{ void StopKeyScan(); void ScanDatabase(const storage::DataType& type); KeyScanInfo GetKeyScanInfo(); - Status GetPartitionsKeyScanInfo(std::map* infos); + pstd::Status GetPartitionsKeyScanInfo(std::map* infos); // Compact use; void Compact(const storage::DataType& type); @@ -53,8 +54,8 @@ class Table : public std::enable_shared_from_this
{ std::shared_ptr GetPartitionById(uint32_t partition_id); std::shared_ptr GetPartitionByKey(const std::string& key); bool TableIsEmpty(); - Status MovetoToTrash(const std::string& path); - Status Leave(); + pstd::Status MovetoToTrash(const std::string& path); + pstd::Status Leave(); private: std::string table_name_; @@ -76,12 +77,6 @@ class Table : public std::enable_shared_from_this
{ void InitKeyScan(); pstd::Mutex key_scan_protector_; KeyScanInfo key_scan_info_; - - /* - * No allowed copy and copy assign - */ - Table(const Table&); - void operator=(const Table&); }; struct BgTaskArg { diff --git a/include/pika_zset.h b/include/pika_zset.h index 7ef4d1fe56..181035a43a 100644 --- a/include/pika_zset.h +++ b/include/pika_zset.h @@ -17,58 +17,58 @@ class ZAddCmd : public Cmd { public: ZAddCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZAddCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZAddCmd(*this); } private: std::string key_; std::vector score_members; - virtual void DoInitial() override; + void DoInitial() override; }; class ZCardCmd : public Cmd { public: ZCardCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZCardCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZCardCmd(*this); } private: std::string key_; - virtual void DoInitial() override; + void DoInitial() override; }; class ZScanCmd : public Cmd { public: - ZScanCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*"), count_(10) {} - virtual std::vector current_key() const { + ZScanCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), pattern_("*") {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZScanCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZScanCmd(*this); } private: std::string key_, pattern_ = "*"; int64_t cursor_ = 0, count_ = 10; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { pattern_ = "*"; count_ = 10; } @@ -77,80 +77,80 @@ class ZScanCmd : public Cmd { class ZIncrbyCmd : public Cmd { public: ZIncrbyCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZIncrbyCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZIncrbyCmd(*this); } private: std::string key_, member_; double by_ = 0; - virtual void DoInitial() override; + void DoInitial() override; }; class ZsetRangeParentCmd : public Cmd { public: - ZsetRangeParentCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag), is_ws_(false) {} + ZsetRangeParentCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} protected: std::string key_; int64_t start_ = 0, stop_ = -1; bool is_ws_ = false; - virtual void DoInitial() override; - virtual void Clear() { is_ws_ = false; } + void DoInitial() override; + void Clear() override { is_ws_ = false; } }; class ZRangeCmd : public ZsetRangeParentCmd { public: ZRangeCmd(const std::string& name, int arity, uint16_t flag) : ZsetRangeParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRangeCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZRevrangeCmd : public ZsetRangeParentCmd { public: ZRevrangeCmd(const std::string& name, int arity, uint16_t flag) : ZsetRangeParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRevrangeCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRevrangeCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZsetRangebyscoreParentCmd : public Cmd { public: ZsetRangebyscoreParentCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), left_close_(true), right_close_(true), with_scores_(false), offset_(0), count_(-1) {} + : Cmd(name, arity, flag) {} protected: std::string key_; double min_score_ = 0, max_score_ = 0; bool left_close_ = true, right_close_ = true, with_scores_ = false; int64_t offset_ = 0, count_ = -1; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { left_close_ = right_close_ = true; with_scores_ = false; offset_ = 0; @@ -161,58 +161,58 @@ class ZsetRangebyscoreParentCmd : public Cmd { class ZRangebyscoreCmd : public ZsetRangebyscoreParentCmd { public: ZRangebyscoreCmd(const std::string& name, int arity, uint16_t flag) : ZsetRangebyscoreParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRangebyscoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRangebyscoreCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZRevrangebyscoreCmd : public ZsetRangebyscoreParentCmd { public: ZRevrangebyscoreCmd(const std::string& name, int arity, uint16_t flag) : ZsetRangebyscoreParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRevrangebyscoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRevrangebyscoreCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZCountCmd : public Cmd { public: ZCountCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), left_close_(true), right_close_(true) {} - virtual std::vector current_key() const { + : Cmd(name, arity, flag) {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZCountCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZCountCmd(*this); } private: std::string key_; double min_score_ = 0, max_score_ = 0; bool left_close_ = true, right_close_ = true; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { left_close_ = true; right_close_ = true; } @@ -221,20 +221,20 @@ class ZCountCmd : public Cmd { class ZRemCmd : public Cmd { public: ZRemCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRemCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRemCmd(*this); } private: std::string key_; std::vector members_; - virtual void DoInitial() override; + void DoInitial() override; }; class ZsetUIstoreParentCmd : public Cmd { @@ -248,32 +248,32 @@ class ZsetUIstoreParentCmd : public Cmd { storage::AGGREGATE aggregate_; std::vector keys_; std::vector weights_; - virtual void DoInitial() override; - virtual void Clear() { aggregate_ = storage::SUM; } + void DoInitial() override; + void Clear() override { aggregate_ = storage::SUM; } }; class ZUnionstoreCmd : public ZsetUIstoreParentCmd { public: ZUnionstoreCmd(const std::string& name, int arity, uint16_t flag) : ZsetUIstoreParentCmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZUnionstoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZUnionstoreCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZInterstoreCmd : public ZsetUIstoreParentCmd { public: ZInterstoreCmd(const std::string& name, int arity, uint16_t flag) : ZsetUIstoreParentCmd(name, arity, flag) {} - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZInterstoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZInterstoreCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZsetRankParentCmd : public Cmd { @@ -282,72 +282,72 @@ class ZsetRankParentCmd : public Cmd { protected: std::string key_, member_; - virtual void DoInitial() override; + void DoInitial() override; }; class ZRankCmd : public ZsetRankParentCmd { public: ZRankCmd(const std::string& name, int arity, uint16_t flag) : ZsetRankParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRankCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRankCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZRevrankCmd : public ZsetRankParentCmd { public: ZRevrankCmd(const std::string& name, int arity, uint16_t flag) : ZsetRankParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRevrankCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRevrankCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZScoreCmd : public ZsetRankParentCmd { public: ZScoreCmd(const std::string& name, int arity, uint16_t flag) : ZsetRankParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZScoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZScoreCmd(*this); } private: std::string key_, member_; - virtual void DoInitial() override; + void DoInitial() override; }; class ZsetRangebylexParentCmd : public Cmd { public: ZsetRangebylexParentCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), left_close_(true), right_close_(true), offset_(0), count_(-1) {} + : Cmd(name, arity, flag) {} protected: std::string key_, min_member_, max_member_; bool left_close_ = true, right_close_ = true; int64_t offset_ = 0, count_ = -1; - virtual void DoInitial() override; - virtual void Clear() { + void DoInitial() override; + void Clear() override { left_close_ = right_close_ = true; offset_ = 0; count_ = -1; @@ -357,136 +357,136 @@ class ZsetRangebylexParentCmd : public Cmd { class ZRangebylexCmd : public ZsetRangebylexParentCmd { public: ZRangebylexCmd(const std::string& name, int arity, uint16_t flag) : ZsetRangebylexParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRangebylexCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRangebylexCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZRevrangebylexCmd : public ZsetRangebylexParentCmd { public: ZRevrangebylexCmd(const std::string& name, int arity, uint16_t flag) : ZsetRangebylexParentCmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRevrangebylexCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRevrangebylexCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; }; class ZLexcountCmd : public Cmd { public: ZLexcountCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), left_close_(true), right_close_(true) {} - virtual std::vector current_key() const { + : Cmd(name, arity, flag) {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZLexcountCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZLexcountCmd(*this); } private: std::string key_, min_member_, max_member_; bool left_close_ = true, right_close_ = true; - virtual void DoInitial() override; - virtual void Clear() { left_close_ = right_close_ = true; } + void DoInitial() override; + void Clear() override { left_close_ = right_close_ = true; } }; class ZRemrangebyrankCmd : public Cmd { public: ZRemrangebyrankCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRemrangebyrankCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRemrangebyrankCmd(*this); } private: std::string key_; int64_t start_rank_ = 0, stop_rank_ = -1; - virtual void DoInitial() override; + void DoInitial() override; }; class ZRemrangebyscoreCmd : public Cmd { public: ZRemrangebyscoreCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), left_close_(true), right_close_(true) {} - virtual std::vector current_key() const { + : Cmd(name, arity, flag) {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRemrangebyscoreCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRemrangebyscoreCmd(*this); } private: std::string key_; double min_score_ = 0, max_score_ = 0; bool left_close_ = true, right_close_ = true; - virtual void DoInitial() override; - virtual void Clear() { left_close_ = right_close_ = true; } + void DoInitial() override; + void Clear() override { left_close_ = right_close_ = true; } }; class ZRemrangebylexCmd : public Cmd { public: ZRemrangebylexCmd(const std::string& name, int arity, uint16_t flag) - : Cmd(name, arity, flag), left_close_(true), right_close_(true) {} - virtual std::vector current_key() const { + : Cmd(name, arity, flag) {} + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZRemrangebylexCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZRemrangebylexCmd(*this); } private: std::string key_; std::string min_member_, max_member_; bool left_close_ = true, right_close_ = true; - virtual void DoInitial() override; - virtual void Clear() { left_close_ = right_close_ = true; } + void DoInitial() override; + void Clear() override { left_close_ = right_close_ = true; } }; class ZPopmaxCmd : public Cmd { public: ZPopmaxCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.emplace_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZPopmaxCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZPopmaxCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; std::string key_; int64_t count_ = 0; }; @@ -494,18 +494,18 @@ class ZPopmaxCmd : public Cmd { class ZPopminCmd : public Cmd { public: ZPopminCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} - virtual std::vector current_key() const { + std::vector current_key() const override { std::vector res; res.push_back(key_); return res; } - virtual void Do(std::shared_ptr partition = nullptr); - virtual void Split(std::shared_ptr partition, const HintKeys& hint_keys){}; - virtual void Merge(){}; - virtual Cmd* Clone() override { return new ZPopminCmd(*this); } + void Do(std::shared_ptr partition = nullptr) override; + void Split(std::shared_ptr partition, const HintKeys& hint_keys) override {}; + void Merge() override {}; + Cmd* Clone() override { return new ZPopminCmd(*this); } private: - virtual void DoInitial() override; + void DoInitial() override; std::string key_; int64_t count_ = 0; }; diff --git a/run_clang_tidy.py b/run_clang_tidy.py new file mode 100755 index 0000000000..54086fad96 --- /dev/null +++ b/run_clang_tidy.py @@ -0,0 +1,401 @@ +#!/usr/bin/env python3 +# +#===- run-clang-tidy.py - Parallel clang-tidy runner ---------*- python -*--===# +# +# The LLVM Compiler Infrastructure +# +#===------------------------------------------------------------------------===# +# FIXME: Integrate with clang-tidy-diff.py + +""" +Parallel clang-tidy runner +========================== +Runs clang-tidy over all files in a compilation database. Requires clang-tidy +and clang-apply-replacements in $PATH. +Example invocations. +- Run clang-tidy on all files in the current working directory with a default + set of checks and show warnings in the cpp files and all project headers. + run-clang-tidy.py $PWD +- Fix all header guards. + run-clang-tidy.py -fix -checks=-*,llvm-header-guard +- Fix all header guards included from clang-tidy and header guards + for clang-tidy headers. + run-clang-tidy.py -fix -checks=-*,llvm-header-guard extra/clang-tidy \ + -header-filter=extra/clang-tidy +Compilation database setup: +http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html +""" + +from __future__ import division +from __future__ import print_function + +import argparse +import glob +import json +import multiprocessing +import os +import pprint +import re +import shutil +import subprocess +import sys +import tempfile +import threading +import traceback +# import yaml + + +is_py2 = sys.version[0] == '2' + +if is_py2: + import Queue as queue +else: + import queue as queue + + +def find_compilation_database(path): + """Adjusts the directory until a compilation database is found.""" + result = './' + while not os.path.isfile(os.path.join(result, path)): + if os.path.realpath(result) == '/': + print('Error: could not find compilation database.') + sys.exit(1) + result += '../' + return os.path.realpath(result) + + +def make_absolute(f, directory): + if os.path.isabs(f): + return f + return os.path.normpath(os.path.join(directory, f)) + + +def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path, + header_filter, extra_arg, extra_arg_before, quiet, + config): + """Gets a command line for clang-tidy.""" + start = [clang_tidy_binary] + if header_filter is not None: + start.append('-header-filter=' + header_filter) + else: + pass + if checks: + start.append('-checks=' + checks) + if tmpdir is not None: + start.append('-export-fixes') + # Get a temporary file. We immediately close the handle so clang-tidy can + # overwrite it. + (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir) + os.close(handle) + start.append(name) + for arg in extra_arg: + start.append('-extra-arg=%s' % arg) + for arg in extra_arg_before: + start.append('-extra-arg-before=%s' % arg) + start.append('-p=' + build_path) + if quiet: + start.append('-quiet') + if config: + start.append('-config=' + config) + start.append(f) + return start + + +def merge_replacement_files(tmpdir, mergefile): + """Merge all replacement files in a directory into a single file""" + # The fixes suggested by clang-tidy >= 4.0.0 are given under + # the top level key 'Diagnostics' in the output yaml files + mergekey = "Diagnostics" + merged = [] + for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')): + content = yaml.safe_load(open(replacefile, 'r')) + if not content: + continue # Skip empty files. + merged.extend(content.get(mergekey, [])) + + if merged: + # MainSourceFile: The key is required by the definition inside + # include/clang/Tooling/ReplacementsYaml.h, but the value + # is actually never used inside clang-apply-replacements, + # so we set it to '' here. + output = {'MainSourceFile': '', mergekey: merged} + with open(mergefile, 'w') as out: + yaml.safe_dump(output, out) + else: + # Empty the file: + open(mergefile, 'w').close() + + +def check_clang_apply_replacements_binary(args): + """Checks if invoking supplied clang-apply-replacements binary works.""" + try: + subprocess.check_call( + [args.clang_apply_replacements_binary, '--version']) + except: + print('Unable to run clang-apply-replacements. Is clang-apply-replacements ' + 'binary correctly specified?', file=sys.stderr) + traceback.print_exc() + sys.exit(1) + + +def apply_fixes(args, tmpdir): + """Calls clang-apply-fixes on a given directory.""" + invocation = [args.clang_apply_replacements_binary] + if args.format: + invocation.append('-format') + if args.style: + invocation.append('-style=' + args.style) + print(tmpdir) + invocation.append(tmpdir) + subprocess.call(invocation) + +def remove_pb_files(filenames): + for file in filenames.copy(): + if file.endswith('.pb.cc'): + filenames.remove(file) + +def remove_test_files(filenames): + for file in filenames.copy(): + if file.endswith('_test.cc'): + filenames.remove(file) + +# TODO(LeeHao): add some compile failed file ,eg src/storage/benchmark +def remove_custom_files(filenames): + for file in filenames.copy(): + # if file.endswith('pika_pubsub.cc') or file.endswith('pika_stable_log.cc') or file.endswith('pstd_string.cc') or file.endswith('pika_zset.cc') or file.endswith('pika_server.cc'): + # filenames.remove(file) + if 'benchmark' in os.path.dirname(file) or 'examples' in os.path.dirname(file) or 'performance' in os.path.dirname(file): + filenames.remove(file) + + +def run_tidy(args, tmpdir, build_path, queue, lock, failed_files): + """Takes filenames out of queue and runs clang-tidy on them.""" + while True: + name = queue.get() + print("Checking: {}".format(name)) + sys.stdout.flush() + invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks, + tmpdir, build_path, args.header_filter, + args.extra_arg, args.extra_arg_before, + args.quiet, args.config) + + proc = subprocess.Popen( + invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output, err = proc.communicate() + if proc.returncode != 0: + failed_files.append(name) + with lock: + output = output.decode('utf-8') if output is not None else None + err = err.decode('utf-8') if output is not None else None + # unfortunately, our error messages are actually on STDOUT + # STDERR tells how many warnings are generated, + # but this includes non-user-code warnings, so it is useless... + if output: + sys.stdout.write('\n') + sys.stdout.write(output) + queue.task_done() + + +def main(): + parser = argparse.ArgumentParser(description='Runs clang-tidy over all files ' + 'in a compilation database. Requires ' + 'clang-tidy and clang-apply-replacements in ' + '$PATH.') + parser.add_argument('-clang-tidy-binary', metavar='PATH', + default='clang-tidy', + help='path to clang-tidy binary') + parser.add_argument('-clang-apply-replacements-binary', metavar='PATH', + default='clang-apply-replacements', + help='path to clang-apply-replacements binary') + parser.add_argument('-checks', default=None, + help='checks filter, when not specified, use clang-tidy ' + 'default') + parser.add_argument('-config', default=None, + help='Specifies a configuration in YAML/JSON format: ' + ' -config="{Checks: \'*\', ' + ' CheckOptions: [{key: x, ' + ' value: y}]}" ' + 'When the value is empty, clang-tidy will ' + 'attempt to find a file named .clang-tidy for ' + 'each source file in its parent directories.') + parser.add_argument('-header-filter', default=None, + help='regular expression matching the names of the ' + 'headers to output diagnostics from. Diagnostics from ' + 'the main file of each translation unit are always ' + 'displayed.') + parser.add_argument('-export-fixes', metavar='filename', dest='export_fixes', + help='Create a yaml file to store suggested fixes in, ' + 'which can be applied with clang-apply-replacements.') + parser.add_argument('-j', type=int, default=0, + help='number of tidy instances to be run in parallel.') + parser.add_argument('files', nargs='*', default=['.*'], + help='files to be processed (regex on path)') + parser.add_argument('-fix', action='store_true', help='apply fix-its') + parser.add_argument('-format', action='store_true', help='Reformat code ' + 'after applying fixes') + parser.add_argument('-style', default='file', help='The style of reformat ' + 'code after applying fixes') + parser.add_argument('-p', dest='build_path', + help='Path used to read a compile command database.') + parser.add_argument('-extra-arg', dest='extra_arg', + action='append', default=[], + help='Additional argument to append to the compiler ' + 'command line.') + parser.add_argument('-extra-arg-before', dest='extra_arg_before', + action='append', default=[], + help='Additional argument to prepend to the compiler ' + 'command line.') + parser.add_argument('-quiet', action='store_true', + help='Run clang-tidy in quiet mode') + parser.add_argument('-only-diff', action='store_true', + help='Only run clang-tidy on diff file to master branch') + args = parser.parse_args() + + db_path = 'compile_commands.json' + + if args.build_path is not None: + build_path = args.build_path + else: + # Find our database + build_path = find_compilation_database(db_path) + + try: + invocation = [args.clang_tidy_binary, '-list-checks'] + invocation.append('-p=' + build_path) + if args.checks: + invocation.append('-checks=' + args.checks) + invocation.append('-') + subprocess.check_call(invocation) + except: + print("Unable to run clang-tidy.", file=sys.stderr) + sys.exit(1) + + # Load the database and extract all files. + database = json.load(open(os.path.join(build_path, db_path))) + files = [make_absolute(entry['file'], entry['directory']) + for entry in database] + + remove_pb_files(files) + remove_test_files(files) + remove_custom_files(files) + + # Running clang-tidy in the whole project is slow. Therefore, we added + # support for running clang-tidy on git diff. When `only_diff` is + # specified in the command line, we only check files modified compared + # with origin/master, so as to speed up clang-tidy check. + # + # This functionality is set as CMake target `check-clang-tidy-diff`. + # You can use `make check-clang-tidy-diff` to do a fast clang-tidy + # check. + if args.only_diff: + git_repo = subprocess.run( + ["git", "rev-parse", "--show-toplevel"], capture_output=True) + git_repo_path = git_repo.stdout.decode("utf-8").strip() + # Get all files changed compared with origin/master + result = subprocess.run( + ["git", "--no-pager", "diff", "--name-only", "origin/master"], capture_output=True) + git_changed_file_list = list(map(lambda x: make_absolute( + x, git_repo_path), result.stdout.decode("utf-8").strip().split("\n"))) + git_changed_file_set = set(git_changed_file_list) + # Only retain files that exists in git diff + files = list(filter(lambda x: x in git_changed_file_set, files)) + + max_task = args.j + if max_task == 0: + max_task = multiprocessing.cpu_count() + + tmpdir = None + if args.fix or args.export_fixes: + check_clang_apply_replacements_binary(args) + tmpdir = tempfile.mkdtemp() + + # Build up a big regexy filter from all command line arguments. + file_name_re = re.compile('|'.join(args.files)) + + return_code = 0 + try: + # Spin up a bunch of tidy-launching threads. + task_queue = queue.Queue(max_task) + # List of files with a non-zero return code. + failed_files = [] + lock = threading.Lock() + for _ in range(max_task): + t = threading.Thread(target=run_tidy, + args=(args, tmpdir, build_path, task_queue, lock, failed_files)) + t.daemon = True + t.start() + + def update_progress(current_file, num_files): + pct = int(current_file / num_files * 100) + if current_file == num_files or pct % max(2, num_files // 10) == 0: + stars = pct // 10 + spaces = 10 - pct // 10 + print('\rProgress: [{}{}] ({}% / File {} of {})'.format( + 'x' * stars, + ' ' * spaces, + pct, + current_file, + num_files + ), end='') + sys.stdout.flush() + if current_file == num_files: + print() + + # Fill the queue with files. + for i, name in enumerate(files): + if file_name_re.search(name): + put_file = False + while not put_file: + try: + task_queue.put(name, block=True, timeout=300) + put_file = True + # update_progress(i, len(files)) + except queue.Full: + print('Still waiting to put files into clang-tidy queue.') + sys.stdout.flush() + + # Wait for all threads to be done. + task_queue.join() + # update_progress(100, 100) + if len(failed_files): + return_code = 1 + print('The files that failed were:') + print(pprint.pformat(failed_files)) + print( + 'Note that a failing .h file will fail all the .cpp files that include it.\n') + + except KeyboardInterrupt: + # This is a sad hack. Unfortunately subprocess goes + # bonkers with ctrl-c and we start forking merrily. + print('\nCtrl-C detected, goodbye.') + if tmpdir: + shutil.rmtree(tmpdir) + os.kill(0, 9) + + if args.export_fixes: + print('Writing fixes to ' + args.export_fixes + ' ...') + try: + merge_replacement_files(tmpdir, args.export_fixes) + except: + print('Error exporting fixes.\n', file=sys.stderr) + traceback.print_exc() + return_code = 1 + + if args.fix: + print('Applying fixes ...') + try: + apply_fixes(args, tmpdir) + except: + print('Error applying fixes.\n', file=sys.stderr) + traceback.print_exc() + return_code = 1 + + if tmpdir: + shutil.rmtree(tmpdir) + print("") + sys.stdout.flush() + sys.exit(return_code) + + +if __name__ == '__main__': + main() diff --git a/src/net/include/backend_thread.h b/src/net/include/backend_thread.h index 84c211d565..ad944ccc22 100644 --- a/src/net/include/backend_thread.h +++ b/src/net/include/backend_thread.h @@ -37,8 +37,8 @@ class NetConn; */ class BackendHandle { public: - BackendHandle() {} - virtual ~BackendHandle() {} + BackendHandle() = default; + virtual ~BackendHandle() = default; /* * CronHandle() will be invoked on every cron_interval elapsed. @@ -103,22 +103,22 @@ class BackendThread : public Thread { public: BackendThread(ConnFactory* conn_factory, int cron_interval, int keepalive_timeout, BackendHandle* handle, void* private_data); - virtual ~BackendThread(); + ~BackendThread() override; /* * StartThread will return the error code as pthread_create return * Return 0 if success */ - virtual int StartThread() override; - virtual int StopThread() override; - pstd::Status Write(const int fd, const std::string& msg); - pstd::Status Close(const int fd); + int StartThread() override; + int StopThread() override; + pstd::Status Write(int fd, const std::string& msg); + pstd::Status Close(int fd); // Try to connect fd noblock, if return EINPROGRESS or EAGAIN or EWOULDBLOCK // put this fd in epoll (SetWaitConnectOnEpoll), process in ProcessConnectStatus - pstd::Status Connect(const std::string& dst_ip, const int dst_port, int* fd); + pstd::Status Connect(const std::string& dst_ip, int dst_port, int* fd); std::shared_ptr GetConn(int fd); private: - virtual void* ThreadMain() override; + void* ThreadMain() override; void InternalDebugPrint(); // Set connect fd into epoll @@ -127,13 +127,13 @@ class BackendThread : public Thread { void SetWaitConnectOnEpoll(int sockfd); void AddConnection(const std::string& peer_ip, int peer_port, int sockfd); - void CloseFd(std::shared_ptr conn); - void CloseFd(const int fd); - void CleanUpConnRemaining(const int fd); + void CloseFd(const std::shared_ptr& conn); + void CloseFd(int fd); + void CleanUpConnRemaining(int fd); void DoCronTask(); - void NotifyWrite(const std::string ip_port); - void NotifyWrite(const int fd); - void NotifyClose(const int fd); + void NotifyWrite(std::string& ip_port); + void NotifyWrite(int fd); + void NotifyClose(int fd); void ProcessNotifyEvents(const NetFiredEvent* pfe); int keepalive_timeout_; diff --git a/src/net/include/bg_thread.h b/src/net/include/bg_thread.h index 7b1f9bfa08..5da80e1d69 100644 --- a/src/net/include/bg_thread.h +++ b/src/net/include/bg_thread.h @@ -26,14 +26,14 @@ struct TimerItem { class BGThread final : public Thread { public: - explicit BGThread(int full = 100000) : Thread::Thread(), full_(full) {} + explicit BGThread(int full = 100000) : full_(full) {} - virtual ~BGThread() { + ~BGThread() override { // call virtual in destructor, BGThread must be final StopThread(); } - virtual int StopThread() override { + int StopThread() override { should_stop_ = true; rsignal_.notify_one(); wsignal_.notify_one(); @@ -65,7 +65,7 @@ class BGThread final : public Thread { pstd::Mutex mu_; pstd::CondVar rsignal_; pstd::CondVar wsignal_; - virtual void* ThreadMain() override; + void* ThreadMain() override; }; } // namespace net diff --git a/src/net/include/client_thread.h b/src/net/include/client_thread.h index 7ab603065e..6a6ee6c5ac 100644 --- a/src/net/include/client_thread.h +++ b/src/net/include/client_thread.h @@ -37,8 +37,8 @@ class NetConn; */ class ClientHandle { public: - ClientHandle() {} - virtual ~ClientHandle() {} + ClientHandle() = default; + virtual ~ClientHandle() = default; /* * CronHandle() will be invoked on every cron_interval elapsed. @@ -93,7 +93,7 @@ class ClientHandle { /* * DestConnectFailedHandle(...) will run the invoker's logic when socket connect failed */ - virtual void DestConnectFailedHandle(std::string ip_port, std::string reason) const { + virtual void DestConnectFailedHandle(const std::string& ip_port, const std::string& reason) const { UNUSED(ip_port); UNUSED(reason); } @@ -103,18 +103,18 @@ class ClientThread : public Thread { public: ClientThread(ConnFactory* conn_factory, int cron_interval, int keepalive_timeout, ClientHandle* handle, void* private_data); - virtual ~ClientThread(); + ~ClientThread() override; /* * StartThread will return the error code as pthread_create return * Return 0 if success */ - virtual int StartThread() override; - virtual int StopThread() override; - pstd::Status Write(const std::string& ip, const int port, const std::string& msg); - pstd::Status Close(const std::string& ip, const int port); + int StartThread() override; + int StopThread() override; + pstd::Status Write(const std::string& ip, int port, const std::string& msg); + pstd::Status Close(const std::string& ip, int port); private: - virtual void* ThreadMain() override; + void* ThreadMain() override; void InternalDebugPrint(); // Set connect fd into epoll @@ -126,7 +126,7 @@ class ClientThread : public Thread { // Try to connect fd noblock, if return EINPROGRESS or EAGAIN or EWOULDBLOCK // put this fd in epoll (SetWaitConnectOnEpoll), process in ProcessConnectStatus pstd::Status ScheduleConnect(const std::string& dst_ip, int dst_port); - void CloseFd(std::shared_ptr conn); + void CloseFd(const std::shared_ptr& conn); void CloseFd(int fd, const std::string& ip_port); void CleanUpConnRemaining(const std::string& ip_port); void DoCronTask(); diff --git a/src/net/include/http_conn.h b/src/net/include/http_conn.h index e040a6e01b..4cabc3f914 100644 --- a/src/net/include/http_conn.h +++ b/src/net/include/http_conn.h @@ -12,6 +12,7 @@ #include "pstd/include/pstd_status.h" #include "pstd/include/xdebug.h" +#include "pstd/include/noncopyable.h" #include "net/include/net_conn.h" #include "net/include/net_define.h" @@ -23,17 +24,17 @@ class HTTPConn; class HTTPRequest { public: - const std::string url() const; - const std::string path() const; - const std::string query_value(const std::string& field) const; - const std::map query_params() const; - const std::map postform_params() const; - const std::map headers() const; - const std::string postform_value(const std::string& field) const; - const std::string method() const; - const std::string content_type() const; - - const std::string client_ip_port() const; + std::string url() const; + std::string path() const; + std::string query_value(const std::string& field) const; + std::map query_params() const; + std::map postform_params() const; + std::map headers() const; + std::string postform_value(const std::string& field) const; + std::string method() const; + std::string content_type() const; + + std::string client_ip_port() const; void Reset(); void Dump() const; @@ -83,17 +84,17 @@ class HTTPRequest { int ParseHeader(); ReadStatus DoRead(); - bool ParseHeadFromArray(const char* data, const int size); + bool ParseHeadFromArray(const char* data, int size); bool ParseGetUrl(); bool ParseHeadLine(const char* data, int line_start, int line_end); - bool ParseParameters(const std::string data, size_t line_start = 0); + bool ParseParameters(std::string& data, size_t line_start = 0); }; class HTTPResponse { public: void SetStatusCode(int code); void SetHeaders(const std::string& key, const std::string& value); - void SetHeaders(const std::string& key, const size_t value); + void SetHeaders(const std::string& key, size_t value); void SetContentLength(uint64_t size); void Reset(); @@ -128,7 +129,7 @@ class HTTPResponse { bool SerializeHeader(); }; -class HTTPHandles { +class HTTPHandles : public pstd::noncopyable { public: // You need implement these handles. /* @@ -161,8 +162,8 @@ class HTTPHandles { // Close handle virtual void HandleConnClosed() {} - HTTPHandles() {} - virtual ~HTTPHandles() {} + HTTPHandles() = default; + virtual ~HTTPHandles() = default; protected: /* @@ -173,22 +174,16 @@ class HTTPHandles { private: friend class HTTPConn; - - /* - * No allowed copy and copy assign - */ - HTTPHandles(const HTTPHandles&); - void operator=(const HTTPHandles&); }; class HTTPConn : public NetConn { public: - HTTPConn(const int fd, const std::string& ip_port, Thread* sthread, std::shared_ptr handles_, + HTTPConn(int fd, const std::string& ip_port, Thread* sthread, std::shared_ptr handles_, void* worker_specific_data); - ~HTTPConn(); + ~HTTPConn() override; - virtual ReadStatus GetRequest() override; - virtual WriteStatus SendReply() override; + ReadStatus GetRequest() override; + WriteStatus SendReply() override; private: friend class HTTPRequest; diff --git a/src/net/include/net_cli.h b/src/net/include/net_cli.h index 01f348be36..8fff4b9c4b 100644 --- a/src/net/include/net_cli.h +++ b/src/net/include/net_cli.h @@ -8,26 +8,26 @@ #include #include -#include "pstd/include/pstd_status.h" -using pstd::Status; +#include "pstd/include/pstd_status.h" +#include "pstd/include/noncopyable.h" namespace net { -class NetCli { +class NetCli : public pstd::noncopyable { public: - explicit NetCli(const std::string& ip = "", const int port = 0); + explicit NetCli(const std::string& ip = "", int port = 0); virtual ~NetCli(); - Status Connect(const std::string& bind_ip = ""); - Status Connect(const std::string& peer_ip, const int peer_port, const std::string& bind_ip = ""); + pstd::Status Connect(const std::string& bind_ip = ""); + pstd::Status Connect(const std::string& peer_ip, int peer_port, const std::string& bind_ip = ""); // Check whether the connection got fin from peer or not - virtual int CheckAliveness(void); + virtual int CheckAliveness(); // Compress and write the message - virtual Status Send(void* msg) = 0; + virtual pstd::Status Send(void* msg) = 0; // Read, parse and store the reply - virtual Status Recv(void* result = nullptr) = 0; + virtual pstd::Status Recv(void* result = nullptr) = 0; void Close(); @@ -42,19 +42,17 @@ class NetCli { void set_connect_timeout(int connect_timeout); protected: - Status SendRaw(void* buf, size_t len); - Status RecvRaw(void* buf, size_t* len); + pstd::Status SendRaw(void* buf, size_t count); + pstd::Status RecvRaw(void* buf, size_t* count); private: struct Rep; std::unique_ptr rep_; int set_tcp_nodelay(); - NetCli(const NetCli&); - void operator=(const NetCli&); }; -extern NetCli* NewPbCli(const std::string& peer_ip = "", const int peer_port = 0); +extern NetCli* NewPbCli(const std::string& peer_ip = "", int peer_port = 0); extern NetCli* NewRedisCli(); diff --git a/src/net/include/net_conn.h b/src/net/include/net_conn.h index 323ac4cdcf..fab23f71b2 100644 --- a/src/net/include/net_conn.h +++ b/src/net/include/net_conn.h @@ -19,15 +19,20 @@ #include "net/include/server_thread.h" #include "net/src/net_multiplexer.h" #include "pstd/include/testutil.h" +#include "pstd/include/noncopyable.h" namespace net { class Thread; -class NetConn : public std::enable_shared_from_this { +class NetConn : public std::enable_shared_from_this, public pstd::noncopyable { public: - NetConn(const int fd, const std::string& ip_port, Thread* thread, NetMultiplexer* mpx = nullptr); + NetConn(int fd, std::string ip_port, Thread* thread, NetMultiplexer* mpx = nullptr); +#ifdef __ENABLE_SSL virtual ~NetConn(); +#else + virtual ~NetConn() = default; +#endif /* * Set the fd to nonblock && set the flag_ the fd flag @@ -109,11 +114,6 @@ class NetConn : public std::enable_shared_from_this { // the net epoll this conn belong to NetMultiplexer* net_multiplexer_ = nullptr; - /* - * No allowed copy and copy assign operator - */ - NetConn(const NetConn&); - void operator=(const NetConn&); }; /* @@ -121,7 +121,7 @@ class NetConn : public std::enable_shared_from_this { */ class ConnFactory { public: - virtual ~ConnFactory() {} + virtual ~ConnFactory() = default; virtual std::shared_ptr NewNetConn(int connfd, const std::string& ip_port, Thread* thread, void* worker_private_data, /* Has set in ThreadEnvHandle */ NetMultiplexer* net_mpx = nullptr) const = 0; diff --git a/src/net/include/net_pubsub.h b/src/net/include/net_pubsub.h index 8891f3dc35..28ef98a764 100644 --- a/src/net/include/net_pubsub.h +++ b/src/net/include/net_pubsub.h @@ -33,16 +33,16 @@ class PubSubThread : public Thread { public: PubSubThread(); - virtual ~PubSubThread(); + ~PubSubThread() override; // PubSub int Publish(const std::string& channel, const std::string& msg); - void Subscribe(std::shared_ptr conn, const std::vector& channels, const bool pattern, + void Subscribe(const std::shared_ptr& conn, const std::vector& channels, bool pattern, std::vector>* result); - int UnSubscribe(std::shared_ptr conn, const std::vector& channels, const bool pattern, + int UnSubscribe(const std::shared_ptr& conn, const std::vector& channels, bool pattern, std::vector>* result); void PubSubChannels(const std::string& pattern, std::vector* result); @@ -52,9 +52,9 @@ class PubSubThread : public Thread { int PubSubNumPat(); // Move out from pubsub thread - void MoveConnOut(std::shared_ptr conn); + void MoveConnOut(const std::shared_ptr& conn); // Move into pubsub thread - void MoveConnIn(std::shared_ptr conn, const NotifyType& notify_type); + void MoveConnIn(const std::shared_ptr& conn, const NotifyType& notify_type); enum ReadyState { kNotReady, @@ -62,7 +62,7 @@ class PubSubThread : public Thread { }; struct ConnHandle { - ConnHandle(std::shared_ptr pc, ReadyState state = kNotReady) : conn(pc), ready_state(state) {} + ConnHandle(std::shared_ptr pc, ReadyState state = kNotReady) : conn(std::move(pc)), ready_state(state) {} void UpdateReadyState(const ReadyState& state); bool IsReady(); std::shared_ptr conn; @@ -74,9 +74,9 @@ class PubSubThread : public Thread { bool IsReady(int fd); private: - void RemoveConn(std::shared_ptr conn); + void RemoveConn(const std::shared_ptr& conn); - int ClientChannelSize(std::shared_ptr conn); + int ClientChannelSize(const std::shared_ptr& conn); int msg_pfd_[2]; bool should_exit_; @@ -96,14 +96,14 @@ class PubSubThread : public Thread { std::string channel_; std::string message_; - int receivers_; + int receivers_{-1}; /* * The epoll handler */ std::unique_ptr net_multiplexer_; - virtual void* ThreadMain(); + void* ThreadMain() override; // clean conns void Cleanup(); @@ -115,9 +115,6 @@ class PubSubThread : public Thread { std::map>> pubsub_channel_; // channel <---> conns std::map>> pubsub_pattern_; // channel <---> conns - // No copying allowed - PubSubThread(const PubSubThread&); - void operator=(const PubSubThread&); }; // class PubSubThread } // namespace net diff --git a/src/net/include/net_thread.h b/src/net/include/net_thread.h index 50163f15ef..133a611dea 100644 --- a/src/net/include/net_thread.h +++ b/src/net/include/net_thread.h @@ -11,10 +11,11 @@ #include #include "pstd/include/pstd_mutex.h" +#include "pstd/include/noncopyable.h" namespace net { -class Thread { +class Thread : public pstd::noncopyable { public: Thread(); virtual ~Thread(); @@ -43,15 +44,9 @@ class Thread { virtual void* ThreadMain() = 0; pstd::Mutex running_mu_; - bool running_; - pthread_t thread_id_; + bool running_{false}; + pthread_t thread_id_{}; std::string thread_name_; - - /* - * No allowed copy and copy assign - */ - Thread(const Thread&); - void operator=(const Thread&); }; } // namespace net diff --git a/src/net/include/pb_conn.h b/src/net/include/pb_conn.h index 306d8a8be6..dd9b4db267 100644 --- a/src/net/include/pb_conn.h +++ b/src/net/include/pb_conn.h @@ -26,8 +26,8 @@ class PbConn : public NetConn { std::queue queue_; size_t item_pos_; }; - PbConn(const int fd, const std::string& ip_port, Thread* thread, NetMultiplexer* net_mpx = nullptr); - virtual ~PbConn(); + PbConn(int fd, const std::string& ip_port, Thread* thread, NetMultiplexer* net_mpx = nullptr); + ~PbConn() override; ReadStatus GetRequest() override; WriteStatus SendReply() override; @@ -35,7 +35,7 @@ class PbConn : public NetConn { int WriteResp(const std::string& resp) override; void NotifyWrite(); void NotifyClose(); - void set_is_reply(const bool reply) override; + void set_is_reply(bool reply) override; bool is_reply() override; /* * The Variable need by read the buf, diff --git a/src/net/include/period_thread.h b/src/net/include/period_thread.h index 98aee0f5b9..051140b2bf 100644 --- a/src/net/include/period_thread.h +++ b/src/net/include/period_thread.h @@ -15,7 +15,7 @@ namespace net { class PeriodThread : public Thread { public: explicit PeriodThread(struct timeval period = (struct timeval){1, 0}); - virtual void* ThreadMain(); + void* ThreadMain() override; virtual void PeriodMain() = 0; private: diff --git a/src/net/include/redis_cli.h b/src/net/include/redis_cli.h index 9980f795af..d54d9ef523 100644 --- a/src/net/include/redis_cli.h +++ b/src/net/include/redis_cli.h @@ -11,7 +11,7 @@ namespace net { -typedef std::vector RedisCmdArgsType; +using RedisCmdArgsType = std::vector; // We can serialize redis command by 2 ways: // 1. by variable argmuments; // eg. RedisCli::Serialize(cmd, "set %s %d", "key", 5); diff --git a/src/net/include/redis_conn.h b/src/net/include/redis_conn.h index e384f5c76e..24005b1dd2 100644 --- a/src/net/include/redis_conn.h +++ b/src/net/include/redis_conn.h @@ -17,15 +17,15 @@ namespace net { -typedef std::vector RedisCmdArgsType; +using RedisCmdArgsType = std::vector; enum HandleType { kSynchronous, kAsynchronous }; class RedisConn : public NetConn { public: - RedisConn(const int fd, const std::string& ip_port, Thread* thread, NetMultiplexer* net_mpx = nullptr, - const HandleType& handle_type = kSynchronous, const int rbuf_max_len = REDIS_MAX_MESSAGE); - virtual ~RedisConn(); + RedisConn(int fd, const std::string& ip_port, Thread* thread, NetMultiplexer* net_mpx = nullptr, + const HandleType& handle_type = kSynchronous, int rbuf_max_len = REDIS_MAX_MESSAGE); + ~RedisConn() override; ReadStatus GetRequest() override; WriteStatus SendReply() override; diff --git a/src/net/include/redis_parser.h b/src/net/include/redis_parser.h index a357ce4aa3..de5cd77dd2 100644 --- a/src/net/include/redis_parser.h +++ b/src/net/include/redis_parser.h @@ -17,11 +17,11 @@ namespace net { class RedisParser; -typedef std::vector RedisCmdArgsType; -typedef int (*RedisParserDataCb)(RedisParser*, const RedisCmdArgsType&); -typedef int (*RedisParserMultiDataCb)(RedisParser*, const std::vector&); -typedef int (*RedisParserCb)(RedisParser*); -typedef int RedisParserType; +using RedisCmdArgsType = std::vector; +using RedisParserDataCb = int (*)(RedisParser *, const RedisCmdArgsType &); +using RedisParserMultiDataCb = int (*)(RedisParser *, const std::vector &); +using RedisParserCb = int (*)(RedisParser *); +using RedisParserType = int; enum RedisParserStatus { kRedisParserNone = 0, @@ -73,8 +73,8 @@ class RedisParser { void ResetCommandStatus(); RedisParserSettings parser_settings_; - RedisParserStatus status_code_; - RedisParserError error_code_; + RedisParserStatus status_code_{kRedisParserNone}; + RedisParserError error_code_{kRedisParserOk}; int redis_type_ = -1; // REDIS_REQ_INLINE or REDIS_REQ_MULTIBULK @@ -88,7 +88,7 @@ class RedisParser { std::vector argvs_; int cur_pos_ = 0; - const char* input_buf_; + const char* input_buf_{nullptr}; std::string input_str_; int length_ = 0; }; diff --git a/src/net/include/server_thread.h b/src/net/include/server_thread.h index a445d29544..c1dce29930 100644 --- a/src/net/include/server_thread.h +++ b/src/net/include/server_thread.h @@ -44,8 +44,8 @@ class WorkerThread; */ class ServerHandle { public: - ServerHandle() {} - virtual ~ServerHandle() {} + ServerHandle() = default; + virtual ~ServerHandle() = default; /* * CronHandle() will be invoked on every cron_interval elapsed. @@ -131,7 +131,7 @@ class ServerThread : public Thread { * StartThread will return the error code as pthread_create * Return 0 if success */ - virtual int StartThread() override; + int StartThread() override; virtual void set_keepalive_timeout(int timeout) = 0; @@ -156,7 +156,7 @@ class ServerThread : public Thread { virtual void SetQueueLimit(int queue_limit) {} - virtual ~ServerThread(); + ~ServerThread() override; protected: /* @@ -192,7 +192,7 @@ class ServerThread : public Thread { std::set server_fds_; virtual int InitHandle(); - virtual void* ThreadMain() override; + void* ThreadMain() override; /* * The server event handle */ diff --git a/src/net/include/simple_http_conn.h b/src/net/include/simple_http_conn.h index cd529f8ad7..2a11632768 100644 --- a/src/net/include/simple_http_conn.h +++ b/src/net/include/simple_http_conn.h @@ -38,20 +38,20 @@ class Request { Request(); void Clear(); - bool ParseHeadFromArray(const char* data, const int size); - bool ParseBodyFromArray(const char* data, const int size); + bool ParseHeadFromArray(const char* data, int size); + bool ParseBodyFromArray(const char* data, int size); private: enum ParseStatus { kHeaderMethod, kHeaderPath, kHeaderVersion, kHeaderParamKey, kHeaderParamValue, kBody }; bool ParseGetUrl(); bool ParseHeadLine(const char* data, int line_start, int line_end, ParseStatus* parseStatus); - bool ParseParameters(const std::string data, size_t line_start = 0, bool from_url = true); + bool ParseParameters(const std::string& data, size_t line_start = 0, bool from_url = true); }; class Response { public: - Response() : status_code_(0) {} + Response() = default; void Clear(); int SerializeHeaderToArray(char* data, size_t size); int SerializeBodyToArray(char* data, size_t size, int* pos); @@ -66,7 +66,7 @@ class Response { void SetBody(const std::string& body) { body_.assign(body); } private: - int status_code_; + int status_code_{0}; std::string reason_phrase_; std::map headers_; std::string body_; @@ -74,11 +74,11 @@ class Response { class SimpleHTTPConn : public NetConn { public: - SimpleHTTPConn(const int fd, const std::string& ip_port, Thread* thread); - virtual ~SimpleHTTPConn(); + SimpleHTTPConn(int fd, const std::string& ip_port, Thread* thread); + ~SimpleHTTPConn() override; - virtual ReadStatus GetRequest() override; - virtual WriteStatus SendReply() override; + ReadStatus GetRequest() override; + WriteStatus SendReply() override; private: virtual void DealMessage(const Request* req, Response* res) = 0; diff --git a/src/net/include/thread_pool.h b/src/net/include/thread_pool.h index f2cf26c0a2..c3b3999914 100644 --- a/src/net/include/thread_pool.h +++ b/src/net/include/thread_pool.h @@ -16,7 +16,7 @@ namespace net { -typedef void (*TaskFunc)(void*); +using TaskFunc = void (*)(void *); struct Task { TaskFunc func; @@ -32,7 +32,7 @@ struct TimeTask { bool operator<(const TimeTask& task) const { return exec_time > task.exec_time; } }; -class ThreadPool { +class ThreadPool : public pstd::noncopyable { public: class Worker { public: @@ -47,14 +47,9 @@ class ThreadPool { std::atomic start_; ThreadPool* const thread_pool_; std::string worker_name_; - /* - * No allowed copy and copy assign - */ - Worker(const Worker&); - void operator=(const Worker&); }; - explicit ThreadPool(size_t worker_num, size_t max_queue_size, const std::string& thread_pool_name = "ThreadPool"); + explicit ThreadPool(size_t worker_num, size_t max_queue_size, std::string thread_pool_name = "ThreadPool"); virtual ~ThreadPool(); int start_thread_pool(); @@ -86,11 +81,6 @@ class ThreadPool { pstd::CondVar rsignal_; pstd::CondVar wsignal_; - /* - * No allowed copy and copy assign - */ - ThreadPool(const ThreadPool&); - void operator=(const ThreadPool&); }; } // namespace net diff --git a/src/net/src/backend_thread.cc b/src/net/src/backend_thread.cc index 7116c34fac..a6d943c9ca 100644 --- a/src/net/src/backend_thread.cc +++ b/src/net/src/backend_thread.cc @@ -36,7 +36,7 @@ BackendThread::BackendThread(ConnFactory* conn_factory, int cron_interval, int k net_multiplexer_->Initialize(); } -BackendThread::~BackendThread() {} +BackendThread::~BackendThread() = default; int BackendThread::StartThread() { if (!handle_) { @@ -45,7 +45,7 @@ int BackendThread::StartThread() { } own_handle_ = false; int res = handle_->CreateWorkerSpecificData(&private_data_); - if (res != 0) { + if (res) { return res; } return Thread::StartThread(); @@ -54,7 +54,7 @@ int BackendThread::StartThread() { int BackendThread::StopThread() { if (private_data_) { int res = handle_->DeleteWorkerSpecificData(private_data_); - if (res != 0) { + if (res) { return res; } private_data_ = nullptr; @@ -141,17 +141,19 @@ Status BackendThread::Connect(const std::string& dst_ip, const int dst_port, int int sockfd = -1; int rv; char cport[6]; - struct addrinfo hints, *servinfo, *p; + struct addrinfo hints; + struct addrinfo *servinfo; + struct addrinfo *p; snprintf(cport, sizeof(cport), "%d", dst_port); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; - if (fd == nullptr) { + if (!fd) { return Status::InvalidArgument("fd argument is nullptr"); } // We do not handle IPv6 - if ((rv = getaddrinfo(dst_ip.c_str(), cport, &hints, &servinfo)) != 0) { + if (rv = getaddrinfo(dst_ip.c_str(), cport, &hints, &servinfo); rv) { return Status::IOError("connect getaddrinfo error for ", dst_ip); } for (p = servinfo; p != nullptr; p = p->ai_next) { @@ -182,7 +184,7 @@ Status BackendThread::Connect(const std::string& dst_ip, const int dst_port, int net_multiplexer_->NetAddEvent(sockfd, kReadable | kWritable); struct sockaddr_in laddr; socklen_t llen = sizeof(laddr); - getsockname(sockfd, (struct sockaddr*)&laddr, &llen); + getsockname(sockfd, reinterpret_cast(&laddr), &llen); std::string lip(inet_ntoa(laddr.sin_addr)); int lport = ntohs(laddr.sin_port); if (dst_ip == lip && dst_port == lport) { @@ -192,7 +194,7 @@ Status BackendThread::Connect(const std::string& dst_ip, const int dst_port, int freeaddrinfo(servinfo); return s; } - if (p == nullptr) { + if (!p) { s = Status::IOError(strerror(errno), "Can't create socket "); return s; } @@ -212,7 +214,7 @@ std::shared_ptr BackendThread::GetConn(int fd) { return nullptr; } -void BackendThread::CloseFd(std::shared_ptr conn) { +void BackendThread::CloseFd(const std::shared_ptr& conn) { close(conn->fd()); CleanUpConnRemaining(conn->fd()); handle_->FdClosedHandle(conn->fd(), conn->ip_port()); @@ -234,7 +236,7 @@ void BackendThread::DoCronTask() { struct timeval now; gettimeofday(&now, nullptr); std::lock_guard l(mu_); - std::map>::iterator iter = conns_.begin(); + auto iter = conns_.begin(); while (iter != conns_.end()) { std::shared_ptr conn = iter->second; @@ -289,7 +291,7 @@ void BackendThread::InternalDebugPrint() { LOG(INFO) << "___________________________________"; } -void BackendThread::NotifyWrite(const std::string ip_port) { +void BackendThread::NotifyWrite(std::string& ip_port) { // put fd = 0, cause this lib user doesnt need to know which fd to write to // we will check fd by checking ipport_conns_ NetItem ti(0, ip_port, kNotiWrite); @@ -320,7 +322,7 @@ void BackendThread::ProcessNotifyEvents(const NetFiredEvent* pfe) { std::lock_guard l(mu_); if (ti.notify_type() == kNotiWrite) { if (conns_.find(fd) == conns_.end()) { - // TODO: need clean and notify? + // TODO(): need clean and notify? continue; } else { // connection exist @@ -388,7 +390,7 @@ void* BackendThread::ThreadMain() { nfds = net_multiplexer_->NetPoll(timeout); for (int i = 0; i < nfds; i++) { pfe = (net_multiplexer_->FiredEvents()) + i; - if (pfe == nullptr) { + if (!pfe) { continue; } @@ -419,7 +421,7 @@ void* BackendThread::ThreadMain() { connecting_fds_.erase(pfe->fd); } - if (!should_close && (pfe->mask & kWritable) && conn->is_reply()) { + if ((should_close == 0) && (pfe->mask & kWritable) && conn->is_reply()) { WriteStatus write_status = conn->SendReply(); conn->set_last_interaction(now); if (write_status == kWriteAll) { diff --git a/src/net/src/client_thread.cc b/src/net/src/client_thread.cc index 58e59d293b..f51080d793 100644 --- a/src/net/src/client_thread.cc +++ b/src/net/src/client_thread.cc @@ -36,7 +36,7 @@ ClientThread::ClientThread(ConnFactory* conn_factory, int cron_interval, int kee net_multiplexer_->Initialize(); } -ClientThread::~ClientThread() {} +ClientThread::~ClientThread() = default; int ClientThread::StartThread() { if (!handle_) { @@ -45,7 +45,7 @@ int ClientThread::StartThread() { } own_handle_ = false; int res = handle_->CreateWorkerSpecificData(&private_data_); - if (res != 0) { + if (res) { return res; } return Thread::StartThread(); @@ -54,7 +54,7 @@ int ClientThread::StartThread() { int ClientThread::StopThread() { if (private_data_) { int res = handle_->DeleteWorkerSpecificData(private_data_); - if (res != 0) { + if (res) { return res; } private_data_ = nullptr; @@ -133,14 +133,16 @@ Status ClientThread::ScheduleConnect(const std::string& dst_ip, int dst_port) { int sockfd = -1; int rv; char cport[6]; - struct addrinfo hints, *servinfo, *p; + struct addrinfo hints; + struct addrinfo *servinfo; + struct addrinfo *p; snprintf(cport, sizeof(cport), "%d", dst_port); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; // We do not handle IPv6 - if ((rv = getaddrinfo(dst_ip.c_str(), cport, &hints, &servinfo)) != 0) { + if (rv = getaddrinfo(dst_ip.c_str(), cport, &hints, &servinfo); rv) { return Status::IOError("connect getaddrinfo error for ", dst_ip); } for (p = servinfo; p != nullptr; p = p->ai_next) { @@ -170,7 +172,7 @@ Status ClientThread::ScheduleConnect(const std::string& dst_ip, int dst_port) { net_multiplexer_->NetAddEvent(sockfd, kReadable | kWritable); struct sockaddr_in laddr; socklen_t llen = sizeof(laddr); - getsockname(sockfd, (struct sockaddr*)&laddr, &llen); + getsockname(sockfd, reinterpret_cast(&laddr), &llen); std::string lip(inet_ntoa(laddr.sin_addr)); int lport = ntohs(laddr.sin_port); if (dst_ip == lip && dst_port == lport) { @@ -181,7 +183,7 @@ Status ClientThread::ScheduleConnect(const std::string& dst_ip, int dst_port) { return s; } - if (p == nullptr) { + if (!p) { s = Status::IOError(strerror(errno), "Can't create socket "); return s; } @@ -192,7 +194,7 @@ Status ClientThread::ScheduleConnect(const std::string& dst_ip, int dst_port) { return s; } -void ClientThread::CloseFd(std::shared_ptr conn) { +void ClientThread::CloseFd(const std::shared_ptr& conn) { close(conn->fd()); CleanUpConnRemaining(conn->ip_port()); handle_->FdClosedHandle(conn->fd(), conn->ip_port()); @@ -212,7 +214,7 @@ void ClientThread::CleanUpConnRemaining(const std::string& ip_port) { void ClientThread::DoCronTask() { struct timeval now; gettimeofday(&now, nullptr); - std::map>::iterator iter = fd_conns_.begin(); + auto iter = fd_conns_.begin(); while (iter != fd_conns_.end()) { std::shared_ptr conn = iter->second; @@ -248,7 +250,7 @@ void ClientThread::DoCronTask() { } for (auto& conn_name : to_del) { - std::map>::iterator iter = ipport_conns_.find(conn_name); + auto iter = ipport_conns_.find(conn_name); if (iter == ipport_conns_.end()) { continue; } @@ -396,7 +398,7 @@ void* ClientThread::ThreadMain() { nfds = net_multiplexer_->NetPoll(timeout); for (int i = 0; i < nfds; i++) { pfe = (net_multiplexer_->FiredEvents()) + i; - if (pfe == nullptr) { + if (!pfe) { continue; } @@ -406,7 +408,7 @@ void* ClientThread::ThreadMain() { } int should_close = 0; - std::map>::iterator iter = fd_conns_.find(pfe->fd); + auto iter = fd_conns_.find(pfe->fd); if (iter == fd_conns_.end()) { LOG(INFO) << "fd " << pfe->fd << "not found in fd_conns"; net_multiplexer_->NetDelEvent(pfe->fd, 0); @@ -423,7 +425,7 @@ void* ClientThread::ThreadMain() { connecting_fds_.erase(pfe->fd); } - if (!should_close && (pfe->mask & kWritable) && conn->is_reply()) { + if ((should_close == 0) && (pfe->mask & kWritable) && conn->is_reply()) { WriteStatus write_status = conn->SendReply(); conn->set_last_interaction(now); if (write_status == kWriteAll) { @@ -437,7 +439,7 @@ void* ClientThread::ThreadMain() { } } - if (!should_close && (pfe->mask & kReadable)) { + if ((should_close == 0) && (pfe->mask & kReadable)) { ReadStatus read_status = conn->GetRequest(); conn->set_last_interaction(now); if (read_status == kReadAll) { diff --git a/src/net/src/dispatch_thread.cc b/src/net/src/dispatch_thread.cc index f8e5b0cd72..83ad7cdef9 100644 --- a/src/net/src/dispatch_thread.cc +++ b/src/net/src/dispatch_thread.cc @@ -50,14 +50,12 @@ DispatchThread::DispatchThread(const std::set& ips, int port, int w } } -DispatchThread::~DispatchThread() { - -} +DispatchThread::~DispatchThread() = default; int DispatchThread::StartThread() { for (int i = 0; i < work_num_; i++) { int ret = handle_->CreateWorkerSpecificData(&(worker_thread_[i]->private_data_)); - if (ret != 0) { + if (ret) { return ret; } @@ -65,7 +63,7 @@ int DispatchThread::StartThread() { worker_thread_[i]->set_thread_name("WorkerThread"); } ret = worker_thread_[i]->StartThread(); - if (ret != 0) { + if (ret) { return ret; } } @@ -78,12 +76,12 @@ int DispatchThread::StopThread() { } for (int i = 0; i < work_num_; i++) { int ret = worker_thread_[i]->StopThread(); - if (ret != 0) { + if (ret) { return ret; } - if (worker_thread_[i]->private_data_ != nullptr) { + if (worker_thread_[i]->private_data_) { ret = handle_->DeleteWorkerSpecificData(worker_thread_[i]->private_data_); - if (ret != 0) { + if (ret) { return ret; } worker_thread_[i]->private_data_ = nullptr; @@ -118,7 +116,7 @@ std::vector DispatchThread::conns_info() const { std::shared_ptr DispatchThread::MoveConnOut(int fd) { for (int i = 0; i < work_num_; ++i) { std::shared_ptr conn = worker_thread_[i]->MoveConnOut(fd); - if (conn != nullptr) { + if (conn) { return conn; } } diff --git a/src/net/src/dispatch_thread.h b/src/net/src/dispatch_thread.h index 45839604ec..fb52016666 100644 --- a/src/net/src/dispatch_thread.h +++ b/src/net/src/dispatch_thread.h @@ -31,27 +31,27 @@ class DispatchThread : public ServerThread { DispatchThread(const std::set& ips, int port, int work_num, ConnFactory* conn_factory, int cron_interval, int queue_limit, const ServerHandle* handle); - virtual ~DispatchThread(); + ~DispatchThread() override; - virtual int StartThread() override; + int StartThread() override; - virtual int StopThread() override; + int StopThread() override; - virtual void set_keepalive_timeout(int timeout) override; + void set_keepalive_timeout(int timeout) override; - virtual int conn_num() const override; + int conn_num() const override; - virtual std::vector conns_info() const override; + std::vector conns_info() const override; - virtual std::shared_ptr MoveConnOut(int fd) override; + std::shared_ptr MoveConnOut(int fd) override; - virtual void MoveConnIn(std::shared_ptr conn, const NotifyType& type) override; + void MoveConnIn(std::shared_ptr conn, const NotifyType& type) override; - virtual void KillAllConns() override; + void KillAllConns() override; - virtual bool KillConn(const std::string& ip_port) override; + bool KillConn(const std::string& ip_port) override; - void HandleNewConn(const int connfd, const std::string& ip_port) override; + void HandleNewConn(int connfd, const std::string& ip_port) override; void SetQueueLimit(int queue_limit) override; @@ -71,9 +71,6 @@ class DispatchThread : public ServerThread { void HandleConnEvent(NetFiredEvent* pfe) override { UNUSED(pfe); } - // No copying allowed - DispatchThread(const DispatchThread&); - void operator=(const DispatchThread&); }; // class DispatchThread } // namespace net diff --git a/src/net/src/holy_thread.cc b/src/net/src/holy_thread.cc index f27f2ca993..b7c2f1990a 100644 --- a/src/net/src/holy_thread.cc +++ b/src/net/src/holy_thread.cc @@ -19,7 +19,7 @@ namespace net { HolyThread::HolyThread(int port, ConnFactory* conn_factory, int cron_interval, const ServerHandle* handle, bool async) : ServerThread::ServerThread(port, cron_interval, handle), conn_factory_(conn_factory), - private_data_(nullptr), + keepalive_timeout_(kDefaultKeepAliveTime), async_(async) {} @@ -72,7 +72,7 @@ std::shared_ptr HolyThread::get_conn(int fd) { int HolyThread::StartThread() { int ret = handle_->CreateWorkerSpecificData(&private_data_); - if (ret != 0) { + if (ret) { return ret; } return ServerThread::StartThread(); @@ -81,7 +81,7 @@ int HolyThread::StartThread() { int HolyThread::StopThread() { if (private_data_) { int ret = handle_->DeleteWorkerSpecificData(private_data_); - if (ret != 0) { + if (ret) { return ret; } private_data_ = nullptr; @@ -101,7 +101,7 @@ void HolyThread::HandleNewConn(const int connfd, const std::string& ip_port) { } void HolyThread::HandleConnEvent(NetFiredEvent* pfe) { - if (pfe == nullptr) { + if (!pfe) { return; } std::shared_ptr in_conn = nullptr; @@ -198,13 +198,13 @@ void HolyThread::DoCronTask() { } conns_.clear(); deleting_conn_ipport_.clear(); - for (const auto conn : to_close) { + for (const auto& conn : to_close) { CloseFd(conn); } return; } - std::map>::iterator iter = conns_.begin(); + auto iter = conns_.begin(); while (iter != conns_.end()) { std::shared_ptr conn = iter->second; // Check connection should be closed @@ -228,16 +228,16 @@ void HolyThread::DoCronTask() { ++iter; } } - for (const auto conn : to_close) { + for (const auto& conn : to_close) { CloseFd(conn); } - for (const auto conn : to_timeout) { + for (const auto& conn : to_timeout) { CloseFd(conn); handle_->FdTimeoutHandle(conn->fd(), conn->ip_port()); } } -void HolyThread::CloseFd(std::shared_ptr conn) { +void HolyThread::CloseFd(const std::shared_ptr& conn) { close(conn->fd()); handle_->FdClosedHandle(conn->fd(), conn->ip_port()); } @@ -292,7 +292,7 @@ void HolyThread::ProcessNotifyEvents(const net::NetFiredEvent* pfe) { } else if (ti.notify_type() == net::kNotiClose) { LOG(INFO) << "receive noti close"; std::shared_ptr conn = get_conn(fd); - if (conn == nullptr) { + if (!conn) { continue; } CloseFd(conn); diff --git a/src/net/src/holy_thread.h b/src/net/src/holy_thread.h index 2cdbc36ab2..94dcf58107 100644 --- a/src/net/src/holy_thread.h +++ b/src/net/src/holy_thread.h @@ -29,25 +29,25 @@ class HolyThread : public ServerThread { const ServerHandle* handle = nullptr, bool async = true); HolyThread(const std::set& bind_ips, int port, ConnFactory* conn_factory, int cron_interval = 0, const ServerHandle* handle = nullptr, bool async = true); - virtual ~HolyThread(); + ~HolyThread() override; - virtual int StartThread() override; + int StartThread() override; - virtual int StopThread() override; + int StopThread() override; - virtual void set_keepalive_timeout(int timeout) override { keepalive_timeout_ = timeout; } + void set_keepalive_timeout(int timeout) override { keepalive_timeout_ = timeout; } - virtual int conn_num() const override; + int conn_num() const override; - virtual std::vector conns_info() const override; + std::vector conns_info() const override; - virtual std::shared_ptr MoveConnOut(int fd) override; + std::shared_ptr MoveConnOut(int fd) override; - virtual void MoveConnIn(std::shared_ptr conn, const NotifyType& type) override {} + void MoveConnIn(std::shared_ptr conn, const NotifyType& type) override {} - virtual void KillAllConns() override; + void KillAllConns() override; - virtual bool KillConn(const std::string& ip_port) override; + bool KillConn(const std::string& ip_port) override; virtual std::shared_ptr get_conn(int fd); @@ -71,7 +71,7 @@ class HolyThread : public ServerThread { void HandleNewConn(int connfd, const std::string& ip_port) override; void HandleConnEvent(NetFiredEvent* pfe) override; - void CloseFd(std::shared_ptr conn); + void CloseFd(const std::shared_ptr& conn); void Cleanup(); }; // class HolyThread diff --git a/src/net/src/http_conn.cc b/src/net/src/http_conn.cc index 9077ced4ed..e485a65a7c 100644 --- a/src/net/src/http_conn.cc +++ b/src/net/src/http_conn.cc @@ -3,12 +3,13 @@ // 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 "net/include/http_conn.h" -#include -#include -#include +#include +#include +#include #include #include +#include #include "net/include/net_define.h" #include "pstd/include/pstd_string.h" @@ -140,8 +141,10 @@ bool HTTPRequest::ParseGetUrl() { // Parse query parameter from GET url or POST application/x-www-form-urlencoded // format: key1=value1&key2=value2&key3=value3 -bool HTTPRequest::ParseParameters(const std::string data, size_t line_start) { - size_t pre = line_start, mid, end; +bool HTTPRequest::ParseParameters(std::string& data, size_t line_start) { + size_t pre = line_start; + size_t mid; + size_t end; while (pre < data.size()) { mid = data.find('=', pre); if (mid == std::string::npos) { @@ -231,7 +234,7 @@ bool HTTPResponse::SerializeHeader() { int serial_size = 0; int ret; - std::string reason_phrase = http_status_map.at(status_code_); + const std::string& reason_phrase = http_status_map.at(status_code_); // Serialize statues line ret = snprintf(wbuf_, kHTTPMaxHeader, "HTTP/1.1 %d %s\r\n", status_code_, reason_phrase.c_str()); @@ -265,7 +268,7 @@ HTTPConn::HTTPConn(const int fd, const std::string& ip_port, Thread* thread, std #ifdef __ENABLE_SSL // security_(thread->security()), #endif - handles_(handles) { + handles_(std::move(handles)) { handles_->worker_specific_data_ = worker_specific_data; // this pointer is safe here request_ = new HTTPRequest(this); @@ -289,35 +292,35 @@ HTTPRequest::HTTPRequest(HTTPConn* conn) HTTPRequest::~HTTPRequest() { delete[] rbuf_; } -const std::string HTTPRequest::url() const { return url_; } +std::string HTTPRequest::url() const { return url_; } -const std::string HTTPRequest::path() const { return path_; } +std::string HTTPRequest::path() const { return path_; } -const std::string HTTPRequest::query_value(const std::string& field) const { +std::string HTTPRequest::query_value(const std::string& field) const { if (query_params_.count(field)) { return query_params_.at(field); } return ""; } -const std::string HTTPRequest::postform_value(const std::string& field) const { +std::string HTTPRequest::postform_value(const std::string& field) const { if (postform_params_.count(field)) { return postform_params_.at(field); } return ""; } -const std::string HTTPRequest::method() const { return method_; } +std::string HTTPRequest::method() const { return method_; } -const std::string HTTPRequest::content_type() const { return content_type_; } +std::string HTTPRequest::content_type() const { return content_type_; } -const std::map HTTPRequest::query_params() const { return query_params_; } +std::map HTTPRequest::query_params() const { return query_params_; } -const std::map HTTPRequest::postform_params() const { return postform_params_; } +std::map HTTPRequest::postform_params() const { return postform_params_; } -const std::map HTTPRequest::headers() const { return headers_; } +std::map HTTPRequest::headers() const { return headers_; } -const std::string HTTPRequest::client_ip_port() const { return client_ip_port_; } +std::string HTTPRequest::client_ip_port() const { return client_ip_port_; } void HTTPRequest::Reset() { rbuf_pos_ = 0; @@ -495,7 +498,7 @@ void HTTPResponse::SetHeaders(const std::string& key, const size_t value) { head void HTTPResponse::SetContentLength(uint64_t size) { remain_send_len_ = size; - if (headers_.count("Content-Length") || headers_.count("content-length")) { + if (headers_.count("Content-Length") || (headers_.count("content-length"))) { return; } SetHeaders("Content-Length", size); diff --git a/src/net/src/net_cli.cc b/src/net/src/net_cli.cc index f588c7a4f9..41c1e7aaf0 100644 --- a/src/net/src/net_cli.cc +++ b/src/net/src/net_cli.cc @@ -14,38 +14,26 @@ #include #include +#include + +using pstd::Status; + namespace net { struct NetCli::Rep { std::string peer_ip; int peer_port; - int send_timeout; - int recv_timeout; - int connect_timeout; - bool keep_alive; - bool is_block; - int sockfd; - bool available; - - Rep() - : send_timeout(0), - recv_timeout(0), - connect_timeout(1000), - keep_alive(0), - is_block(true), - sockfd(-1), - available(false) {} - - Rep(const std::string& ip, int port) - : peer_ip(ip), - peer_port(port), - send_timeout(0), - recv_timeout(0), - connect_timeout(1000), - keep_alive(0), - is_block(true), - sockfd(-1), - available(false) {} + int send_timeout{0}; + int recv_timeout{0}; + int connect_timeout{1000}; + bool keep_alive{false}; + bool is_block{true}; + int sockfd{-1}; + bool available{false}; + + Rep() = default; + + Rep(std::string ip, int port) : peer_ip(std::move(ip)),peer_port(port) {} }; NetCli::NetCli(const std::string& ip, const int port) : rep_(std::make_unique(ip, port)) {} @@ -61,7 +49,9 @@ Status NetCli::Connect(const std::string& ip, const int port, const std::string& Status s; int rv; char cport[6]; - struct addrinfo hints, *servinfo, *p; + struct addrinfo hints; + struct addrinfo *servinfo; + struct addrinfo *p; snprintf(cport, sizeof(cport), "%d", port); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; @@ -82,7 +72,10 @@ Status NetCli::Connect(const std::string& ip, const int port, const std::string& localaddr.sin_family = AF_INET; localaddr.sin_addr.s_addr = inet_addr(bind_ip.c_str()); localaddr.sin_port = 0; // Any local port will do - bind(r->sockfd, (struct sockaddr*)&localaddr, sizeof(localaddr)); + if (bind(r->sockfd, reinterpret_cast(&localaddr), sizeof(localaddr)) < 0) { + close(r->sockfd); + continue; + } } int flags = fcntl(r->sockfd, F_GETFL, 0); @@ -118,7 +111,7 @@ Status NetCli::Connect(const std::string& ip, const int port, const std::string& return Status::IOError("EHOSTUNREACH", "connect host getsockopt error"); } - if (val) { + if (val != 0) { close(r->sockfd); freeaddrinfo(servinfo); return Status::IOError("EHOSTUNREACH", "connect host error"); @@ -132,7 +125,7 @@ Status NetCli::Connect(const std::string& ip, const int port, const std::string& struct sockaddr_in laddr; socklen_t llen = sizeof(laddr); - getsockname(r->sockfd, (struct sockaddr*)&laddr, &llen); + getsockname(r->sockfd, reinterpret_cast(&laddr), &llen); std::string lip(inet_ntoa(laddr.sin_addr)); int lport = ntohs(laddr.sin_port); if (ip == lip && port == lport) { @@ -147,7 +140,7 @@ Status NetCli::Connect(const std::string& ip, const int port, const std::string& rep_->available = true; return s; } - if (p == nullptr) { + if (!p) { s = Status::IOError(strerror(errno), "Can't create socket "); return s; } @@ -202,7 +195,7 @@ int NetCli::CheckAliveness() { } flag = fcntl(sock, F_GETFL, 0); - block = !(flag & O_NONBLOCK); + block = ((flag & O_NONBLOCK) == 0); if (block) { fcntl(sock, F_SETFL, flag | O_NONBLOCK); } diff --git a/src/net/src/net_conn.cc b/src/net/src/net_conn.cc index 8b8f91399a..a83a93c9e4 100644 --- a/src/net/src/net_conn.cc +++ b/src/net/src/net_conn.cc @@ -3,11 +3,13 @@ // 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 #include +#include + #include "net/include/net_conn.h" #include "net/include/net_thread.h" #include "net/src/net_util.h" @@ -15,10 +17,10 @@ namespace net { -NetConn::NetConn(const int fd, const std::string& ip_port, Thread* thread, NetMultiplexer* net_mpx) +NetConn::NetConn(const int fd, std::string ip_port, Thread* thread, NetMultiplexer* net_mpx) : fd_(fd), - ip_port_(ip_port), - is_reply_(false), + ip_port_(std::move(ip_port)), + #ifdef __ENABLE_SSL ssl_(nullptr), #endif @@ -27,12 +29,12 @@ NetConn::NetConn(const int fd, const std::string& ip_port, Thread* thread, NetMu gettimeofday(&last_interaction_, nullptr); } -NetConn::~NetConn() { #ifdef __ENABLE_SSL +NetConn::~NetConn() { SSL_free(ssl_); ssl_ = nullptr; -#endif } +#endif void NetConn::SetClose(bool close) { close_ = close; @@ -40,10 +42,7 @@ void NetConn::SetClose(bool close) { bool NetConn::SetNonblock() { flags_ = Setnonblocking(fd()); - if (flags_ == -1) { - return false; - } - return true; + return flags_ != -1; } #ifdef __ENABLE_SSL diff --git a/src/net/src/net_epoll.cc b/src/net/src/net_epoll.cc index 66d9f3bbfe..2215a62764 100644 --- a/src/net/src/net_epoll.cc +++ b/src/net/src/net_epoll.cc @@ -40,8 +40,12 @@ int NetEpoll::NetAddEvent(int fd, int mask) { ee.data.fd = fd; ee.events = 0; - if (mask & kReadable) ee.events |= EPOLLIN; - if (mask & kWritable) ee.events |= EPOLLOUT; + if (mask & kReadable) { + ee.events |= EPOLLIN; + } + if (mask & kWritable) { + ee.events |= EPOLLOUT; + } return epoll_ctl(multiplexer_, EPOLL_CTL_ADD, fd, &ee); } @@ -52,12 +56,16 @@ int NetEpoll::NetModEvent(int fd, int old_mask, int mask) { ee.events = (old_mask | mask); ee.events = 0; - if ((old_mask | mask) & kReadable) ee.events |= EPOLLIN; - if ((old_mask | mask) & kWritable) ee.events |= EPOLLOUT; + if ((old_mask | mask) & kReadable) { + ee.events |= EPOLLIN; + } + if ((old_mask | mask) & kWritable) { + ee.events |= EPOLLOUT; + } return epoll_ctl(multiplexer_, EPOLL_CTL_MOD, fd, &ee); } -int NetEpoll::NetDelEvent(int fd, int) { +int NetEpoll::NetDelEvent(int fd, [[maybe_unused]] int mask) { /* * Kernel < 2.6.9 need a non null event point to EPOLL_CTL_DEL */ @@ -68,7 +76,9 @@ int NetEpoll::NetDelEvent(int fd, int) { int NetEpoll::NetPoll(int timeout) { int num_events = epoll_wait(multiplexer_, &events_[0], NET_MAX_CLIENTS, timeout); - if (num_events <= 0) return 0; + if (num_events <= 0) { + return 0; + } for (int i = 0; i < num_events; i++) { NetFiredEvent& ev = fired_events_[i]; diff --git a/src/net/src/net_epoll.h b/src/net/src/net_epoll.h index 22b9724916..751665560e 100644 --- a/src/net/src/net_epoll.h +++ b/src/net/src/net_epoll.h @@ -19,7 +19,7 @@ class NetEpoll final : public NetMultiplexer { ~NetEpoll() = default; int NetAddEvent(int fd, int mask) override; - int NetDelEvent(int fd, int) override; + int NetDelEvent(int fd, [[maybe_unused]] int mask) override; int NetModEvent(int fd, int old_mask, int mask) override; int NetPoll(int timeout) override; diff --git a/src/net/src/net_interfaces.cc b/src/net/src/net_interfaces.cc index 0c934613f2..fd8b1a7906 100644 --- a/src/net/src/net_interfaces.cc +++ b/src/net/src/net_interfaces.cc @@ -63,7 +63,7 @@ std::string GetDefaultInterface() { break; } - ifreq = (struct ifreq*)((char*)ifreq + len); + ifreq = reinterpret_cast(reinterpret_cast(ifreq) + len); i += len; } @@ -71,7 +71,9 @@ std::string GetDefaultInterface() { #else std::string name("eth0"); std::ifstream routeFile("/proc/net/route", std::ios_base::in); - if (!routeFile.good()) return name; + if (!routeFile.good()) { + return name; + } std::string line; std::vector tokens; @@ -111,13 +113,13 @@ std::string GetIpByInterface(const std::string& network_interface) { } std::string host; - for (ifa = ifAddrStruct; ifa; ifa = ifa->ifa_next) { - if (!ifa->ifa_addr) { + for (ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next) { + if (!(ifa->ifa_addr)) { continue; } if (ifa->ifa_addr->sa_family == AF_INET) { // Check it is a valid IPv4 address - tmpAddrPtr = &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr; + tmpAddrPtr = &(reinterpret_cast(ifa->ifa_addr))->sin_addr; char addressBuffer[INET_ADDRSTRLEN]; inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); if (std::string(ifa->ifa_name) == network_interface) { @@ -125,7 +127,7 @@ std::string GetIpByInterface(const std::string& network_interface) { break; } } else if (ifa->ifa_addr->sa_family == AF_INET6) { // Check it is a valid IPv6 address - tmpAddrPtr = &((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr; + tmpAddrPtr = &(reinterpret_cast(ifa->ifa_addr))->sin6_addr; char addressBuffer[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN); if (std::string(ifa->ifa_name) == network_interface) { diff --git a/src/net/src/net_item.h b/src/net/src/net_item.h index 0cfc1f5a6a..a6863e376b 100644 --- a/src/net/src/net_item.h +++ b/src/net/src/net_item.h @@ -7,6 +7,7 @@ #define NET_SRC_NET_ITEM_H_ #include +#include #include "net/include/net_define.h" @@ -14,9 +15,9 @@ namespace net { class NetItem { public: - NetItem() {} - NetItem(const int fd, const std::string& ip_port, const NotifyType& type = kNotiConnect) - : fd_(fd), ip_port_(ip_port), notify_type_(type) {} + NetItem() = default; + NetItem(const int fd, std::string ip_port, const NotifyType& type = kNotiConnect) + : fd_(fd), ip_port_(std::move(ip_port)), notify_type_(type) {} int fd() const { return fd_; } std::string ip_port() const { return ip_port_; } diff --git a/src/net/src/net_kqueue.cc b/src/net/src/net_kqueue.cc index c42477b08e..16c831ff37 100644 --- a/src/net/src/net_kqueue.cc +++ b/src/net/src/net_kqueue.cc @@ -5,9 +5,9 @@ #include "net/src/net_kqueue.h" -#include #include #include +#include #include @@ -49,9 +49,11 @@ int NetKqueue::NetAddEvent(int fd, int mask) { return kevent(multiplexer_, change, cnt, nullptr, 0, nullptr); } -int NetKqueue::NetModEvent(int fd, int, int mask) { +int NetKqueue::NetModEvent(int fd, int /*old_mask*/, int mask) { int ret = NetDelEvent(fd, kReadable | kWritable); - if (mask == 0) return ret; + if (mask == 0) { + return ret; + } return NetAddEvent(fd, mask); } @@ -70,7 +72,9 @@ int NetKqueue::NetDelEvent(int fd, int mask) { ++cnt; } - if (cnt == 0) return -1; + if (cnt == 0) { + return -1; + } return kevent(multiplexer_, change, cnt, nullptr, 0, nullptr); } @@ -85,7 +89,9 @@ int NetKqueue::NetPoll(int timeout) { } int num_events = ::kevent(multiplexer_, nullptr, 0, &events_[0], NET_MAX_CLIENTS, p_timeout); - if (num_events <= 0) return 0; + if (num_events <= 0) { + return 0; + } for (int i = 0; i < num_events; i++) { NetFiredEvent& ev = fired_events_[i]; diff --git a/src/net/src/net_kqueue.h b/src/net/src/net_kqueue.h index 08cff50bc8..402a8b2a22 100644 --- a/src/net/src/net_kqueue.h +++ b/src/net/src/net_kqueue.h @@ -16,7 +16,7 @@ namespace net { class NetKqueue final : public NetMultiplexer { public: NetKqueue(int queue_limit = kUnlimitedQueue); - ~NetKqueue() = default; + ~NetKqueue() override = default; int NetAddEvent(int fd, int mask) override; int NetDelEvent(int fd, int mask) override; diff --git a/src/net/src/net_multiplexer.cc b/src/net/src/net_multiplexer.cc index 6e3798c297..1405432003 100644 --- a/src/net/src/net_multiplexer.cc +++ b/src/net/src/net_multiplexer.cc @@ -17,7 +17,7 @@ namespace net { NetMultiplexer::NetMultiplexer(int queue_limit) : queue_limit_(queue_limit), fired_events_(NET_MAX_CLIENTS) { int fds[2]; - if (pipe(fds)) { + if (pipe(fds) != 0) { exit(-1); } notify_receive_fd_ = fds[0]; diff --git a/src/net/src/net_pubsub.cc b/src/net/src/net_pubsub.cc index 6430cb3574..b7513454c3 100644 --- a/src/net/src/net_pubsub.cc +++ b/src/net/src/net_pubsub.cc @@ -11,7 +11,6 @@ #include "net/include/net_conn.h" #include "net/include/net_pubsub.h" -#include "net/src/net_item.h" namespace net { @@ -42,13 +41,13 @@ static std::string ConstructPublishResp(const std::string& subscribe_channel, co return resp.str(); } -void CloseFd(std::shared_ptr conn) { close(conn->fd()); } +void CloseFd(const std::shared_ptr& conn) { close(conn->fd()); } void PubSubThread::ConnHandle::UpdateReadyState(const ReadyState& state) { ready_state = state; } bool PubSubThread::ConnHandle::IsReady() { return ready_state == PubSubThread::ReadyState::kReady; } -PubSubThread::PubSubThread() : receivers_(-1) { +PubSubThread::PubSubThread() { set_thread_name("PubSubThread"); net_multiplexer_.reset(CreateNetMultiplexer()); net_multiplexer_->Initialize(); @@ -63,7 +62,7 @@ PubSubThread::PubSubThread() : receivers_(-1) { PubSubThread::~PubSubThread() { StopThread(); } -void PubSubThread::MoveConnOut(std::shared_ptr conn) { +void PubSubThread::MoveConnOut(const std::shared_ptr& conn) { RemoveConn(conn); net_multiplexer_->NetDelEvent(conn->fd(), 0); @@ -73,7 +72,7 @@ void PubSubThread::MoveConnOut(std::shared_ptr conn) { } } -void PubSubThread::MoveConnIn(std::shared_ptr conn, const NotifyType& notify_type) { +void PubSubThread::MoveConnIn(const std::shared_ptr& conn, const NotifyType& notify_type) { NetItem it(conn->fd(), conn->ip_port(), notify_type); net_multiplexer_->Register(it, true); { @@ -101,13 +100,13 @@ bool PubSubThread::IsReady(int fd) { return false; } -void PubSubThread::RemoveConn(std::shared_ptr conn) { +void PubSubThread::RemoveConn(const std::shared_ptr& conn) { { std::lock_guard lock(pattern_mutex_); - for (auto it = pubsub_pattern_.begin(); it != pubsub_pattern_.end(); it++) { - for (auto conn_ptr = it->second.begin(); conn_ptr != it->second.end(); conn_ptr++) { + for (auto & it : pubsub_pattern_) { + for (auto conn_ptr = it.second.begin(); conn_ptr != it.second.end(); conn_ptr++) { if ((*conn_ptr) == conn) { - conn_ptr = it->second.erase(conn_ptr); + conn_ptr = it.second.erase(conn_ptr); break; } } @@ -116,10 +115,10 @@ void PubSubThread::RemoveConn(std::shared_ptr conn) { { std::lock_guard lock(channel_mutex_); - for (auto it = pubsub_channel_.begin(); it != pubsub_channel_.end(); it++) { - for (auto conn_ptr = it->second.begin(); conn_ptr != it->second.end(); conn_ptr++) { + for (auto & it : pubsub_channel_) { + for (auto conn_ptr = it.second.begin(); conn_ptr != it.second.end(); conn_ptr++) { if ((*conn_ptr) == conn) { - conn_ptr = it->second.erase(conn_ptr); + conn_ptr = it.second.erase(conn_ptr); break; } } @@ -146,7 +145,7 @@ int PubSubThread::Publish(const std::string& channel, const std::string& msg) { /* * return the number of channels that the specific connection currently subscribed */ -int PubSubThread::ClientChannelSize(std::shared_ptr conn) { +int PubSubThread::ClientChannelSize(const std::shared_ptr& conn) { int subscribed = 0; channel_mutex_.lock(); @@ -170,7 +169,7 @@ int PubSubThread::ClientChannelSize(std::shared_ptr conn) { return subscribed; } -void PubSubThread::Subscribe(std::shared_ptr conn, const std::vector& channels, +void PubSubThread::Subscribe(const std::shared_ptr& conn, const std::vector& channels, const bool pattern, std::vector>* result) { int subscribed = ClientChannelSize(conn); @@ -178,35 +177,35 @@ void PubSubThread::Subscribe(std::shared_ptr conn, const std::vector> conns = {conn}; - pubsub_pattern_[channels[i]] = conns; + pubsub_pattern_[channel] = conns; ++subscribed; } - result->push_back(std::make_pair(channels[i], subscribed)); + result->push_back(std::make_pair(channel, subscribed)); } else { // if general mode, reigster channel to map std::lock_guard channel_lock(channel_mutex_); - if (pubsub_channel_.find(channels[i]) != pubsub_channel_.end()) { - auto conn_ptr = std::find(pubsub_channel_[channels[i]].begin(), pubsub_channel_[channels[i]].end(), conn); - if (conn_ptr == pubsub_channel_[channels[i]].end()) { // the connection first subscribed - pubsub_channel_[channels[i]].push_back(conn); + if (pubsub_channel_.find(channel) != pubsub_channel_.end()) { + auto conn_ptr = std::find(pubsub_channel_[channel].begin(), pubsub_channel_[channel].end(), conn); + if (conn_ptr == pubsub_channel_[channel].end()) { // the connection first subscribed + pubsub_channel_[channel].push_back(conn); ++subscribed; } } else { // the channel first subscribed std::vector> conns = {conn}; - pubsub_channel_[channels[i]] = conns; + pubsub_channel_[channel] = conns; ++subscribed; } - result->push_back(std::make_pair(channels[i], subscribed)); + result->push_back(std::make_pair(channel, subscribed)); } } } @@ -215,14 +214,14 @@ void PubSubThread::Subscribe(std::shared_ptr conn, const std::vector conn, const std::vector& channels, +int PubSubThread::UnSubscribe(const std::shared_ptr& conn, const std::vector& channels, const bool pattern, std::vector>* result) { int subscribed = ClientChannelSize(conn); bool exist = true; if (subscribed == 0) { exist = false; } - if (channels.size() == 0) { // if client want to unsubscribe all of channels + if (channels.empty()) { // if client want to unsubscribe all of channels if (pattern) { // all of pattern channels std::lock_guard l(pattern_mutex_); for (auto& channel : pubsub_pattern_) { @@ -246,36 +245,36 @@ int PubSubThread::UnSubscribe(std::shared_ptr conn, const std::vectorsecond.begin(), channel_ptr->second.end(), conn); if (it != channel_ptr->second.end()) { channel_ptr->second.erase(std::remove(channel_ptr->second.begin(), channel_ptr->second.end(), conn), channel_ptr->second.end()); - result->push_back(std::make_pair(channels[i], --subscribed)); + result->push_back(std::make_pair(channel, --subscribed)); } else { - result->push_back(std::make_pair(channels[i], subscribed)); + result->push_back(std::make_pair(channel, subscribed)); } } else { - result->push_back(std::make_pair(channels[i], 0)); + result->push_back(std::make_pair(channel, 0)); } } else { // if general mode, unsubscribe the channels of specified std::lock_guard l(channel_mutex_); - auto channel_ptr = pubsub_channel_.find(channels[i]); + auto channel_ptr = pubsub_channel_.find(channel); if (channel_ptr != pubsub_channel_.end()) { auto it = std::find(channel_ptr->second.begin(), channel_ptr->second.end(), conn); if (it != channel_ptr->second.end()) { channel_ptr->second.erase(std::remove(channel_ptr->second.begin(), channel_ptr->second.end(), conn), channel_ptr->second.end()); - result->push_back(std::make_pair(channels[i], --subscribed)); + result->push_back(std::make_pair(channel, --subscribed)); } else { - result->push_back(std::make_pair(channels[i], subscribed)); + result->push_back(std::make_pair(channel, subscribed)); } } else { - result->push_back(std::make_pair(channels[i], 0)); + result->push_back(std::make_pair(channel, 0)); } } } @@ -289,10 +288,10 @@ int PubSubThread::UnSubscribe(std::shared_ptr conn, const std::vector* result) { - if (pattern == "") { + if (pattern.empty()) { std::lock_guard l(channel_mutex_); for (auto& channel : pubsub_channel_) { - if (channel.second.size() != 0) { + if (!channel.second.empty()) { result->push_back(channel.first); } } @@ -300,7 +299,7 @@ void PubSubThread::PubSubChannels(const std::string& pattern, std::vectorpush_back(channel.first); } } @@ -312,14 +311,14 @@ void PubSubThread::PubSubNumSub(const std::vector& channels, std::vector>* result) { int subscribed; std::lock_guard l(channel_mutex_); - for (size_t i = 0; i < channels.size(); i++) { + for (const auto & i : channels) { subscribed = 0; for (auto& channel : pubsub_channel_) { - if (channel.first == channels[i]) { + if (channel.first == i) { subscribed = channel.second.size(); } } - result->push_back(std::make_pair(channels[i], subscribed)); + result->push_back(std::make_pair(i, subscribed)); } } @@ -366,7 +365,8 @@ void* PubSubThread::ThreadMain() { if (pfe->fd == msg_pfd_[0]) { // Publish message if (pfe->mask & kReadable) { read(msg_pfd_[0], triger, 1); - std::string channel, msg; + std::string channel; + std::string msg; int32_t receivers = 0; channel = channel_; msg = message_; @@ -402,24 +402,24 @@ void* PubSubThread::ThreadMain() { // Send message to a channel pattern's clients pattern_mutex_.lock(); - for (auto it = pubsub_pattern_.begin(); it != pubsub_pattern_.end(); it++) { - if (pstd::stringmatchlen(it->first.c_str(), it->first.size(), channel.c_str(), channel.size(), 0)) { - for (size_t i = 0; i < it->second.size(); i++) { - if (!IsReady(it->second[i]->fd())) { + for (auto & it : pubsub_pattern_) { + if (pstd::stringmatchlen(it.first.c_str(), it.first.size(), channel.c_str(), channel.size(), 0)) { + for (size_t i = 0; i < it.second.size(); i++) { + if (!IsReady(it.second[i]->fd())) { continue; } - std::string resp = ConstructPublishResp(it->first, channel, msg, true); - it->second[i]->WriteResp(resp); - WriteStatus write_status = it->second[i]->SendReply(); + std::string resp = ConstructPublishResp(it.first, channel, msg, true); + it.second[i]->WriteResp(resp); + WriteStatus write_status = it.second[i]->SendReply(); if (write_status == kWriteHalf) { - net_multiplexer_->NetModEvent(it->second[i]->fd(), kReadable, kWritable); + net_multiplexer_->NetModEvent(it.second[i]->fd(), kReadable, kWritable); } else if (write_status == kWriteError) { pattern_mutex_.unlock(); - MoveConnOut(it->second[i]); + MoveConnOut(it.second[i]); pattern_mutex_.lock(); - CloseFd(it->second[i]); + CloseFd(it.second[i]); } else if (write_status == kWriteAll) { receivers++; } @@ -450,7 +450,7 @@ void* PubSubThread::ThreadMain() { } // Send reply - if (pfe->mask & kWritable && in_conn->is_ready_to_reply()) { + if ((pfe->mask & kWritable) && in_conn->is_ready_to_reply()) { WriteStatus write_status = in_conn->SendReply(); if (write_status == kWriteAll) { in_conn->set_is_reply(false); @@ -465,7 +465,7 @@ void* PubSubThread::ThreadMain() { } // Client request again - if (!should_close && pfe->mask & kReadable) { + if (!should_close && (pfe->mask & kReadable)) { ReadStatus getRes = in_conn->GetRequest(); // Do not response to client when we leave the pub/sub status here if (getRes != kReadAll && getRes != kReadHalf) { diff --git a/src/net/src/net_thread.cc b/src/net/src/net_thread.cc index 31c4fafb71..c6c669c5ee 100644 --- a/src/net/src/net_thread.cc +++ b/src/net/src/net_thread.cc @@ -10,12 +10,12 @@ namespace net { -Thread::Thread() : should_stop_(false), running_(false), thread_id_(0) {} +Thread::Thread() : should_stop_(false) {} -Thread::~Thread() {} +Thread::~Thread() = default; void* Thread::RunThread(void* arg) { - Thread* thread = reinterpret_cast(arg); + auto thread = reinterpret_cast(arg); if (!(thread->thread_name().empty())) { SetThreadName(pthread_self(), thread->thread_name()); } @@ -28,7 +28,7 @@ int Thread::StartThread() { should_stop_ = false; if (!running_) { running_ = true; - return pthread_create(&thread_id_, nullptr, RunThread, (void*)this); + return pthread_create(&thread_id_, nullptr, RunThread, this); } return 0; } diff --git a/src/net/src/pb_cli.cc b/src/net/src/pb_cli.cc index 08b0e1e5c7..f6e4ea0e07 100644 --- a/src/net/src/pb_cli.cc +++ b/src/net/src/pb_cli.cc @@ -10,29 +10,32 @@ #include "net/include/net_cli.h" #include "net/include/net_define.h" +#include "pstd/include/pstd_status.h" #include "pstd/include/xdebug.h" +#include "pstd/include/noncopyable.h" + + +using pstd::Status; namespace net { // Default PBCli is block IO; class PbCli : public NetCli { public: - PbCli(const std::string& ip, const int port); - virtual ~PbCli(); + PbCli(const std::string& ip, int port); + ~PbCli() override; // msg should have been parsed - virtual Status Send(void* msg_req) override; + Status Send(void* msg_req) override; // Read, parse and store the reply - virtual Status Recv(void* msg_res) override; + Status Recv(void* msg_res) override; private: // BuildWbuf need to access rbuf_, wbuf_; char* rbuf_; char* wbuf_; - PbCli(const PbCli&); - void operator=(const PbCli&); }; PbCli::PbCli(const std::string& ip, const int port) : NetCli(ip, port) { @@ -46,7 +49,7 @@ PbCli::~PbCli() { } Status PbCli::Send(void* msg) { - google::protobuf::Message* req = reinterpret_cast(msg); + auto req = reinterpret_cast(msg); int wbuf_len = req->ByteSizeLong(); req->SerializeToArray(wbuf_ + kCommandHeaderLength, wbuf_len); @@ -58,7 +61,7 @@ Status PbCli::Send(void* msg) { } Status PbCli::Recv(void* msg_res) { - google::protobuf::Message* res = reinterpret_cast(msg_res); + auto res = reinterpret_cast(msg_res); // Read Header size_t read_len = kCommandHeaderLength; diff --git a/src/net/src/pb_conn.cc b/src/net/src/pb_conn.cc index 4c96bd94b0..e0ff5f7ca0 100644 --- a/src/net/src/pb_conn.cc +++ b/src/net/src/pb_conn.cc @@ -64,7 +64,7 @@ ReadStatus PbConn::GetRequest() { uint32_t new_size = header_len_ + COMMAND_HEADER_LENGTH; if (new_size < kProtoMaxMessage) { rbuf_ = reinterpret_cast(realloc(rbuf_, sizeof(char) * new_size)); - if (rbuf_ == nullptr) { + if (!rbuf_) { return kFullError; } rbuf_len_ = new_size; diff --git a/src/net/src/redis_cli.cc b/src/net/src/redis_cli.cc index 2e3f290cb6..663f57ba86 100644 --- a/src/net/src/redis_cli.cc +++ b/src/net/src/redis_cli.cc @@ -7,36 +7,40 @@ #include #include -#include #include +#include #include #include +#include #include +#include "pstd/include/noncopyable.h" #include "net/include/net_cli.h" #include "net/include/net_define.h" +using pstd::Status; + namespace net { class RedisCli : public NetCli { public: RedisCli(); - virtual ~RedisCli(); + ~RedisCli() override; // msg should have been parsed - virtual Status Send(void* msg); + Status Send(void* msg) override; // Read, parse and store the reply - virtual Status Recv(void* result = nullptr); + Status Recv(void* trival = nullptr) override; private: RedisCmdArgsType argv_; // The parsed result char* rbuf_; - int32_t rbuf_size_; - int32_t rbuf_pos_; - int32_t rbuf_offset_; + int32_t rbuf_size_{REDIS_IOBUF_LEN}; + int32_t rbuf_pos_{0}; + int32_t rbuf_offset_{0}; int elements_; // the elements number of this current reply int err_; @@ -51,9 +55,6 @@ class RedisCli : public NetCli { char* ReadBytes(unsigned int bytes); char* ReadLine(int* _len); - // No copyable - RedisCli(const RedisCli&); - void operator=(const RedisCli&); }; enum REDIS_STATUS { @@ -72,7 +73,7 @@ enum REDIS_STATUS { REDIS_REPLY_ERROR }; -RedisCli::RedisCli() : rbuf_size_(REDIS_IOBUF_LEN), rbuf_pos_(0), rbuf_offset_(0), err_(REDIS_OK) { +RedisCli::RedisCli() { rbuf_ = reinterpret_cast(malloc(sizeof(char) * rbuf_size_)); } @@ -83,7 +84,7 @@ Status RedisCli::Send(void* msg) { Status s; // TODO(anan) use socket_->SendRaw instead - std::string* storage = reinterpret_cast(msg); + auto storage = reinterpret_cast(msg); const char* wbuf = storage->data(); size_t nleft = storage->size(); @@ -118,7 +119,7 @@ Status RedisCli::Recv(void* trival) { int result = GetReply(); switch (result) { case REDIS_OK: - if (trival != nullptr) { + if (trival) { *static_cast(trival) = argv_; } return Status::OK(); @@ -178,7 +179,9 @@ static char* seekNewline(char* s, size_t len) { * allow to search a limited length and the buffer that is being searched * might not have a trailing nullptr character. */ while (pos < _len) { - while (pos < _len && s[pos] != '\r') pos++; + while (pos < _len && s[pos] != '\r') { + pos++; + } if (s[pos] != '\r' || pos >= _len) { /* Not found. */ return nullptr; @@ -199,7 +202,8 @@ static char* seekNewline(char* s, size_t len) { * terminated by \r\n. Ambiguously returns -1 for unexpected input. */ static long long readLongLong(char* s) { long long v = 0; - int dec, mult = 1; + int dec; + int mult = 1; char c; if (*s == '-') { @@ -228,7 +232,7 @@ int RedisCli::ProcessLineItem() { char* p; int len; - if ((p = ReadLine(&len)) == nullptr) { + if (!(p = ReadLine(&len))) { return REDIS_HALF; } @@ -240,13 +244,14 @@ int RedisCli::ProcessLineItem() { } int RedisCli::ProcessBulkItem() { - char *p, *s; + char *p; + char *s; int len; int bytelen; p = rbuf_ + rbuf_pos_; s = seekNewline(p, rbuf_offset_); - if (s != nullptr) { + if (s) { bytelen = s - p + 2; /* include \r\n */ len = readLongLong(p); @@ -274,7 +279,7 @@ int RedisCli::ProcessMultiBulkItem() { char* p; int len; - if ((p = ReadLine(&len)) != nullptr) { + if (p = ReadLine(&len); p) { elements_ = readLongLong(p); return REDIS_OK; } @@ -305,7 +310,7 @@ int RedisCli::GetReply() { char* RedisCli::ReadBytes(unsigned int bytes) { char* p = nullptr; - if ((unsigned int)rbuf_offset_ >= bytes) { + if (static_cast(rbuf_offset_) >= bytes) { p = rbuf_ + rbuf_pos_; rbuf_pos_ += bytes; rbuf_offset_ -= bytes; @@ -314,16 +319,19 @@ char* RedisCli::ReadBytes(unsigned int bytes) { } char* RedisCli::ReadLine(int* _len) { - char *p, *s; + char *p; + char *s; int len; p = rbuf_ + rbuf_pos_; s = seekNewline(p, rbuf_offset_); - if (s != nullptr) { + if (s) { len = s - (rbuf_ + rbuf_pos_); rbuf_pos_ += len + 2; /* skip \r\n */ rbuf_offset_ -= len + 2; - if (_len) *_len = len; + if (_len) { + *_len = len; + } return p; } return nullptr; @@ -339,7 +347,7 @@ int RedisCli::GetReplyFromReader() { } char* p; - if ((p = ReadBytes(1)) == nullptr) { + if (!(p = ReadBytes(1))) { return REDIS_HALF; } @@ -398,7 +406,7 @@ static int intlen(int i) { do { len++; i /= 10; - } while (i); + } while (i != 0); return len; } @@ -416,7 +424,7 @@ int redisvFormatCommand(std::string* cmd, const char* format, va_list ap) { while (*c != '\0') { if (*c != '%' || c[1] == '\0') { if (*c == ' ') { - if (touched) { + if (touched != 0) { args.push_back(curarg); totlen += bulklen(curarg.size()); curarg.clear(); @@ -459,53 +467,67 @@ int redisvFormatCommand(std::string* cmd, const char* format, va_list ap) { bool fmt_valid = false; /* Flags */ - if (*_p != '\0' && *_p == '#') _p++; - if (*_p != '\0' && *_p == '0') _p++; - if (*_p != '\0' && *_p == '-') _p++; - if (*_p != '\0' && *_p == ' ') _p++; - if (*_p != '\0' && *_p == '+') _p++; + if (*_p != '\0' && *_p == '#') { + _p++; + } + if (*_p != '\0' && *_p == '0') { + _p++; + } + if (*_p != '\0' && *_p == '-') { + _p++; + } + if (*_p != '\0' && *_p == ' ') { + _p++; + } + if (*_p != '\0' && *_p == '+') { + _p++; + } /* Field width */ - while (*_p != '\0' && isdigit(*_p)) _p++; + while (*_p != '\0' && (isdigit(*_p) != 0)) { + _p++; + } /* Precision */ if (*_p == '.') { _p++; - while (*_p != '\0' && isdigit(*_p)) _p++; + while (*_p != '\0' && (isdigit(*_p) != 0)) { + _p++; + } } /* Copy va_list before consuming with va_arg */ va_copy(_cpy, ap); - if (strchr(intfmts, *_p) != nullptr) { + if (strchr(intfmts, *_p)) { /* Integer conversion (without modifiers) */ va_arg(ap, int); fmt_valid = true; - } else if (strchr("eEfFgGaA", *_p) != nullptr) { + } else if (strchr("eEfFgGaA", *_p)) { /* Double conversion (without modifiers) */ va_arg(ap, double); fmt_valid = true; } else if (_p[0] == 'h' && _p[1] == 'h') { /* Size: char */ _p += 2; - if (*_p != '\0' && strchr(intfmts, *_p) != nullptr) { + if (*_p != '\0' && strchr(intfmts, *_p)) { va_arg(ap, int); /* char gets promoted to int */ fmt_valid = true; } } else if (_p[0] == 'h') { /* Size: short */ _p += 1; - if (*_p != '\0' && strchr(intfmts, *_p) != nullptr) { + if (*_p != '\0' && strchr(intfmts, *_p)) { va_arg(ap, int); /* short gets promoted to int */ fmt_valid = true; } } else if (_p[0] == 'l' && _p[1] == 'l') { /* Size: long long */ _p += 2; - if (*_p != '\0' && strchr(intfmts, *_p) != nullptr) { + if (*_p != '\0' && strchr(intfmts, *_p)) { va_arg(ap, long long); fmt_valid = true; } } else if (_p[0] == 'l') { /* Size: long */ _p += 1; - if (*_p != '\0' && strchr(intfmts, *_p) != nullptr) { + if (*_p != '\0' && strchr(intfmts, *_p)) { va_arg(ap, long); fmt_valid = true; } @@ -545,7 +567,7 @@ int redisvFormatCommand(std::string* cmd, const char* format, va_list ap) { } /* Add the last argument if needed */ - if (touched) { + if (touched != 0) { args.push_back(curarg); totlen += bulklen(curarg.size()); } @@ -560,11 +582,11 @@ int redisvFormatCommand(std::string* cmd, const char* format, va_list ap) { cmd->append(1, '*'); cmd->append(std::to_string(args.size())); cmd->append("\r\n"); - for (size_t i = 0; i < args.size(); i++) { + for (auto & arg : args) { cmd->append(1, '$'); - cmd->append(std::to_string(args[i].size())); + cmd->append(std::to_string(arg.size())); cmd->append("\r\n"); - cmd->append(args[i]); + cmd->append(arg); cmd->append("\r\n"); } assert(cmd->size() == totlen); @@ -614,6 +636,6 @@ int SerializeRedisCommand(std::string* cmd, const char* format, ...) { return result; } -int SerializeRedisCommand(RedisCmdArgsType argv, std::string* cmd) { return redisFormatCommandArgv(argv, cmd); } +int SerializeRedisCommand(RedisCmdArgsType argv, std::string* cmd) { return redisFormatCommandArgv(std::move(argv), cmd); } }; // namespace net diff --git a/src/net/src/redis_conn.cc b/src/net/src/redis_conn.cc index a09f6ecfd4..9cd5b3be2c 100644 --- a/src/net/src/redis_conn.cc +++ b/src/net/src/redis_conn.cc @@ -5,8 +5,8 @@ #include "net/include/redis_conn.h" -#include -#include +#include +#include #include #include @@ -22,14 +22,9 @@ RedisConn::RedisConn(const int fd, const std::string& ip_port, Thread* thread, N const HandleType& handle_type, const int rbuf_max_len) : NetConn(fd, ip_port, thread, net_mpx), handle_type_(handle_type), - rbuf_(nullptr), - rbuf_len_(0), - rbuf_max_len_(rbuf_max_len), - msg_peak_(0), - command_len_(0), - wbuf_pos_(0), - last_read_pos_(-1), - bulk_len_(-1) { + + rbuf_max_len_(rbuf_max_len) + { RedisParserSettings settings; settings.DealMessage = ParserDealMessageCb; settings.Complete = ParserCompleteCb; @@ -84,8 +79,8 @@ ReadStatus RedisConn::GetRequest() { if (new_size > rbuf_max_len_) { return kFullError; } - rbuf_ = static_cast(realloc(rbuf_, new_size)); - if (rbuf_ == nullptr) { + rbuf_ = static_cast(realloc(rbuf_, new_size)); // NOLINT + if (!rbuf_) { return kFullError; } rbuf_len_ = new_size; @@ -199,7 +194,7 @@ void RedisConn::NotifyEpoll(bool success) { } int RedisConn::ParserDealMessageCb(RedisParser* parser, const RedisCmdArgsType& argv) { - RedisConn* conn = reinterpret_cast(parser->data); + auto conn = reinterpret_cast(parser->data); if (conn->GetHandleType() == HandleType::kSynchronous) { return conn->DealMessage(argv, &(conn->response_)); } else { @@ -208,7 +203,7 @@ int RedisConn::ParserDealMessageCb(RedisParser* parser, const RedisCmdArgsType& } int RedisConn::ParserCompleteCb(RedisParser* parser, const std::vector& argvs) { - RedisConn* conn = reinterpret_cast(parser->data); + auto conn = reinterpret_cast(parser->data); bool async = conn->GetHandleType() == HandleType::kAsynchronous; conn->ProcessRedisCmds(argvs, async, &(conn->response_)); return 0; diff --git a/src/net/src/redis_parser.cc b/src/net/src/redis_parser.cc index 4070ae123b..12d8a2c4c1 100644 --- a/src/net/src/redis_parser.cc +++ b/src/net/src/redis_parser.cc @@ -5,7 +5,7 @@ #include "net/include/redis_parser.h" -#include /* assert */ +#include /* assert */ #include @@ -34,23 +34,25 @@ static int split2args(const std::string& req_buf, RedisCmdArgsType& argv) { const char* p = req_buf.data(); std::string arg; - while (1) { + while (true) { // skip blanks - while (*p && isspace(*p)) p++; - if (*p) { + while ((*p != 0) && (isspace(*p) != 0)) { + p++; + } + if (*p != 0) { // get a token int inq = 0; // set to 1 if we are in "quotes" int insq = 0; // set to 1 if we are in 'single quotes' int done = 0; arg.clear(); - while (!done) { - if (inq) { + while (done == 0) { + if (inq != 0) { if (*p == '\\' && *(p + 1) == 'x' && IsHexDigit(*(p + 2)) && IsHexDigit(*(p + 3))) { unsigned char byte = HexDigitToInt32(*(p + 2)) * 16 + HexDigitToInt32(*(p + 3)); arg.append(1, byte); p += 3; - } else if (*p == '\\' && *(p + 1)) { + } else if (*p == '\\' && (*(p + 1) != 0)) { char c; p++; @@ -78,31 +80,31 @@ static int split2args(const std::string& req_buf, RedisCmdArgsType& argv) { } else if (*p == '"') { /* closing quote must be followed by a space or * nothing at all. */ - if (*(p + 1) && !isspace(*(p + 1))) { + if ((*(p + 1) != 0) && (isspace(*(p + 1)) == 0)) { argv.clear(); return -1; } done = 1; - } else if (!*p) { + } else if (*p == 0) { // unterminated quotes argv.clear(); return -1; } else { arg.append(1, *p); } - } else if (insq) { + } else if (insq != 0) { if (*p == '\\' && *(p + 1) == '\'') { p++; arg.append(1, '\''); } else if (*p == '\'') { /* closing quote must be followed by a space or * nothing at all. */ - if (*(p + 1) && !isspace(*(p + 1))) { + if ((*(p + 1) != 0) && (isspace(*(p + 1)) == 0)) { argv.clear(); return -1; } done = 1; - } else if (!*p) { + } else if (*p == 0) { // unterminated quotes argv.clear(); return -1; @@ -130,7 +132,9 @@ static int split2args(const std::string& req_buf, RedisCmdArgsType& argv) { break; } } - if (*p) p++; + if (*p != 0) { + p++; + } } argv.push_back(arg); } else { @@ -160,22 +164,14 @@ int RedisParser::GetNextNum(int pos, long* value) { // | | // *3\r\n // [cur_pos_ + 1, pos - cur_pos_ - 2] - if (pstd::string2int(input_buf_ + cur_pos_ + 1, pos - cur_pos_ - 2, value)) { + if (pstd::string2int(input_buf_ + cur_pos_ + 1, pos - cur_pos_ - 2, value) != 0) { return 0; // Success } return -1; // Failed } RedisParser::RedisParser() - : status_code_(kRedisParserNone), - error_code_(kRedisParserOk), - redis_type_(0), - multibulk_len_(0), - bulk_len_(-1), - redis_parser_type_(REDIS_PARSER_REQUEST), - cur_pos_(0), - input_buf_(nullptr), - length_(0) {} + : redis_type_(0), bulk_len_(-1), redis_parser_type_(REDIS_PARSER_REQUEST) {} void RedisParser::SetParserStatus(RedisParserStatus status, RedisParserError error) { if (status == kRedisParserHalf) { @@ -207,7 +203,8 @@ RedisParserStatus RedisParser::RedisParserInit(RedisParserType type, const Redis } RedisParserStatus RedisParser::ProcessInlineBuffer() { - int pos, ret; + int pos; + int ret; pos = FindNextSeparators(); if (pos == -1) { // change rbuf_len_ to length_ @@ -256,7 +253,7 @@ RedisParserStatus RedisParser::ProcessMultibulkBuffer() { return status_code_; // HALF } } - while (multibulk_len_) { + while (multibulk_len_ != 0) { if (bulk_len_ == -1) { pos = FindNextSeparators(); if (pos != -1) { @@ -306,7 +303,7 @@ void RedisParser::PrintCurrentStatus() { // } LOG(INFO) << "cur_pos : " << cur_pos_; LOG(INFO) << "input_buf_ is clean ? " << (input_buf_ == nullptr); - if (input_buf_ != nullptr) { + if (input_buf_) { LOG(INFO) << " input_buf " << input_buf_; } LOG(INFO) << "half_argv_ : " << half_argv_; @@ -315,7 +312,7 @@ void RedisParser::PrintCurrentStatus() { RedisParserStatus RedisParser::ProcessInputBuffer(const char* input_buf, int length, int* parsed_len) { if (status_code_ == kRedisParserInitDone || status_code_ == kRedisParserHalf || status_code_ == kRedisParserDone) { - // TODO AZ: avoid copy + // TODO(): AZ: avoid copy std::string tmp_str(input_buf, length); input_str_ = half_argv_ + tmp_str; input_buf_ = input_str_.c_str(); @@ -338,7 +335,7 @@ RedisParserStatus RedisParser::ProcessInputBuffer(const char* input_buf, int len return status_code_; } -// TODO AZ +// TODO(): AZ RedisParserStatus RedisParser::ProcessResponseBuffer() { SetParserStatus(kRedisParserDone); return status_code_; @@ -347,7 +344,7 @@ RedisParserStatus RedisParser::ProcessResponseBuffer() { RedisParserStatus RedisParser::ProcessRequestBuffer() { RedisParserStatus ret; while (cur_pos_ <= length_ - 1) { - if (!redis_type_) { + if (redis_type_ == 0) { if (input_buf_[cur_pos_] == '*') { redis_type_ = REDIS_REQ_MULTIBULK; } else { diff --git a/src/net/src/server_socket.cc b/src/net/src/server_socket.cc index 6f223ca424..1454ede325 100644 --- a/src/net/src/server_socket.cc +++ b/src/net/src/server_socket.cc @@ -6,11 +6,11 @@ #include #include #include -#include -#include -#include #include #include +#include +#include +#include #include "net/include/net_define.h" #include "net/src/net_util.h" @@ -57,7 +57,7 @@ int ServerSocket::Listen(const std::string& bind_ip) { fcntl(sockfd_, F_SETFD, fcntl(sockfd_, F_GETFD) | FD_CLOEXEC); - ret = bind(sockfd_, (struct sockaddr*)&servaddr_, sizeof(servaddr_)); + ret = bind(sockfd_, reinterpret_cast(&servaddr_), sizeof(servaddr_)); if (ret < 0) { return kBindError; } @@ -67,7 +67,7 @@ int ServerSocket::Listen(const std::string& bind_ip) { } listening_ = true; - if (is_block_ == false) { + if (!is_block_) { SetNonBlock(); } return kSuccess; diff --git a/src/net/src/server_socket.h b/src/net/src/server_socket.h index 5efc62f5b2..9baef97081 100644 --- a/src/net/src/server_socket.h +++ b/src/net/src/server_socket.h @@ -12,9 +12,11 @@ #include #include +#include "pstd/include/noncopyable.h" + namespace net { -class ServerSocket { +class ServerSocket : public pstd::noncopyable { public: explicit ServerSocket(int port, bool is_block = false); @@ -69,12 +71,6 @@ class ServerSocket { struct sockaddr_in servaddr_; int sockfd_; - /* - * No allowed copy and copy assign operator - */ - - ServerSocket(const ServerSocket&); - void operator=(const ServerSocket&); }; } // namespace net diff --git a/src/net/src/server_thread.cc b/src/net/src/server_thread.cc index c64e5a5085..a4f0e72f54 100644 --- a/src/net/src/server_thread.cc +++ b/src/net/src/server_thread.cc @@ -24,36 +24,36 @@ using pstd::Status; class DefaultServerHandle : public ServerHandle { public: - virtual void CronHandle() const override {} - virtual void FdTimeoutHandle(int fd, const std::string& ip_port) const override { + void CronHandle() const override {} + void FdTimeoutHandle(int fd, const std::string& ip_port) const override { UNUSED(fd); UNUSED(ip_port); } - virtual void FdClosedHandle(int fd, const std::string& ip_port) const override { + void FdClosedHandle(int fd, const std::string& ip_port) const override { UNUSED(fd); UNUSED(ip_port); } - virtual bool AccessHandle(std::string& ip) const override { + bool AccessHandle(std::string& ip) const override { UNUSED(ip); return true; } - virtual bool AccessHandle(int fd, std::string& ip) const override { + bool AccessHandle(int fd, std::string& ip) const override { UNUSED(fd); UNUSED(ip); return true; } - virtual int CreateWorkerSpecificData(void** data) const override { + int CreateWorkerSpecificData(void** data) const override { UNUSED(data); return 0; } - virtual int DeleteWorkerSpecificData(void* data) const override { + int DeleteWorkerSpecificData(void* data) const override { UNUSED(data); return 0; } }; static const ServerHandle* SanitizeHandle(const ServerHandle* raw_handle) { - if (raw_handle == nullptr) { + if (!raw_handle) { return new DefaultServerHandle(); } return raw_handle; @@ -106,7 +106,6 @@ ServerThread::~ServerThread() { EVP_cleanup(); } #endif - if (own_handle_) { delete handle_; } @@ -120,7 +119,9 @@ int ServerThread::SetTcpNoDelay(int connfd) { int ServerThread::StartThread() { int ret = 0; ret = InitHandle(); - if (ret != kSuccess) return ret; + if (ret != kSuccess) { + return ret; + } return Thread::StartThread(); } @@ -131,10 +132,11 @@ int ServerThread::InitHandle() { ips_.clear(); ips_.insert("0.0.0.0"); } - for (std::set::iterator iter = ips_.begin(); iter != ips_.end(); ++iter) { + + for (const auto & ip : ips_) { socket_p = std::make_shared(port_); server_sockets_.emplace_back(socket_p); - ret = socket_p->Listen(*iter); + ret = socket_p->Listen(ip); if (ret != kSuccess) { return ret; } @@ -156,7 +158,8 @@ void* ServerThread::ThreadMain() { Status s; struct sockaddr_in cliaddr; socklen_t clilen = sizeof(struct sockaddr); - int fd, connfd; + int fd; + int connfd; struct timeval when; gettimeofday(&when, nullptr); @@ -203,8 +206,8 @@ void* ServerThread::ThreadMain() { * Handle server event */ if (server_fds_.find(fd) != server_fds_.end()) { - if (pfe->mask & kReadable) { - connfd = accept(fd, (struct sockaddr*)&cliaddr, &clilen); + if ((pfe->mask & kReadable) != 0) { + connfd = accept(fd, reinterpret_cast(&cliaddr), &clilen); if (connfd == -1) { LOG(WARNING) << "accept error, errno numberis " << errno << ", error reason " << strerror(errno); continue; @@ -236,7 +239,7 @@ void* ServerThread::ThreadMain() { */ HandleNewConn(connfd, ip_port); - } else if (pfe->mask & kErrorEvent) { + } else if ((pfe->mask & kErrorEvent) != 0) { /* * this branch means there is error on the listen fd */ diff --git a/src/net/src/simple_http_conn.cc b/src/net/src/simple_http_conn.cc index 3796dabb32..c2e8b670e4 100644 --- a/src/net/src/simple_http_conn.cc +++ b/src/net/src/simple_http_conn.cc @@ -4,9 +4,9 @@ // of patent rights can be found in the PATENTS file in the same directory. #include "net/include/simple_http_conn.h" -#include -#include -#include +#include +#include +#include #include #include @@ -141,8 +141,10 @@ bool Request::ParseGetUrl() { // Parse query parameter from GET url or POST application/x-www-form-urlencoded // format: key1=value1&key2=value2&key3=value3 -bool Request::ParseParameters(const std::string data, size_t line_start, bool from_url) { - size_t pre = line_start, mid, end; +bool Request::ParseParameters(const std::string& data, size_t line_start, bool from_url) { + size_t pre = line_start; + size_t mid; + size_t end; while (pre < data.size()) { mid = data.find('=', pre); if (mid == std::string::npos) { @@ -195,10 +197,7 @@ bool Request::ParseHeadFromArray(const char* data, const int size) { } // Parse query parameter from url - if (!ParseGetUrl()) { - return false; - } - return true; + return ParseGetUrl(); } bool Request::ParseBodyFromArray(const char* data, const int size) { @@ -312,7 +311,7 @@ bool SimpleHTTPConn::BuildRequestHeader() { remain_packet_len_ = 0; } else { long tmp = 0; - if (pstd::string2int(iter->second.data(), iter->second.size(), &tmp)) { + if (pstd::string2int(iter->second.data(), iter->second.size(), &tmp) != 0) { remain_packet_len_ = tmp; } else { remain_packet_len_ = 0; @@ -358,14 +357,16 @@ ReadStatus SimpleHTTPConn::GetRequest() { return kReadError; } - std::string sign = request_->headers.count("expect") ? request_->headers.at("expect") : ""; + std::string sign = request_->headers.count("expect") != 0U ? request_->headers.at("expect") : ""; if (sign == "100-continue" || sign == "100-Continue") { // Reply 100 Continue, then receive body response_->Clear(); response_->SetStatusCode(100); set_is_reply(true); conn_status_ = kPacket; - if (remain_packet_len_ > 0) return kReadHalf; + if (remain_packet_len_ > 0) { + return kReadHalf; + } } conn_status_ = kPacket; } diff --git a/src/net/src/thread_pool.cc b/src/net/src/thread_pool.cc index 94c2afe471..4ea4b82125 100644 --- a/src/net/src/thread_pool.cc +++ b/src/net/src/thread_pool.cc @@ -8,17 +8,19 @@ #include +#include + namespace net { void* ThreadPool::Worker::WorkerMain(void* arg) { - ThreadPool* tp = static_cast(arg); + auto tp = static_cast(arg); tp->runInThread(); return nullptr; } int ThreadPool::Worker::start() { if (!start_.load()) { - if (pthread_create(&thread_id_, nullptr, &WorkerMain, thread_pool_)) { + if (pthread_create(&thread_id_, nullptr, &WorkerMain, thread_pool_) != 0) { return -1; } else { start_.store(true); @@ -30,7 +32,7 @@ int ThreadPool::Worker::start() { int ThreadPool::Worker::stop() { if (start_.load()) { - if (pthread_join(thread_id_, nullptr)) { + if (pthread_join(thread_id_, nullptr) != 0) { return -1; } else { start_.store(false); @@ -39,10 +41,10 @@ int ThreadPool::Worker::stop() { return 0; } -ThreadPool::ThreadPool(size_t worker_num, size_t max_queue_size, const std::string& thread_pool_name) +ThreadPool::ThreadPool(size_t worker_num, size_t max_queue_size, std::string thread_pool_name) : worker_num_(worker_num), max_queue_size_(max_queue_size), - thread_pool_name_(thread_pool_name), + thread_pool_name_(std::move(thread_pool_name)), running_(false), should_stop_(false) {} diff --git a/src/net/src/worker_thread.cc b/src/net/src/worker_thread.cc index 85a154977c..dff3295aff 100644 --- a/src/net/src/worker_thread.cc +++ b/src/net/src/worker_thread.cc @@ -16,7 +16,7 @@ namespace net { WorkerThread::WorkerThread(ConnFactory* conn_factory, ServerThread* server_thread, int queue_limit, int cron_interval) - : private_data_(nullptr), + : server_thread_(server_thread), conn_factory_(conn_factory), cron_interval_(cron_interval), @@ -28,7 +28,7 @@ WorkerThread::WorkerThread(ConnFactory* conn_factory, ServerThread* server_threa net_multiplexer_->Initialize(); } -WorkerThread::~WorkerThread() {} +WorkerThread::~WorkerThread() = default; int WorkerThread::conn_num() const { std::shared_lock lock(rwlock_); @@ -58,7 +58,7 @@ std::shared_ptr WorkerThread::MoveConnOut(int fd) { } } -bool WorkerThread::MoveConnIn(std::shared_ptr conn, const NotifyType& notify_type, bool force) { +bool WorkerThread::MoveConnIn(const std::shared_ptr& conn, const NotifyType& notify_type, bool force) { NetItem it(conn->fd(), conn->ip_port(), notify_type); bool success = MoveConnIn(it, force); if (success) { @@ -105,11 +105,11 @@ void* WorkerThread::ThreadMain() { for (int i = 0; i < nfds; i++) { pfe = (net_multiplexer_->FiredEvents()) + i; - if (pfe == nullptr) { + if (!pfe) { continue; } if (pfe->fd == net_multiplexer_->NotifyReceiveFd()) { - if (pfe->mask & kReadable) { + if ((pfe->mask & kReadable) != 0) { int32_t nread = read(net_multiplexer_->NotifyReceiveFd(), bb, 2048); if (nread == 0) { continue; @@ -167,7 +167,7 @@ void* WorkerThread::ThreadMain() { } } - if ((pfe->mask & kWritable) && in_conn->is_reply()) { + if (((pfe->mask & kWritable) != 0) && in_conn->is_reply()) { WriteStatus write_status = in_conn->SendReply(); in_conn->set_last_interaction(now); if (write_status == kWriteAll) { @@ -184,7 +184,7 @@ void* WorkerThread::ThreadMain() { } } - if (!should_close && (pfe->mask & kReadable)) { + if ((should_close == 0) && ((pfe->mask & kReadable) != 0)) { ReadStatus read_status = in_conn->GetRequest(); in_conn->set_last_interaction(now); if (read_status == kReadAll) { @@ -198,7 +198,7 @@ void* WorkerThread::ThreadMain() { } } - if ((pfe->mask & kErrorEvent) || should_close) { + if (((pfe->mask & kErrorEvent) != 0) || (should_close != 0)) { net_multiplexer_->NetDelEvent(pfe->fd, 0); CloseFd(in_conn); in_conn = nullptr; @@ -226,7 +226,7 @@ void WorkerThread::DoCronTask() { // Check whether close all connection std::lock_guard kl(killer_mutex_); - if (deleting_conn_ipport_.count(kKillAllConnsTask)) { + if (deleting_conn_ipport_.count(kKillAllConnsTask) != 0U) { for (auto& conn : conns_) { to_close.push_back(conn.second); } @@ -235,11 +235,11 @@ void WorkerThread::DoCronTask() { return; } - std::map>::iterator iter = conns_.begin(); + auto iter = conns_.begin(); while (iter != conns_.end()) { std::shared_ptr conn = iter->second; // Check connection should be closed - if (deleting_conn_ipport_.count(conn->ip_port())) { + if (deleting_conn_ipport_.count(conn->ip_port()) != 0U) { to_close.push_back(conn); deleting_conn_ipport_.erase(conn->ip_port()); iter = conns_.erase(iter); @@ -261,10 +261,10 @@ void WorkerThread::DoCronTask() { ++iter; } } - for (const auto conn : to_close) { + for (const auto& conn : to_close) { CloseFd(conn); } - for (const auto conn : to_timeout) { + for (const auto& conn : to_timeout) { CloseFd(conn); server_thread_->handle_->FdTimeoutHandle(conn->fd(), conn->ip_port()); } @@ -289,7 +289,7 @@ bool WorkerThread::TryKillConn(const std::string& ip_port) { return false; } -void WorkerThread::CloseFd(std::shared_ptr conn) { +void WorkerThread::CloseFd(const std::shared_ptr& conn) { close(conn->fd()); server_thread_->handle_->FdClosedHandle(conn->fd(), conn->ip_port()); } diff --git a/src/net/src/worker_thread.h b/src/net/src/worker_thread.h index c2d8f245a0..6a859b91c6 100644 --- a/src/net/src/worker_thread.h +++ b/src/net/src/worker_thread.h @@ -32,7 +32,7 @@ class WorkerThread : public Thread { public: explicit WorkerThread(ConnFactory* conn_factory, ServerThread* server_thread, int queue_limit, int cron_interval = 0); - virtual ~WorkerThread(); + ~WorkerThread() override; void set_keepalive_timeout(int timeout) { keepalive_timeout_ = timeout; } @@ -42,7 +42,7 @@ class WorkerThread : public Thread { std::shared_ptr MoveConnOut(int fd); - bool MoveConnIn(std::shared_ptr conn, const NotifyType& notify_type, bool force); + bool MoveConnIn(const std::shared_ptr& conn, const NotifyType& notify_type, bool force); bool MoveConnIn(const NetItem& it, bool force); @@ -66,14 +66,14 @@ class WorkerThread : public Thread { std::atomic keepalive_timeout_; // keepalive second - virtual void* ThreadMain() override; + void* ThreadMain() override; void DoCronTask(); pstd::Mutex killer_mutex_; std::set deleting_conn_ipport_; // clean conns - void CloseFd(std::shared_ptr conn); + void CloseFd(const std::shared_ptr& conn); void Cleanup(); }; // class WorkerThread diff --git a/src/net/test/net_thread_test.cc b/src/net/test/net_thread_test.cc index dfbe289971..0859dbc085 100644 --- a/src/net/test/net_thread_test.cc +++ b/src/net/test/net_thread_test.cc @@ -5,7 +5,7 @@ #include "net/include/net_thread.h" -#include +#include #include #include "gmock/gmock.h" diff --git a/src/pika.cc b/src/pika.cc index e8204657ed..d879d001a3 100644 --- a/src/pika.cc +++ b/src/pika.cc @@ -4,8 +4,8 @@ // of patent rights can be found in the PATENTS file in the same directory. #include -#include #include +#include #include "include/build_version.h" #include "include/pika_cmd_table_manager.h" @@ -64,7 +64,9 @@ static void PikaGlogInit() { } static void daemonize() { - if (fork() != 0) exit(0); /* parent exits */ + if (fork()) { + exit(0); /* parent exits */ + } setsid(); /* create a new session */ } @@ -78,7 +80,7 @@ static void close_std() { } } -static void create_pid_file(void) { +static void create_pid_file() { /* Try to write the pid file in a best-effort way. */ std::string path(g_pika_conf->pidfile()); @@ -92,7 +94,7 @@ static void create_pid_file(void) { FILE* fp = fopen(path.c_str(), "w"); if (fp) { - fprintf(fp, "%d\n", (int)getpid()); + fprintf(fp, "%d\n", static_cast(getpid())); fclose(fp); } } @@ -149,7 +151,7 @@ int main(int argc, char* argv[]) { } } - if (path_opt == false) { + if (!path_opt) { fprintf(stderr, "Please specify the conf file path\n"); usage(); exit(-1); diff --git a/src/pika_admin.cc b/src/pika_admin.cc index e56af17ee4..b74d01c534 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -19,8 +19,9 @@ #include "include/pika_version.h" #include "pstd/include/rsync.h" +using pstd::Status; + extern PikaServer* g_pika_server; -extern std::unique_ptr g_pika_conf; extern std::unique_ptr g_pika_rm; static std::string ConstructPinginPubSubResp(const PikaCmdArgsType& argv) { @@ -91,20 +92,20 @@ void SlaveofCmd::DoInitial() { return; } - if (argv_.size() == 3 && !strcasecmp(argv_[1].data(), "no") && !strcasecmp(argv_[2].data(), "one")) { + if (argv_.size() == 3 && (strcasecmp(argv_[1].data(), "no") == 0) && (strcasecmp(argv_[2].data(), "one") == 0)) { is_none_ = true; return; } // self is master of A , want to slavof B - if (g_pika_server->role() & PIKA_ROLE_MASTER) { + if ((g_pika_server->role() & PIKA_ROLE_MASTER) != 0) { res_.SetRes(CmdRes::kErrOther, "already master of others, invalid usage"); return; } master_ip_ = argv_[1]; std::string str_master_port = argv_[2]; - if (!pstd::string2int(str_master_port.data(), str_master_port.size(), &master_port_) || master_port_ <= 0) { + if ((pstd::string2int(str_master_port.data(), str_master_port.size(), &master_port_) == 0) || master_port_ <= 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -115,7 +116,7 @@ void SlaveofCmd::DoInitial() { } if (argv_.size() == 4) { - if (!strcasecmp(argv_[3].data(), "force")) { + if (strcasecmp(argv_[3].data(), "force") == 0) { g_pika_server->SetForceFullSync(true); } else { res_.SetRes(CmdRes::kWrongNum, kCmdNameSlaveof); @@ -161,7 +162,7 @@ void DbSlaveofCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNameDbSlaveof); return; } - if (g_pika_server->role() ^ PIKA_ROLE_SLAVE || !g_pika_server->MetaSyncDone()) { + if (((g_pika_server->role() ^ PIKA_ROLE_SLAVE) != 0) || !g_pika_server->MetaSyncDone()) { res_.SetRes(CmdRes::kErrOther, "Not currently a slave"); return; } @@ -177,22 +178,22 @@ void DbSlaveofCmd::DoInitial() { return; } - if (argv_.size() == 3 && !strcasecmp(argv_[2].data(), "force")) { + if (argv_.size() == 3 && (strcasecmp(argv_[2].data(), "force") == 0)) { force_sync_ = true; return; } if (argv_.size() == 4) { - if (!strcasecmp(argv_[2].data(), "no") && !strcasecmp(argv_[3].data(), "one")) { + if ((strcasecmp(argv_[2].data(), "no") == 0) && (strcasecmp(argv_[3].data(), "one") == 0)) { is_none_ = true; return; } - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &filenum_) || filenum_ < 0) { + if ((pstd::string2int(argv_[2].data(), argv_[2].size(), &filenum_) == 0) || filenum_ < 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (!pstd::string2int(argv_[3].data(), argv_[3].size(), &offset_) || offset_ < 0) { + if ((pstd::string2int(argv_[3].data(), argv_[3].size(), &offset_) == 0) || offset_ < 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -326,17 +327,17 @@ void CompactCmd::DoInitial() { } void CompactCmd::Do(std::shared_ptr partition) { - if (!strcasecmp(struct_type_.data(), "all")) { + if (strcasecmp(struct_type_.data(), "all") == 0) { g_pika_server->DoSameThingSpecificTable(TaskType::kCompactAll, compact_tables_); - } else if (!strcasecmp(struct_type_.data(), "string")) { + } else if (strcasecmp(struct_type_.data(), "string") == 0) { g_pika_server->DoSameThingSpecificTable(TaskType::kCompactStrings, compact_tables_); - } else if (!strcasecmp(struct_type_.data(), "hash")) { + } else if (strcasecmp(struct_type_.data(), "hash") == 0) { g_pika_server->DoSameThingSpecificTable(TaskType::kCompactHashes, compact_tables_); - } else if (!strcasecmp(struct_type_.data(), "set")) { + } else if (strcasecmp(struct_type_.data(), "set") == 0) { g_pika_server->DoSameThingSpecificTable(TaskType::kCompactSets, compact_tables_); - } else if (!strcasecmp(struct_type_.data(), "zset")) { + } else if (strcasecmp(struct_type_.data(), "zset") == 0) { g_pika_server->DoSameThingSpecificTable(TaskType::kCompactZSets, compact_tables_); - } else if (!strcasecmp(struct_type_.data(), "list")) { + } else if (strcasecmp(struct_type_.data(), "list") == 0) { g_pika_server->DoSameThingSpecificTable(TaskType::kCompactList, compact_tables_); } else { res_.SetRes(CmdRes::kInvalidDbType, struct_type_); @@ -358,7 +359,7 @@ void PurgelogstoCmd::DoInitial() { } std::string str_num = filename.substr(kBinlogPrefixLen); int64_t num = 0; - if (!pstd::string2int(str_num.data(), str_num.size(), &num) || num < 0) { + if ((pstd::string2int(str_num.data(), str_num.size(), &num) == 0) || num < 0) { res_.SetRes(CmdRes::kInvalidParameter); return; } @@ -474,15 +475,15 @@ void FlushdbCmd::DoInitial() { db_name_ = "all"; } else { std::string struct_type = argv_[1]; - if (!strcasecmp(struct_type.data(), "string")) { + if (strcasecmp(struct_type.data(), "string") == 0) { db_name_ = "strings"; - } else if (!strcasecmp(struct_type.data(), "hash")) { + } else if (strcasecmp(struct_type.data(), "hash") == 0) { db_name_ = "hashes"; - } else if (!strcasecmp(struct_type.data(), "set")) { + } else if (strcasecmp(struct_type.data(), "set") == 0) { db_name_ = "sets"; - } else if (!strcasecmp(struct_type.data(), "zset")) { + } else if (strcasecmp(struct_type.data(), "zset") == 0) { db_name_ = "zsets"; - } else if (!strcasecmp(struct_type.data(), "list")) { + } else if (strcasecmp(struct_type.data(), "list") == 0) { db_name_ = "lists"; } else { res_.SetRes(CmdRes::kInvalidDbType); @@ -508,39 +509,38 @@ void ClientCmd::DoInitial() { return; } - if (!strcasecmp(argv_[1].data(), "getname") && argv_.size() == 2) { + if ((strcasecmp(argv_[1].data(), "getname") == 0) && argv_.size() == 2) { operation_ = argv_[1]; return; } - if (!strcasecmp(argv_[1].data(), "setname") && argv_.size() != 3) { + if ((strcasecmp(argv_[1].data(), "setname") == 0) && argv_.size() != 3) { res_.SetRes(CmdRes::kErrOther, "Unknown subcommand or wrong number of arguments for " "'SETNAME'., try CLIENT SETNAME "); return; } - if (!strcasecmp(argv_[1].data(), "setname") && argv_.size() == 3) { + if ((strcasecmp(argv_[1].data(), "setname") == 0) && argv_.size() == 3) { operation_ = argv_[1]; return; } - if (!strcasecmp(argv_[1].data(), "list") && argv_.size() == 2) { + if ((strcasecmp(argv_[1].data(), "list") == 0) && argv_.size() == 2) { // nothing - } else if (!strcasecmp(argv_[1].data(), "list") && argv_.size() == 5) { - if (!strcasecmp(argv_[2].data(), "order") && !strcasecmp(argv_[3].data(), "by")) { + } else if ((strcasecmp(argv_[1].data(), "list") == 0) && argv_.size() == 5) { + if ((strcasecmp(argv_[2].data(), "order") == 0) && (strcasecmp(argv_[3].data(), "by") == 0)) { info_ = argv_[4]; } else { res_.SetRes(CmdRes::kErrOther, "Syntax error, try CLIENT (LIST [order by [addr|idle])"); return; } - } else if (!strcasecmp(argv_[1].data(), "kill") && argv_.size() == 3) { + } else if ((strcasecmp(argv_[1].data(), "kill") == 0) && argv_.size() == 3) { info_ = argv_[2]; } else { res_.SetRes(CmdRes::kErrOther, "Syntax error, try CLIENT (LIST [order by [addr|idle]| KILL ip:port)"); return; } operation_ = argv_[1]; - return; } void ClientCmd::Do(std::shared_ptr partition) { @@ -550,39 +550,39 @@ void ClientCmd::Do(std::shared_ptr partition) { return; } - if (!strcasecmp(operation_.data(), "getname") && argv_.size() == 2) { + if ((strcasecmp(operation_.data(), "getname") == 0) && argv_.size() == 2) { res_.AppendString(conn->name()); return; } - if (!strcasecmp(operation_.data(), "setname") && argv_.size() == 3) { + if ((strcasecmp(operation_.data(), "setname") == 0) && argv_.size() == 3) { std::string name = argv_[2]; conn->set_name(name); res_.SetRes(CmdRes::kOk); return; } - if (!strcasecmp(operation_.data(), "list")) { + if (strcasecmp(operation_.data(), "list") == 0) { struct timeval now; gettimeofday(&now, nullptr); std::vector clients; g_pika_server->ClientList(&clients); - std::vector::iterator iter = clients.begin(); - std::string reply = ""; + auto iter = clients.begin(); + std::string reply; char buf[128]; - if (!strcasecmp(info_.data(), "addr")) { + if (strcasecmp(info_.data(), "addr") == 0) { std::sort(clients.begin(), clients.end(), AddrCompare); - } else if (!strcasecmp(info_.data(), "idle")) { + } else if (strcasecmp(info_.data(), "idle") == 0) { std::sort(clients.begin(), clients.end(), IdleCompare); } while (iter != clients.end()) { - snprintf(buf, sizeof(buf), "addr=%s fd=%d idle=%ld\n", iter->ip_port.c_str(), iter->fd, - iter->last_interaction == 0 ? 0 : now.tv_sec - iter->last_interaction); + snprintf(buf, sizeof(buf), "addr=%s fd=%d idle=%lld\n", iter->ip_port.c_str(), iter->fd, + iter->last_interaction == 0 ? 0 : now.tv_sec - iter->last_interaction); // NOLINT reply.append(buf); iter++; } res_.AppendString(reply); - } else if (!strcasecmp(operation_.data(), "kill") && !strcasecmp(info_.data(), "all")) { + } else if ((strcasecmp(operation_.data(), "kill") == 0) && (strcasecmp(info_.data(), "all") == 0)) { g_pika_server->ClientKillAll(); res_.SetRes(CmdRes::kOk); } else if (g_pika_server->ClientKill(info_) == 1) { @@ -590,8 +590,6 @@ void ClientCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "No such client"); } - - return; } void ShutdownCmd::DoInitial() { @@ -647,21 +645,21 @@ void InfoCmd::DoInitial() { return; } // then the agc is 2 or 3 - if (!strcasecmp(argv_[1].data(), kAllSection.data())) { + if (strcasecmp(argv_[1].data(), kAllSection.data()) == 0) { info_section_ = kInfoAll; - } else if (!strcasecmp(argv_[1].data(), kServerSection.data())) { + } else if (strcasecmp(argv_[1].data(), kServerSection.data()) == 0) { info_section_ = kInfoServer; - } else if (!strcasecmp(argv_[1].data(), kClientsSection.data())) { + } else if (strcasecmp(argv_[1].data(), kClientsSection.data()) == 0) { info_section_ = kInfoClients; - } else if (!strcasecmp(argv_[1].data(), kStatsSection.data())) { + } else if (strcasecmp(argv_[1].data(), kStatsSection.data()) == 0) { info_section_ = kInfoStats; - } else if (!strcasecmp(argv_[1].data(), kExecCountSection.data())) { + } else if (strcasecmp(argv_[1].data(), kExecCountSection.data()) == 0) { info_section_ = kInfoExecCount; - } else if (!strcasecmp(argv_[1].data(), kCPUSection.data())) { + } else if (strcasecmp(argv_[1].data(), kCPUSection.data()) == 0) { info_section_ = kInfoCPU; - } else if (!strcasecmp(argv_[1].data(), kReplicationSection.data())) { + } else if (strcasecmp(argv_[1].data(), kReplicationSection.data()) == 0) { info_section_ = kInfoReplication; - } else if (!strcasecmp(argv_[1].data(), kKeyspaceSection.data())) { + } else if (strcasecmp(argv_[1].data(), kKeyspaceSection.data()) == 0) { info_section_ = kInfoKeyspace; if (argc == 2) { LogCommand(); @@ -697,9 +695,9 @@ void InfoCmd::DoInitial() { } LogCommand(); return; - } else if (!strcasecmp(argv_[1].data(), kDataSection.data())) { + } else if (strcasecmp(argv_[1].data(), kDataSection.data()) == 0) { info_section_ = kInfoData; - } else if (!strcasecmp(argv_[1].data(), kDebugSection.data())) { + } else if (strcasecmp(argv_[1].data(), kDebugSection.data()) == 0) { info_section_ = kInfoDebug; } else { info_section_ = kInfoErr; @@ -778,7 +776,6 @@ void InfoCmd::Do(std::shared_ptr partition) { res_.AppendStringLen(info.size()); res_.AppendContent(info); - return; } void InfoCmd::InfoServer(std::string& info) { @@ -850,19 +847,20 @@ void InfoCmd::InfoExecCount(std::string& info) { } void InfoCmd::InfoCPU(std::string& info) { - struct rusage self_ru, c_ru; + struct rusage self_ru; + struct rusage c_ru; getrusage(RUSAGE_SELF, &self_ru); getrusage(RUSAGE_CHILDREN, &c_ru); std::stringstream tmp_stream; tmp_stream << "# CPU\r\n"; tmp_stream << "used_cpu_sys:" << std::setiosflags(std::ios::fixed) << std::setprecision(2) - << (float)self_ru.ru_stime.tv_sec + (float)self_ru.ru_stime.tv_usec / 1000000 << "\r\n"; + << static_cast(self_ru.ru_stime.tv_sec) + static_cast(self_ru.ru_stime.tv_usec) / 1000000 << "\r\n"; tmp_stream << "used_cpu_user:" << std::setiosflags(std::ios::fixed) << std::setprecision(2) - << (float)self_ru.ru_utime.tv_sec + (float)self_ru.ru_utime.tv_usec / 1000000 << "\r\n"; + << static_cast(self_ru.ru_utime.tv_sec) + static_cast(self_ru.ru_utime.tv_usec) / 1000000 << "\r\n"; tmp_stream << "used_cpu_sys_children:" << std::setiosflags(std::ios::fixed) << std::setprecision(2) - << (float)c_ru.ru_stime.tv_sec + (float)c_ru.ru_stime.tv_usec / 1000000 << "\r\n"; + << static_cast(c_ru.ru_stime.tv_sec) + static_cast(c_ru.ru_stime.tv_usec) / 1000000 << "\r\n"; tmp_stream << "used_cpu_user_children:" << std::setiosflags(std::ios::fixed) << std::setprecision(2) - << (float)c_ru.ru_utime.tv_sec + (float)c_ru.ru_utime.tv_usec / 1000000 << "\r\n"; + << static_cast(c_ru.ru_utime.tv_sec) + static_cast(c_ru.ru_utime.tv_usec) / 1000000 << "\r\n"; info.append(tmp_stream.str()); } @@ -870,7 +868,7 @@ void InfoCmd::InfoShardingReplication(std::string& info) { int role = 0; std::string slave_list_string; uint32_t slave_num = g_pika_server->GetShardingSlaveListString(slave_list_string); - if (slave_num) { + if (slave_num != 0U) { role |= PIKA_ROLE_MASTER; } std::string common_master; @@ -1027,7 +1025,7 @@ void InfoCmd::InfoReplication(std::string& info) { tmp_stream << table_name << " binlog_offset=" << filenum << " " << offset; s = master_partition->GetSafetyPurgeBinlog(&safety_purge); tmp_stream << ",safety_purge=" << (s.ok() ? safety_purge : "error") << "\r\n"; - if (g_pika_conf->consensus_level()) { + if (g_pika_conf->consensus_level() != 0) { LogOffset last_log = master_partition->ConsensusLastIndex(); tmp_stream << table_name << " consensus last_log=" << last_log.ToString() << "\r\n"; } @@ -1099,7 +1097,6 @@ void InfoCmd::InfoKeyspace(std::string& info) { if (rescan_) { g_pika_server->DoSameThingSpecificTable(TaskType::kStartKeyScan, keyspace_scan_tables_); } - return; } void InfoCmd::InfoData(std::string& info) { @@ -1119,8 +1116,10 @@ void InfoCmd::InfoData(std::string& info) { // rocksdb related memory usage std::map type_result; uint64_t total_background_errors = 0; - uint64_t total_memtable_usage = 0, memtable_usage = 0; - uint64_t total_table_reader_usage = 0, table_reader_usage = 0; + uint64_t total_memtable_usage = 0; + uint64_t memtable_usage = 0; + uint64_t total_table_reader_usage = 0; + uint64_t table_reader_usage = 0; std::shared_lock table_rwl(g_pika_server->tables_rw_); for (const auto& table_item : g_pika_server->tables_) { std::shared_lock partition_rwl(table_item.second->partitions_rw_); @@ -1152,7 +1151,6 @@ void InfoCmd::InfoData(std::string& info) { tmp_stream << "db_fatal_msg:" << (total_background_errors != 0 ? db_fatal_msg_stream.str() : "nullptr") << "\r\n"; info.append(tmp_stream.str()); - return; } void InfoCmd::InfoDebug(std::string& info) { @@ -1167,7 +1165,6 @@ void InfoCmd::InfoDebug(std::string& info) { << "\r\n"; info.append(tmp_stream.str()); g_pika_server->ServerStatus(&info); - return; } void ConfigCmd::DoInitial() { @@ -1176,12 +1173,12 @@ void ConfigCmd::DoInitial() { return; } size_t argc = argv_.size(); - if (!strcasecmp(argv_[1].data(), "get")) { + if (strcasecmp(argv_[1].data(), "get") == 0) { if (argc != 3) { res_.SetRes(CmdRes::kErrOther, "Wrong number of arguments for CONFIG get"); return; } - } else if (!strcasecmp(argv_[1].data(), "set")) { + } else if (strcasecmp(argv_[1].data(), "set") == 0) { if (argc == 3 && argv_[2] != "*") { res_.SetRes(CmdRes::kErrOther, "Wrong number of arguments for CONFIG set"); return; @@ -1189,12 +1186,12 @@ void ConfigCmd::DoInitial() { res_.SetRes(CmdRes::kErrOther, "Wrong number of arguments for CONFIG set"); return; } - } else if (!strcasecmp(argv_[1].data(), "rewrite")) { + } else if (strcasecmp(argv_[1].data(), "rewrite") == 0) { if (argc != 2) { res_.SetRes(CmdRes::kErrOther, "Wrong number of arguments for CONFIG rewrite"); return; } - } else if (!strcasecmp(argv_[1].data(), "resetstat")) { + } else if (strcasecmp(argv_[1].data(), "resetstat") == 0) { if (argc != 2) { res_.SetRes(CmdRes::kErrOther, "Wrong number of arguments for CONFIG resetstat"); return; @@ -1204,22 +1201,20 @@ void ConfigCmd::DoInitial() { return; } config_args_v_.assign(argv_.begin() + 1, argv_.end()); - return; } void ConfigCmd::Do(std::shared_ptr partition) { std::string config_ret; - if (!strcasecmp(config_args_v_[0].data(), "get")) { + if (strcasecmp(config_args_v_[0].data(), "get") == 0) { ConfigGet(config_ret); - } else if (!strcasecmp(config_args_v_[0].data(), "set")) { + } else if (strcasecmp(config_args_v_[0].data(), "set") == 0) { ConfigSet(config_ret); - } else if (!strcasecmp(config_args_v_[0].data(), "rewrite")) { + } else if (strcasecmp(config_args_v_[0].data(), "rewrite") == 0) { ConfigRewrite(config_ret); - } else if (!strcasecmp(config_args_v_[0].data(), "resetstat")) { + } else if (strcasecmp(config_args_v_[0].data(), "resetstat") == 0) { ConfigResetstat(config_ret); } res_.AppendStringRaw(config_ret); - return; } static void EncodeString(std::string* dst, const std::string& value) { @@ -1253,103 +1248,103 @@ void ConfigCmd::ConfigGet(std::string& ret) { std::string config_body; std::string pattern = config_args_v_[1]; - if (pstd::stringmatch(pattern.data(), "port", 1)) { + if (pstd::stringmatch(pattern.data(), "port", 1) != 0) { elements += 2; EncodeString(&config_body, "port"); EncodeInt32(&config_body, g_pika_conf->port()); } - if (pstd::stringmatch(pattern.data(), "thread-num", 1)) { + if (pstd::stringmatch(pattern.data(), "thread-num", 1) != 0) { elements += 2; EncodeString(&config_body, "thread-num"); EncodeInt32(&config_body, g_pika_conf->thread_num()); } - if (pstd::stringmatch(pattern.data(), "thread-pool-size", 1)) { + if (pstd::stringmatch(pattern.data(), "thread-pool-size", 1) != 0) { elements += 2; EncodeString(&config_body, "thread-pool-size"); EncodeInt32(&config_body, g_pika_conf->thread_pool_size()); } - if (pstd::stringmatch(pattern.data(), "sync-thread-num", 1)) { + if (pstd::stringmatch(pattern.data(), "sync-thread-num", 1) != 0) { elements += 2; EncodeString(&config_body, "sync-thread-num"); EncodeInt32(&config_body, g_pika_conf->sync_thread_num()); } - if (pstd::stringmatch(pattern.data(), "log-path", 1)) { + if (pstd::stringmatch(pattern.data(), "log-path", 1) != 0) { elements += 2; EncodeString(&config_body, "log-path"); EncodeString(&config_body, g_pika_conf->log_path()); } - if (pstd::stringmatch(pattern.data(), "db-path", 1)) { + if (pstd::stringmatch(pattern.data(), "db-path", 1) != 0) { elements += 2; EncodeString(&config_body, "db-path"); EncodeString(&config_body, g_pika_conf->db_path()); } - if (pstd::stringmatch(pattern.data(), "maxmemory", 1)) { + if (pstd::stringmatch(pattern.data(), "maxmemory", 1) != 0) { elements += 2; EncodeString(&config_body, "maxmemory"); EncodeInt64(&config_body, g_pika_conf->write_buffer_size()); } - if (pstd::stringmatch(pattern.data(), "write-buffer-size", 1)) { + if (pstd::stringmatch(pattern.data(), "write-buffer-size", 1) != 0) { elements += 2; EncodeString(&config_body, "write-buffer-size"); EncodeInt64(&config_body, g_pika_conf->write_buffer_size()); } - if (pstd::stringmatch(pattern.data(), "arena-block-size", 1)) { + if (pstd::stringmatch(pattern.data(), "arena-block-size", 1) != 0) { elements += 2; EncodeString(&config_body, "arena-block-size"); EncodeInt64(&config_body, g_pika_conf->arena_block_size()); } - if (pstd::stringmatch(pattern.data(), "max-write-buffer-num", 1)) { + if (pstd::stringmatch(pattern.data(), "max-write-buffer-num", 1) != 0) { elements += 2; EncodeString(&config_body, "max-write-buffer-num"); EncodeInt32(&config_body, g_pika_conf->max_write_buffer_number()); } - if (pstd::stringmatch(pattern.data(), "timeout", 1)) { + if (pstd::stringmatch(pattern.data(), "timeout", 1) != 0) { elements += 2; EncodeString(&config_body, "timeout"); EncodeInt32(&config_body, g_pika_conf->timeout()); } - if (pstd::stringmatch(pattern.data(), "requirepass", 1)) { + if (pstd::stringmatch(pattern.data(), "requirepass", 1) != 0) { elements += 2; EncodeString(&config_body, "requirepass"); EncodeString(&config_body, g_pika_conf->requirepass()); } - if (pstd::stringmatch(pattern.data(), "masterauth", 1)) { + if (pstd::stringmatch(pattern.data(), "masterauth", 1) != 0) { elements += 2; EncodeString(&config_body, "masterauth"); EncodeString(&config_body, g_pika_conf->masterauth()); } - if (pstd::stringmatch(pattern.data(), "userpass", 1)) { + if (pstd::stringmatch(pattern.data(), "userpass", 1) != 0) { elements += 2; EncodeString(&config_body, "userpass"); EncodeString(&config_body, g_pika_conf->userpass()); } - if (pstd::stringmatch(pattern.data(), "userblacklist", 1)) { + if (pstd::stringmatch(pattern.data(), "userblacklist", 1) != 0) { elements += 2; EncodeString(&config_body, "userblacklist"); - EncodeString(&config_body, (g_pika_conf->suser_blacklist()).c_str()); + EncodeString(&config_body, g_pika_conf->suser_blacklist()); } - if (pstd::stringmatch(pattern.data(), "instance-mode", 1)) { + if (pstd::stringmatch(pattern.data(), "instance-mode", 1) != 0) { elements += 2; EncodeString(&config_body, "instance-mode"); EncodeString(&config_body, "classic"); } - if (pstd::stringmatch(pattern.data(), "databases", 1)) { + if (pstd::stringmatch(pattern.data(), "databases", 1) != 0) { elements += 2; EncodeString(&config_body, "databases"); EncodeInt32(&config_body, g_pika_conf->databases()); @@ -1361,277 +1356,277 @@ void ConfigCmd::ConfigGet(std::string& ret) { EncodeString(&config_body, g_pika_conf->daemonize() ? "yes" : "no"); } - if (pstd::stringmatch(pattern.data(), "dump-path", 1)) { + if (pstd::stringmatch(pattern.data(), "dump-path", 1) != 0) { elements += 2; EncodeString(&config_body, "dump-path"); EncodeString(&config_body, g_pika_conf->bgsave_path()); } - if (pstd::stringmatch(pattern.data(), "dump-expire", 1)) { + if (pstd::stringmatch(pattern.data(), "dump-expire", 1) != 0) { elements += 2; EncodeString(&config_body, "dump-expire"); EncodeInt32(&config_body, g_pika_conf->expire_dump_days()); } - if (pstd::stringmatch(pattern.data(), "dump-prefix", 1)) { + if (pstd::stringmatch(pattern.data(), "dump-prefix", 1) != 0) { elements += 2; EncodeString(&config_body, "dump-prefix"); EncodeString(&config_body, g_pika_conf->bgsave_prefix()); } - if (pstd::stringmatch(pattern.data(), "pidfile", 1)) { + if (pstd::stringmatch(pattern.data(), "pidfile", 1) != 0) { elements += 2; EncodeString(&config_body, "pidfile"); EncodeString(&config_body, g_pika_conf->pidfile()); } - if (pstd::stringmatch(pattern.data(), "maxclients", 1)) { + if (pstd::stringmatch(pattern.data(), "maxclients", 1) != 0) { elements += 2; EncodeString(&config_body, "maxclients"); EncodeInt32(&config_body, g_pika_conf->maxclients()); } - if (pstd::stringmatch(pattern.data(), "target-file-size-base", 1)) { + if (pstd::stringmatch(pattern.data(), "target-file-size-base", 1) != 0) { elements += 2; EncodeString(&config_body, "target-file-size-base"); EncodeInt32(&config_body, g_pika_conf->target_file_size_base()); } - if (pstd::stringmatch(pattern.data(), "max-cache-statistic-keys", 1)) { + if (pstd::stringmatch(pattern.data(), "max-cache-statistic-keys", 1) != 0) { elements += 2; EncodeString(&config_body, "max-cache-statistic-keys"); EncodeInt32(&config_body, g_pika_conf->max_cache_statistic_keys()); } - if (pstd::stringmatch(pattern.data(), "small-compaction-threshold", 1)) { + if (pstd::stringmatch(pattern.data(), "small-compaction-threshold", 1) != 0) { elements += 2; EncodeString(&config_body, "small-compaction-threshold"); EncodeInt32(&config_body, g_pika_conf->small_compaction_threshold()); } - if (pstd::stringmatch(pattern.data(), "max-background-flushes", 1)) { + if (pstd::stringmatch(pattern.data(), "max-background-flushes", 1) != 0) { elements += 2; EncodeString(&config_body, "max-background-flushes"); EncodeInt32(&config_body, g_pika_conf->max_background_flushes()); } - if (pstd::stringmatch(pattern.data(), "max-background-compactions", 1)) { + if (pstd::stringmatch(pattern.data(), "max-background-compactions", 1) != 0) { elements += 2; EncodeString(&config_body, "max-background-compactions"); EncodeInt32(&config_body, g_pika_conf->max_background_compactions()); } - if (pstd::stringmatch(pattern.data(), "max-cache-files", 1)) { + if (pstd::stringmatch(pattern.data(), "max-cache-files", 1) != 0) { elements += 2; EncodeString(&config_body, "max-cache-files"); EncodeInt32(&config_body, g_pika_conf->max_cache_files()); } - if (pstd::stringmatch(pattern.data(), "max-bytes-for-level-multiplier", 1)) { + if (pstd::stringmatch(pattern.data(), "max-bytes-for-level-multiplier", 1) != 0) { elements += 2; EncodeString(&config_body, "max-bytes-for-level-multiplier"); EncodeInt32(&config_body, g_pika_conf->max_bytes_for_level_multiplier()); } - if (pstd::stringmatch(pattern.data(), "block-size", 1)) { + if (pstd::stringmatch(pattern.data(), "block-size", 1) != 0) { elements += 2; EncodeString(&config_body, "block-size"); EncodeInt64(&config_body, g_pika_conf->block_size()); } - if (pstd::stringmatch(pattern.data(), "block-cache", 1)) { + if (pstd::stringmatch(pattern.data(), "block-cache", 1) != 0) { elements += 2; EncodeString(&config_body, "block-cache"); EncodeInt64(&config_body, g_pika_conf->block_cache()); } - if (pstd::stringmatch(pattern.data(), "share-block-cache", 1)) { + if (pstd::stringmatch(pattern.data(), "share-block-cache", 1) != 0) { elements += 2; EncodeString(&config_body, "share-block-cache"); EncodeString(&config_body, g_pika_conf->share_block_cache() ? "yes" : "no"); } - if (pstd::stringmatch(pattern.data(), "cache-index-and-filter-blocks", 1)) { + if (pstd::stringmatch(pattern.data(), "cache-index-and-filter-blocks", 1) != 0) { elements += 2; EncodeString(&config_body, "cache-index-and-filter-blocks"); EncodeString(&config_body, g_pika_conf->cache_index_and_filter_blocks() ? "yes" : "no"); } - if (pstd::stringmatch(pattern.data(), "optimize-filters-for-hits", 1)) { + if (pstd::stringmatch(pattern.data(), "optimize-filters-for-hits", 1) != 0) { elements += 2; EncodeString(&config_body, "optimize-filters-for-hits"); EncodeString(&config_body, g_pika_conf->optimize_filters_for_hits() ? "yes" : "no"); } - if (pstd::stringmatch(pattern.data(), "level-compaction-dynamic-level-bytes", 1)) { + if (pstd::stringmatch(pattern.data(), "level-compaction-dynamic-level-bytes", 1) != 0) { elements += 2; EncodeString(&config_body, "level-compaction-dynamic-level-bytes"); EncodeString(&config_body, g_pika_conf->level_compaction_dynamic_level_bytes() ? "yes" : "no"); } - if (pstd::stringmatch(pattern.data(), "expire-logs-days", 1)) { + if (pstd::stringmatch(pattern.data(), "expire-logs-days", 1) != 0) { elements += 2; EncodeString(&config_body, "expire-logs-days"); EncodeInt32(&config_body, g_pika_conf->expire_logs_days()); } - if (pstd::stringmatch(pattern.data(), "expire-logs-nums", 1)) { + if (pstd::stringmatch(pattern.data(), "expire-logs-nums", 1) != 0) { elements += 2; EncodeString(&config_body, "expire-logs-nums"); EncodeInt32(&config_body, g_pika_conf->expire_logs_nums()); } - if (pstd::stringmatch(pattern.data(), "root-connection-num", 1)) { + if (pstd::stringmatch(pattern.data(), "root-connection-num", 1) != 0) { elements += 2; EncodeString(&config_body, "root-connection-num"); EncodeInt32(&config_body, g_pika_conf->root_connection_num()); } - if (pstd::stringmatch(pattern.data(), "slowlog-write-errorlog", 1)) { + if (pstd::stringmatch(pattern.data(), "slowlog-write-errorlog", 1) != 0) { elements += 2; EncodeString(&config_body, "slowlog-write-errorlog"); EncodeString(&config_body, g_pika_conf->slowlog_write_errorlog() ? "yes" : "no"); } - if (pstd::stringmatch(pattern.data(), "slowlog-log-slower-than", 1)) { + if (pstd::stringmatch(pattern.data(), "slowlog-log-slower-than", 1) != 0) { elements += 2; EncodeString(&config_body, "slowlog-log-slower-than"); EncodeInt32(&config_body, g_pika_conf->slowlog_slower_than()); } - if (pstd::stringmatch(pattern.data(), "slowlog-max-len", 1)) { + if (pstd::stringmatch(pattern.data(), "slowlog-max-len", 1) != 0) { elements += 2; EncodeString(&config_body, "slowlog-max-len"); EncodeInt32(&config_body, g_pika_conf->slowlog_max_len()); } - if (pstd::stringmatch(pattern.data(), "write-binlog", 1)) { + if (pstd::stringmatch(pattern.data(), "write-binlog", 1) != 0) { elements += 2; EncodeString(&config_body, "write-binlog"); EncodeString(&config_body, g_pika_conf->write_binlog() ? "yes" : "no"); } - if (pstd::stringmatch(pattern.data(), "binlog-file-size", 1)) { + if (pstd::stringmatch(pattern.data(), "binlog-file-size", 1) != 0) { elements += 2; EncodeString(&config_body, "binlog-file-size"); EncodeInt32(&config_body, g_pika_conf->binlog_file_size()); } - if (pstd::stringmatch(pattern.data(), "max-write-buffer-size", 1)) { + if (pstd::stringmatch(pattern.data(), "max-write-buffer-size", 1) != 0) { elements += 2; EncodeString(&config_body, "max-write-buffer-size"); EncodeInt64(&config_body, g_pika_conf->max_write_buffer_size()); } - if (pstd::stringmatch(pattern.data(), "max-client-response-size", 1)) { + if (pstd::stringmatch(pattern.data(), "max-client-response-size", 1) != 0) { elements += 2; EncodeString(&config_body, "max-client-response-size"); EncodeInt64(&config_body, g_pika_conf->max_client_response_size()); } - if (pstd::stringmatch(pattern.data(), "compression", 1)) { + if (pstd::stringmatch(pattern.data(), "compression", 1) != 0) { elements += 2; EncodeString(&config_body, "compression"); EncodeString(&config_body, g_pika_conf->compression()); } - if (pstd::stringmatch(pattern.data(), "db-sync-path", 1)) { + if (pstd::stringmatch(pattern.data(), "db-sync-path", 1) != 0) { elements += 2; EncodeString(&config_body, "db-sync-path"); EncodeString(&config_body, g_pika_conf->db_sync_path()); } - if (pstd::stringmatch(pattern.data(), "db-sync-speed", 1)) { + if (pstd::stringmatch(pattern.data(), "db-sync-speed", 1) != 0) { elements += 2; EncodeString(&config_body, "db-sync-speed"); EncodeInt32(&config_body, g_pika_conf->db_sync_speed()); } - if (pstd::stringmatch(pattern.data(), "compact-cron", 1)) { + if (pstd::stringmatch(pattern.data(), "compact-cron", 1) != 0) { elements += 2; EncodeString(&config_body, "compact-cron"); EncodeString(&config_body, g_pika_conf->compact_cron()); } - if (pstd::stringmatch(pattern.data(), "compact-interval", 1)) { + if (pstd::stringmatch(pattern.data(), "compact-interval", 1) != 0) { elements += 2; EncodeString(&config_body, "compact-interval"); EncodeString(&config_body, g_pika_conf->compact_interval()); } - if (pstd::stringmatch(pattern.data(), "network-interface", 1)) { + if (pstd::stringmatch(pattern.data(), "network-interface", 1) != 0) { elements += 2; EncodeString(&config_body, "network-interface"); EncodeString(&config_body, g_pika_conf->network_interface()); } - if (pstd::stringmatch(pattern.data(), "slaveof", 1)) { + if (pstd::stringmatch(pattern.data(), "slaveof", 1) != 0) { elements += 2; EncodeString(&config_body, "slaveof"); EncodeString(&config_body, g_pika_conf->slaveof()); } - if (pstd::stringmatch(pattern.data(), "slave-priority", 1)) { + if (pstd::stringmatch(pattern.data(), "slave-priority", 1) != 0) { elements += 2; EncodeString(&config_body, "slave-priority"); EncodeInt32(&config_body, g_pika_conf->slave_priority()); } // fake string for redis-benchmark - if (pstd::stringmatch(pattern.data(), "save", 1)) { + if (pstd::stringmatch(pattern.data(), "save", 1) != 0) { elements += 2; EncodeString(&config_body, "save"); EncodeString(&config_body, ""); } - if (pstd::stringmatch(pattern.data(), "appendonly", 1)) { + if (pstd::stringmatch(pattern.data(), "appendonly", 1) != 0) { elements += 2; EncodeString(&config_body, "appendonly"); EncodeString(&config_body, "no"); } - if (pstd::stringmatch(pattern.data(), "sync-window-size", 1)) { + if (pstd::stringmatch(pattern.data(), "sync-window-size", 1) != 0) { elements += 2; EncodeString(&config_body, "sync-window-size"); EncodeInt32(&config_body, g_pika_conf->sync_window_size()); } - if (pstd::stringmatch(pattern.data(), "max-conn-rbuf-size", 1)) { + if (pstd::stringmatch(pattern.data(), "max-conn-rbuf-size", 1) != 0) { elements += 2; EncodeString(&config_body, "max-conn-rbuf-size"); EncodeInt32(&config_body, g_pika_conf->max_conn_rbuf_size()); } - if (pstd::stringmatch(pattern.data(), "replication-num", 1)) { + if (pstd::stringmatch(pattern.data(), "replication-num", 1) != 0) { elements += 2; EncodeString(&config_body, "replication-num"); EncodeInt32(&config_body, g_pika_conf->replication_num()); } - if (pstd::stringmatch(pattern.data(), "consensus-level", 1)) { + if (pstd::stringmatch(pattern.data(), "consensus-level", 1) != 0) { elements += 2; EncodeString(&config_body, "consensus-level"); EncodeInt32(&config_body, g_pika_conf->consensus_level()); } - if (pstd::stringmatch(pattern.data(), "rate-limiter-bandwidth", 1)) { + if (pstd::stringmatch(pattern.data(), "rate-limiter-bandwidth", 1) != 0) { elements += 2; EncodeString(&config_body, "rate-limiter-bandwidth"); EncodeInt64(&config_body, g_pika_conf->rate_limiter_bandwidth()); } - if (pstd::stringmatch(pattern.data(), "rate-limiter-refill-period-us", 1)) { + if (pstd::stringmatch(pattern.data(), "rate-limiter-refill-period-us", 1) != 0) { elements += 2; EncodeString(&config_body, "rate-limiter-refill-period-us"); EncodeInt64(&config_body, g_pika_conf->rate_limiter_refill_period_us()); } - if (pstd::stringmatch(pattern.data(), "rate-limiter-fairness", 1)) { + if (pstd::stringmatch(pattern.data(), "rate-limiter-fairness", 1) != 0) { elements += 2; EncodeString(&config_body, "rate-limiter-fairness"); EncodeInt64(&config_body, g_pika_conf->rate_limiter_fairness()); } - if (pstd::stringmatch(pattern.data(), "rate-limiter-auto-tuned", 1)) { + if (pstd::stringmatch(pattern.data(), "rate-limiter-auto-tuned", 1) != 0) { elements += 2; EncodeString(&config_body, "rate-limiter-auto-tuned"); EncodeString(&config_body, g_pika_conf->rate_limiter_auto_tuned() ? "yes" : "no"); @@ -1683,7 +1678,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { long int ival; std::string value = config_args_v_[2]; if (set_item == "timeout") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument " + value + " for CONFIG SET 'timeout'\r\n"; return; } @@ -1705,7 +1700,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_conf->SetBgsavePrefix(value); ret = "+OK\r\n"; } else if (set_item == "maxclients") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival <= 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival <= 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'maxclients'\r\n"; return; } @@ -1713,35 +1708,35 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_server->SetDispatchQueueLimit(ival); ret = "+OK\r\n"; } else if (set_item == "dump-expire") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'dump-expire'\r\n"; return; } g_pika_conf->SetExpireDumpDays(ival); ret = "+OK\r\n"; } else if (set_item == "slave-priority") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'slave-priority'\r\n"; return; } g_pika_conf->SetSlavePriority(ival); ret = "+OK\r\n"; } else if (set_item == "expire-logs-days") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival <= 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival <= 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'expire-logs-days'\r\n"; return; } g_pika_conf->SetExpireLogsDays(ival); ret = "+OK\r\n"; } else if (set_item == "expire-logs-nums") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival <= 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival <= 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'expire-logs-nums'\r\n"; return; } g_pika_conf->SetExpireLogsNums(ival); ret = "+OK\r\n"; } else if (set_item == "root-connection-num") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival <= 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival <= 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'root-connection-num'\r\n"; return; } @@ -1760,14 +1755,14 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_conf->SetSlowlogWriteErrorlog(is_write_errorlog); ret = "+OK\r\n"; } else if (set_item == "slowlog-log-slower-than") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival < 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival < 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'slowlog-log-slower-than'\r\n"; return; } g_pika_conf->SetSlowlogSlowerThan(ival); ret = "+OK\r\n"; } else if (set_item == "slowlog-max-len") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival < 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival < 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'slowlog-max-len'\r\n"; return; } @@ -1775,7 +1770,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_server->SlowlogTrim(); ret = "+OK\r\n"; } else if (set_item == "max-cache-statistic-keys") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival < 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival < 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-cache-statistic-keys'\r\n"; return; } @@ -1783,7 +1778,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_server->PartitionSetMaxCacheStatisticKeys(ival); ret = "+OK\r\n"; } else if (set_item == "small-compaction-threshold") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival < 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival < 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'small-compaction-threshold'\r\n"; return; } @@ -1791,7 +1786,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_server->PartitionSetSmallCompactionThreshold(ival); ret = "+OK\r\n"; } else if (set_item == "max-client-response-size") { - if (!pstd::string2int(value.data(), value.size(), &ival) || ival < 0) { + if ((pstd::string2int(value.data(), value.size(), &ival) == 0) || ival < 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-client-response-size'\r\n"; return; } @@ -1810,7 +1805,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { ret = "+OK\r\n"; } } else if (set_item == "db-sync-speed") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'db-sync-speed(MB)'\r\n"; return; } @@ -1821,13 +1816,14 @@ void ConfigCmd::ConfigSet(std::string& ret) { ret = "+OK\r\n"; } else if (set_item == "compact-cron") { bool invalid = false; - if (value != "") { + if (!value.empty()) { bool have_week = false; - std::string compact_cron, week_str; + std::string compact_cron; + std::string week_str; int slash_num = count(value.begin(), value.end(), '/'); if (slash_num == 2) { have_week = true; - std::string::size_type first_slash = value.find("/"); + std::string::size_type first_slash = value.find('/'); week_str = value.substr(0, first_slash); compact_cron = value.substr(first_slash + 1); } else { @@ -1835,8 +1831,8 @@ void ConfigCmd::ConfigSet(std::string& ret) { } std::string::size_type len = compact_cron.length(); - std::string::size_type colon = compact_cron.find("-"); - std::string::size_type underline = compact_cron.find("/"); + std::string::size_type colon = compact_cron.find('-'); + std::string::size_type underline = compact_cron.find('/'); if (colon == std::string::npos || underline == std::string::npos || colon >= underline || colon + 1 >= len || colon + 1 == underline || underline + 1 >= len) { invalid = true; @@ -1860,9 +1856,9 @@ void ConfigCmd::ConfigSet(std::string& ret) { } } else if (set_item == "compact-interval") { bool invalid = false; - if (value != "") { + if (!value.empty()) { std::string::size_type len = value.length(); - std::string::size_type slash = value.find("/"); + std::string::size_type slash = value.find('/'); if (slash == std::string::npos || slash + 1 >= len) { invalid = true; } else { @@ -1881,7 +1877,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { ret = "+OK\r\n"; } } else if (set_item == "sync-window-size") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'sync-window-size'\r\n"; return; } @@ -1892,7 +1888,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_conf->SetSyncWindowSize(ival); ret = "+OK\r\n"; } else if (set_item == "max-cache-files") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-cache-files'\r\n"; return; } @@ -1905,7 +1901,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_conf->SetMaxCacheFiles(ival); ret = "+OK\r\n"; } else if (set_item == "max-background-compactions") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-background-compactions'\r\n"; return; } @@ -1918,7 +1914,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_conf->SetMaxBackgroudCompactions(ival); ret = "+OK\r\n"; } else if (set_item == "write-buffer-size") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'write-buffer-size'\r\n"; return; } @@ -1931,7 +1927,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_conf->SetWriteBufferSize(ival); ret = "+OK\r\n"; } else if (set_item == "max-write-buffer-num") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-write-buffer-number'\r\n"; return; } @@ -1944,7 +1940,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { g_pika_conf->SetMaxWriteBufferNumber(ival); ret = "+OK\r\n"; } else if (set_item == "arena-block-size") { - if (!pstd::string2int(value.data(), value.size(), &ival)) { + if (pstd::string2int(value.data(), value.size(), &ival) == 0) { ret = "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'arena-block-size'\r\n"; return; } @@ -1962,7 +1958,7 @@ void ConfigCmd::ConfigSet(std::string& ret) { } void ConfigCmd::ConfigRewrite(std::string& ret) { - if (g_pika_conf->ConfigRewrite()) { + if (g_pika_conf->ConfigRewrite() != 0) { ret = "+OK\r\n"; } else { ret = "-ERR Rewire CONFIG fail\r\n"; @@ -2064,20 +2060,20 @@ void DelbackupCmd::Do(std::shared_ptr partition) { } int len = dump_dir.size(); - for (size_t i = 0; i < dump_dir.size(); i++) { - if (dump_dir[i].substr(0, db_sync_prefix.size()) != db_sync_prefix || - dump_dir[i].size() != (db_sync_prefix.size() + 8)) { + for (auto & i : dump_dir) { + if (i.substr(0, db_sync_prefix.size()) != db_sync_prefix || + i.size() != (db_sync_prefix.size() + 8)) { continue; } - std::string str_date = dump_dir[i].substr(db_sync_prefix.size(), (dump_dir[i].size() - db_sync_prefix.size())); + std::string str_date = i.substr(db_sync_prefix.size(), (i.size() - db_sync_prefix.size())); char* end = nullptr; std::strtol(str_date.c_str(), &end, 10); if (*end != 0) { continue; } - std::string dump_dir_name = db_sync_path + dump_dir[i] + "/" + table_name_; + std::string dump_dir_name = db_sync_path + i + "/" + table_name_; if (g_pika_server->CountSyncSlaves() == 0) { LOG(INFO) << "Not syncing, delete dump file: " << dump_dir_name; pstd::DeleteDirIfExist(dump_dir_name); @@ -2087,7 +2083,6 @@ void DelbackupCmd::Do(std::shared_ptr partition) { } } res_.SetRes(CmdRes::kOk); - return; } void EchoCmd::DoInitial() { @@ -2096,12 +2091,10 @@ void EchoCmd::DoInitial() { return; } body_ = argv_[1]; - return; } void EchoCmd::Do(std::shared_ptr partition) { res_.AppendString(body_); - return; } void ScandbCmd::DoInitial() { @@ -2112,22 +2105,21 @@ void ScandbCmd::DoInitial() { if (argv_.size() == 1) { type_ = storage::kAll; } else { - if (!strcasecmp(argv_[1].data(), "string")) { + if (strcasecmp(argv_[1].data(), "string") == 0) { type_ = storage::kStrings; - } else if (!strcasecmp(argv_[1].data(), "hash")) { + } else if (strcasecmp(argv_[1].data(), "hash") == 0) { type_ = storage::kHashes; - } else if (!strcasecmp(argv_[1].data(), "set")) { + } else if (strcasecmp(argv_[1].data(), "set") == 0) { type_ = storage::kSets; - } else if (!strcasecmp(argv_[1].data(), "zset")) { + } else if (strcasecmp(argv_[1].data(), "zset") == 0) { type_ = storage::kZSets; - } else if (!strcasecmp(argv_[1].data(), "list")) { + } else if (strcasecmp(argv_[1].data(), "list") == 0) { type_ = storage::kLists; } else { res_.SetRes(CmdRes::kInvalidDbType); } } - return; -} + } void ScandbCmd::Do(std::shared_ptr partition) { std::shared_ptr
table = g_pika_server->GetTable(table_name_); @@ -2137,21 +2129,20 @@ void ScandbCmd::Do(std::shared_ptr partition) { table->ScanDatabase(type_); res_.SetRes(CmdRes::kOk); } - return; -} + } void SlowlogCmd::DoInitial() { if (!CheckArg(argv_.size())) { res_.SetRes(CmdRes::kWrongNum, kCmdNameSlowlog); return; } - if (argv_.size() == 2 && !strcasecmp(argv_[1].data(), "reset")) { + if (argv_.size() == 2 && (strcasecmp(argv_[1].data(), "reset") == 0)) { condition_ = SlowlogCmd::kRESET; - } else if (argv_.size() == 2 && !strcasecmp(argv_[1].data(), "len")) { + } else if (argv_.size() == 2 && (strcasecmp(argv_[1].data(), "len") == 0)) { condition_ = SlowlogCmd::kLEN; - } else if ((argv_.size() == 2 || argv_.size() == 3) && !strcasecmp(argv_[1].data(), "get")) { + } else if ((argv_.size() == 2 || argv_.size() == 3) && (strcasecmp(argv_[1].data(), "get") == 0)) { condition_ = SlowlogCmd::kGET; - if (argv_.size() == 3 && !pstd::string2int(argv_[2].data(), argv_[2].size(), &number_)) { + if (argv_.size() == 3 && (pstd::string2int(argv_[2].data(), argv_[2].size(), &number_) == 0)) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -2182,7 +2173,6 @@ void SlowlogCmd::Do(std::shared_ptr partition) { } } } - return; } void PaddingCmd::DoInitial() { @@ -2208,15 +2198,15 @@ void PKPatternMatchDelCmd::DoInitial() { return; } pattern_ = argv_[1]; - if (!strcasecmp(argv_[2].data(), "set")) { + if (strcasecmp(argv_[2].data(), "set") == 0) { type_ = storage::kSets; - } else if (!strcasecmp(argv_[2].data(), "list")) { + } else if (strcasecmp(argv_[2].data(), "list") == 0) { type_ = storage::kLists; - } else if (!strcasecmp(argv_[2].data(), "string")) { + } else if (strcasecmp(argv_[2].data(), "string") == 0) { type_ = storage::kStrings; - } else if (!strcasecmp(argv_[2].data(), "zset")) { + } else if (strcasecmp(argv_[2].data(), "zset") == 0) { type_ = storage::kZSets; - } else if (!strcasecmp(argv_[2].data(), "hash")) { + } else if (strcasecmp(argv_[2].data(), "hash") == 0) { type_ = storage::kHashes; } else { res_.SetRes(CmdRes::kInvalidDbType, kCmdNamePKPatternMatchDel); @@ -2264,7 +2254,7 @@ void HelloCmd::Do(std::shared_ptr partition) { size_t next_arg = 1; long ver = 0; if (argv_.size() >= 2) { - if (!pstd::string2int(argv_[next_arg].data(), argv_[next_arg].size(), &ver)) { + if (pstd::string2int(argv_[next_arg].data(), argv_[next_arg].size(), &ver) == 0) { res_.SetRes(CmdRes::kErrOther, "Protocol version is not an integer or out of range"); return; } @@ -2285,9 +2275,9 @@ void HelloCmd::Do(std::shared_ptr partition) { for (; next_arg < argv_.size(); ++next_arg) { size_t more_args = argv_.size() - next_arg - 1; const std::string opt = argv_[next_arg]; - if (!strcasecmp(opt.data(), "AUTH") && more_args) { + if ((strcasecmp(opt.data(), "AUTH") == 0) && (more_args != 0U)) { const std::string pwd = argv_[next_arg + 1]; - std::string msg_role = ""; + std::string msg_role; auto authResult = AuthenticateUser(pwd, conn, msg_role); switch (authResult) { case AuthResult::INVALID_CONN: @@ -2303,7 +2293,7 @@ void HelloCmd::Do(std::shared_ptr partition) { break; } next_arg++; - } else if (!strcasecmp(opt.data(), "SETNAME") && more_args) { + } else if ((strcasecmp(opt.data(), "SETNAME") == 0) && (more_args != 0U)) { const std::string name = argv_[next_arg + 1]; conn->set_name(name); next_arg++; @@ -2350,6 +2340,4 @@ void HelloCmd::Do(std::shared_ptr partition) { } res_.AppendArrayLen(fvs.size() * 2); res_.AppendStringRaw(raw); - - return; } diff --git a/src/pika_auxiliary_thread.cc b/src/pika_auxiliary_thread.cc index b314dc6858..3256f4bd74 100644 --- a/src/pika_auxiliary_thread.cc +++ b/src/pika_auxiliary_thread.cc @@ -26,7 +26,8 @@ void* PikaAuxiliaryThread::ThreadMain() { } else if (g_pika_server->MetaSyncDone()) { g_pika_rm->RunSyncSlavePartitionStateMachine(); } - Status s = g_pika_rm->CheckSyncTimeout(pstd::NowMicros()); + + pstd::Status s = g_pika_rm->CheckSyncTimeout(pstd::NowMicros()); if (!s.ok()) { LOG(WARNING) << s.ToString(); } @@ -40,7 +41,7 @@ void* PikaAuxiliaryThread::ThreadMain() { } // send to peer int res = g_pika_server->SendToPeer(); - if (!res) { + if (res == 0) { // sleep 100 ms std::unique_lock lock(mu_); cv_.wait_for(lock, 100ms); diff --git a/src/pika_binlog.cc b/src/pika_binlog.cc index 20d062e6a8..40ade37dd6 100644 --- a/src/pika_binlog.cc +++ b/src/pika_binlog.cc @@ -9,18 +9,23 @@ #include #include +#include + #include "include/pika_binlog_transverter.h" +#include "pstd_status.h" + +using pstd::Status; -std::string NewFileName(const std::string name, const uint32_t current) { +std::string NewFileName(const std::string& name, const uint32_t current) { char buf[256]; snprintf(buf, sizeof(buf), "%s%u", name.c_str(), current); - return std::string(buf); + return {buf}; } /* * Version */ -Version::Version(std::shared_ptr save) : pro_num_(0), pro_offset_(0), logic_id_(0), save_(save) { +Version::Version(const std::shared_ptr& save) : save_(save) { assert(save_ != nullptr); } @@ -40,11 +45,11 @@ Status Version::StableSave() { Status Version::Init() { Status s; - if (save_->GetData() != nullptr) { - memcpy((char*)(&pro_num_), save_->GetData(), sizeof(uint32_t)); - memcpy((char*)(&pro_offset_), save_->GetData() + 4, sizeof(uint64_t)); - memcpy((char*)(&logic_id_), save_->GetData() + 12, sizeof(uint64_t)); - memcpy((char*)(&term_), save_->GetData() + 20, sizeof(uint32_t)); + if (save_->GetData()) { + memcpy(reinterpret_cast(&pro_num_), save_->GetData(), sizeof(uint32_t)); + memcpy(reinterpret_cast(&pro_offset_), save_->GetData() + 4, sizeof(uint64_t)); + memcpy(reinterpret_cast(&logic_id_), save_->GetData() + 12, sizeof(uint64_t)); + memcpy(reinterpret_cast(&term_), save_->GetData() + 20, sizeof(uint32_t)); return Status::OK(); } else { return Status::Corruption("version init error"); @@ -54,15 +59,9 @@ Status Version::Init() { /* * Binlog */ -Binlog::Binlog(const std::string& binlog_path, const int file_size) +Binlog::Binlog(std::string binlog_path, const int file_size) : opened_(false), - version_(nullptr), - queue_(nullptr), - versionfile_(nullptr), - pro_num_(0), - pool_(nullptr), - exit_all_consume_(false), - binlog_path_(binlog_path), + binlog_path_(std::move(binlog_path)), file_size_(file_size), binlog_io_error_(false) { // To intergrate with old version, we don't set mmap file size to 100M; @@ -154,10 +153,10 @@ Status Binlog::GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32 *filenum = version_->pro_num_; *pro_offset = version_->pro_offset_; - if (logic_id != nullptr) { + if (logic_id) { *logic_id = version_->logic_id_; } - if (term != nullptr) { + if (term) { *term = version_->term_; } @@ -204,7 +203,7 @@ Status Binlog::Put(const char* item, int len) { } int pro_offset; - s = Produce(Slice(item, len), &pro_offset); + s = Produce(pstd::Slice(item, len), &pro_offset); if (s.ok()) { std::lock_guard l(version_->rwlock_); version_->pro_offset_ = pro_offset; @@ -235,9 +234,9 @@ Status Binlog::EmitPhysicalRecord(RecordType t, const char* ptr, size_t n, int* buf[6] = static_cast((now & 0xff000000) >> 24); buf[7] = static_cast(t); - s = queue_->Append(Slice(buf, kHeaderSize)); + s = queue_->Append(pstd::Slice(buf, kHeaderSize)); if (s.ok()) { - s = queue_->Append(Slice(ptr, n)); + s = queue_->Append(pstd::Slice(ptr, n)); if (s.ok()) { s = queue_->Flush(); } @@ -248,7 +247,7 @@ Status Binlog::EmitPhysicalRecord(RecordType t, const char* ptr, size_t n, int* return s; } -Status Binlog::Produce(const Slice& item, int* temp_pro_offset) { +Status Binlog::Produce(const pstd::Slice& item, int* temp_pro_offset) { Status s; const char* ptr = item.data(); size_t left = item.size(); @@ -260,7 +259,7 @@ Status Binlog::Produce(const Slice& item, int* temp_pro_offset) { assert(leftover >= 0); if (static_cast(leftover) < kHeaderSize) { if (leftover > 0) { - s = queue_->Append(Slice("\x00\x00\x00\x00\x00\x00\x00", leftover)); + s = queue_->Append(pstd::Slice("\x00\x00\x00\x00\x00\x00\x00", leftover)); if (!s.ok()) { return s; } @@ -321,9 +320,9 @@ Status Binlog::AppendPadding(pstd::WritableFile* file, uint64_t* len) { buf[6] = static_cast((now & 0xff000000) >> 24); // kBadRecord here buf[7] = static_cast(kBadRecord); - s = file->Append(Slice(buf, kHeaderSize)); + s = file->Append(pstd::Slice(buf, kHeaderSize)); if (s.ok()) { - s = file->Append(Slice(binlog.data(), binlog.size())); + s = file->Append(pstd::Slice(binlog.data(), binlog.size())); if (s.ok()) { s = file->Flush(); left -= size; @@ -387,7 +386,7 @@ Status Binlog::Truncate(uint32_t pro_num, uint64_t pro_offset, uint64_t index) { if (fd < 0) { return Status::IOError("fd open failed"); } - if (ftruncate(fd, pro_offset)) { + if (ftruncate(fd, pro_offset) != 0) { return Status::IOError("ftruncate failed"); } close(fd); diff --git a/src/pika_binlog_reader.cc b/src/pika_binlog_reader.cc index 0108c0e3ac..b825d8864d 100644 --- a/src/pika_binlog_reader.cc +++ b/src/pika_binlog_reader.cc @@ -7,23 +7,17 @@ #include +using pstd::Status; + PikaBinlogReader::PikaBinlogReader(uint32_t cur_filenum, uint64_t cur_offset) : cur_filenum_(cur_filenum), cur_offset_(cur_offset), - logger_(nullptr), - queue_(nullptr), backing_store_(std::make_unique(kBlockSize)), buffer_() { last_record_offset_ = cur_offset % kBlockSize; } -PikaBinlogReader::PikaBinlogReader() - : cur_filenum_(0), - cur_offset_(0), - logger_(nullptr), - queue_(nullptr), - backing_store_(std::make_unique(kBlockSize)), - buffer_() { +PikaBinlogReader::PikaBinlogReader() : backing_store_(std::make_unique(kBlockSize)), buffer_() { last_record_offset_ = 0 % kBlockSize; } @@ -41,7 +35,7 @@ bool PikaBinlogReader::ReadToTheEnd() { return (pro_num == cur_filenum_ && pro_offset == cur_offset_); } -int PikaBinlogReader::Seek(std::shared_ptr logger, uint32_t filenum, uint64_t offset) { +int PikaBinlogReader::Seek(const std::shared_ptr& logger, uint32_t filenum, uint64_t offset) { std::string confile = NewFileName(logger->filename(), filenum); if (!pstd::FileExists(confile)) { LOG(WARNING) << confile << " not exits"; @@ -78,7 +72,7 @@ int PikaBinlogReader::Seek(std::shared_ptr logger, uint32_t filenum, uin } ret = 0; is_error = GetNext(&ret); - if (is_error == true) { + if (is_error) { return -1; } res += ret; @@ -107,7 +101,9 @@ bool PikaBinlogReader::GetNext(uint64_t* size) { const unsigned int type = header[7]; const uint32_t length = a | (b << 8) | (c << 16); - if (length > (kBlockSize - kHeaderSize)) return true; + if (length > (kBlockSize - kHeaderSize)) { + return true; + } if (type == kFullType) { s = queue_->Read(length, &buffer_, backing_store_.get()); @@ -159,7 +155,9 @@ unsigned int PikaBinlogReader::ReadPhysicalRecord(pstd::Slice* result, uint32_t* const unsigned int type = header[7]; const uint32_t length = a | (b << 8) | (c << 16); - if (length > (kBlockSize - kHeaderSize)) return kBadRecord; + if (length > (kBlockSize - kHeaderSize)) { + return kBadRecord; + } if (type == kZeroType || length == 0) { buffer_.clear(); @@ -226,7 +224,7 @@ Status PikaBinlogReader::Consume(std::string* scratch, uint32_t* filenum, uint64 // Append to scratch; // the status will be OK, IOError or Corruption, EndFile; Status PikaBinlogReader::Get(std::string* scratch, uint32_t* filenum, uint64_t* offset) { - if (logger_ == nullptr || queue_ == nullptr) { + if (!logger_ || !queue_) { return Status::Corruption("Not seek"); } scratch->clear(); diff --git a/src/pika_binlog_transverter.cc b/src/pika_binlog_transverter.cc index 90e800eb5e..2bf158ccfd 100644 --- a/src/pika_binlog_transverter.cc +++ b/src/pika_binlog_transverter.cc @@ -5,13 +5,15 @@ #include "include/pika_binlog_transverter.h" -#include #include +#include #include #include "pstd/include/pstd_coding.h" #include "include/pika_command.h" +#include "storage/storage.h" + uint32_t BinlogItem::exec_time() const { return exec_time_; } @@ -43,13 +45,13 @@ std::string BinlogItem::ToString() const { str.append(",filenum: " + std::to_string(filenum_)); str.append(",offset: " + std::to_string(offset_)); str.append("\ncontent: "); - for (size_t idx = 0; idx < content_.size(); ++idx) { - if (content_[idx] == '\n') { + for (char idx : content_) { + if (idx == '\n') { str.append("\\n"); - } else if (content_[idx] == '\r') { + } else if (idx == '\r') { str.append("\\r"); } else { - str.append(1, content_[idx]); + str.append(1, idx); } } str.append("\n"); @@ -75,7 +77,7 @@ std::string PikaBinlogTransverter::BinlogEncode(BinlogType type, uint32_t exec_t bool PikaBinlogTransverter::BinlogDecode(BinlogType type, const std::string& binlog, BinlogItem* binlog_item) { uint16_t binlog_type = 0; uint32_t content_length = 0; - Slice binlog_str = binlog; + pstd::Slice binlog_str = binlog; pstd::GetFixed16(&binlog_str, &binlog_type); if (binlog_type != type) { LOG(ERROR) << "Binlog Item type error, expect type:" << type << " actualy type: " << binlog_type; @@ -98,7 +100,7 @@ bool PikaBinlogTransverter::BinlogDecode(BinlogType type, const std::string& bin } /* -/******************* Type First Binlog Item Format ****************** +******************* Type First Binlog Item Format ****************** * +-----------------------------------------------------------------+ * | Type (2 bytes) | Create Time (4 bytes) | Term Id (4 bytes) | * |-----------------------------------------------------------------| @@ -127,7 +129,7 @@ std::string PikaBinlogTransverter::ConstructPaddingBinlog(BinlogType type, uint3 int32_t content_len = size - BINLOG_ITEM_HEADER_SIZE; int32_t parameter_len = content_len - PADDING_BINLOG_PROTOCOL_SIZE - SPACE_STROE_PARAMETER_LENGTH; if (parameter_len < 0) { - return std::string(); + return {}; } std::string content; @@ -141,7 +143,7 @@ std::string PikaBinlogTransverter::ConstructPaddingBinlog(BinlogType type, uint3 std::istringstream is(os.str()); is >> parameter_len_str; if (parameter_len_str.size() > SPACE_STROE_PARAMETER_LENGTH) { - return std::string(); + return {}; } content.append("$"); @@ -158,7 +160,7 @@ std::string PikaBinlogTransverter::ConstructPaddingBinlog(BinlogType type, uint3 bool PikaBinlogTransverter::BinlogItemWithoutContentDecode(BinlogType type, const std::string& binlog, BinlogItem* binlog_item) { uint16_t binlog_type = 0; - Slice binlog_str = binlog; + pstd::Slice binlog_str = binlog; pstd::GetFixed16(&binlog_str, &binlog_type); if (binlog_type != type) { LOG(ERROR) << "Binlog Item type error, expect type:" << type << " actualy type: " << binlog_type; diff --git a/src/pika_bit.cc b/src/pika_bit.cc index 891d00a35b..b7b6f2cf3f 100644 --- a/src/pika_bit.cc +++ b/src/pika_bit.cc @@ -15,11 +15,11 @@ void BitSetCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &bit_offset_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &bit_offset_) == 0) { res_.SetRes(CmdRes::kInvalidBitOffsetInt); return; } - if (!pstd::string2int(argv_[3].data(), argv_[3].size(), &on_)) { + if (pstd::string2int(argv_[3].data(), argv_[3].size(), &on_) == 0) { res_.SetRes(CmdRes::kInvalidBitInt); return; } @@ -32,11 +32,10 @@ void BitSetCmd::DoInitial() { res_.SetRes(CmdRes::kInvalidBitOffsetInt); return; } - if (on_ & ~1) { + if ((on_ & ~1) != 0) { res_.SetRes(CmdRes::kInvalidBitInt); return; } - return; } void BitSetCmd::Do(std::shared_ptr partition) { @@ -44,7 +43,7 @@ void BitSetCmd::Do(std::shared_ptr partition) { int32_t bit_val = 0; rocksdb::Status s = partition->db()->SetBit(key_, bit_offset_, on_, &bit_val); if (s.ok()) { - res_.AppendInteger((int)bit_val); + res_.AppendInteger(static_cast(bit_val)); } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } @@ -56,7 +55,7 @@ void BitGetCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &bit_offset_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &bit_offset_) == 0) { res_.SetRes(CmdRes::kInvalidBitOffsetInt); return; } @@ -64,14 +63,13 @@ void BitGetCmd::DoInitial() { res_.SetRes(CmdRes::kInvalidBitOffsetInt); return; } - return; } void BitGetCmd::Do(std::shared_ptr partition) { int32_t bit_val = 0; rocksdb::Status s = partition->db()->GetBit(key_, bit_offset_, &bit_val); if (s.ok()) { - res_.AppendInteger((int)bit_val); + res_.AppendInteger(static_cast(bit_val)); } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } @@ -85,11 +83,11 @@ void BitCountCmd::DoInitial() { key_ = argv_[1]; if (argv_.size() == 4) { count_all_ = false; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &start_offset_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &start_offset_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (!pstd::string2int(argv_[3].data(), argv_[3].size(), &end_offset_)) { + if (pstd::string2int(argv_[3].data(), argv_[3].size(), &end_offset_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -98,7 +96,6 @@ void BitCountCmd::DoInitial() { } else { res_.SetRes(CmdRes::kSyntaxErr, kCmdNameBitCount); } - return; } void BitCountCmd::Do(std::shared_ptr partition) { @@ -123,11 +120,11 @@ void BitPosCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &bit_val_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &bit_val_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (bit_val_ & ~1) { + if ((bit_val_ & ~1) != 0) { res_.SetRes(CmdRes::kInvalidBitPosArgument); return; } @@ -137,24 +134,24 @@ void BitPosCmd::DoInitial() { } else if (argv_.size() == 4) { pos_all_ = false; endoffset_set_ = false; - if (!pstd::string2int(argv_[3].data(), argv_[3].size(), &start_offset_)) { + if (pstd::string2int(argv_[3].data(), argv_[3].size(), &start_offset_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } } else if (argv_.size() == 5) { pos_all_ = false; endoffset_set_ = true; - if (!pstd::string2int(argv_[3].data(), argv_[3].size(), &start_offset_)) { + if (pstd::string2int(argv_[3].data(), argv_[3].size(), &start_offset_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (!pstd::string2int(argv_[4].data(), argv_[4].size(), &end_offset_)) { + if (pstd::string2int(argv_[4].data(), argv_[4].size(), &end_offset_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - } else + } else { res_.SetRes(CmdRes::kSyntaxErr, kCmdNameBitPos); - return; + } } void BitPosCmd::Do(std::shared_ptr partition) { @@ -168,7 +165,7 @@ void BitPosCmd::Do(std::shared_ptr partition) { s = partition->db()->BitPos(key_, bit_val_, start_offset_, end_offset_, &pos); } if (s.ok()) { - res_.AppendInteger((int)pos); + res_.AppendInteger(static_cast(pos)); } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } @@ -180,13 +177,13 @@ void BitOpCmd::DoInitial() { return; } std::string op_str = argv_[1]; - if (!strcasecmp(op_str.data(), "not")) { + if (strcasecmp(op_str.data(), "not") == 0) { op_ = storage::kBitOpNot; - } else if (!strcasecmp(op_str.data(), "and")) { + } else if (strcasecmp(op_str.data(), "and") == 0) { op_ = storage::kBitOpAnd; - } else if (!strcasecmp(op_str.data(), "or")) { + } else if (strcasecmp(op_str.data(), "or") == 0) { op_ = storage::kBitOpOr; - } else if (!strcasecmp(op_str.data(), "xor")) { + } else if (strcasecmp(op_str.data(), "xor") == 0) { op_ = storage::kBitOpXor; } else { res_.SetRes(CmdRes::kSyntaxErr, kCmdNameBitOp); @@ -203,11 +200,10 @@ void BitOpCmd::DoInitial() { return; } - dest_key_ = argv_[2].data(); + dest_key_ = argv_[2]; for (unsigned int i = 3; i <= argv_.size() - 1; i++) { - src_keys_.push_back(argv_[i].data()); + src_keys_.emplace_back(argv_[i].data()); } - return; } void BitOpCmd::Do(std::shared_ptr partition) { diff --git a/src/pika_client_conn.cc b/src/pika_client_conn.cc index 46a3a6d63e..690b8bb66f 100644 --- a/src/pika_client_conn.cc +++ b/src/pika_client_conn.cc @@ -6,6 +6,7 @@ #include "include/pika_client_conn.h" #include +#include #include #include @@ -21,17 +22,16 @@ extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; extern std::unique_ptr g_pika_cmd_table_manager; -PikaClientConn::PikaClientConn(int fd, std::string ip_port, net::Thread* thread, net::NetMultiplexer* mpx, +PikaClientConn::PikaClientConn(int fd, const std::string& ip_port, net::Thread* thread, net::NetMultiplexer* mpx, const net::HandleType& handle_type, int max_conn_rbuf_size) : RedisConn(fd, ip_port, thread, mpx, handle_type, max_conn_rbuf_size), server_thread_(reinterpret_cast(thread)), - current_table_(g_pika_conf->default_table()), - is_pubsub_(false) { + current_table_(g_pika_conf->default_table()) { auth_stat_.Init(); } std::shared_ptr PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const std::string& opt, - std::shared_ptr resp_ptr) { + const std::shared_ptr& resp_ptr) { // Get command info std::shared_ptr c_ptr = g_pika_cmd_table_manager->GetCmd(opt); if (!c_ptr) { @@ -97,7 +97,6 @@ std::shared_ptr PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st return c_ptr; } - // TODO: Consider special commands, like flushall, flushdb? if (c_ptr->is_write()) { if (g_pika_server->IsTableBinlogIoError(current_table_)) { c_ptr->res().SetRes(CmdRes::kErrOther, "Writing binlog failed, maybe no space left on device"); @@ -139,11 +138,11 @@ void PikaClientConn::ProcessSlowlog(const PikaCmdArgsType& argv, uint64_t start_ bool trim = false; std::string slow_log; uint32_t cmd_size = 0; - for (unsigned int i = 0; i < argv.size(); i++) { - cmd_size += 1 + argv[i].size(); // blank space and argument length + for (const auto & i : argv) { + cmd_size += 1 + i.size(); // blank space and argument length if (!trim) { slow_log.append(" "); - slow_log.append(pstd::ToRead(argv[i])); + slow_log.append(pstd::ToRead(i)); if (slow_log.size() >= 1000) { trim = true; slow_log.resize(1000); @@ -163,8 +162,8 @@ void PikaClientConn::ProcessMonitor(const PikaCmdArgsType& argv) { std::string monitor_message; std::string table_name = current_table_.substr(2); monitor_message = std::to_string(1.0 * pstd::NowMicros() / 1000000) + " [" + table_name + " " + this->ip_port() + "]"; - for (PikaCmdArgsType::const_iterator iter = argv.begin(); iter != argv.end(); iter++) { - monitor_message += " " + pstd::ToRead(*iter); + for (const auto & iter : argv) { + monitor_message += " " + pstd::ToRead(iter); } g_pika_server->AddMonitorMessage(monitor_message); } @@ -172,7 +171,7 @@ void PikaClientConn::ProcessMonitor(const PikaCmdArgsType& argv) { void PikaClientConn::ProcessRedisCmds(const std::vector& argvs, bool async, std::string* response) { if (async) { - BgTaskArg* arg = new BgTaskArg(); + auto arg = new BgTaskArg(); arg->redis_cmds = argvs; arg->conn_ptr = std::dynamic_pointer_cast(shared_from_this()); g_pika_server->ScheduleClientPool(&DoBackgroundTask, arg); @@ -184,12 +183,12 @@ void PikaClientConn::ProcessRedisCmds(const std::vector& void PikaClientConn::DoBackgroundTask(void* arg) { std::unique_ptr bg_arg(static_cast(arg)); std::shared_ptr conn_ptr = bg_arg->conn_ptr; - if (bg_arg->redis_cmds.size() == 0) { + if (bg_arg->redis_cmds.empty()) { conn_ptr->NotifyEpoll(false); return; } for (const auto& argv : bg_arg->redis_cmds) { - if (argv.size() == 0) { + if (argv.empty()) { conn_ptr->NotifyEpoll(false); return; } @@ -220,13 +219,13 @@ void PikaClientConn::DoExecTask(void* arg) { std::shared_ptr partition = g_pika_rm->GetSyncMasterPartitionByName(PartitionInfo(table_name, partition_id)); - if (partition == nullptr) { + if (!partition) { LOG(WARNING) << "Sync Master Partition not exist " << table_name << partition_id; return; } partition->ConsensusUpdateAppliedIndex(offset); - if (conn_ptr == nullptr || resp_ptr == nullptr) { + if (!conn_ptr || !resp_ptr) { return; } @@ -239,10 +238,10 @@ void PikaClientConn::DoExecTask(void* arg) { void PikaClientConn::BatchExecRedisCmd(const std::vector& argvs) { resp_num.store(argvs.size()); - for (size_t i = 0; i < argvs.size(); ++i) { + for (const auto & argv : argvs) { std::shared_ptr resp_ptr = std::make_shared(); resp_array.push_back(resp_ptr); - ExecRedisCmd(argvs[i], resp_ptr); + ExecRedisCmd(argv, resp_ptr); } TryWriteResp(); } @@ -251,9 +250,9 @@ void PikaClientConn::TryWriteResp() { int expected = 0; if (resp_num.compare_exchange_strong(expected, -1)) { for (auto& resp : resp_array) { - WriteResp(std::move(*resp)); + WriteResp(*resp); } - if (write_completed_cb_ != nullptr) { + if (write_completed_cb_) { write_completed_cb_(); write_completed_cb_ = nullptr; } @@ -262,7 +261,7 @@ void PikaClientConn::TryWriteResp() { } } -void PikaClientConn::ExecRedisCmd(const PikaCmdArgsType& argv, std::shared_ptr resp_ptr) { +void PikaClientConn::ExecRedisCmd(const PikaCmdArgsType& argv, const std::shared_ptr& resp_ptr) { // get opt std::string opt = argv[0]; pstd::StringToLower(opt); @@ -284,14 +283,14 @@ void PikaClientConn::ExecRedisCmd(const PikaCmdArgsType& argv, std::shared_ptruserpass() == "" ? kLimitAuthed : kNoAuthed; - if (stat_ == kLimitAuthed && g_pika_conf->requirepass() == "") { + stat_ = g_pika_conf->userpass().empty() ? kLimitAuthed : kNoAuthed; + if (stat_ == kLimitAuthed && g_pika_conf->requirepass().empty()) { stat_ = kAdminAuthed; } } // Check permission for current command -bool PikaClientConn::AuthStat::IsAuthed(const std::shared_ptr cmd_ptr) { +bool PikaClientConn::AuthStat::IsAuthed(const std::shared_ptr& cmd_ptr) { std::string opt = cmd_ptr->name(); if (opt == kCmdNameAuth) { return true; diff --git a/src/pika_client_processor.cc b/src/pika_client_processor.cc index 9b2463e01c..6242ad721f 100644 --- a/src/pika_client_processor.cc +++ b/src/pika_client_processor.cc @@ -24,8 +24,8 @@ int PikaClientProcessor::Start() { if (res != net::kSuccess) { return res; } - for (size_t i = 0; i < bg_threads_.size(); ++i) { - res = bg_threads_[i]->StartThread(); + for (auto & bg_thread : bg_threads_) { + res = bg_thread->StartThread(); if (res != net::kSuccess) { return res; } @@ -35,8 +35,8 @@ int PikaClientProcessor::Start() { void PikaClientProcessor::Stop() { pool_->stop_thread_pool(); - for (size_t i = 0; i < bg_threads_.size(); ++i) { - bg_threads_[i]->StopThread(); + for (auto & bg_thread : bg_threads_) { + bg_thread->StopThread(); } } diff --git a/src/pika_cmd_table_manager.cc b/src/pika_cmd_table_manager.cc index 335ee72210..041cd58426 100644 --- a/src/pika_cmd_table_manager.cc +++ b/src/pika_cmd_table_manager.cc @@ -20,7 +20,7 @@ PikaCmdTableManager::PikaCmdTableManager() { } std::shared_ptr PikaCmdTableManager::GetCmd(const std::string& opt) { - std::string internal_opt = opt; + const std::string& internal_opt = opt; return NewCommand(internal_opt); } @@ -34,10 +34,7 @@ std::shared_ptr PikaCmdTableManager::NewCommand(const std::string& opt) { bool PikaCmdTableManager::CheckCurrentThreadDistributionMapExist(const std::thread::id& tid) { std::shared_lock l(map_protector_); - if (thread_distribution_map_.find(tid) == thread_distribution_map_.end()) { - return false; - } - return true; + return thread_distribution_map_.find(tid) != thread_distribution_map_.end(); } void PikaCmdTableManager::InsertCurrentThreadDistributionMap() { diff --git a/src/pika_command.cc b/src/pika_command.cc index 77de589427..cae2805c46 100644 --- a/src/pika_command.cc +++ b/src/pika_command.cc @@ -3,6 +3,8 @@ // 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/pika_command.h" #include "include/pika_admin.h" @@ -19,6 +21,8 @@ #include "include/pika_set.h" #include "include/pika_zset.h" +using pstd::Status; + extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; extern std::unique_ptr g_pika_cmd_table_manager; @@ -462,14 +466,13 @@ void InitCmdTable(CmdTable* cmd_table) { } Cmd* GetCmdFromTable(const std::string& opt, const CmdTable& cmd_table) { - CmdTable::const_iterator it = cmd_table.find(opt); + auto it = cmd_table.find(opt); if (it != cmd_table.end()) { return it->second.get(); } return nullptr; } - void Cmd::Initial(const PikaCmdArgsType& argv, const std::string& table_name) { argv_ = argv; table_name_ = table_name; @@ -480,7 +483,7 @@ void Cmd::Initial(const PikaCmdArgsType& argv, const std::string& table_name) { std::vector Cmd::current_key() const { std::vector res; - res.push_back(""); + res.emplace_back(""); return res; } @@ -563,7 +566,7 @@ void Cmd::ProcessSinglePartitionCmd() { ProcessCommand(partition, sync_partition); } -void Cmd::ProcessCommand(std::shared_ptr partition, std::shared_ptr sync_partition, +void Cmd::ProcessCommand(const std::shared_ptr& partition, const std::shared_ptr& sync_partition, const HintKeys& hint_keys) { if (stage_ == kNone) { InternalProcessCommand(partition, sync_partition, hint_keys); @@ -576,8 +579,8 @@ void Cmd::ProcessCommand(std::shared_ptr partition, std::shared_ptr partition, - std::shared_ptr sync_partition, const HintKeys& hint_keys) { +void Cmd::InternalProcessCommand(const std::shared_ptr& partition, + const std::shared_ptr& sync_partition, const HintKeys& hint_keys) { pstd::lock::MultiRecordLock record_lock(partition->LockMgr()); if (is_write()) { record_lock.Lock(current_key()); @@ -598,7 +601,7 @@ void Cmd::InternalProcessCommand(std::shared_ptr partition, } } -void Cmd::DoCommand(std::shared_ptr partition, const HintKeys& hint_keys) { +void Cmd::DoCommand(const std::shared_ptr& partition, const HintKeys& hint_keys) { if (!is_suspend()) { partition->DbRWLockReader(); } @@ -610,7 +613,7 @@ void Cmd::DoCommand(std::shared_ptr partition, const HintKeys& hint_k } } -void Cmd::DoBinlog(std::shared_ptr partition) { +void Cmd::DoBinlog(const std::shared_ptr& partition) { if (res().ok() && is_write() && g_pika_conf->write_binlog()) { std::shared_ptr conn_ptr = GetConn(); std::shared_ptr resp_ptr = GetResp(); @@ -658,7 +661,7 @@ void Cmd::ProcessMultiPartitionCmd() { for (auto& key : cur_key) { // in sharding mode we select partition by key uint32_t partition_id = g_pika_cmd_table_manager->DistributeKey(key, table->PartitionNum()); - std::unordered_map::iterator iter = process_map.find(partition_id); + auto iter = process_map.find(partition_id); if (iter == process_map.end()) { std::shared_ptr partition = table->GetPartitionById(partition_id); if (!partition) { @@ -728,10 +731,7 @@ std::string Cmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_i } bool Cmd::CheckArg(int num) const { - if ((arity_ > 0 && num != arity_) || (arity_ < 0 && num < -arity_)) { - return false; - } - return true; + return !((arity_ > 0 && num != arity_) || (arity_ < 0 && num < -arity_)); } void Cmd::LogCommand() const { @@ -743,11 +743,11 @@ void Cmd::LogCommand() const { LOG(INFO) << "command:" << command; } -void Cmd::SetConn(const std::shared_ptr conn) { conn_ = conn; } +void Cmd::SetConn(const std::shared_ptr& conn) { conn_ = conn; } std::shared_ptr Cmd::GetConn() { return conn_.lock(); } -void Cmd::SetResp(const std::shared_ptr resp) { resp_ = resp; } +void Cmd::SetResp(const std::shared_ptr &resp) { resp_ = resp; } std::shared_ptr Cmd::GetResp() { return resp_.lock(); } diff --git a/src/pika_conf.cc b/src/pika_conf.cc index d4719a0e96..2ab5d65c33 100644 --- a/src/pika_conf.cc +++ b/src/pika_conf.cc @@ -14,10 +14,11 @@ #include "include/pika_define.h" +using pstd::Status; + PikaConf::PikaConf(const std::string& path) : pstd::BaseConf(path), conf_path_(path), local_meta_(std::make_unique()) {} - Status PikaConf::InternalGetTargetTable(const std::string& table_name, uint32_t* const target) { int32_t table_index = -1; for (size_t idx = 0; idx < table_structs_.size(); ++idx) { @@ -134,7 +135,7 @@ Status PikaConf::DelTableSanityCheck(const std::string& table_name) { int PikaConf::Load() { int ret = LoadConf(); - if (ret != 0) { + if (ret) { return ret; } @@ -162,7 +163,7 @@ int PikaConf::Load() { std::string swe; GetConfStr("slowlog-write-errorlog", &swe); - slowlog_write_errorlog_.store(swe == "yes" ? true : false); + slowlog_write_errorlog_.store(swe == "yes"); int tmp_slowlog_log_slower_than; GetConfInt("slowlog-log-slower-than", &tmp_slowlog_log_slower_than); @@ -278,13 +279,14 @@ int PikaConf::Load() { compact_cron_ = ""; GetConfStr("compact-cron", &compact_cron_); - if (compact_cron_ != "") { + if (!compact_cron_.empty()) { bool have_week = false; - std::string compact_cron, week_str; + std::string compact_cron; + std::string week_str; int slash_num = count(compact_cron_.begin(), compact_cron_.end(), '/'); if (slash_num == 2) { have_week = true; - std::string::size_type first_slash = compact_cron_.find("/"); + std::string::size_type first_slash = compact_cron_.find('/'); week_str = compact_cron_.substr(0, first_slash); compact_cron = compact_cron_.substr(first_slash + 1); } else { @@ -292,8 +294,8 @@ int PikaConf::Load() { } std::string::size_type len = compact_cron.length(); - std::string::size_type colon = compact_cron.find("-"); - std::string::size_type underline = compact_cron.find("/"); + std::string::size_type colon = compact_cron.find('-'); + std::string::size_type underline = compact_cron.find('/'); if (colon == std::string::npos || underline == std::string::npos || colon >= underline || colon + 1 >= len || colon + 1 == underline || underline + 1 >= len) { compact_cron_ = ""; @@ -311,9 +313,9 @@ int PikaConf::Load() { compact_interval_ = ""; GetConfStr("compact-interval", &compact_interval_); - if (compact_interval_ != "") { + if (!compact_interval_.empty()) { std::string::size_type len = compact_interval_.length(); - std::string::size_type slash = compact_interval_.find("/"); + std::string::size_type slash = compact_interval_.find('/'); if (slash == std::string::npos || slash + 1 >= len) { compact_interval_ = ""; } else { @@ -363,7 +365,7 @@ int PikaConf::Load() { std::string at; GetConfStr("rate-limiter-auto-tuned", &at); - rate_limiter_auto_tuned_ = (at == "yes" || at.empty()) ? true : false; + rate_limiter_auto_tuned_ = at == "yes" || at.empty(); // max_write_buffer_num max_write_buffer_num_ = 2; @@ -442,33 +444,33 @@ int PikaConf::Load() { std::string sbc; GetConfStr("share-block-cache", &sbc); - share_block_cache_ = (sbc == "yes") ? true : false; + share_block_cache_ = sbc == "yes"; std::string ciafb; GetConfStr("cache-index-and-filter-blocks", &ciafb); - cache_index_and_filter_blocks_ = (ciafb == "yes") ? true : false; + cache_index_and_filter_blocks_ = ciafb == "yes"; std::string plfaibic; GetConfStr("pin_l0_filter_and_index_blocks_in_cache", &plfaibic); - pin_l0_filter_and_index_blocks_in_cache_ = (plfaibic == "yes") ? true : false; + pin_l0_filter_and_index_blocks_in_cache_ = plfaibic == "yes"; std::string offh; GetConfStr("optimize-filters-for-hits", &offh); - optimize_filters_for_hits_ = (offh == "yes") ? true : false; + optimize_filters_for_hits_ = offh == "yes"; std::string lcdlb; GetConfStr("level-compaction-dynamic-level-bytes", &lcdlb); - level_compaction_dynamic_level_bytes_ = (lcdlb == "yes") ? true : false; + level_compaction_dynamic_level_bytes_ = lcdlb == "yes"; // daemonize std::string dmz; GetConfStr("daemonize", &dmz); - daemonize_ = (dmz == "yes") ? true : false; + daemonize_ = dmz == "yes"; // binlog std::string wb; GetConfStr("write-binlog", &wb); - write_binlog_ = (wb == "no") ? false : true; + write_binlog_ = wb != "no"; GetConfIntHuman("binlog-file-size", &binlog_file_size_); if (binlog_file_size_ < 1024 || static_cast(binlog_file_size_) > (1024LL * 1024 * 1024)) { binlog_file_size_ = 100 * 1024 * 1024; // 100M @@ -601,7 +603,7 @@ int PikaConf::ConfigRewrite() { } diff_commands_.clear(); } - return WriteBack(); + return static_cast(WriteBack()); } rocksdb::CompressionType PikaConf::GetCompression(const std::string& value) { diff --git a/src/pika_consensus.cc b/src/pika_consensus.cc index f4c57150bf..87e7e678fa 100644 --- a/src/pika_consensus.cc +++ b/src/pika_consensus.cc @@ -3,6 +3,8 @@ // 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/pika_consensus.h" #include "include/pika_client_conn.h" @@ -11,6 +13,8 @@ #include "include/pika_rm.h" #include "include/pika_server.h" +using pstd::Status; + extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_conf; extern std::unique_ptr g_pika_rm; @@ -18,7 +22,7 @@ extern std::unique_ptr g_pika_cmd_table_manager; /* Context */ -Context::Context(const std::string path) : applied_index_(), path_(path), save_(nullptr) {} +Context::Context(std::string path) : path_(std::move(path)) {} Status Context::StableSave() { char* p = save_->GetData(); @@ -47,11 +51,11 @@ Status Context::Init() { LOG(FATAL) << "Context new file failed " << s.ToString(); } } - if (save_->GetData() != nullptr) { - memcpy((char*)(&(applied_index_.b_offset.filenum)), save_->GetData(), sizeof(uint32_t)); - memcpy((char*)(&(applied_index_.b_offset.offset)), save_->GetData() + 4, sizeof(uint64_t)); - memcpy((char*)(&(applied_index_.l_offset.term)), save_->GetData() + 12, sizeof(uint32_t)); - memcpy((char*)(&(applied_index_.l_offset.index)), save_->GetData() + 16, sizeof(uint64_t)); + if (save_->GetData()) { + memcpy(reinterpret_cast(&(applied_index_.b_offset.filenum)), save_->GetData(), sizeof(uint32_t)); + memcpy(reinterpret_cast(&(applied_index_.b_offset.offset)), save_->GetData() + 4, sizeof(uint64_t)); + memcpy(reinterpret_cast(&(applied_index_.l_offset.term)), save_->GetData() + 12, sizeof(uint32_t)); + memcpy(reinterpret_cast(&(applied_index_.l_offset.index)), save_->GetData() + 16, sizeof(uint64_t)); return Status::OK(); } else { return Status::Corruption("Context init error"); @@ -164,16 +168,17 @@ int SyncProgress::SlaveSize() { return slaves_.size(); } -LogOffset SyncProgress::InternalCalCommittedIndex(std::unordered_map match_index) { +LogOffset SyncProgress::InternalCalCommittedIndex(const std::unordered_map& match_index) { int consensus_level = g_pika_conf->consensus_level(); if (consensus_level == 0) { - return LogOffset(); + return {}; } if (static_cast(match_index.size()) < consensus_level) { - return LogOffset(); + return {}; } std::vector offsets; - for (const auto& index : match_index) { + offsets.reserve(match_index.size()); +for (const auto& index : match_index) { offsets.push_back(index.second); } std::sort(offsets.begin(), offsets.end()); @@ -183,7 +188,7 @@ LogOffset SyncProgress::InternalCalCommittedIndex(std::unordered_map(logs_.size()); } @@ -276,7 +281,7 @@ ConsensusCoordinator::ConsensusCoordinator(const std::string& table_name, uint32 } } -ConsensusCoordinator::~ConsensusCoordinator() {} +ConsensusCoordinator::~ConsensusCoordinator() = default; // since it is invoked in constructor all locks not hold void ConsensusCoordinator::Init() { @@ -301,11 +306,11 @@ void ConsensusCoordinator::Init() { PikaBinlogReader binlog_reader; int res = binlog_reader.Seek(stable_logger_->Logger(), committed_index_.b_offset.filenum, committed_index_.b_offset.offset); - if (res) { + if (res != 0) { LOG(FATAL) << PartitionInfo(table_name_, partition_id_).ToString() << "Binlog reader init failed"; } - while (1) { + while (true) { LogOffset offset; std::string binlog; Status s = binlog_reader.Get(&binlog, &(offset.b_offset.filenum), &(offset.b_offset.offset)); @@ -330,7 +335,7 @@ void ConsensusCoordinator::Init() { LOG(FATAL) << PartitionInfo(table_name_, partition_id_).ToString() << "Redis parser parse failed"; return; } - CmdPtrArg* arg = static_cast(redis_parser.data); + auto arg = static_cast(redis_parser.data); std::shared_ptr cmd_ptr = arg->cmd_ptr; delete arg; redis_parser.data = nullptr; @@ -363,14 +368,16 @@ Status ConsensusCoordinator::Reset(const LogOffset& offset) { return Status::OK(); } -Status ConsensusCoordinator::ProposeLog(std::shared_ptr cmd_ptr, std::shared_ptr conn_ptr, +Status ConsensusCoordinator::ProposeLog(const std::shared_ptr& cmd_ptr, std::shared_ptr conn_ptr, std::shared_ptr resp_ptr) { LogOffset log_offset; stable_logger_->Logger()->Lock(); // build BinlogItem - uint32_t filenum = 0, term = 0; - uint64_t offset = 0, logic_id = 0; + uint32_t filenum = 0; + uint32_t term = 0; + uint64_t offset = 0; + uint64_t logic_id = 0; Status s = stable_logger_->Logger()->GetProducerStatus(&filenum, &offset, &term, &logic_id); if (!s.ok()) { stable_logger_->Logger()->Unlock(); @@ -383,7 +390,7 @@ Status ConsensusCoordinator::ProposeLog(std::shared_ptr cmd_ptr, std::share item.set_filenum(filenum); item.set_offset(offset); // make sure stable log and mem log consistent - s = InternalAppendLog(item, cmd_ptr, conn_ptr, resp_ptr); + s = InternalAppendLog(item, cmd_ptr, std::move(conn_ptr), std::move(resp_ptr)); if (!s.ok()) { stable_logger_->Logger()->Unlock(); return s; @@ -394,7 +401,7 @@ Status ConsensusCoordinator::ProposeLog(std::shared_ptr cmd_ptr, std::share return Status::OK(); } -Status ConsensusCoordinator::InternalAppendLog(const BinlogItem& item, std::shared_ptr cmd_ptr, +Status ConsensusCoordinator::InternalAppendLog(const BinlogItem& item, const std::shared_ptr& cmd_ptr, std::shared_ptr conn_ptr, std::shared_ptr resp_ptr) { LogOffset log_offset; @@ -405,12 +412,12 @@ Status ConsensusCoordinator::InternalAppendLog(const BinlogItem& item, std::shar if (g_pika_conf->consensus_level() == 0) { return Status::OK(); } - mem_logger_->AppendLog(MemLog::LogItem(log_offset, cmd_ptr, conn_ptr, resp_ptr)); + mem_logger_->AppendLog(MemLog::LogItem(log_offset, cmd_ptr, std::move(conn_ptr), std::move(resp_ptr))); return Status::OK(); } // precheck if prev_offset match && drop this log if this log exist -Status ConsensusCoordinator::ProcessLeaderLog(std::shared_ptr cmd_ptr, const BinlogItem& attribute) { +Status ConsensusCoordinator::ProcessLeaderLog(const std::shared_ptr& cmd_ptr, const BinlogItem& attribute) { LogOffset last_index = mem_logger_->last_offset(); if (attribute.logic_id() < last_index.l_offset.index) { LOG(WARNING) << PartitionInfo(table_name_, partition_id_).ToString() << "Drop log from leader logic_id " @@ -467,7 +474,7 @@ Status ConsensusCoordinator::UpdateSlave(const std::string& ip, int port, const // do not commit log which is not current term log if (committed_index.l_offset.term != term()) { - LOG_EVERY_N(INFO, 1000) << "Will not commit log term which is not equals to current term" + LOG_EVERY_N(INFO, 1000) << "Will not commit log term which is not equals to current term" // NOLINT << " To updated committed_index" << committed_index.ToString() << " current term " << term() << " from " << ip << " " << port << " start " << start.ToString() << " end " << end.ToString(); @@ -503,7 +510,7 @@ bool ConsensusCoordinator::InternalUpdateCommittedIndex(const LogOffset& slave_c return true; } -Status ConsensusCoordinator::InternalAppendBinlog(const BinlogItem& item, std::shared_ptr cmd_ptr, +Status ConsensusCoordinator::InternalAppendBinlog(const BinlogItem& item, const std::shared_ptr& cmd_ptr, LogOffset* log_offset) { std::string binlog = cmd_ptr->ToBinlog(item.exec_time(), item.term_id(), item.logic_id(), item.filenum(), item.offset()); @@ -594,7 +601,7 @@ bool ConsensusCoordinator::MatchConsensusLevel() { } void ConsensusCoordinator::InternalApply(const MemLog::LogItem& log) { - PikaClientConn::BgTaskArg* arg = new PikaClientConn::BgTaskArg(); + auto arg = new PikaClientConn::BgTaskArg(); arg->cmd_ptr = log.cmd_ptr; arg->conn_ptr = log.conn_ptr; arg->resp_ptr = log.resp_ptr; @@ -609,7 +616,7 @@ void ConsensusCoordinator::InternalApplyFollower(const MemLog::LogItem& log) { } int ConsensusCoordinator::InitCmd(net::RedisParser* parser, const net::RedisCmdArgsType& argv) { - std::string* table_name = static_cast(parser->data); + auto table_name = static_cast(parser->data); std::string opt = argv[0]; std::shared_ptr c_ptr = g_pika_cmd_table_manager->GetCmd(pstd::StringToLower(opt)); if (!c_ptr) { @@ -658,7 +665,7 @@ Status ConsensusCoordinator::TruncateTo(const LogOffset& offset) { Status ConsensusCoordinator::GetBinlogOffset(const BinlogOffset& start_offset, LogOffset* log_offset) { PikaBinlogReader binlog_reader; int res = binlog_reader.Seek(stable_logger_->Logger(), start_offset.filenum, start_offset.offset); - if (res) { + if (res != 0) { return Status::Corruption("Binlog reader init failed"); } std::string binlog; @@ -685,10 +692,10 @@ Status ConsensusCoordinator::GetBinlogOffset(const BinlogOffset& start_offset, c std::vector* log_offset) { PikaBinlogReader binlog_reader; int res = binlog_reader.Seek(stable_logger_->Logger(), start_offset.filenum, start_offset.offset); - if (res) { + if (res != 0) { return Status::Corruption("Binlog reader init failed"); } - while (1) { + while (true) { BinlogOffset b_offset; std::string binlog; Status s = binlog_reader.Get(&binlog, &(b_offset.filenum), &(b_offset.offset)); @@ -713,7 +720,7 @@ Status ConsensusCoordinator::GetBinlogOffset(const BinlogOffset& start_offset, c return Status::OK(); } -Status ConsensusCoordinator::FindBinlogFileNum(const std::map binlogs, uint64_t target_index, +Status ConsensusCoordinator::FindBinlogFileNum(const std::map& binlogs, uint64_t target_index, uint32_t start_filenum, uint32_t* founded_filenum) { // low boundary & high boundary uint32_t lb_binlogs = binlogs.begin()->first; @@ -721,7 +728,7 @@ Status ConsensusCoordinator::FindBinlogFileNum(const std::map offsets; @@ -915,7 +923,7 @@ Status ConsensusCoordinator::FollowerNegotiate(const std::vector& hin return Status::Corruption("invalid hints all smaller than committed_index"); } if (mem_logger_->last_offset().l_offset.index > hints[hints.size() - 1].l_offset.index) { - LogOffset truncate_offset = hints[hints.size() - 1]; + const auto &truncate_offset = hints[hints.size() - 1]; // trunck to hints end Status s = TruncateTo(truncate_offset); if (!s.ok()) { diff --git a/src/pika_data_distribution.cc b/src/pika_data_distribution.cc index df43c19e4b..f7259ca8a4 100644 --- a/src/pika_data_distribution.cc +++ b/src/pika_data_distribution.cc @@ -17,11 +17,12 @@ uint32_t HashModulo::Distribute(const std::string& str, uint32_t partition_num) void Crc32::Init() { Crc32TableInit(IEEE_POLY); } void Crc32::Crc32TableInit(uint32_t poly) { - int i, j; + int i; + int j; for (i = 0; i < 256; i++) { uint32_t crc = i; for (j = 0; j < 8; j++) { - if (crc & 1) { + if ((crc & 1) != 0U) { crc = (crc >> 1) ^ poly; } else { crc = (crc >> 1); @@ -33,7 +34,7 @@ void Crc32::Crc32TableInit(uint32_t poly) { uint32_t Crc32::Distribute(const std::string& str, uint32_t partition_num) { std::string key = GetHashkey(str); - uint32_t crc = Crc32Update(0, key.data(), (int)key.size()); + uint32_t crc = Crc32Update(0, key.data(), static_cast(key.size())); assert(partition_num != 0); return crc % partition_num; } @@ -42,7 +43,7 @@ uint32_t Crc32::Crc32Update(uint32_t crc, const char* buf, int len) { int i; crc = ~crc; for (i = 0; i < len; i++) { - crc = crc32tab[(uint8_t)((char)crc ^ buf[i])] ^ (crc >> 8); + crc = crc32tab[static_cast(static_cast(crc) ^ buf[i])] ^ (crc >> 8); } return ~crc; } diff --git a/src/pika_dispatch_thread.cc b/src/pika_dispatch_thread.cc index 2904d18ba7..288d7e0757 100644 --- a/src/pika_dispatch_thread.cc +++ b/src/pika_dispatch_thread.cc @@ -11,7 +11,6 @@ #include "include/pika_server.h" #include "pstd/include/testutil.h" -extern std::unique_ptr g_pika_conf; extern PikaServer* g_pika_server; PikaDispatchThread::PikaDispatchThread(std::set& ips, int port, int work_num, int cron_interval, @@ -31,7 +30,7 @@ int PikaDispatchThread::StartThread() { return thread_rep_->StartThread(); } int64_t PikaDispatchThread::ThreadClientList(std::vector* clients) { std::vector conns_info = thread_rep_->conns_info(); - if (clients != nullptr) { + if (clients) { for (auto& info : conns_info) { clients->push_back({ info.fd, info.ip_port, info.last_interaction.tv_sec, nullptr /* NetConn pointer, doesn't need here */ diff --git a/src/pika_geo.cc b/src/pika_geo.cc index 94537f4bea..2cb3c0ff91 100644 --- a/src/pika_geo.cc +++ b/src/pika_geo.cc @@ -24,13 +24,14 @@ void GeoAddCmd::DoInitial() { key_ = argv_[1]; pos_.clear(); struct GeoPoint point; - double longitude, latitude; + double longitude; + double latitude; for (size_t index = 2; index < argc; index += 3) { - if (!pstd::string2d(argv_[index].data(), argv_[index].size(), &longitude)) { + if (pstd::string2d(argv_[index].data(), argv_[index].size(), &longitude) == 0) { res_.SetRes(CmdRes::kInvalidFloat); return; } - if (!pstd::string2d(argv_[index + 1].data(), argv_[index + 1].size(), &latitude)) { + if (pstd::string2d(argv_[index + 1].data(), argv_[index + 1].size(), &latitude) == 0) { res_.SetRes(CmdRes::kInvalidFloat); return; } @@ -39,7 +40,6 @@ void GeoAddCmd::DoInitial() { point.latitude = latitude; pos_.push_back(point); } - return; } void GeoAddCmd::Do(std::shared_ptr partition) { @@ -62,8 +62,7 @@ void GeoAddCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; -} + } void GeoPosCmd::DoInitial() { if (!CheckArg(argv_.size())) { @@ -85,7 +84,7 @@ void GeoPosCmd::Do(std::shared_ptr partition) { rocksdb::Status s = partition->db()->ZScore(key_, member, &score); if (s.ok()) { double xy[2]; - GeoHashBits hash = {.bits = (uint64_t)score, .step = GEO_STEP_MAX}; + GeoHashBits hash = {.bits = static_cast(score), .step = GEO_STEP_MAX}; geohashDecodeToLongLatWGS84(hash, xy); res_.AppendArrayLen(2); @@ -124,11 +123,7 @@ static double length_converter(double meters, const std::string& unit) { } static bool check_unit(const std::string& unit) { - if (unit == "m" || unit == "km" || unit == "ft" || unit == "mi") { - return true; - } else { - return false; - } + return unit == "m" || unit == "km" || unit == "ft" || unit == "mi"; } void GeoDistCmd::DoInitial() { @@ -158,10 +153,13 @@ void GeoDistCmd::DoInitial() { } void GeoDistCmd::Do(std::shared_ptr partition) { - double first_score, second_score, first_xy[2], second_xy[2]; + double first_score; + double second_score; + double first_xy[2]; + double second_xy[2]; rocksdb::Status s = partition->db()->ZScore(key_, first_pos_, &first_score); if (s.ok()) { - GeoHashBits hash = {.bits = (uint64_t)first_score, .step = GEO_STEP_MAX}; + GeoHashBits hash = {.bits = static_cast(first_score), .step = GEO_STEP_MAX}; geohashDecodeToLongLatWGS84(hash, first_xy); } else if (s.IsNotFound()) { res_.AppendStringLen(-1); @@ -173,7 +171,7 @@ void GeoDistCmd::Do(std::shared_ptr partition) { s = partition->db()->ZScore(key_, second_pos_, &second_score); if (s.ok()) { - GeoHashBits hash = {.bits = (uint64_t)second_score, .step = GEO_STEP_MAX}; + GeoHashBits hash = {.bits = static_cast(second_score), .step = GEO_STEP_MAX}; geohashDecodeToLongLatWGS84(hash, second_xy); } else if (s.IsNotFound()) { res_.AppendStringLen(-1); @@ -212,7 +210,7 @@ void GeoHashCmd::Do(std::shared_ptr partition) { rocksdb::Status s = partition->db()->ZScore(key_, member, &score); if (s.ok()) { double xy[2]; - GeoHashBits hash = {.bits = (uint64_t)score, .step = GEO_STEP_MAX}; + GeoHashBits hash = {.bits = static_cast(score), .step = GEO_STEP_MAX}; geohashDecodeToLongLatWGS84(hash, xy); GeoHashRange r[2]; GeoHashBits encode_hash; @@ -250,9 +248,11 @@ static bool sort_distance_desc(const NeighborPoint& pos1, const NeighborPoint& p return pos1.distance > pos2.distance; } -static void GetAllNeighbors(std::shared_ptr partition, std::string& key, GeoRange& range, CmdRes& res) { +static void GetAllNeighbors(const std::shared_ptr& partition, std::string& key, GeoRange& range, CmdRes& res) { rocksdb::Status s; - double longitude = range.longitude, latitude = range.latitude, distance = range.distance; + double longitude = range.longitude; + double latitude = range.latitude; + double distance = range.distance; int count_limit = 0; // Convert other units to meters if (range.unit == "m") { @@ -284,32 +284,36 @@ static void GetAllNeighbors(std::shared_ptr partition, std::string& k std::vector result; int last_processed = 0; for (size_t i = 0; i < sizeof(neighbors) / sizeof(*neighbors); i++) { - GeoHashFix52Bits min, max; - if (HASHISZERO(neighbors[i])) continue; + GeoHashFix52Bits min; + GeoHashFix52Bits max; + if (HASHISZERO(neighbors[i])) { + continue; + } min = geohashAlign52Bits(neighbors[i]); neighbors[i].bits++; max = geohashAlign52Bits(neighbors[i]); // When a huge Radius (in the 5000 km range or more) is used, // adjacent neighbors can be the same, so need to remove duplicated elements - if (last_processed && neighbors[i].bits == neighbors[last_processed].bits && + if ((last_processed != 0) && neighbors[i].bits == neighbors[last_processed].bits && neighbors[i].step == neighbors[last_processed].step) { continue; } std::vector score_members; - s = partition->db()->ZRangebyscore(key, (double)min, (double)max, true, true, &score_members); + s = partition->db()->ZRangebyscore(key, static_cast(min), static_cast(max), true, true, &score_members); if (!s.ok() && !s.IsNotFound()) { res.SetRes(CmdRes::kErrOther, s.ToString()); return; } // Insert into result only if the point is within the search area. - for (size_t i = 0; i < score_members.size(); ++i) { - double xy[2], real_distance; - GeoHashBits hash = {.bits = (uint64_t)score_members[i].score, .step = GEO_STEP_MAX}; + for (auto & score_member : score_members) { + double xy[2]; + double real_distance; + GeoHashBits hash = {.bits = static_cast(score_member.score), .step = GEO_STEP_MAX}; geohashDecodeToLongLatWGS84(hash, xy); - if (geohashGetDistanceIfInRadiusWGS84(longitude, latitude, xy[0], xy[1], distance, &real_distance)) { + if (geohashGetDistanceIfInRadiusWGS84(longitude, latitude, xy[0], xy[1], distance, &real_distance) != 0) { NeighborPoint item; - item.member = score_members[i].member; - item.score = score_members[i].score; + item.member = score_member.member; + item.score = score_member.score; item.distance = real_distance; result.push_back(item); } @@ -362,7 +366,7 @@ static void GetAllNeighbors(std::shared_ptr partition, std::string& k // If using withdist option if (range.withdist) { double xy[2]; - GeoHashBits hash = {.bits = (uint64_t)result[i].score, .step = GEO_STEP_MAX}; + GeoHashBits hash = {.bits = static_cast(result[i].score), .step = GEO_STEP_MAX}; geohashDecodeToLongLatWGS84(hash, xy); double distance = geohashGetDistance(longitude, latitude, xy[0], xy[1]); distance = length_converter(distance, range.unit); @@ -379,7 +383,7 @@ static void GetAllNeighbors(std::shared_ptr partition, std::string& k if (range.withcoord) { res.AppendArrayLen(2); double xy[2]; - GeoHashBits hash = {.bits = (uint64_t)result[i].score, .step = GEO_STEP_MAX}; + GeoHashBits hash = {.bits = static_cast(result[i].score), .step = GEO_STEP_MAX}; geohashDecodeToLongLatWGS84(hash, xy); char longitude[32]; @@ -412,16 +416,16 @@ void GeoRadiusCmd::DoInitial() { } size_t pos = 6; while (pos < argv_.size()) { - if (!strcasecmp(argv_[pos].c_str(), "withdist")) { + if (strcasecmp(argv_[pos].c_str(), "withdist") == 0) { range_.withdist = true; range_.option_num++; - } else if (!strcasecmp(argv_[pos].c_str(), "withhash")) { + } else if (strcasecmp(argv_[pos].c_str(), "withhash") == 0) { range_.withhash = true; range_.option_num++; - } else if (!strcasecmp(argv_[pos].c_str(), "withcoord")) { + } else if (strcasecmp(argv_[pos].c_str(), "withcoord") == 0) { range_.withcoord = true; range_.option_num++; - } else if (!strcasecmp(argv_[pos].c_str(), "count")) { + } else if (strcasecmp(argv_[pos].c_str(), "count") == 0) { range_.count = true; if (argv_.size() < (pos + 2)) { res_.SetRes(CmdRes::kSyntaxErr); @@ -429,29 +433,29 @@ void GeoRadiusCmd::DoInitial() { } std::string str_count = argv_[++pos]; for (auto s : str_count) { - if (!isdigit(s)) { + if (isdigit(s) == 0) { res_.SetRes(CmdRes::kErrOther, "value is not an integer or out of range"); return; } } range_.count_limit = std::stoi(str_count); - } else if (!strcasecmp(argv_[pos].c_str(), "store")) { + } else if (strcasecmp(argv_[pos].c_str(), "store") == 0) { range_.store = true; if (argv_.size() < (pos + 2)) { res_.SetRes(CmdRes::kSyntaxErr); return; } range_.storekey = argv_[++pos]; - } else if (!strcasecmp(argv_[pos].c_str(), "storedist")) { + } else if (strcasecmp(argv_[pos].c_str(), "storedist") == 0) { range_.storedist = true; if (argv_.size() < (pos + 2)) { res_.SetRes(CmdRes::kSyntaxErr); return; } range_.storekey = argv_[++pos]; - } else if (!strcasecmp(argv_[pos].c_str(), "asc")) { + } else if (strcasecmp(argv_[pos].c_str(), "asc") == 0) { range_.sort = Asc; - } else if (!strcasecmp(argv_[pos].c_str(), "desc")) { + } else if (strcasecmp(argv_[pos].c_str(), "desc") == 0) { range_.sort = Desc; } else { res_.SetRes(CmdRes::kSyntaxErr); @@ -483,16 +487,16 @@ void GeoRadiusByMemberCmd::DoInitial() { } size_t pos = 5; while (pos < argv_.size()) { - if (!strcasecmp(argv_[pos].c_str(), "withdist")) { + if (strcasecmp(argv_[pos].c_str(), "withdist") == 0) { range_.withdist = true; range_.option_num++; - } else if (!strcasecmp(argv_[pos].c_str(), "withhash")) { + } else if (strcasecmp(argv_[pos].c_str(), "withhash") == 0) { range_.withhash = true; range_.option_num++; - } else if (!strcasecmp(argv_[pos].c_str(), "withcoord")) { + } else if (strcasecmp(argv_[pos].c_str(), "withcoord") == 0) { range_.withcoord = true; range_.option_num++; - } else if (!strcasecmp(argv_[pos].c_str(), "count")) { + } else if (strcasecmp(argv_[pos].c_str(), "count") == 0) { range_.count = true; if (argv_.size() < (pos + 2)) { res_.SetRes(CmdRes::kSyntaxErr); @@ -500,29 +504,29 @@ void GeoRadiusByMemberCmd::DoInitial() { } std::string str_count = argv_[++pos]; for (auto s : str_count) { - if (!isdigit(s)) { + if (isdigit(s) == 0) { res_.SetRes(CmdRes::kErrOther, "value is not an integer or out of range"); return; } } range_.count_limit = std::stoi(str_count); - } else if (!strcasecmp(argv_[pos].c_str(), "store")) { + } else if (strcasecmp(argv_[pos].c_str(), "store") == 0) { range_.store = true; if (argv_.size() < (pos + 2)) { res_.SetRes(CmdRes::kSyntaxErr); return; } range_.storekey = argv_[++pos]; - } else if (!strcasecmp(argv_[pos].c_str(), "storedist")) { + } else if (strcasecmp(argv_[pos].c_str(), "storedist") == 0) { range_.storedist = true; if (argv_.size() < (pos + 2)) { res_.SetRes(CmdRes::kSyntaxErr); return; } range_.storekey = argv_[++pos]; - } else if (!strcasecmp(argv_[pos].c_str(), "asc")) { + } else if (strcasecmp(argv_[pos].c_str(), "asc") == 0) { range_.sort = Asc; - } else if (!strcasecmp(argv_[pos].c_str(), "desc")) { + } else if (strcasecmp(argv_[pos].c_str(), "desc") == 0) { range_.sort = Desc; } else { res_.SetRes(CmdRes::kSyntaxErr); @@ -542,7 +546,7 @@ void GeoRadiusByMemberCmd::Do(std::shared_ptr partition) { rocksdb::Status s = partition->db()->ZScore(key_, range_.member, &score); if (s.ok()) { double xy[2]; - GeoHashBits hash = {.bits = (uint64_t)score, .step = GEO_STEP_MAX}; + GeoHashBits hash = {.bits = static_cast(score), .step = GEO_STEP_MAX}; geohashDecodeToLongLatWGS84(hash, xy); range_.longitude = xy[0]; range_.latitude = xy[1]; diff --git a/src/pika_geohash.cc b/src/pika_geohash.cc index 1187651309..1874acf36a 100644 --- a/src/pika_geohash.cc +++ b/src/pika_geohash.cc @@ -119,11 +119,15 @@ void geohashGetCoordRange(GeoHashRange* long_range, GeoHashRange* lat_range) { int geohashEncode(const GeoHashRange* long_range, const GeoHashRange* lat_range, double longitude, double latitude, uint8_t step, GeoHashBits* hash) { /* Check basic arguments sanity. */ - if (hash == nullptr || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0; + if (!hash || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) { + return 0; + } /* Return an error when trying to index outside the supported * constraints. */ - if (longitude > 180 || longitude < -180 || latitude > 85.05112878 || latitude < -85.05112878) return 0; + if (longitude > 180 || longitude < -180 || latitude > 85.05112878 || latitude < -85.05112878) { + return 0; + } hash->bits = 0; hash->step = step; @@ -172,10 +176,10 @@ int geohashDecode(const GeoHashRange long_range, const GeoHashRange lat_range, c /* divide by 2**step. * Then, for 0-1 coordinate, multiply times scale and add to the min to get the absolute coordinate. */ - area->latitude.min = lat_range.min + (ilato * 1.0 / (1ull << step)) * lat_scale; - area->latitude.max = lat_range.min + ((ilato + 1) * 1.0 / (1ull << step)) * lat_scale; - area->longitude.min = long_range.min + (ilono * 1.0 / (1ull << step)) * long_scale; - area->longitude.max = long_range.min + ((ilono + 1) * 1.0 / (1ull << step)) * long_scale; + area->latitude.min = lat_range.min + (ilato * 1.0 / (1ULL << step)) * lat_scale; + area->latitude.max = lat_range.min + ((ilato + 1) * 1.0 / (1ULL << step)) * lat_scale; + area->longitude.min = long_range.min + (ilono * 1.0 / (1ULL << step)) * long_scale; + area->longitude.max = long_range.min + ((ilono + 1) * 1.0 / (1ULL << step)) * long_scale; return 1; } @@ -189,7 +193,9 @@ int geohashDecodeType(const GeoHashBits hash, GeoHashArea* area) { int geohashDecodeWGS84(const GeoHashBits hash, GeoHashArea* area) { return geohashDecodeType(hash, area); } int geohashDecodeAreaToLongLat(const GeoHashArea* area, double* xy) { - if (!xy) return 0; + if (!xy) { + return 0; + } xy[0] = (area->longitude.min + area->longitude.max) / 2; xy[1] = (area->latitude.min + area->latitude.max) / 2; return 1; @@ -197,14 +203,18 @@ int geohashDecodeAreaToLongLat(const GeoHashArea* area, double* xy) { int geohashDecodeToLongLatType(const GeoHashBits hash, double* xy) { GeoHashArea area = {{0}}; - if (!xy || !geohashDecodeType(hash, &area)) return 0; + if (!xy || !(geohashDecodeType(hash, &area))) { + return 0; + } return geohashDecodeAreaToLongLat(&area, xy); } int geohashDecodeToLongLatWGS84(const GeoHashBits hash, double* xy) { return geohashDecodeToLongLatType(hash, xy); } static void geohash_move_x(GeoHashBits* hash, int8_t d) { - if (d == 0) return; + if (d == 0) { + return; + } uint64_t x = hash->bits & 0xaaaaaaaaaaaaaaaaULL; uint64_t y = hash->bits & 0x5555555555555555ULL; @@ -223,7 +233,9 @@ static void geohash_move_x(GeoHashBits* hash, int8_t d) { } static void geohash_move_y(GeoHashBits* hash, int8_t d) { - if (d == 0) return; + if (d == 0) { + return; + } uint64_t x = hash->bits & 0xaaaaaaaaaaaaaaaaULL; uint64_t y = hash->bits & 0x5555555555555555ULL; diff --git a/src/pika_geohash_helper.cc b/src/pika_geohash_helper.cc index 134cec7976..e2f58725b9 100644 --- a/src/pika_geohash_helper.cc +++ b/src/pika_geohash_helper.cc @@ -37,7 +37,7 @@ // #include "fmacros.h" #include "include/pika_geohash_helper.h" // #include "debugmacro.h" -#include +#include #define D_R (M_PI / 180.0) #define R_MAJOR 6378137.0 @@ -60,7 +60,9 @@ static inline double rad_deg(double ang) { return ang / D_R; } /* This function is used in order to estimate the step (bits precision) * of the 9 search area boxes during radius queries. */ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) { - if (range_meters == 0) return 26; + if (range_meters == 0) { + return 26; + } int step = 1; while (range_meters < MERCATOR_MAX) { range_meters *= 2; @@ -73,12 +75,18 @@ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) { * at this latitude, but this does the trick for now. */ if (lat > 66 || lat < -66) { step--; - if (lat > 80 || lat < -80) step--; + if (lat > 80 || lat < -80) { + step--; + } } /* Frame to valid range. */ - if (step < 1) step = 1; - if (step > 26) step = 26; + if (step < 1) { + step = 1; + } + if (step > 26) { + step = 26; + } return step; } @@ -101,7 +109,9 @@ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) { * optimization is not used for very big radiuses, however the function * should be fixed. */ int geohashBoundingBox(double longitude, double latitude, double radius_meters, double* bounds) { - if (!bounds) return 0; + if (!bounds) { + return 0; + } bounds[0] = longitude - rad_deg(radius_meters / EARTH_RADIUS_IN_METERS / cos(deg_rad(latitude))); bounds[2] = longitude + rad_deg(radius_meters / EARTH_RADIUS_IN_METERS / cos(deg_rad(latitude))); @@ -113,12 +123,16 @@ int geohashBoundingBox(double longitude, double latitude, double radius_meters, /* Return a set of areas (center + 8) that are able to cover a range query * for the specified position and radius. */ GeoHashRadius geohashGetAreasByRadius(double longitude, double latitude, double radius_meters) { - GeoHashRange long_range, lat_range; + GeoHashRange long_range; + GeoHashRange lat_range; GeoHashRadius radius; GeoHashBits hash; GeoHashNeighbors neighbors; GeoHashArea area; - double min_lon, max_lon, min_lat, max_lat; + double min_lon; + double max_lon; + double min_lat; + double max_lat; double bounds[4]; int steps; @@ -142,20 +156,31 @@ GeoHashRadius geohashGetAreasByRadius(double longitude, double latitude, double * to cover everything. */ int decrease_step = 0; { - GeoHashArea north, south, east, west; + GeoHashArea north; + GeoHashArea south; + GeoHashArea east; + GeoHashArea west; geohashDecode(long_range, lat_range, neighbors.north, &north); geohashDecode(long_range, lat_range, neighbors.south, &south); geohashDecode(long_range, lat_range, neighbors.east, &east); geohashDecode(long_range, lat_range, neighbors.west, &west); - if (geohashGetDistance(longitude, latitude, longitude, north.latitude.max) < radius_meters) decrease_step = 1; - if (geohashGetDistance(longitude, latitude, longitude, south.latitude.min) < radius_meters) decrease_step = 1; - if (geohashGetDistance(longitude, latitude, east.longitude.max, latitude) < radius_meters) decrease_step = 1; - if (geohashGetDistance(longitude, latitude, west.longitude.min, latitude) < radius_meters) decrease_step = 1; + if (geohashGetDistance(longitude, latitude, longitude, north.latitude.max) < radius_meters) { + decrease_step = 1; + } + if (geohashGetDistance(longitude, latitude, longitude, south.latitude.min) < radius_meters) { + decrease_step = 1; + } + if (geohashGetDistance(longitude, latitude, east.longitude.max, latitude) < radius_meters) { + decrease_step = 1; + } + if (geohashGetDistance(longitude, latitude, west.longitude.min, latitude) < radius_meters) { + decrease_step = 1; + } } - if (steps > 1 && decrease_step) { + if (steps > 1 && (decrease_step != 0)) { steps--; geohashEncode(&long_range, &lat_range, longitude, latitude, steps, &hash); geohashNeighbors(&hash, &neighbors); @@ -195,7 +220,7 @@ GeoHashRadius geohashGetAreasByRadiusWGS84(double longitude, double latitude, do return geohashGetAreasByRadius(longitude, latitude, radius_meters); } -GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits hash) { +GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits& hash) { uint64_t bits = hash.bits; bits <<= (52 - hash.step * 2); return bits; @@ -203,7 +228,12 @@ GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits hash) { /* Calculate distance using haversin great circle distance formula. */ double geohashGetDistance(double lon1d, double lat1d, double lon2d, double lat2d) { - double lat1r, lon1r, lat2r, lon2r, u, v; + double lat1r; + double lon1r; + double lat2r; + double lon2r; + double u; + double v; lat1r = deg_rad(lat1d); lon1r = deg_rad(lon1d); lat2r = deg_rad(lat2d); @@ -215,7 +245,9 @@ double geohashGetDistance(double lon1d, double lat1d, double lon2d, double lat2d int geohashGetDistanceIfInRadius(double x1, double y1, double x2, double y2, double radius, double* distance) { *distance = geohashGetDistance(x1, y1, x2, y2); - if (*distance > radius) return 0; + if (*distance > radius) { + return 0; + } return 1; } diff --git a/src/pika_hash.cc b/src/pika_hash.cc index c101cecd8a..42f9fc74c0 100644 --- a/src/pika_hash.cc +++ b/src/pika_hash.cc @@ -17,11 +17,10 @@ void HDelCmd::DoInitial() { return; } key_ = argv_[1]; - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); iter++; iter++; fields_.assign(iter, argv_.end()); - return; } void HDelCmd::Do(std::shared_ptr partition) { @@ -32,7 +31,6 @@ void HDelCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HSetCmd::DoInitial() { @@ -43,7 +41,6 @@ void HSetCmd::DoInitial() { key_ = argv_[1]; field_ = argv_[2]; value_ = argv_[3]; - return; } void HSetCmd::Do(std::shared_ptr partition) { @@ -54,7 +51,6 @@ void HSetCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HGetCmd::DoInitial() { @@ -64,7 +60,6 @@ void HGetCmd::DoInitial() { } key_ = argv_[1]; field_ = argv_[2]; - return; } void HGetCmd::Do(std::shared_ptr partition) { @@ -86,12 +81,12 @@ void HGetallCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void HGetallCmd::Do(std::shared_ptr partition) { int64_t total_fv = 0; - int64_t cursor = 0, next_cursor = 0; + int64_t cursor = 0; + int64_t next_cursor = 0; size_t raw_limit = g_pika_conf->max_client_response_size(); std::string raw; rocksdb::Status s; @@ -126,7 +121,6 @@ void HGetallCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HExistsCmd::DoInitial() { @@ -136,7 +130,6 @@ void HExistsCmd::DoInitial() { } key_ = argv_[1]; field_ = argv_[2]; - return; } void HExistsCmd::Do(std::shared_ptr partition) { @@ -157,11 +150,10 @@ void HIncrbyCmd::DoInitial() { } key_ = argv_[1]; field_ = argv_[2]; - if (argv_[3].find(" ") != std::string::npos || !pstd::string2int(argv_[3].data(), argv_[3].size(), &by_)) { + if (argv_[3].find(' ') != std::string::npos || (pstd::string2int(argv_[3].data(), argv_[3].size(), &by_) == 0)) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } void HIncrbyCmd::Do(std::shared_ptr partition) { @@ -176,7 +168,6 @@ void HIncrbyCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HIncrbyfloatCmd::DoInitial() { @@ -187,7 +178,6 @@ void HIncrbyfloatCmd::DoInitial() { key_ = argv_[1]; field_ = argv_[2]; by_ = argv_[3]; - return; } void HIncrbyfloatCmd::Do(std::shared_ptr partition) { @@ -203,7 +193,6 @@ void HIncrbyfloatCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HKeysCmd::DoInitial() { @@ -212,7 +201,6 @@ void HKeysCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void HKeysCmd::Do(std::shared_ptr partition) { @@ -226,7 +214,6 @@ void HKeysCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HLenCmd::DoInitial() { @@ -235,7 +222,6 @@ void HLenCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void HLenCmd::Do(std::shared_ptr partition) { @@ -246,7 +232,6 @@ void HLenCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "something wrong in hlen"); } - return; } void HMgetCmd::DoInitial() { @@ -255,11 +240,10 @@ void HMgetCmd::DoInitial() { return; } key_ = argv_[1]; - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); iter++; iter++; fields_.assign(iter, argv_.end()); - return; } void HMgetCmd::Do(std::shared_ptr partition) { @@ -278,7 +262,6 @@ void HMgetCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HMsetCmd::DoInitial() { @@ -297,7 +280,6 @@ void HMsetCmd::DoInitial() { for (; index < argc; index += 2) { fvs_.push_back({argv_[index], argv_[index + 1]}); } - return; } void HMsetCmd::Do(std::shared_ptr partition) { @@ -307,7 +289,6 @@ void HMsetCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HSetnxCmd::DoInitial() { @@ -318,7 +299,6 @@ void HSetnxCmd::DoInitial() { key_ = argv_[1]; field_ = argv_[2]; value_ = argv_[3]; - return; } void HSetnxCmd::Do(std::shared_ptr partition) { @@ -338,7 +318,6 @@ void HStrlenCmd::DoInitial() { } key_ = argv_[1]; field_ = argv_[2]; - return; } void HStrlenCmd::Do(std::shared_ptr partition) { @@ -349,7 +328,6 @@ void HStrlenCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "something wrong in hstrlen"); } - return; } void HValsCmd::DoInitial() { @@ -358,7 +336,6 @@ void HValsCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void HValsCmd::Do(std::shared_ptr partition) { @@ -373,7 +350,6 @@ void HValsCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HScanCmd::DoInitial() { @@ -382,23 +358,24 @@ void HScanCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &cursor_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &cursor_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - size_t index = 3, argc = argv_.size(); + size_t index = 3; + size_t argc = argv_.size(); while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "count")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "count") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &count_)) { + } else if (pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -412,7 +389,6 @@ void HScanCmd::DoInitial() { res_.SetRes(CmdRes::kSyntaxErr); return; } - return; } void HScanCmd::Do(std::shared_ptr partition) { @@ -435,7 +411,6 @@ void HScanCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void HScanxCmd::DoInitial() { @@ -446,18 +421,19 @@ void HScanxCmd::DoInitial() { key_ = argv_[1]; start_field_ = argv_[2]; - size_t index = 3, argc = argv_.size(); + size_t index = 3; + size_t argc = argv_.size(); while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "count")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "count") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &count_)) { + } else if (pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -471,7 +447,6 @@ void HScanxCmd::DoInitial() { res_.SetRes(CmdRes::kSyntaxErr); return; } - return; } void HScanxCmd::Do(std::shared_ptr partition) { @@ -492,7 +467,6 @@ void HScanxCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void PKHScanRangeCmd::DoInitial() { @@ -504,18 +478,19 @@ void PKHScanRangeCmd::DoInitial() { field_start_ = argv_[2]; field_end_ = argv_[3]; - size_t index = 4, argc = argv_.size(); + size_t index = 4; + size_t argc = argv_.size(); while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "limit")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "limit") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &limit_) || limit_ <= 0) { + } else if ((pstd::string2int(argv_[index].data(), argv_[index].size(), &limit_) == 0) || limit_ <= 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -525,7 +500,6 @@ void PKHScanRangeCmd::DoInitial() { } index++; } - return; } void PKHScanRangeCmd::Do(std::shared_ptr partition) { @@ -546,7 +520,6 @@ void PKHScanRangeCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void PKHRScanRangeCmd::DoInitial() { @@ -558,18 +531,19 @@ void PKHRScanRangeCmd::DoInitial() { field_start_ = argv_[2]; field_end_ = argv_[3]; - size_t index = 4, argc = argv_.size(); + size_t index = 4; + size_t argc = argv_.size(); while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "limit")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "limit") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &limit_) || limit_ <= 0) { + } else if ((pstd::string2int(argv_[index].data(), argv_[index].size(), &limit_) == 0) || limit_ <= 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -579,7 +553,6 @@ void PKHRScanRangeCmd::DoInitial() { } index++; } - return; } void PKHRScanRangeCmd::Do(std::shared_ptr partition) { @@ -600,5 +573,4 @@ void PKHRScanRangeCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } diff --git a/src/pika_kv.cc b/src/pika_kv.cc index 3ecb1d434c..111d2077ff 100644 --- a/src/pika_kv.cc +++ b/src/pika_kv.cc @@ -26,11 +26,11 @@ void SetCmd::DoInitial() { size_t index = 3; while (index != argv_.size()) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "xx")) { + if (strcasecmp(opt.data(), "xx") == 0) { condition_ = SetCmd::kXX; - } else if (!strcasecmp(opt.data(), "nx")) { + } else if (strcasecmp(opt.data(), "nx") == 0) { condition_ = SetCmd::kNX; - } else if (!strcasecmp(opt.data(), "vx")) { + } else if (strcasecmp(opt.data(), "vx") == 0) { condition_ = SetCmd::kVX; index++; if (index == argv_.size()) { @@ -39,19 +39,19 @@ void SetCmd::DoInitial() { } else { target_ = argv_[index]; } - } else if (!strcasecmp(opt.data(), "ex") || !strcasecmp(opt.data(), "px")) { + } else if ((strcasecmp(opt.data(), "ex") == 0) || (strcasecmp(opt.data(), "px") == 0)) { condition_ = (condition_ == SetCmd::kNONE) ? SetCmd::kEXORPX : condition_; index++; if (index == argv_.size()) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &sec_)) { + if (pstd::string2int(argv_[index].data(), argv_[index].size(), &sec_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (!strcasecmp(opt.data(), "px")) { + if (strcasecmp(opt.data(), "px") == 0) { sec_ /= 1000; } } else { @@ -60,7 +60,6 @@ void SetCmd::DoInitial() { } index++; } - return; } void SetCmd::Do(std::shared_ptr partition) { @@ -136,7 +135,6 @@ void GetCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void GetCmd::Do(std::shared_ptr partition) { @@ -157,9 +155,8 @@ void DelCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, name()); return; } - std::vector::iterator iter = argv_.begin(); + auto iter = argv_.begin(); keys_.assign(++iter, argv_.end()); - return; } void DelCmd::Do(std::shared_ptr partition) { @@ -170,7 +167,6 @@ void DelCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "delete error"); } - return; } void DelCmd::Split(std::shared_ptr partition, const HintKeys& hint_keys) { @@ -181,12 +177,10 @@ void DelCmd::Split(std::shared_ptr partition, const HintKeys& hint_ke } else { res_.SetRes(CmdRes::kErrOther, "delete error"); } - return; } void DelCmd::Merge() { res_.AppendInteger(split_res_); - return; } void IncrCmd::DoInitial() { @@ -195,7 +189,6 @@ void IncrCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void IncrCmd::Do(std::shared_ptr partition) { @@ -209,7 +202,6 @@ void IncrCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void IncrbyCmd::DoInitial() { @@ -218,11 +210,10 @@ void IncrbyCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &by_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &by_) == 0) { res_.SetRes(CmdRes::kInvalidInt, kCmdNameIncrby); return; } - return; } void IncrbyCmd::Do(std::shared_ptr partition) { @@ -236,7 +227,6 @@ void IncrbyCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void IncrbyfloatCmd::DoInitial() { @@ -246,11 +236,10 @@ void IncrbyfloatCmd::DoInitial() { } key_ = argv_[1]; value_ = argv_[2]; - if (!pstd::string2d(argv_[2].data(), argv_[2].size(), &by_)) { + if (pstd::string2d(argv_[2].data(), argv_[2].size(), &by_) == 0) { res_.SetRes(CmdRes::kInvalidFloat); return; } - return; } void IncrbyfloatCmd::Do(std::shared_ptr partition) { @@ -265,7 +254,6 @@ void IncrbyfloatCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void DecrCmd::DoInitial() { @@ -274,7 +262,6 @@ void DecrCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void DecrCmd::Do(std::shared_ptr partition) { @@ -288,7 +275,6 @@ void DecrCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void DecrbyCmd::DoInitial() { @@ -297,11 +283,10 @@ void DecrbyCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &by_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &by_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } void DecrbyCmd::Do(std::shared_ptr partition) { @@ -315,7 +300,6 @@ void DecrbyCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void GetsetCmd::DoInitial() { @@ -325,7 +309,6 @@ void GetsetCmd::DoInitial() { } key_ = argv_[1]; new_value_ = argv_[2]; - return; } void GetsetCmd::Do(std::shared_ptr partition) { @@ -341,7 +324,6 @@ void GetsetCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void AppendCmd::DoInitial() { @@ -351,7 +333,6 @@ void AppendCmd::DoInitial() { } key_ = argv_[1]; value_ = argv_[2]; - return; } void AppendCmd::Do(std::shared_ptr partition) { @@ -362,7 +343,6 @@ void AppendCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void MgetCmd::DoInitial() { @@ -373,7 +353,6 @@ void MgetCmd::DoInitial() { keys_ = argv_; keys_.erase(keys_.begin()); split_res_.resize(keys_.size()); - return; } void MgetCmd::Do(std::shared_ptr partition) { @@ -392,7 +371,6 @@ void MgetCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void MgetCmd::Split(std::shared_ptr partition, const HintKeys& hint_keys) { @@ -410,7 +388,6 @@ void MgetCmd::Split(std::shared_ptr partition, const HintKeys& hint_k } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void MgetCmd::Merge() { @@ -433,15 +410,15 @@ void KeysCmd::DoInitial() { pattern_ = argv_[1]; if (argv_.size() == 3) { std::string opt = argv_[2]; - if (!strcasecmp(opt.data(), "string")) { + if (strcasecmp(opt.data(), "string") == 0) { type_ = storage::DataType::kStrings; - } else if (!strcasecmp(opt.data(), "zset")) { + } else if (strcasecmp(opt.data(), "zset") == 0) { type_ = storage::DataType::kZSets; - } else if (!strcasecmp(opt.data(), "set")) { + } else if (strcasecmp(opt.data(), "set") == 0) { type_ = storage::DataType::kSets; - } else if (!strcasecmp(opt.data(), "list")) { + } else if (strcasecmp(opt.data(), "list") == 0) { type_ = storage::DataType::kLists; - } else if (!strcasecmp(opt.data(), "hash")) { + } else if (strcasecmp(opt.data(), "hash") == 0) { type_ = storage::DataType::kHashes; } else { res_.SetRes(CmdRes::kSyntaxErr); @@ -449,7 +426,6 @@ void KeysCmd::DoInitial() { } else if (argv_.size() > 3) { res_.SetRes(CmdRes::kSyntaxErr); } - return; } void KeysCmd::Do(std::shared_ptr partition) { @@ -474,7 +450,6 @@ void KeysCmd::Do(std::shared_ptr partition) { res_.AppendArrayLen(total_key); res_.AppendStringRaw(raw); - return; } void SetnxCmd::DoInitial() { @@ -484,7 +459,6 @@ void SetnxCmd::DoInitial() { } key_ = argv_[1]; value_ = argv_[2]; - return; } void SetnxCmd::Do(std::shared_ptr partition) { @@ -495,7 +469,6 @@ void SetnxCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } std::string SetnxCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, @@ -526,12 +499,11 @@ void SetexCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &sec_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &sec_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } value_ = argv_[3]; - return; } void SetexCmd::Do(std::shared_ptr partition) { @@ -576,12 +548,11 @@ void PsetexCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &usec_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &usec_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } value_ = argv_[3]; - return; } void PsetexCmd::Do(std::shared_ptr partition) { @@ -627,7 +598,6 @@ void DelvxCmd::DoInitial() { } key_ = argv_[1]; value_ = argv_[2]; - return; } void DelvxCmd::Do(std::shared_ptr partition) { @@ -653,8 +623,7 @@ void MsetCmd::DoInitial() { for (size_t index = 1; index != argc; index += 2) { kvs_.push_back({argv_[index], argv_[index + 1]}); } - return; -} + } void MsetCmd::Do(std::shared_ptr partition) { storage::Status s = partition->db()->MSet(kvs_); @@ -705,7 +674,6 @@ void MsetnxCmd::DoInitial() { for (size_t index = 1; index != argc; index += 2) { kvs_.push_back({argv_[index], argv_[index + 1]}); } - return; } void MsetnxCmd::Do(std::shared_ptr partition) { @@ -724,15 +692,14 @@ void GetrangeCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &start_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &start_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (!pstd::string2int(argv_[3].data(), argv_[3].size(), &end_)) { + if (pstd::string2int(argv_[3].data(), argv_[3].size(), &end_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } void GetrangeCmd::Do(std::shared_ptr partition) { @@ -752,12 +719,11 @@ void SetrangeCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &offset_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &offset_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } value_ = argv_[3]; - return; } void SetrangeCmd::Do(std::shared_ptr partition) { @@ -768,7 +734,6 @@ void SetrangeCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void StrlenCmd::DoInitial() { @@ -777,7 +742,6 @@ void StrlenCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void StrlenCmd::Do(std::shared_ptr partition) { @@ -788,7 +752,6 @@ void StrlenCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ExistsCmd::DoInitial() { @@ -798,7 +761,6 @@ void ExistsCmd::DoInitial() { } keys_ = argv_; keys_.erase(keys_.begin()); - return; } void ExistsCmd::Do(std::shared_ptr partition) { @@ -809,7 +771,6 @@ void ExistsCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "exists internal error"); } - return; } void ExistsCmd::Split(std::shared_ptr partition, const HintKeys& hint_keys) { @@ -824,7 +785,6 @@ void ExistsCmd::Split(std::shared_ptr partition, const HintKeys& hint void ExistsCmd::Merge() { res_.AppendInteger(split_res_); - return; } void ExpireCmd::DoInitial() { @@ -833,11 +793,10 @@ void ExpireCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &sec_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &sec_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } void ExpireCmd::Do(std::shared_ptr partition) { @@ -848,7 +807,6 @@ void ExpireCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "expire internal error"); } - return; } std::string ExpireCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, @@ -882,11 +840,10 @@ void PexpireCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &msec_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &msec_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } void PexpireCmd::Do(std::shared_ptr partition) { @@ -897,7 +854,6 @@ void PexpireCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "expire internal error"); } - return; } std::string PexpireCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, @@ -931,11 +887,10 @@ void ExpireatCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &time_stamp_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &time_stamp_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } void ExpireatCmd::Do(std::shared_ptr partition) { @@ -954,11 +909,10 @@ void PexpireatCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &time_stamp_ms_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &time_stamp_ms_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } std::string PexpireatCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, @@ -994,7 +948,6 @@ void PexpireatCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "pexpireat internal error"); } - return; } void TtlCmd::DoInitial() { @@ -1003,7 +956,6 @@ void TtlCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void TtlCmd::Do(std::shared_ptr partition) { @@ -1031,7 +983,6 @@ void TtlCmd::Do(std::shared_ptr partition) { // mean this key not exist res_.AppendInteger(-2); } - return; } void PttlCmd::DoInitial() { @@ -1040,7 +991,6 @@ void PttlCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void PttlCmd::Do(std::shared_ptr partition) { @@ -1088,7 +1038,6 @@ void PttlCmd::Do(std::shared_ptr partition) { // mean this key not exist res_.AppendInteger(-2); } - return; } void PersistCmd::DoInitial() { @@ -1097,7 +1046,6 @@ void PersistCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void PersistCmd::Do(std::shared_ptr partition) { @@ -1108,7 +1056,6 @@ void PersistCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "persist internal error"); } - return; } void TypeCmd::DoInitial() { @@ -1117,7 +1064,6 @@ void TypeCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void TypeCmd::Do(std::shared_ptr partition) { @@ -1128,7 +1074,6 @@ void TypeCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ScanCmd::DoInitial() { @@ -1136,23 +1081,24 @@ void ScanCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNameScan); return; } - if (!pstd::string2int(argv_[1].data(), argv_[1].size(), &cursor_)) { + if (pstd::string2int(argv_[1].data(), argv_[1].size(), &cursor_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - size_t index = 2, argc = argv_.size(); + size_t index = 2; + size_t argc = argv_.size(); while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "count")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "count") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) || count_ <= 0) { + } else if ((pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) == 0) || count_ <= 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -1162,7 +1108,6 @@ void ScanCmd::DoInitial() { } index++; } - return; } void ScanCmd::Do(std::shared_ptr partition) { @@ -1188,7 +1133,7 @@ void ScanCmd::Do(std::shared_ptr partition) { return; } total_key += keys.size(); - } while (cursor_ret != 0 && left); + } while (cursor_ret != 0 && (left != 0)); res_.AppendArrayLen(2); @@ -1199,7 +1144,6 @@ void ScanCmd::Do(std::shared_ptr partition) { res_.AppendArrayLen(total_key); res_.AppendStringRaw(raw); - return; } void ScanxCmd::DoInitial() { @@ -1207,15 +1151,15 @@ void ScanxCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNameScanx); return; } - if (!strcasecmp(argv_[1].data(), "string")) { + if (strcasecmp(argv_[1].data(), "string") == 0) { type_ = storage::kStrings; - } else if (!strcasecmp(argv_[1].data(), "hash")) { + } else if (strcasecmp(argv_[1].data(), "hash") == 0) { type_ = storage::kHashes; - } else if (!strcasecmp(argv_[1].data(), "set")) { + } else if (strcasecmp(argv_[1].data(), "set") == 0) { type_ = storage::kSets; - } else if (!strcasecmp(argv_[1].data(), "zset")) { + } else if (strcasecmp(argv_[1].data(), "zset") == 0) { type_ = storage::kZSets; - } else if (!strcasecmp(argv_[1].data(), "list")) { + } else if (strcasecmp(argv_[1].data(), "list") == 0) { type_ = storage::kLists; } else { res_.SetRes(CmdRes::kInvalidDbType); @@ -1223,18 +1167,19 @@ void ScanxCmd::DoInitial() { } start_key_ = argv_[2]; - size_t index = 3, argc = argv_.size(); + size_t index = 3; + size_t argc = argv_.size(); while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "count")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "count") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) || count_ <= 0) { + } else if ((pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) == 0) || count_ <= 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -1244,8 +1189,7 @@ void ScanxCmd::DoInitial() { } index++; } - return; -} + } void ScanxCmd::Do(std::shared_ptr partition) { std::string next_key; @@ -1265,8 +1209,7 @@ void ScanxCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; -} + } void PKSetexAtCmd::DoInitial() { if (!CheckArg(argv_.size())) { @@ -1275,11 +1218,10 @@ void PKSetexAtCmd::DoInitial() { } key_ = argv_[1]; value_ = argv_[3]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &time_stamp_) || time_stamp_ >= INT32_MAX) { + if ((pstd::string2int(argv_[2].data(), argv_[2].size(), &time_stamp_) == 0) || time_stamp_ >= INT32_MAX) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } void PKSetexAtCmd::Do(std::shared_ptr partition) { @@ -1289,7 +1231,6 @@ void PKSetexAtCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void PKScanRangeCmd::DoInitial() { @@ -1297,18 +1238,18 @@ void PKScanRangeCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNamePKScanRange); return; } - if (!strcasecmp(argv_[1].data(), "string_with_value")) { + if (strcasecmp(argv_[1].data(), "string_with_value") == 0) { type_ = storage::kStrings; string_with_value = true; - } else if (!strcasecmp(argv_[1].data(), "string")) { + } else if (strcasecmp(argv_[1].data(), "string") == 0) { type_ = storage::kStrings; - } else if (!strcasecmp(argv_[1].data(), "hash")) { + } else if (strcasecmp(argv_[1].data(), "hash") == 0) { type_ = storage::kHashes; - } else if (!strcasecmp(argv_[1].data(), "set")) { + } else if (strcasecmp(argv_[1].data(), "set") == 0) { type_ = storage::kSets; - } else if (!strcasecmp(argv_[1].data(), "zset")) { + } else if (strcasecmp(argv_[1].data(), "zset") == 0) { type_ = storage::kZSets; - } else if (!strcasecmp(argv_[1].data(), "list")) { + } else if (strcasecmp(argv_[1].data(), "list") == 0) { type_ = storage::kLists; } else { res_.SetRes(CmdRes::kInvalidDbType); @@ -1322,18 +1263,19 @@ void PKScanRangeCmd::DoInitial() { res_.SetRes(CmdRes::kInconsistentHashTag); return; } - size_t index = 4, argc = argv_.size(); + size_t index = 4; + size_t argc = argv_.size(); while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "limit")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "limit") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &limit_) || limit_ <= 0) { + } else if ((pstd::string2int(argv_[index].data(), argv_[index].size(), &limit_) == 0) || limit_ <= 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -1343,7 +1285,6 @@ void PKScanRangeCmd::DoInitial() { } index++; } - return; } void PKScanRangeCmd::Do(std::shared_ptr partition) { @@ -1375,7 +1316,6 @@ void PKScanRangeCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void PKRScanRangeCmd::DoInitial() { @@ -1383,18 +1323,18 @@ void PKRScanRangeCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNamePKRScanRange); return; } - if (!strcasecmp(argv_[1].data(), "string_with_value")) { + if (strcasecmp(argv_[1].data(), "string_with_value") == 0) { type_ = storage::kStrings; string_with_value = true; - } else if (!strcasecmp(argv_[1].data(), "string")) { + } else if (strcasecmp(argv_[1].data(), "string") == 0) { type_ = storage::kStrings; - } else if (!strcasecmp(argv_[1].data(), "hash")) { + } else if (strcasecmp(argv_[1].data(), "hash") == 0) { type_ = storage::kHashes; - } else if (!strcasecmp(argv_[1].data(), "set")) { + } else if (strcasecmp(argv_[1].data(), "set") == 0) { type_ = storage::kSets; - } else if (!strcasecmp(argv_[1].data(), "zset")) { + } else if (strcasecmp(argv_[1].data(), "zset") == 0) { type_ = storage::kZSets; - } else if (!strcasecmp(argv_[1].data(), "list")) { + } else if (strcasecmp(argv_[1].data(), "list") == 0) { type_ = storage::kLists; } else { res_.SetRes(CmdRes::kInvalidDbType); @@ -1408,18 +1348,19 @@ void PKRScanRangeCmd::DoInitial() { res_.SetRes(CmdRes::kInconsistentHashTag); return; } - size_t index = 4, argc = argv_.size(); + size_t index = 4; + size_t argc = argv_.size(); while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "limit")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "limit") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &limit_) || limit_ <= 0) { + } else if ((pstd::string2int(argv_[index].data(), argv_[index].size(), &limit_) == 0) || limit_ <= 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -1429,7 +1370,6 @@ void PKRScanRangeCmd::DoInitial() { } index++; } - return; } void PKRScanRangeCmd::Do(std::shared_ptr partition) { @@ -1461,5 +1401,4 @@ void PKRScanRangeCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } diff --git a/src/pika_list.cc b/src/pika_list.cc index d184252d37..ce69f44b03 100644 --- a/src/pika_list.cc +++ b/src/pika_list.cc @@ -15,11 +15,10 @@ void LIndexCmd::DoInitial() { } key_ = argv_[1]; std::string index = argv_[2]; - if (!pstd::string2int(index.data(), index.size(), &index_)) { + if (pstd::string2int(index.data(), index.size(), &index_) == 0) { res_.SetRes(CmdRes::kInvalidInt); } - return; -} + } void LIndexCmd::Do(std::shared_ptr partition) { std::string value; rocksdb::Status s = partition->db()->LIndex(key_, index_, &value); @@ -39,9 +38,9 @@ void LInsertCmd::DoInitial() { } key_ = argv_[1]; std::string dir = argv_[2]; - if (!strcasecmp(dir.data(), "before")) { + if (strcasecmp(dir.data(), "before") == 0) { dir_ = storage::Before; - } else if (!strcasecmp(dir.data(), "after")) { + } else if (strcasecmp(dir.data(), "after") == 0) { dir_ = storage::After; } else { res_.SetRes(CmdRes::kSyntaxErr); @@ -142,16 +141,15 @@ void LRangeCmd::DoInitial() { } key_ = argv_[1]; std::string left = argv_[2]; - if (!pstd::string2int(left.data(), left.size(), &left_)) { + if (pstd::string2int(left.data(), left.size(), &left_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } std::string right = argv_[3]; - if (!pstd::string2int(right.data(), right.size(), &right_)) { + if (pstd::string2int(right.data(), right.size(), &right_) == 0) { res_.SetRes(CmdRes::kInvalidInt); } - return; -} + } void LRangeCmd::Do(std::shared_ptr partition) { std::vector values; rocksdb::Status s = partition->db()->LRange(key_, left_, right_, &values); @@ -174,7 +172,7 @@ void LRemCmd::DoInitial() { } key_ = argv_[1]; std::string count = argv_[2]; - if (!pstd::string2int(count.data(), count.size(), &count_)) { + if (pstd::string2int(count.data(), count.size(), &count_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -197,7 +195,7 @@ void LSetCmd::DoInitial() { } key_ = argv_[1]; std::string index = argv_[2]; - if (!pstd::string2int(index.data(), index.size(), &index_)) { + if (pstd::string2int(index.data(), index.size(), &index_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -210,7 +208,7 @@ void LSetCmd::Do(std::shared_ptr partition) { } else if (s.IsNotFound()) { res_.SetRes(CmdRes::kNotFound); } else if (s.IsCorruption() && s.ToString() == "Corruption: index out of range") { - // TODO refine return value + // TODO(): refine return value res_.SetRes(CmdRes::kOutOfRange); } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); @@ -224,16 +222,15 @@ void LTrimCmd::DoInitial() { } key_ = argv_[1]; std::string start = argv_[2]; - if (!pstd::string2int(start.data(), start.size(), &start_)) { + if (pstd::string2int(start.data(), start.size(), &start_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } std::string stop = argv_[3]; - if (!pstd::string2int(stop.data(), stop.size(), &stop_)) { + if (pstd::string2int(stop.data(), stop.size(), &stop_) == 0) { res_.SetRes(CmdRes::kInvalidInt); } - return; -} + } void LTrimCmd::Do(std::shared_ptr partition) { rocksdb::Status s = partition->db()->LTrim(key_, start_, stop_); if (s.ok() || s.IsNotFound()) { diff --git a/src/pika_meta.cc b/src/pika_meta.cc index bba6e18c88..59c280ba62 100644 --- a/src/pika_meta.cc +++ b/src/pika_meta.cc @@ -6,11 +6,9 @@ #include "include/pika_meta.h" #include "pika_inner_message.pb.h" -const uint32_t VERSION = 1; - -PikaMeta::PikaMeta() : local_meta_path_("") {} +using pstd::Status; -PikaMeta::~PikaMeta() {} +const uint32_t VERSION = 1; void PikaMeta::SetPath(const std::string& path) { local_meta_path_ = path; } @@ -59,10 +57,10 @@ Status PikaMeta::StableSave(const std::vector& table_structs) { p += sizeof(uint32_t); memcpy(p, &meta_str_size, sizeof(uint32_t)); p += sizeof(uint32_t); - memcpy(p, meta_str.data(), meta_str.size()); + strncpy(p, meta_str.data(), meta_str.size()); pstd::DeleteFile(local_meta_file); - if (pstd::RenameFile(tmp_file, local_meta_file)) { + if (pstd::RenameFile(tmp_file, local_meta_file) != 0) { LOG(WARNING) << "Failed to rename file, error: " << strerror(errno); return Status::Corruption("faild to rename file"); } @@ -84,15 +82,15 @@ Status PikaMeta::ParseMeta(std::vector* const table_structs) { return Status::Corruption("open local meta file failed"); } - if (reader->GetData() == nullptr) { + if (!reader->GetData()) { LOG(WARNING) << "Meta file init error"; return Status::Corruption("meta file init error"); } uint32_t version = 0; uint32_t meta_size = 0; - memcpy((char*)(&version), reader->GetData(), sizeof(uint32_t)); - memcpy((char*)(&meta_size), reader->GetData() + sizeof(uint32_t), sizeof(uint32_t)); + memcpy(reinterpret_cast(&version), reader->GetData(), sizeof(uint32_t)); + memcpy(reinterpret_cast(&meta_size), reader->GetData() + sizeof(uint32_t), sizeof(uint32_t)); auto const buf_ptr = std::make_unique(meta_size); char* const buf = buf_ptr.get(); memcpy(buf, reader->GetData() + 2 * sizeof(uint32_t), meta_size); @@ -105,7 +103,7 @@ Status PikaMeta::ParseMeta(std::vector* const table_structs) { table_structs->clear(); for (int idx = 0; idx < meta.table_infos_size(); ++idx) { - InnerMessage::TableInfo ti = meta.table_infos(idx); + const InnerMessage::TableInfo& ti = meta.table_infos(idx); std::set partition_ids; for (int sidx = 0; sidx < ti.partition_ids_size(); ++sidx) { partition_ids.insert(ti.partition_ids(sidx)); diff --git a/src/pika_monitor_thread.cc b/src/pika_monitor_thread.cc new file mode 100644 index 0000000000..5943745319 --- /dev/null +++ b/src/pika_monitor_thread.cc @@ -0,0 +1,193 @@ +// Copyright (c) 2015-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/pika_monitor_thread.h" + +#include + +PikaMonitorThread::PikaMonitorThread() { + set_thread_name("MonitorThread"); + has_monitor_clients_.store(false); +} + +PikaMonitorThread::~PikaMonitorThread() { + set_should_stop(); + if (is_running()) { + monitor_cond_.notify_all(); + StopThread(); + } + for (auto & monitor_client : monitor_clients_) { + close(monitor_client.fd); + } + LOG(INFO) << "PikaMonitorThread " << pthread_self() << " exit!!!"; +} + +void PikaMonitorThread::AddMonitorClient(const std::shared_ptr& client_ptr) { + StartThread(); + std::lock_guard lm(monitor_mutex_protector_); + monitor_clients_.push_back(ClientInfo{client_ptr->fd(), client_ptr->ip_port(), 0, client_ptr}); + has_monitor_clients_.store(true); +} + +void PikaMonitorThread::RemoveMonitorClient(const std::string& ip_port) { + auto iter = monitor_clients_.begin(); + for (; iter != monitor_clients_.end(); ++iter) { + if (ip_port == "all") { + close(iter->fd); + continue; + } + if (iter->ip_port == ip_port) { + close(iter->fd); + break; + } + } + if (ip_port == "all") { + monitor_clients_.clear(); + } else if (iter != monitor_clients_.end()) { + monitor_clients_.erase(iter); + } + has_monitor_clients_.store(!monitor_clients_.empty()); +} + +void PikaMonitorThread::AddMonitorMessage(const std::string& monitor_message) { + std::lock_guard lm(monitor_mutex_protector_); + if (monitor_messages_.empty() && cron_tasks_.empty()) { + monitor_messages_.push_back(monitor_message); + monitor_cond_.notify_one(); + } else { + monitor_messages_.push_back(monitor_message); + } +} + +int32_t PikaMonitorThread::ThreadClientList(std::vector* clients_ptr) { + if (clients_ptr) { + for (auto & monitor_client : monitor_clients_) { + clients_ptr->push_back(monitor_client); + } + } + return monitor_clients_.size(); +} + +void PikaMonitorThread::AddCronTask(const MonitorCronTask& task) { + std::lock_guard lm(monitor_mutex_protector_); + if (monitor_messages_.empty() && cron_tasks_.empty()) { + cron_tasks_.push(task); + monitor_cond_.notify_one(); + } else { + cron_tasks_.push(task); + } +} + +bool PikaMonitorThread::FindClient(const std::string& ip_port) { + std::lock_guard lm(monitor_mutex_protector_); + for (auto & monitor_client : monitor_clients_) { + if (monitor_client.ip_port == ip_port) { + return true; + } + } + return false; +} + +bool PikaMonitorThread::ThreadClientKill(const std::string& ip_port) { + if (is_running()) { + if (ip_port == "all") { + AddCronTask({TASK_KILLALL, "all"}); + } else if (FindClient(ip_port)) { + AddCronTask({TASK_KILL, ip_port}); + } else { + return false; + } + } + return true; +} + +bool PikaMonitorThread::HasMonitorClients() { return has_monitor_clients_.load(); } + +net::WriteStatus PikaMonitorThread::SendMessage(int32_t fd, std::string& message) { + size_t retry = 0; + ssize_t nwritten = 0; + ssize_t message_len_sended = 0; + ssize_t message_len_left = message.size(); + while (message_len_left > 0) { + nwritten = write(fd, message.data() + message_len_sended, message_len_left); + if (nwritten == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + // If the write buffer is full, but the client no longer consumes, it will + // get stuck in the loop and cause the entire Pika to block becase of monitor_mutex_protector_. + // So we put a limit on the number of retries + if (++retry >= 10) { + return net::kWriteError; + } else { + // Sleep one second wait for client consume message + sleep(1); + continue; + } + } else if (nwritten == -1) { + return net::kWriteError; + } + if (retry > 0) { + retry = 0; + } + message_len_sended += nwritten; + message_len_left -= nwritten; + } + return net::kWriteAll; +} + +void* PikaMonitorThread::ThreadMain() { + std::deque messages_deque; + std::string messages_transfer; + MonitorCronTask task; + net::WriteStatus write_status; + while (!should_stop()) { + { + std::unique_lock lm(monitor_mutex_protector_); + monitor_cond_.wait(lm, [this]() { return !monitor_messages_.empty() || !cron_tasks_.empty() || should_stop(); }); + } + if (should_stop()) { + break; + } + { + std::lock_guard lm(monitor_mutex_protector_); + while (!cron_tasks_.empty()) { + task = cron_tasks_.front(); + cron_tasks_.pop(); + RemoveMonitorClient(task.ip_port); + if (task.task == TASK_KILLALL) { + std::queue empty_queue; + cron_tasks_.swap(empty_queue); + } + } + } + + messages_deque.clear(); + { + std::lock_guard lm(monitor_mutex_protector_); + messages_deque.swap(monitor_messages_); + if (monitor_clients_.empty() || messages_deque.empty()) { + continue; + } + } + messages_transfer = "+"; + for (const auto& msg : messages_deque) { + messages_transfer.append(msg.data(), msg.size()); + messages_transfer.append(" ", 1); + } + if (messages_transfer == "+") { + continue; + } + + messages_transfer.pop_back(); // no space follow last param + messages_transfer.append("\r\n", 2); + + std::lock_guard lm(monitor_mutex_protector_); + for (auto & monitor_client : monitor_clients_) { + write_status = SendMessage(monitor_client.fd, messages_transfer); + if (write_status == net::kWriteError) { + cron_tasks_.push({TASK_KILL, monitor_client.ip_port}); + } + } + } + return nullptr; +} diff --git a/src/pika_partition.cc b/src/pika_partition.cc index bfe8ef78fe..e46c6216ee 100644 --- a/src/pika_partition.cc +++ b/src/pika_partition.cc @@ -6,6 +6,7 @@ #include "include/pika_partition.h" #include +#include #include "include/pika_conf.h" #include "include/pika_rm.h" @@ -13,7 +14,8 @@ #include "pstd/include/mutex_impl.h" -extern std::unique_ptr g_pika_conf; +using pstd::Status; + extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; @@ -26,14 +28,14 @@ std::string PartitionPath(const std::string& table_path, uint32_t partition_id) std::string PartitionName(const std::string& table_name, uint32_t partition_id) { char buf[256]; snprintf(buf, sizeof(buf), "(%s:%u)", table_name.data(), partition_id); - return std::string(buf); + return {buf}; } std::string BgsaveSubPath(const std::string& table_name, uint32_t partition_id) { char buf[256]; std::string partition_id_str = std::to_string(partition_id); snprintf(buf, sizeof(buf), "%s/%s", table_name.data(), partition_id_str.data()); - return std::string(buf); + return {buf}; } std::string DbSyncPath(const std::string& sync_path, const std::string& table_name, const uint32_t partition_id) { @@ -50,12 +52,12 @@ Partition::Partition(const std::string& table_name, uint32_t partition_id, const dbsync_path_ = DbSyncPath(g_pika_conf->db_sync_path(), table_name_, partition_id_); partition_name_ = table_name; - db_ = std::make_unique(); + db_ = std::make_shared(); rocksdb::Status s = db_->Open(g_pika_server->storage_options(), db_path_); lock_mgr_ = std::make_shared(1000, 0, std::make_shared()); - opened_ = s.ok() ? true : false; + opened_ = s.ok(); assert(db_); assert(s.ok()); LOG(INFO) << partition_name_ << " DB Success"; @@ -92,7 +94,7 @@ void Partition::MoveToTrash() { dbpath.erase(dbpath.length() - 1); } dbpath.append("_deleting/"); - if (pstd::RenameFile(db_path_, dbpath.c_str())) { + if (pstd::RenameFile(db_path_, dbpath) != 0) { LOG(WARNING) << "Failed to move db to trash, error: " << strerror(errno); return; } @@ -110,7 +112,9 @@ std::string Partition::GetPartitionName() const { return partition_name_; } std::shared_ptr Partition::db() const { return db_; } void Partition::Compact(const storage::DataType& type) { - if (!opened_) return; + if (!opened_) { + return; + } db_->Compact(type); } @@ -157,15 +161,21 @@ bool Partition::TryUpdateMasterOffset() { slave_partition->SetReplState(ReplState::kError); return false; } - std::string line, master_ip; + std::string line; + std::string master_ip; int lineno = 0; - int64_t filenum = 0, offset = 0, term = 0, index = 0, tmp = 0, master_port = 0; + int64_t filenum = 0; + int64_t offset = 0; + int64_t term = 0; + int64_t index = 0; + int64_t tmp = 0; + int64_t master_port = 0; while (std::getline(is, line)) { lineno++; if (lineno == 2) { master_ip = line; } else if (lineno > 2 && lineno < 8) { - if (!pstd::string2int(line.data(), line.size(), &tmp) || tmp < 0) { + if ((pstd::string2int(line.data(), line.size(), &tmp) == 0) || tmp < 0) { LOG(WARNING) << "Partition: " << partition_name_ << ", Format of info file after db sync error, line : " << line; is.close(); @@ -244,19 +254,19 @@ bool Partition::ChangeDb(const std::string& new_path) { LOG(INFO) << "Partition: " << partition_name_ << ", Prepare change db from: " << tmp_path; db_.reset(); - if (0 != pstd::RenameFile(db_path_.c_str(), tmp_path)) { + if (0 != pstd::RenameFile(db_path_, tmp_path)) { LOG(WARNING) << "Partition: " << partition_name_ << ", Failed to rename db path when change db, error: " << strerror(errno); return false; } - if (0 != pstd::RenameFile(new_path.c_str(), db_path_.c_str())) { + if (0 != pstd::RenameFile(new_path, db_path_)) { LOG(WARNING) << "Partition: " << partition_name_ << ", Failed to rename new db path when change db, error: " << strerror(errno); return false; } - db_.reset(new storage::Storage()); + db_ = std::make_shared(); rocksdb::Status s = db_->Open(g_pika_server->storage_options(), db_path_); assert(db_); assert(s.ok()); @@ -276,7 +286,7 @@ void Partition::BgSavePartition() { return; } bgsave_info_.bgsaving = true; - BgTaskArg* bg_task_arg = new BgTaskArg(); + auto bg_task_arg = new BgTaskArg(); bg_task_arg->partition = shared_from_this(); g_pika_server->BGSaveTaskSchedule(&DoBgSave, static_cast(bg_task_arg)); } @@ -309,7 +319,7 @@ void Partition::DoBgSave(void* arg) { } if (!success) { std::string fail_path = info.path + "_FAILED"; - pstd::RenameFile(info.path.c_str(), fail_path.c_str()); + pstd::RenameFile(info.path, fail_path); } bg_task_arg->partition->FinishBgsave(); @@ -425,7 +435,7 @@ bool Partition::FlushDB() { dbpath.erase(dbpath.length() - 1); } dbpath.append("_deleting/"); - pstd::RenameFile(db_path_, dbpath.c_str()); + pstd::RenameFile(db_path_, dbpath); db_ = std::make_shared(); rocksdb::Status s = db_->Open(g_pika_server->storage_options(), db_path_); diff --git a/src/pika_pubsub.cc b/src/pika_pubsub.cc index 9812131de5..b642a861c0 100644 --- a/src/pika_pubsub.cc +++ b/src/pika_pubsub.cc @@ -11,20 +11,20 @@ extern PikaServer* g_pika_server; static std::string ConstructPubSubResp(const std::string& cmd, const std::vector>& result) { std::stringstream resp; - if (result.size() == 0) { + if (result.empty()) { resp << "*3\r\n" << "$" << cmd.length() << "\r\n" << cmd << "\r\n" << "$" << -1 << "\r\n" << ":" << 0 << "\r\n"; } - for (auto it = result.begin(); it != result.end(); it++) { + for (const auto & it : result) { resp << "*3\r\n" << "$" << cmd.length() << "\r\n" << cmd << "\r\n" - << "$" << it->first.length() << "\r\n" - << it->first << "\r\n" - << ":" << it->second << "\r\n"; + << "$" << it.first.length() << "\r\n" + << it.first << "\r\n" + << ":" << it.second << "\r\n"; } return resp.str(); } @@ -41,7 +41,6 @@ void PublishCmd::DoInitial() { void PublishCmd::Do(std::shared_ptr partition) { int receivers = g_pika_server->Publish(channel_, msg_); res_.AppendInteger(receivers); - return; } void SubscribeCmd::DoInitial() { @@ -204,8 +203,8 @@ void PubSubCmd::DoInitial() { return; } subcommand_ = argv_[1]; - if (strcasecmp(subcommand_.data(), "channels") && strcasecmp(subcommand_.data(), "numsub") && - strcasecmp(subcommand_.data(), "numpat")) { + if (strcasecmp(subcommand_.data(), "channels") != 0 && strcasecmp(subcommand_.data(), "numsub") != 0 && + strcasecmp(subcommand_.data(), "numpat") != 0) { res_.SetRes(CmdRes::kErrOther, "Unknown PUBSUB subcommand or wrong number of arguments for '" + subcommand_ + "'"); } for (size_t i = 2; i < argv_.size(); i++) { @@ -214,8 +213,8 @@ void PubSubCmd::DoInitial() { } void PubSubCmd::Do(std::shared_ptr partition) { - if (!strcasecmp(subcommand_.data(), "channels")) { - std::string pattern = ""; + if (strcasecmp(subcommand_.data(), "channels") == 0) { + std::string pattern; std::vector result; if (arguments_.size() == 1) { pattern = arguments_[0]; @@ -227,23 +226,22 @@ void PubSubCmd::Do(std::shared_ptr partition) { g_pika_server->PubSubChannels(pattern, &result); res_.AppendArrayLen(result.size()); - for (auto it = result.begin(); it != result.end(); ++it) { - res_.AppendStringLen((*it).length()); - res_.AppendContent(*it); + for (auto &it : result) { + res_.AppendStringLen(it.length()); + res_.AppendContent(it); } - } else if (!strcasecmp(subcommand_.data(), "numsub")) { + } else if (strcasecmp(subcommand_.data(), "numsub") == 0) { std::vector> result; g_pika_server->PubSubNumSub(arguments_, &result); res_.AppendArrayLen(result.size() * 2); - for (auto it = result.begin(); it != result.end(); ++it) { - res_.AppendStringLen(it->first.length()); - res_.AppendContent(it->first); - res_.AppendInteger(it->second); + for (auto &it : result) { + res_.AppendStringLen(it.first.length()); + res_.AppendContent(it.first); + res_.AppendInteger(it.second); } return; - } else if (!strcasecmp(subcommand_.data(), "numpat")) { + } else if (strcasecmp(subcommand_.data(), "numpat") == 0) { int subscribed = g_pika_server->PubSubNumPat(); res_.AppendInteger(subscribed); } - return; } diff --git a/src/pika_repl_bgworker.cc b/src/pika_repl_bgworker.cc index 60ab782d28..0dd1c80b50 100644 --- a/src/pika_repl_bgworker.cc +++ b/src/pika_repl_bgworker.cc @@ -13,7 +13,6 @@ #include "include/pika_server.h" #include "pstd/include/pstd_defer.h" -extern std::unique_ptr g_pika_conf; extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; extern std::unique_ptr g_pika_cmd_table_manager; @@ -36,7 +35,7 @@ void PikaReplBgWorker::Schedule(net::TaskFunc func, void* arg) { bg_thread_.Sche void PikaReplBgWorker::QueueClear() { bg_thread_.QueueClear(); } -void PikaReplBgWorker::ParseBinlogOffset(const InnerMessage::BinlogOffset pb_offset, LogOffset* offset) { +void PikaReplBgWorker::ParseBinlogOffset(const InnerMessage::BinlogOffset& pb_offset, LogOffset* offset) { offset->b_offset.filenum = pb_offset.filenum(); offset->b_offset.offset = pb_offset.offset(); offset->l_offset.term = pb_offset.term(); @@ -44,10 +43,10 @@ void PikaReplBgWorker::ParseBinlogOffset(const InnerMessage::BinlogOffset pb_off } void PikaReplBgWorker::HandleBGWorkerWriteBinlog(void* arg) { - ReplClientWriteBinlogTaskArg* task_arg = static_cast(arg); + auto task_arg = static_cast(arg); const std::shared_ptr res = task_arg->res; std::shared_ptr conn = task_arg->conn; - std::vector* index = static_cast*>(task_arg->res_private_data); + auto index = static_cast*>(task_arg->res_private_data); PikaReplBgWorker* worker = task_arg->worker; worker->ip_port_ = conn->ip_port(); @@ -58,7 +57,8 @@ void PikaReplBgWorker::HandleBGWorkerWriteBinlog(void* arg) { std::string table_name; uint32_t partition_id = 0; - LogOffset pb_begin, pb_end; + LogOffset pb_begin; + LogOffset pb_end; bool only_keepalive = false; // find the first not keepalive binlogsync @@ -142,7 +142,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteBinlog(void* arg) { const InnerMessage::InnerResponse::BinlogSync& binlog_res = res->binlog_sync((*index)[i]); // if pika are not current a slave or partition not in // BinlogSync state, we drop remain write binlog task - if ((!(g_pika_server->role() & PIKA_ROLE_SLAVE)) || + if (((g_pika_server->role() & PIKA_ROLE_SLAVE) == 0) || ((slave_partition->State() != ReplState::kConnected) && (slave_partition->State() != ReplState::kWaitDBSync))) { return; } @@ -204,7 +204,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteBinlog(void* arg) { int PikaReplBgWorker::HandleWriteBinlog(net::RedisParser* parser, const net::RedisCmdArgsType& argv) { std::string opt = argv[0]; - PikaReplBgWorker* worker = static_cast(parser->data); + auto worker = static_cast(parser->data); // Monitor related std::string monitor_message; @@ -243,7 +243,7 @@ int PikaReplBgWorker::HandleWriteBinlog(net::RedisParser* parser, const net::Red } void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) { - std::unique_ptr task_arg(static_cast(arg)); + auto task_arg = static_cast(arg); const std::shared_ptr c_ptr = task_arg->cmd_ptr; const PikaCmdArgsType& argv = c_ptr->argv(); LogOffset offset = task_arg->offset; @@ -281,7 +281,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) { if (g_pika_conf->consensus_level() != 0) { std::shared_ptr partition = g_pika_rm->GetSyncMasterPartitionByName(PartitionInfo(table_name, partition_id)); - if (partition == nullptr) { + if (!partition) { LOG(WARNING) << "Sync Master Partition not exist " << table_name << partition_id; return; } diff --git a/src/pika_repl_client.cc b/src/pika_repl_client.cc index 1e7068628c..03d69d4288 100644 --- a/src/pika_repl_client.cc +++ b/src/pika_repl_client.cc @@ -9,6 +9,8 @@ #include #include +#include + #include "net/include/net_cli.h" #include "net/include/redis_cli.h" #include "pstd/include/env.h" @@ -18,10 +20,11 @@ #include "include/pika_rm.h" #include "include/pika_server.h" +using pstd::Status; extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; -PikaReplClient::PikaReplClient(int cron_interval, int keepalive_timeout) : next_avail_(0) { +PikaReplClient::PikaReplClient(int cron_interval, int keepalive_timeout) { client_thread_ = std::make_unique(cron_interval, keepalive_timeout); client_thread_->set_thread_name("PikaReplClient"); for (int i = 0; i < 2 * g_pika_conf->sync_thread_num(); ++i) { @@ -40,8 +43,8 @@ int PikaReplClient::Start() { LOG(FATAL) << "Start ReplClient ClientThread Error: " << res << (res == net::kCreateThreadError ? ": create thread error " : ": other error"); } - for (size_t i = 0; i < bg_workers_.size(); ++i) { - res = bg_workers_[i]->StartThread(); + for (auto & bg_worker : bg_workers_) { + res = bg_worker->StartThread(); if (res != net::kSuccess) { LOG(FATAL) << "Start Pika Repl Worker Thread Error: " << res << (res == net::kCreateThreadError ? ": create thread error " : ": other error"); @@ -52,8 +55,8 @@ int PikaReplClient::Start() { int PikaReplClient::Stop() { client_thread_->StopThread(); - for (size_t i = 0; i < bg_workers_.size(); ++i) { - bg_workers_[i]->StopThread(); + for (auto & bg_worker : bg_workers_) { + bg_worker->StopThread(); } return 0; } @@ -63,25 +66,24 @@ void PikaReplClient::Schedule(net::TaskFunc func, void* arg) { UpdateNextAvail(); } -void PikaReplClient::ScheduleWriteBinlogTask(std::string table_partition, - const std::shared_ptr res, +void PikaReplClient::ScheduleWriteBinlogTask(const std::string& table_partition, + const std::shared_ptr& res, std::shared_ptr conn, void* res_private_data) { size_t index = GetHashIndex(table_partition, true); - ReplClientWriteBinlogTaskArg* task_arg = - new ReplClientWriteBinlogTaskArg(res, conn, res_private_data, bg_workers_[index].get()); + auto task_arg = new ReplClientWriteBinlogTaskArg(res, std::move(conn), res_private_data, bg_workers_[index].get()); bg_workers_[index]->Schedule(&PikaReplBgWorker::HandleBGWorkerWriteBinlog, static_cast(task_arg)); } -void PikaReplClient::ScheduleWriteDBTask(const std::shared_ptr cmd_ptr, const LogOffset& offset, +void PikaReplClient::ScheduleWriteDBTask(const std::shared_ptr& cmd_ptr, const LogOffset& offset, const std::string& table_name, uint32_t partition_id) { const PikaCmdArgsType& argv = cmd_ptr->argv(); std::string dispatch_key = argv.size() >= 2 ? argv[1] : argv[0]; size_t index = GetHashIndex(dispatch_key, false); - ReplClientWriteDBTaskArg* task_arg = new ReplClientWriteDBTaskArg(cmd_ptr, offset, table_name, partition_id); + auto task_arg = new ReplClientWriteDBTaskArg(cmd_ptr, offset, table_name, partition_id); bg_workers_[index]->Schedule(&PikaReplBgWorker::HandleBGWorkerWriteDB, static_cast(task_arg)); } -size_t PikaReplClient::GetHashIndex(std::string key, bool upper_half) { +size_t PikaReplClient::GetHashIndex(const std::string& key, bool upper_half) { size_t hash_base = bg_workers_.size() / 2; return (str_hash(key) % hash_base) + (upper_half ? 0 : hash_base); } @@ -99,7 +101,7 @@ Status PikaReplClient::SendMetaSync() { if ((cli->Connect(g_pika_server->master_ip(), g_pika_server->master_port(), "")).ok()) { struct sockaddr_in laddr; socklen_t llen = sizeof(laddr); - getsockname(cli->fd(), (struct sockaddr*)&laddr, &llen); + getsockname(cli->fd(), reinterpret_cast(&laddr), &llen); std::string tmp_local_ip(inet_ntoa(laddr.sin_addr)); local_ip = tmp_local_ip; cli->Close(); diff --git a/src/pika_repl_client_conn.cc b/src/pika_repl_client_conn.cc index 7133913809..041c2ffa29 100644 --- a/src/pika_repl_client_conn.cc +++ b/src/pika_repl_client_conn.cc @@ -12,13 +12,10 @@ #include "include/pika_rm.h" #include "include/pika_server.h" #include "pstd/include/pstd_string.h" - -#include "include/pika_rm.h" -#include "include/pika_server.h" - #include "pika_inner_message.pb.h" -extern std::unique_ptr g_pika_conf; +using pstd::Status; + extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; @@ -53,19 +50,19 @@ int PikaReplClientConn::DealMessage() { } switch (response->type()) { case InnerMessage::kMetaSync: { - ReplClientTaskArg* task_arg = + auto task_arg = new ReplClientTaskArg(response, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplClientBGTask(&PikaReplClientConn::HandleMetaSyncResponse, static_cast(task_arg)); break; } case InnerMessage::kDBSync: { - ReplClientTaskArg* task_arg = + auto task_arg = new ReplClientTaskArg(response, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplClientBGTask(&PikaReplClientConn::HandleDBSyncResponse, static_cast(task_arg)); break; } case InnerMessage::kTrySync: { - ReplClientTaskArg* task_arg = + auto task_arg = new ReplClientTaskArg(response, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplClientBGTask(&PikaReplClientConn::HandleTrySyncResponse, static_cast(task_arg)); break; @@ -75,7 +72,7 @@ int PikaReplClientConn::DealMessage() { break; } case InnerMessage::kRemoveSlaveNode: { - ReplClientTaskArg* task_arg = + auto task_arg = new ReplClientTaskArg(response, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplClientBGTask(&PikaReplClientConn::HandleRemoveSlaveNodeResponse, static_cast(task_arg)); @@ -88,7 +85,7 @@ int PikaReplClientConn::DealMessage() { } void PikaReplClientConn::HandleMetaSyncResponse(void* arg) { - std::unique_ptr task_arg(static_cast(arg)); + auto task_arg = static_cast(arg); std::shared_ptr conn = task_arg->conn; std::shared_ptr response = task_arg->res; @@ -111,7 +108,7 @@ void PikaReplClientConn::HandleMetaSyncResponse(void* arg) { std::vector master_table_structs; for (int idx = 0; idx < meta_sync.tables_info_size(); ++idx) { - InnerMessage::InnerResponse_MetaSync_TableInfo table_info = meta_sync.tables_info(idx); + const InnerMessage::InnerResponse_MetaSync_TableInfo& table_info = meta_sync.tables_info(idx); master_table_structs.push_back({table_info.table_name(), static_cast(table_info.partition_num()), {0}}); } @@ -138,8 +135,8 @@ void PikaReplClientConn::HandleDBSyncResponse(void* arg) { const InnerMessage::InnerResponse_DBSync db_sync_response = response->db_sync(); int32_t session_id = db_sync_response.session_id(); - const InnerMessage::Partition partition_response = db_sync_response.partition(); - std::string table_name = partition_response.table_name(); + const InnerMessage::Partition& partition_response = db_sync_response.partition(); + const std::string& table_name = partition_response.table_name(); uint32_t partition_id = partition_response.partition_id(); std::shared_ptr slave_partition = @@ -247,7 +244,7 @@ Status PikaReplClientConn::TrySyncConsensusCheck(const InnerMessage::ConsensusMe const std::shared_ptr& slave_partition) { std::vector hints; for (int i = 0; i < consensus_meta.hint_size(); ++i) { - InnerMessage::BinlogOffset pb_offset = consensus_meta.hint(i); + const InnerMessage::BinlogOffset& pb_offset = consensus_meta.hint(i); LogOffset offset; offset.b_offset.filenum = pb_offset.filenum(); offset.b_offset.offset = pb_offset.offset(); @@ -265,7 +262,7 @@ Status PikaReplClientConn::TrySyncConsensusCheck(const InnerMessage::ConsensusMe return s; } -void PikaReplClientConn::DispatchBinlogRes(const std::shared_ptr res) { +void PikaReplClientConn::DispatchBinlogRes(const std::shared_ptr& res) { // partition to a bunch of binlog chips std::unordered_map*, hash_partition_info> par_binlog; for (int i = 0; i < res->binlog_sync_size(); ++i) { diff --git a/src/pika_repl_client_thread.cc b/src/pika_repl_client_thread.cc index 9c29d50fbe..dec853f106 100644 --- a/src/pika_repl_client_thread.cc +++ b/src/pika_repl_client_thread.cc @@ -42,7 +42,7 @@ void PikaReplClientThread::ReplClientHandle::FdTimeoutHandle(int fd, const std:: } if (ip == g_pika_server->master_ip() && port == g_pika_server->master_port() + kPortShiftReplServer && PIKA_REPL_ERROR != g_pika_server->repl_state() && - g_pika_rm->CheckSlavePartitionState(ip, port)) { // if state machine in error state, no retry + PikaReplicaManager::CheckSlavePartitionState(ip, port)) { // if state machine in error state, no retry LOG(WARNING) << "Master conn timeout : " << ip_port << " try reconnect"; g_pika_server->ResetMetaSyncStatus(); } diff --git a/src/pika_repl_server.cc b/src/pika_repl_server.cc index 2058634921..ad86ae7f38 100644 --- a/src/pika_repl_server.cc +++ b/src/pika_repl_server.cc @@ -11,7 +11,8 @@ #include "include/pika_rm.h" #include "include/pika_server.h" -extern std::unique_ptr g_pika_conf; +using pstd::Status; + extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; @@ -139,7 +140,7 @@ pstd::Status PikaReplServer::Write(const std::string& ip, const int port, const } int fd = client_conn_map_[ip_port]; std::shared_ptr conn = std::dynamic_pointer_cast(pika_repl_server_thread_->get_conn(fd)); - if (conn == nullptr) { + if (!conn) { return Status::NotFound("The" + ip_port + " conn cannot be found"); } @@ -160,7 +161,7 @@ void PikaReplServer::UpdateClientConnMap(const std::string& ip_port, int fd) { void PikaReplServer::RemoveClientConn(int fd) { std::lock_guard l(client_conn_rwlock_); - std::map::const_iterator iter = client_conn_map_.begin(); + auto iter = client_conn_map_.begin(); while (iter != client_conn_map_.end()) { if (iter->second == fd) { iter = client_conn_map_.erase(iter); diff --git a/src/pika_repl_server_conn.cc b/src/pika_repl_server_conn.cc index e87b691a4b..a1eeb4ab6c 100644 --- a/src/pika_repl_server_conn.cc +++ b/src/pika_repl_server_conn.cc @@ -10,14 +10,15 @@ #include "include/pika_rm.h" #include "include/pika_server.h" +using pstd::Status; extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; -PikaReplServerConn::PikaReplServerConn(int fd, std::string ip_port, net::Thread* thread, void* worker_specific_data, +PikaReplServerConn::PikaReplServerConn(int fd, const std::string& ip_port, net::Thread* thread, void* worker_specific_data, net::NetMultiplexer* mpx) : PbConn(fd, ip_port, thread, mpx) {} -PikaReplServerConn::~PikaReplServerConn() {} +PikaReplServerConn::~PikaReplServerConn() = default; void PikaReplServerConn::HandleMetaSyncRequest(void* arg) { std::unique_ptr task_arg(static_cast(arg)); @@ -25,7 +26,7 @@ void PikaReplServerConn::HandleMetaSyncRequest(void* arg) { std::shared_ptr conn = task_arg->conn; InnerMessage::InnerRequest::MetaSync meta_sync_request = req->meta_sync(); - InnerMessage::Node node = meta_sync_request.node(); + const InnerMessage::Node& node = meta_sync_request.node(); std::string masterauth = meta_sync_request.has_auth() ? meta_sync_request.auth() : ""; InnerMessage::InnerResponse response; @@ -55,7 +56,7 @@ void PikaReplServerConn::HandleMetaSyncRequest(void* arg) { } std::string reply_str; - if (!response.SerializeToString(&reply_str) || conn->WriteResp(reply_str)) { + if (!response.SerializeToString(&reply_str) || (conn->WriteResp(reply_str) != 0)) { LOG(WARNING) << "Process MetaSync request serialization failed"; conn->NotifyClose(); return; @@ -69,9 +70,9 @@ void PikaReplServerConn::HandleTrySyncRequest(void* arg) { std::shared_ptr conn = task_arg->conn; InnerMessage::InnerRequest::TrySync try_sync_request = req->try_sync(); - InnerMessage::Partition partition_request = try_sync_request.partition(); - InnerMessage::BinlogOffset slave_boffset = try_sync_request.binlog_offset(); - InnerMessage::Node node = try_sync_request.node(); + const InnerMessage::Partition& partition_request = try_sync_request.partition(); + const InnerMessage::BinlogOffset& slave_boffset = try_sync_request.binlog_offset(); + const InnerMessage::Node& node = try_sync_request.node(); std::string table_name = partition_request.table_name(); uint32_t partition_id = partition_request.partition_id(); std::string partition_name; @@ -128,7 +129,7 @@ void PikaReplServerConn::HandleTrySyncRequest(void* arg) { } std::string reply_str; - if (!response.SerializeToString(&reply_str) || conn->WriteResp(reply_str)) { + if (!response.SerializeToString(&reply_str) || (conn->WriteResp(reply_str) != 0)) { LOG(WARNING) << "Handle Try Sync Failed"; conn->NotifyClose(); return; @@ -140,7 +141,7 @@ bool PikaReplServerConn::TrySyncUpdateSlaveNode(const std::shared_ptr& conn, InnerMessage::InnerResponse::TrySync* try_sync_response) { - InnerMessage::Node node = try_sync_request.node(); + const InnerMessage::Node& node = try_sync_request.node(); std::string partition_name = partition->PartitionName(); if (!partition->CheckSlaveNodeExist(node.ip(), node.port())) { @@ -204,17 +205,14 @@ bool PikaReplServerConn::TrySyncConsensusOffsetCheck(const std::shared_ptrset_reply_code(InnerMessage::InnerResponse::TrySync::kOk); uint32_t term = partition->ConsensusTerm(); BuildConsensusMeta(reject, hints, term, response); - if (reject) { - return false; - } - return true; + return !reject; } bool PikaReplServerConn::TrySyncOffsetCheck(const std::shared_ptr& partition, const InnerMessage::InnerRequest::TrySync& try_sync_request, InnerMessage::InnerResponse::TrySync* try_sync_response) { - InnerMessage::Node node = try_sync_request.node(); - InnerMessage::BinlogOffset slave_boffset = try_sync_request.binlog_offset(); + const InnerMessage::Node& node = try_sync_request.node(); + const InnerMessage::BinlogOffset& slave_boffset = try_sync_request.binlog_offset(); std::string partition_name = partition->PartitionName(); BinlogOffset boffset; @@ -266,7 +264,7 @@ void PikaReplServerConn::BuildConsensusMeta(const bool& reject, const std::vecto if (!reject) { return; } - for (auto hint : hints) { + for (const auto& hint : hints) { InnerMessage::BinlogOffset* offset = consensus_meta->add_hint(); offset->set_filenum(hint.b_offset.filenum); offset->set_offset(hint.b_offset.offset); @@ -281,9 +279,9 @@ void PikaReplServerConn::HandleDBSyncRequest(void* arg) { std::shared_ptr conn = task_arg->conn; InnerMessage::InnerRequest::DBSync db_sync_request = req->db_sync(); - InnerMessage::Partition partition_request = db_sync_request.partition(); - InnerMessage::Node node = db_sync_request.node(); - InnerMessage::BinlogOffset slave_boffset = db_sync_request.binlog_offset(); + const InnerMessage::Partition& partition_request = db_sync_request.partition(); + const InnerMessage::Node& node = db_sync_request.node(); + const InnerMessage::BinlogOffset& slave_boffset = db_sync_request.binlog_offset(); std::string table_name = partition_request.table_name(); uint32_t partition_id = partition_request.partition_id(); std::string partition_name = table_name + "_" + std::to_string(partition_id); @@ -345,7 +343,7 @@ void PikaReplServerConn::HandleDBSyncRequest(void* arg) { g_pika_server->TryDBSync(node.ip(), node.port() + kPortShiftRSync, table_name, partition_id, slave_boffset.filenum()); std::string reply_str; - if (!response.SerializeToString(&reply_str) || conn->WriteResp(reply_str)) { + if (!response.SerializeToString(&reply_str) || (conn->WriteResp(reply_str) != 0)) { LOG(WARNING) << "Handle DBSync Failed"; conn->NotifyClose(); return; @@ -445,14 +443,13 @@ void PikaReplServerConn::HandleBinlogSyncRequest(void* arg) { } g_pika_server->SignalAuxiliary(); - return; } void PikaReplServerConn::HandleRemoveSlaveNodeRequest(void* arg) { std::unique_ptr task_arg(static_cast(arg)); const std::shared_ptr req = task_arg->req; std::shared_ptr conn = task_arg->conn; - if (!req->remove_slave_node_size()) { + if (req->remove_slave_node_size() == 0) { LOG(WARNING) << "Pb parse error"; conn->NotifyClose(); return; @@ -482,7 +479,7 @@ void PikaReplServerConn::HandleRemoveSlaveNodeRequest(void* arg) { node_response->set_port(g_pika_server->port()); std::string reply_str; - if (!response.SerializeToString(&reply_str) || conn->WriteResp(reply_str)) { + if (!response.SerializeToString(&reply_str) || (conn->WriteResp(reply_str) != 0)) { LOG(WARNING) << "Remove Slave Node Failed"; conn->NotifyClose(); return; @@ -499,31 +496,31 @@ int PikaReplServerConn::DealMessage() { } switch (req->type()) { case InnerMessage::kMetaSync: { - ReplServerTaskArg* task_arg = + auto task_arg = new ReplServerTaskArg(req, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplServerBGTask(&PikaReplServerConn::HandleMetaSyncRequest, task_arg); break; } case InnerMessage::kTrySync: { - ReplServerTaskArg* task_arg = + auto task_arg = new ReplServerTaskArg(req, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplServerBGTask(&PikaReplServerConn::HandleTrySyncRequest, task_arg); break; } case InnerMessage::kDBSync: { - ReplServerTaskArg* task_arg = + auto task_arg = new ReplServerTaskArg(req, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplServerBGTask(&PikaReplServerConn::HandleDBSyncRequest, task_arg); break; } case InnerMessage::kBinlogSync: { - ReplServerTaskArg* task_arg = + auto task_arg = new ReplServerTaskArg(req, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplServerBGTask(&PikaReplServerConn::HandleBinlogSyncRequest, task_arg); break; } case InnerMessage::kRemoveSlaveNode: { - ReplServerTaskArg* task_arg = + auto task_arg = new ReplServerTaskArg(req, std::dynamic_pointer_cast(shared_from_this())); g_pika_rm->ScheduleReplServerBGTask(&PikaReplServerConn::HandleRemoveSlaveNodeRequest, task_arg); break; diff --git a/src/pika_repl_server_thread.cc b/src/pika_repl_server_thread.cc index bffe6d9bfd..590ba02f7f 100644 --- a/src/pika_repl_server_thread.cc +++ b/src/pika_repl_server_thread.cc @@ -14,8 +14,7 @@ extern std::unique_ptr g_pika_rm; PikaReplServerThread::PikaReplServerThread(const std::set& ips, int port, int cron_interval) : HolyThread(ips, port, &conn_factory_, cron_interval, &handle_, true), conn_factory_(this), - port_(port), - serial_(0) { + port_(port) { set_keepalive_timeout(180); } diff --git a/src/pika_rm.cc b/src/pika_rm.cc index cdcf3cd2ab..97b1adf383 100644 --- a/src/pika_rm.cc +++ b/src/pika_rm.cc @@ -10,6 +10,8 @@ #include #include +#include + #include "net/include/net_cli.h" #include "include/pika_conf.h" @@ -18,7 +20,8 @@ #include "include/pika_admin.h" #include "include/pika_command.h" -extern std::unique_ptr g_pika_conf; +using pstd::Status; + extern std::unique_ptr g_pika_rm; extern PikaServer* g_pika_server; @@ -34,16 +37,13 @@ std::string SyncPartition::PartitionName() { /* SyncMasterPartition*/ SyncMasterPartition::SyncMasterPartition(const std::string& table_name, uint32_t partition_id) - : SyncPartition(table_name, partition_id), session_id_(0), coordinator_(table_name, partition_id) {} + : SyncPartition(table_name, partition_id), coordinator_(table_name, partition_id) {} int SyncMasterPartition::GetNumberOfSlaveNode() { return coordinator_.SyncPros().SlaveSize(); } bool SyncMasterPartition::CheckSlaveNodeExist(const std::string& ip, int port) { std::shared_ptr slave_ptr = GetSlaveNode(ip, port); - if (!slave_ptr) { - return false; - } - return true; + return static_cast(slave_ptr); } Status SyncMasterPartition::GetSlaveNodeSession(const std::string& ip, int port, int32_t* session) { @@ -139,7 +139,7 @@ Status SyncMasterPartition::ActivateSlaveDbSync(const std::string& ip, int port) Status SyncMasterPartition::ReadBinlogFileToWq(const std::shared_ptr& slave_ptr) { int cnt = slave_ptr->sync_win.Remaining(); std::shared_ptr reader = slave_ptr->binlog_reader; - if (reader == nullptr) { + if (!reader) { return Status::OK(); } std::vector tasks; @@ -195,7 +195,7 @@ Status SyncMasterPartition::ConsensusUpdateSlave(const std::string& ip, int port Status SyncMasterPartition::ConsensusUpdateAppliedIndex(const LogOffset& offset) { std::shared_ptr context = coordinator_.context(); - if (context == nullptr) { + if (!context) { LOG(WARNING) << "Coordinator context empty."; return Status::NotFound("context"); } @@ -366,7 +366,7 @@ Status SyncMasterPartition::CheckSyncTimeout(uint64_t now) { std::shared_ptr slave_ptr = slave_iter.second; std::lock_guard l(slave_ptr->slave_mu); if (slave_ptr->LastRecvTime() + kRecvKeepAliveTimeout < now) { - to_del.push_back(Node(slave_ptr->Ip(), slave_ptr->Port())); + to_del.emplace_back(slave_ptr->Ip(), slave_ptr->Port()); } else if (slave_ptr->LastSendTime() + kSendKeepAliveTimeout < now && slave_ptr->sent_offset == slave_ptr->acked_offset) { std::vector task; @@ -399,7 +399,7 @@ std::string SyncMasterPartition::ToStringStatus() { << coordinator_.ToStringStatus(); std::unordered_map> slaves = GetAllSlaveNodes(); int i = 0; - for (auto slave_iter : slaves) { + for (const auto& slave_iter : slaves) { std::shared_ptr slave_ptr = slave_iter.second; std::lock_guard l(slave_ptr->slave_mu); tmp_stream << " slave[" << i << "]: " << slave_ptr->ToString() << "\r\n" << slave_ptr->ToStringStatus(); @@ -410,7 +410,7 @@ std::string SyncMasterPartition::ToStringStatus() { void SyncMasterPartition::GetValidSlaveNames(std::vector* slavenames) { std::unordered_map> slaves = GetAllSlaveNodes(); - for (auto slave_iter : slaves) { + for (const auto& slave_iter : slaves) { std::shared_ptr slave_ptr = slave_iter.second; std::lock_guard l(slave_ptr->slave_mu); if (slave_ptr->slave_state != kSlaveBinlogSync) { @@ -429,7 +429,7 @@ Status SyncMasterPartition::GetInfo(std::string* info) { << "\r\n"; tmp_stream << " connected_slaves: " << slaves.size() << "\r\n"; int i = 0; - for (auto slave_iter : slaves) { + for (const auto& slave_iter : slaves) { std::shared_ptr slave_ptr = slave_iter.second; std::lock_guard l(slave_ptr->slave_mu); tmp_stream << " slave[" << i++ << "]: " << slave_ptr->Ip() << ":" << std::to_string(slave_ptr->Port()) << "\r\n"; @@ -473,14 +473,14 @@ bool SyncMasterPartition::CheckSessionId(const std::string& ip, int port, const return true; } -Status SyncMasterPartition::ConsensusProposeLog(std::shared_ptr cmd_ptr, std::shared_ptr conn_ptr, +Status SyncMasterPartition::ConsensusProposeLog(const std::shared_ptr& cmd_ptr, std::shared_ptr conn_ptr, std::shared_ptr resp_ptr) { - return coordinator_.ProposeLog(cmd_ptr, conn_ptr, resp_ptr); + return coordinator_.ProposeLog(cmd_ptr, std::move(conn_ptr), std::move(resp_ptr)); } Status SyncMasterPartition::ConsensusSanityCheck() { return coordinator_.CheckEnoughFollower(); } -Status SyncMasterPartition::ConsensusProcessLeaderLog(std::shared_ptr cmd_ptr, const BinlogItem& attribute) { +Status SyncMasterPartition::ConsensusProcessLeaderLog(const std::shared_ptr& cmd_ptr, const BinlogItem& attribute) { return coordinator_.ProcessLeaderLog(cmd_ptr, attribute); } @@ -496,7 +496,7 @@ uint32_t SyncMasterPartition::ConsensusTerm() { return coordinator_.term(); } void SyncMasterPartition::ConsensusUpdateTerm(uint32_t term) { coordinator_.UpdateTerm(term); - if (g_pika_server->role() & PIKA_ROLE_MASTER) { + if ((g_pika_server->role() & PIKA_ROLE_MASTER) != 0) { CommitPreviousLogs(term); } } @@ -529,11 +529,11 @@ Status SyncMasterPartition::ConsensusFollowerNegotiate(const std::vector res, + const std::shared_ptr& res, std::shared_ptr conn, void* res_private_data) { - pika_repl_client_->ScheduleWriteBinlogTask(table_partition, res, conn, res_private_data); + pika_repl_client_->ScheduleWriteBinlogTask(table_partition, res, std::move(conn), res_private_data); } -void PikaReplicaManager::ScheduleWriteDBTask(const std::shared_ptr cmd_ptr, const LogOffset& offset, +void PikaReplicaManager::ScheduleWriteDBTask(const std::shared_ptr& cmd_ptr, const LogOffset& offset, const std::string& table_name, uint32_t partition_id) { pika_repl_client_->ScheduleWriteDBTask(cmd_ptr, offset, table_name, partition_id); } @@ -798,14 +798,14 @@ void PikaReplicaManager::ReplServerUpdateClientConnMap(const std::string& ip_por pika_repl_server_->UpdateClientConnMap(ip_port, fd); } -Status PikaReplicaManager::UpdateSyncBinlogStatus(const RmNode& slave, const LogOffset& range_start, - const LogOffset& range_end) { +Status PikaReplicaManager::UpdateSyncBinlogStatus(const RmNode& slave, const LogOffset& offset_start, + const LogOffset& offset_end) { std::shared_lock l(partitions_rw_); if (sync_master_partitions_.find(slave.NodePartitionInfo()) == sync_master_partitions_.end()) { return Status::NotFound(slave.ToString() + " not found"); } std::shared_ptr partition = sync_master_partitions_[slave.NodePartitionInfo()]; - Status s = partition->ConsensusUpdateSlave(slave.Ip(), slave.Port(), range_start, range_end); + Status s = partition->ConsensusUpdateSlave(slave.Ip(), slave.Port(), offset_start, offset_end); if (!s.ok()) { return s; } @@ -818,7 +818,7 @@ Status PikaReplicaManager::UpdateSyncBinlogStatus(const RmNode& slave, const Log bool PikaReplicaManager::CheckSlavePartitionState(const std::string& ip, const int port) { std::shared_ptr partition = nullptr; - for (auto iter : g_pika_rm->sync_slave_partitions_) { + for (const auto& iter : g_pika_rm->sync_slave_partitions_) { partition = iter.second; if (partition->State() == ReplState::kDBNoConnect && partition->MasterIp() == ip && partition->MasterPort() + kPortShiftReplServer == port) { @@ -911,10 +911,10 @@ Status PikaReplicaManager::GetPartitionInfo(const std::string& table, uint32_t p return s; } - bool add_divider_line = ((role & PIKA_ROLE_MASTER) && (role & PIKA_ROLE_SLAVE)); + bool add_divider_line = (((role & PIKA_ROLE_MASTER) != 0) && ((role & PIKA_ROLE_SLAVE) != 0)); std::shared_lock l(partitions_rw_); PartitionInfo p_info(table, partition_id); - if (role & PIKA_ROLE_MASTER) { + if ((role & PIKA_ROLE_MASTER) != 0) { if (sync_master_partitions_.find(p_info) == sync_master_partitions_.end()) { return Status::NotFound(table + std::to_string(partition_id) + " not found"); } @@ -926,7 +926,7 @@ Status PikaReplicaManager::GetPartitionInfo(const std::string& table, uint32_t p if (add_divider_line) { info->append(" -----------\r\n"); } - if (role & PIKA_ROLE_SLAVE) { + if ((role & PIKA_ROLE_SLAVE) != 0) { if (sync_slave_partitions_.find(p_info) == sync_slave_partitions_.end()) { return Status::NotFound(table + std::to_string(partition_id) + " not found"); } @@ -946,7 +946,7 @@ Status PikaReplicaManager::SelectLocalIp(const std::string& remote_ip, const int if ((cli->Connect(remote_ip, remote_port, "")).ok()) { struct sockaddr_in laddr; socklen_t llen = sizeof(laddr); - getsockname(cli->fd(), (struct sockaddr*)&laddr, &llen); + getsockname(cli->fd(), reinterpret_cast(&laddr), &llen); std::string tmp_ip(inet_ntoa(laddr.sin_addr)); *local_ip = tmp_ip; cli->Close(); @@ -988,7 +988,7 @@ Status PikaReplicaManager::DeactivateSyncSlavePartition(const PartitionInfo& p_i Status PikaReplicaManager::SendMetaSyncRequest() { Status s; if (time(nullptr) - g_pika_server->GetMetaSyncTimestamp() >= PIKA_META_SYNC_MAX_WAIT_TIME || - g_pika_server->IsFirstMetaSync() == true) { + g_pika_server->IsFirstMetaSync()) { s = pika_repl_client_->SendMetaSync(); if (s.ok()) { g_pika_server->UpdateMetaSyncTimestamp(); @@ -1241,7 +1241,7 @@ Status PikaReplicaManager::DelSyncTable(const std::string& table_name) { } std::string table_log_path = g_pika_conf->log_path() + "log_" + table_name; std::string table_log_path_tmp = table_log_path + "_deleting/"; - if (pstd::RenameFile(table_log_path, table_log_path_tmp)) { + if (pstd::RenameFile(table_log_path, table_log_path_tmp) != 0) { LOG(WARNING) << "Failed to move log to trash, error: " << strerror(errno); return Status::Corruption("Failed to move log to trash"); } @@ -1263,7 +1263,7 @@ void PikaReplicaManager::FindCompleteReplica(std::vector* replica) replica_slotnum[name]++; } } - for (auto item : replica_slotnum) { + for (const auto& item : replica_slotnum) { if (item.second == sync_master_partitions_.size()) { replica->push_back(item.first); } diff --git a/src/pika_rsync_service.cc b/src/pika_rsync_service.cc index f203700a3c..5f1d8c0e6b 100644 --- a/src/pika_rsync_service.cc +++ b/src/pika_rsync_service.cc @@ -7,6 +7,7 @@ #include #include +#include #include "pstd/include/env.h" #include "pstd/include/rsync.h" @@ -42,12 +43,12 @@ int PikaRsyncService::StartRsync() { auth = g_pika_conf->masterauth(); } ret = pstd::StartRsync(raw_path_, kDBSyncModule, "0.0.0.0", port_, auth); - if (ret != 0) { + if (ret) { LOG(WARNING) << "Failed to start rsync, path:" << raw_path_ << " error : " << ret; return -1; } ret = CreateSecretFile(); - if (ret != 0) { + if (ret) { LOG(WARNING) << "Failed to create secret file"; return -1; } diff --git a/src/pika_server.cc b/src/pika_server.cc index 92ea28c808..c0351e3511 100644 --- a/src/pika_server.cc +++ b/src/pika_server.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include "net/include/bg_thread.h" #include "net/include/net_cli.h" @@ -23,8 +24,8 @@ #include "include/pika_cmd_table_manager.h" #include "include/pika_dispatch_thread.h" #include "include/pika_rm.h" -#include "include/pika_server.h" +using pstd::Status; extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; extern std::unique_ptr g_pika_cmd_table_manager; @@ -45,18 +46,9 @@ void DoDBSync(void* arg) { PikaServer::PikaServer() : exit_(false), slot_state_(INFREE), - have_scheduled_crontask_(false), last_check_compact_time_({0, 0}), - master_ip_(""), - master_port_(0), repl_state_(PIKA_REPL_NO_CONNECT), - role_(PIKA_ROLE_SINGLE), - leader_protected_mode_(false), - last_meta_sync_timestamp_(0), - first_meta_sync_(false), - loop_partition_state_machine_(false), - force_full_sync_(false), - slowlog_entry_id_(0) { + role_(PIKA_ROLE_SINGLE) { // Init server ip host if (!ServerInit()) { LOG(FATAL) << "ServerInit iotcl error"; @@ -93,7 +85,7 @@ PikaServer::~PikaServer() { { std::lock_guard l(slave_mutex_); - std::vector::iterator iter = slaves_.begin(); + auto iter = slaves_.begin(); while (iter != slaves_.end()) { iter = slaves_.erase(iter); LOG(INFO) << "Delete slave success"; @@ -172,7 +164,7 @@ void PikaServer::Start() { std::string slaveof = g_pika_conf->slaveof(); if (!slaveof.empty()) { - int32_t sep = slaveof.find(":"); + int32_t sep = slaveof.find(':'); std::string master_ip = slaveof.substr(0, sep); int32_t master_port = std::stoi(slaveof.substr(sep + 1)); if ((master_ip == "127.0.0.1" || master_ip == host_) && master_port == port_) { @@ -236,16 +228,13 @@ void PikaServer::CheckLeaderProtectedMode() { bool PikaServer::readonly(const std::string& table_name, const std::string& key) { std::shared_lock l(state_protector_); - if ((role_ & PIKA_ROLE_SLAVE) && g_pika_conf->slave_read_only()) { - return true; - } - return false; + return ((role_ & PIKA_ROLE_SLAVE) != 0) && g_pika_conf->slave_read_only(); } bool PikaServer::ConsensusCheck(const std::string& table_name, const std::string& key) { if (g_pika_conf->consensus_level() != 0) { std::shared_ptr
table = GetTable(table_name); - if (table == nullptr) { + if (!table) { return false; } uint32_t index = g_pika_cmd_table_manager->DistributeKey(key, table->PartitionNum()); @@ -257,11 +246,7 @@ bool PikaServer::ConsensusCheck(const std::string& table_name, const std::string return false; } Status s = master_partition->ConsensusSanityCheck(); - if (!s.ok()) { - return false; - } else { - return true; - } + return s.ok(); } return true; } @@ -331,7 +316,7 @@ void PikaServer::InitTableStruct() { } } -Status PikaServer::AddTableStruct(std::string table_name, uint32_t num) { +Status PikaServer::AddTableStruct(const std::string &table_name, uint32_t num) { std::shared_ptr
table = g_pika_server->GetTable(table_name); if (table) { return Status::Corruption("table already exist"); @@ -344,7 +329,7 @@ Status PikaServer::AddTableStruct(std::string table_name, uint32_t num) { return Status::OK(); } -Status PikaServer::DelTableStruct(std::string table_name) { +Status PikaServer::DelTableStruct(const std::string &table_name) { std::shared_ptr
table = g_pika_server->GetTable(table_name); if (!table) { return Status::Corruption("table not found"); @@ -404,7 +389,7 @@ bool PikaServer::IsCompacting() { partition_item.second->DbRWLockReader(); std::string task_type = partition_item.second->db()->GetCurrentTaskType(); partition_item.second->DbRWUnLock(); - if (strcasecmp(task_type.data(), "no")) { + if (strcasecmp(task_type.data(), "no") != 0) { return true; } } @@ -412,14 +397,14 @@ bool PikaServer::IsCompacting() { return false; } -bool PikaServer::IsTableExist(const std::string& table_name) { return GetTable(table_name) ? true : false; } +bool PikaServer::IsTableExist(const std::string& table_name) { return static_cast(GetTable(table_name)); } bool PikaServer::IsTablePartitionExist(const std::string& table_name, uint32_t partition_id) { std::shared_ptr
table_ptr = GetTable(table_name); if (!table_ptr) { return false; } else { - return table_ptr->GetPartitionById(partition_id) ? true : false; + return static_cast(table_ptr->GetPartitionById(partition_id)); } } @@ -427,7 +412,7 @@ bool PikaServer::IsCommandSupport(const std::string& command) { if (g_pika_conf->consensus_level() != 0) { // dont support multi key command // used the same list as sharding mode use - bool res = !ConsensusNotSupportCommands.count(command); + bool res = ConsensusNotSupportCommands.count(command) == 0U; if (!res) { return res; } @@ -532,10 +517,7 @@ bool PikaServer::GetTablePartitionBinlogOffset(const std::string& table_name, ui return false; } Status s = partition->Logger()->GetProducerStatus(&(boffset->filenum), &(boffset->offset)); - if (!s.ok()) { - return false; - } - return true; + return s.ok(); } // Only use in classic mode @@ -563,7 +545,7 @@ Status PikaServer::DoSameThingEveryPartition(const TaskType& type) { case TaskType::kResetReplState: { slave_partition = g_pika_rm->GetSyncSlavePartitionByName( PartitionInfo(table_item.second->GetTableName(), partition_item.second->GetPartitionId())); - if (slave_partition == nullptr) { + if (!slave_partition) { LOG(WARNING) << "Slave Partition: " << table_item.second->GetTableName() << ":" << partition_item.second->GetPartitionId() << " Not Found"; } @@ -608,7 +590,7 @@ void PikaServer::DeleteSlave(int fd) { int slave_num = -1; { std::lock_guard l(slave_mutex_); - std::vector::iterator iter = slaves_.begin(); + auto iter = slaves_.begin(); while (iter != slaves_.end()) { if (iter->conn_fd == fd) { ip = iter->ip; @@ -645,7 +627,7 @@ int32_t PikaServer::GetShardingSlaveListString(std::string& slave_list_str) { g_pika_rm->FindCompleteReplica(&complete_replica); std::stringstream tmp_stream; size_t index = 0; - for (auto replica : complete_replica) { + for (const auto& replica : complete_replica) { std::string ip; int port; if (!pstd::ParseIpPortString(replica, ip, port)) { @@ -685,7 +667,7 @@ int32_t PikaServer::GetSlaveListString(std::string& slave_list_str) { continue; } else { uint64_t lag = - (uint64_t)(master_boffset.filenum - sent_slave_boffset.filenum) * g_pika_conf->binlog_file_size() + + static_cast((master_boffset.filenum - sent_slave_boffset.filenum)) * g_pika_conf->binlog_file_size() + master_boffset.offset - sent_slave_boffset.offset; tmp_stream << "(" << partition->PartitionName() << ":" << lag << ")"; } @@ -707,7 +689,7 @@ bool PikaServer::TryAddSlave(const std::string& ip, int64_t port, int fd, std::string ip_port = pstd::IpPortString(ip, port); std::lock_guard l(slave_mutex_); - std::vector::iterator iter = slaves_.begin(); + auto iter = slaves_.begin(); while (iter != slaves_.end()) { if (iter->ip_port == ip_port) { LOG(WARNING) << "Slave Already Exist, ip_port: " << ip << ":" << port; @@ -742,7 +724,7 @@ void PikaServer::RemoveMaster() { repl_state_ = PIKA_REPL_NO_CONNECT; role_ &= ~PIKA_ROLE_SLAVE; - if (master_ip_ != "" && master_port_ != -1) { + if (!master_ip_.empty() && master_port_ != -1) { g_pika_rm->CloseReplClientConn(master_ip_, master_port_ + kPortShiftReplServer); g_pika_rm->LostConnection(master_ip_, master_port_); loop_partition_state_machine_ = false; @@ -761,7 +743,7 @@ bool PikaServer::SetMaster(std::string& master_ip, int master_port) { master_ip = host_; } std::lock_guard l(state_protector_); - if ((role_ ^ PIKA_ROLE_SLAVE) && repl_state_ == PIKA_REPL_NO_CONNECT) { + if (((role_ ^ PIKA_ROLE_SLAVE) != 0) && repl_state_ == PIKA_REPL_NO_CONNECT) { master_ip_ = master_ip; master_port_ = master_port; role_ |= PIKA_ROLE_SLAVE; @@ -789,7 +771,7 @@ bool PikaServer::MetaSyncDone() { void PikaServer::ResetMetaSyncStatus() { std::lock_guard sp_l(state_protector_); - if (role_ & PIKA_ROLE_SLAVE) { + if ((role_ & PIKA_ROLE_SLAVE) != 0) { // not change by slaveof no one, so set repl_state = PIKA_REPL_SHOULD_META_SYNC, // continue to connect master repl_state_ = PIKA_REPL_SHOULD_META_SYNC; @@ -806,7 +788,7 @@ bool PikaServer::AllPartitionConnectSuccess() { for (const auto& partition_item : table_item.second->partitions_) { slave_partition = g_pika_rm->GetSyncSlavePartitionByName( PartitionInfo(table_item.second->GetTableName(), partition_item.second->GetPartitionId())); - if (slave_partition == nullptr) { + if (!slave_partition) { LOG(WARNING) << "Slave Partition: " << table_item.second->GetTableName() << ":" << partition_item.second->GetPartitionId() << ", NotFound"; return false; @@ -877,7 +859,7 @@ void PikaServer::PurgelogsTaskSchedule(net::TaskFunc func, void* arg) { } void PikaServer::PurgeDir(const std::string& path) { - std::string* dir_path = new std::string(path); + auto dir_path = new std::string(path); PurgeDirTaskSchedule(&DoPurgeDir, static_cast(dir_path)); } @@ -898,7 +880,7 @@ void PikaServer::DBSync(const std::string& ip, int port, const std::string& tabl // Reuse the bgsave_thread_ // Since we expect BgSave and DBSync execute serially bgsave_thread_.StartThread(); - DBSyncArg* arg = new DBSyncArg(this, ip, port, table_name, partition_id); + auto arg = new DBSyncArg(this, ip, port, table_name, partition_id); bgsave_thread_.Schedule(&DoDBSync, reinterpret_cast(arg)); } @@ -948,7 +930,7 @@ void PikaServer::DbSyncSendFile(const std::string& ip, int port, const std::stri int ret = 0; LOG(INFO) << "Partition: " << partition->GetPartitionName() << " Start Send files in " << bg_path << " to " << ip; ret = pstd::GetChildren(bg_path, descendant); - if (ret != 0) { + if (ret) { std::string ip_port = pstd::IpPortString(ip, port); std::lock_guard ldb(db_sync_protector_); db_sync_slaves_.erase(ip_port); @@ -957,9 +939,10 @@ void PikaServer::DbSyncSendFile(const std::string& ip, int port, const std::stri return; } - std::string local_path, target_path; - std::string remote_path = table_name; - std::vector::const_iterator iter = descendant.begin(); + std::string local_path; + std::string target_path; + const std::string& remote_path = table_name; + auto iter = descendant.begin(); pstd::RsyncRemote remote(ip, port, kDBSyncModule, g_pika_conf->db_sync_speed() * 1024); std::string secret_file_path = g_pika_conf->db_sync_path(); if (g_pika_conf->db_sync_path().back() != '/') { @@ -1000,7 +983,7 @@ void PikaServer::DbSyncSendFile(const std::string& ip, int port, const std::stri if (cli->Connect(ip, port, "").ok()) { struct sockaddr_in laddr; socklen_t llen = sizeof(laddr); - getsockname(cli->fd(), (struct sockaddr*)&laddr, &llen); + getsockname(cli->fd(), reinterpret_cast(&laddr), &llen); lip = inet_ntoa(laddr.sin_addr); cli->Close(); } else { @@ -1011,7 +994,7 @@ void PikaServer::DbSyncSendFile(const std::string& ip, int port, const std::stri // Send info file at last if (0 == ret) { // need to modify the IP addr in the info file - if (lip.compare(host_)) { + if (lip != host_) { std::ofstream fix; std::string fn = bg_path + "/" + kBgsaveInfoFile + "." + std::to_string(time(nullptr)); fix.open(fn, std::ios::in | std::ios::trunc); @@ -1024,7 +1007,7 @@ void PikaServer::DbSyncSendFile(const std::string& ip, int port, const std::stri } ret = pstd::RsyncSendFile(fn, remote_path + "/" + kBgsaveInfoFile, secret_file_path, remote); pstd::DeleteFile(fn); - if (ret != 0) { + if (ret) { LOG(WARNING) << "Partition: " << partition->GetPartitionName() << " Send Modified Info File Failed"; } } else if (0 != (ret = pstd::RsyncSendFile(bg_path + "/" + kBgsaveInfoFile, remote_path + "/" + kBgsaveInfoFile, @@ -1128,8 +1111,8 @@ uint32_t PikaServer::SlowlogLen() { void PikaServer::SlowlogObtain(int64_t number, std::vector* slowlogs) { std::shared_lock l(slowlog_protector_); slowlogs->clear(); - std::list::const_iterator iter = slowlog_list_.begin(); - while (number-- && iter != slowlog_list_.end()) { + auto iter = slowlog_list_.begin(); + while (((number--) != 0) && iter != slowlog_list_.end()) { slowlogs->push_back(*iter); iter++; } @@ -1225,13 +1208,13 @@ void PikaServer::EnablePublish(int fd) { pika_pubsub_thread_->UpdateConnReadyState(fd, net::PubSubThread::ReadyState::kReady); } -int PikaServer::UnSubscribe(std::shared_ptr conn, const std::vector& channels, bool pattern, +int PikaServer::UnSubscribe(const std::shared_ptr &conn, const std::vector& channels, bool pattern, std::vector>* result) { int subscribed = pika_pubsub_thread_->UnSubscribe(conn, channels, pattern, result); return subscribed; } -void PikaServer::Subscribe(std::shared_ptr conn, const std::vector& channels, bool pattern, +void PikaServer::Subscribe(const std::shared_ptr &conn, const std::vector& channels, bool pattern, std::vector>* result) { pika_pubsub_thread_->Subscribe(conn, channels, pattern, result); } @@ -1273,15 +1256,15 @@ void PikaServer::AutoCompactRange() { std::string ci = g_pika_conf->compact_interval(); std::string cc = g_pika_conf->compact_cron(); - if (ci != "") { - std::string::size_type slash = ci.find("/"); + if (!ci.empty()) { + std::string::size_type slash = ci.find('/'); int interval = std::atoi(ci.substr(0, slash).c_str()); int usage = std::atoi(ci.substr(slash + 1).c_str()); struct timeval now; gettimeofday(&now, nullptr); if (last_check_compact_time_.tv_sec == 0 || now.tv_sec - last_check_compact_time_.tv_sec >= interval * 3600) { gettimeofday(&last_check_compact_time_, nullptr); - if (((double)free_size / total_size) * 100 >= usage) { + if ((static_cast(free_size) / total_size) * 100 >= usage) { Status s = DoSameThingSpecificTable(TaskType::kCompactAll); if (s.ok()) { LOG(INFO) << "[Interval]schedule compactRange, freesize: " << free_size / 1048576 @@ -1298,21 +1281,22 @@ void PikaServer::AutoCompactRange() { return; } - if (cc != "") { + if (!cc.empty()) { bool have_week = false; - std::string compact_cron, week_str; + std::string compact_cron; + std::string week_str; int slash_num = count(cc.begin(), cc.end(), '/'); if (slash_num == 2) { have_week = true; - std::string::size_type first_slash = cc.find("/"); + std::string::size_type first_slash = cc.find('/'); week_str = cc.substr(0, first_slash); compact_cron = cc.substr(first_slash + 1); } else { compact_cron = cc; } - std::string::size_type colon = compact_cron.find("-"); - std::string::size_type underline = compact_cron.find("/"); + std::string::size_type colon = compact_cron.find('-'); + std::string::size_type underline = compact_cron.find('/'); int week = have_week ? (std::atoi(week_str.c_str()) % 7) : 0; int start = std::atoi(compact_cron.substr(0, colon).c_str()); int end = std::atoi(compact_cron.substr(colon + 1, underline).c_str()); @@ -1325,13 +1309,13 @@ void PikaServer::AutoCompactRange() { in_window = have_week ? (week == t_m->tm_wday) : true; } else if (start > end && ((t_m->tm_hour >= start && t_m->tm_hour < 24) || (t_m->tm_hour >= 0 && t_m->tm_hour < end))) { - in_window = have_week ? false : true; + in_window = !have_week; } else { have_scheduled_crontask_ = false; } if (!have_scheduled_crontask_ && in_window) { - if (((double)free_size / total_size) * 100 >= usage) { + if ((static_cast(free_size) / total_size) * 100 >= usage) { Status s = DoSameThingEveryPartition(TaskType::kCompactAll); if (s.ok()) { LOG(INFO) << "[Cron]schedule compactRange, freesize: " << free_size / 1048576 @@ -1372,13 +1356,13 @@ void PikaServer::AutoDeleteExpiredDump() { return; } // Handle dump directory - for (size_t i = 0; i < dump_dir.size(); i++) { - if (dump_dir[i].substr(0, db_sync_prefix.size()) != db_sync_prefix || - dump_dir[i].size() != (db_sync_prefix.size() + 8)) { + for (auto & i : dump_dir) { + if (i.substr(0, db_sync_prefix.size()) != db_sync_prefix || + i.size() != (db_sync_prefix.size() + 8)) { continue; } - std::string str_date = dump_dir[i].substr(db_sync_prefix.size(), (dump_dir[i].size() - db_sync_prefix.size())); + std::string str_date = i.substr(db_sync_prefix.size(), (i.size() - db_sync_prefix.size())); char* end = nullptr; std::strtol(str_date.c_str(), &end, 10); if (*end != 0) { @@ -1396,7 +1380,8 @@ void PikaServer::AutoDeleteExpiredDump() { int now_month = now->tm_mon + 1; int now_day = now->tm_mday; - struct tm dump_time, now_time; + struct tm dump_time; + struct tm now_time; dump_time.tm_year = dump_year; dump_time.tm_mon = dump_month; @@ -1418,7 +1403,7 @@ void PikaServer::AutoDeleteExpiredDump() { int interval_days = (now_timestamp - dump_timestamp) / 86400; if (interval_days >= expiry_days) { - std::string dump_file = db_sync_path + dump_dir[i]; + std::string dump_file = db_sync_path + i; if (CountSyncSlaves() == 0) { LOG(INFO) << "Not syncing, delete dump file: " << dump_file; pstd::DeleteDirIfExist(dump_file); @@ -1447,8 +1432,8 @@ void PikaServer::InitStorageOptions() { storage_options_.options.write_buffer_size = g_pika_conf->write_buffer_size(); storage_options_.options.arena_block_size = g_pika_conf->arena_block_size(); - storage_options_.options.write_buffer_manager.reset( - new rocksdb::WriteBufferManager(g_pika_conf->max_write_buffer_size())); + storage_options_.options.write_buffer_manager = + std::make_shared(g_pika_conf->max_write_buffer_size()); storage_options_.options.max_write_buffer_number = g_pika_conf->max_write_buffer_number(); storage_options_.options.target_file_size_base = g_pika_conf->target_file_size_base(); storage_options_.options.max_background_flushes = g_pika_conf->max_background_flushes(); @@ -1525,7 +1510,9 @@ storage::Status PikaServer::RewriteStorageOptions(const storage::OptionType& opt partition_item.second->DbRWLockWriter(); s = partition_item.second->db()->SetOptions(option_type, storage::ALL_DB, options_map); partition_item.second->DbRWUnLock(); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } } std::lock_guard rwl(storage_options_rw_); diff --git a/src/pika_set.cc b/src/pika_set.cc index ab2c7d8255..ec2d2b9b02 100644 --- a/src/pika_set.cc +++ b/src/pika_set.cc @@ -13,11 +13,10 @@ void SAddCmd::DoInitial() { return; } key_ = argv_[1]; - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); iter++; iter++; members_.assign(iter, argv_.end()); - return; } void SAddCmd::Do(std::shared_ptr partition) { @@ -28,12 +27,12 @@ void SAddCmd::Do(std::shared_ptr partition) { return; } res_.AppendInteger(count); - return; } void SPopCmd::DoInitial() { - size_t argc = argv_.size(), index = 2; + size_t argc = argv_.size(); + size_t index = 2; if (!CheckArg(argc)) { res_.SetRes(CmdRes::kWrongNum, kCmdNameSPop); return; @@ -43,7 +42,7 @@ void SPopCmd::DoInitial() { count_ = 1; if (index < argc) { - if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &count_)) { + if (pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) == 0) { res_.SetRes(CmdRes::kErrOther, kCmdNameSPop); return; } @@ -52,8 +51,6 @@ void SPopCmd::DoInitial() { return; } } - - return; } void SPopCmd::Do(std::shared_ptr partition) { @@ -70,7 +67,6 @@ void SPopCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void SCardCmd::DoInitial() { @@ -79,7 +75,6 @@ void SCardCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void SCardCmd::Do(std::shared_ptr partition) { @@ -90,7 +85,6 @@ void SCardCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "scard error"); } - return; } void SMembersCmd::DoInitial() { @@ -99,7 +93,6 @@ void SMembersCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void SMembersCmd::Do(std::shared_ptr partition) { @@ -114,7 +107,6 @@ void SMembersCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void SScanCmd::DoInitial() { @@ -123,22 +115,23 @@ void SScanCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &cursor_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &cursor_) == 0) { res_.SetRes(CmdRes::kWrongNum, kCmdNameSScan); return; } - size_t argc = argv_.size(), index = 3; + size_t argc = argv_.size(); + size_t index = 3; while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "count")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "count") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &count_)) { + } else if (pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -152,7 +145,6 @@ void SScanCmd::DoInitial() { res_.SetRes(CmdRes::kSyntaxErr); return; } - return; } void SScanCmd::Do(std::shared_ptr partition) { @@ -174,7 +166,6 @@ void SScanCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void SRemCmd::DoInitial() { @@ -183,17 +174,15 @@ void SRemCmd::DoInitial() { return; } key_ = argv_[1]; - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); iter++; members_.assign(++iter, argv_.end()); - return; } void SRemCmd::Do(std::shared_ptr partition) { int32_t count = 0; rocksdb::Status s = partition->db()->SRem(key_, members_, &count); res_.AppendInteger(count); - return; } void SUnionCmd::DoInitial() { @@ -201,9 +190,8 @@ void SUnionCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNameSUnion); return; } - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); keys_.assign(++iter, argv_.end()); - return; } void SUnionCmd::Do(std::shared_ptr partition) { @@ -214,7 +202,6 @@ void SUnionCmd::Do(std::shared_ptr partition) { res_.AppendStringLen(member.size()); res_.AppendContent(member); } - return; } void SUnionstoreCmd::DoInitial() { @@ -223,10 +210,9 @@ void SUnionstoreCmd::DoInitial() { return; } dest_key_ = argv_[1]; - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); iter++; keys_.assign(++iter, argv_.end()); - return; } void SUnionstoreCmd::Do(std::shared_ptr partition) { @@ -237,7 +223,6 @@ void SUnionstoreCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void SInterCmd::DoInitial() { @@ -245,9 +230,8 @@ void SInterCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNameSInter); return; } - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); keys_.assign(++iter, argv_.end()); - return; } void SInterCmd::Do(std::shared_ptr partition) { @@ -258,7 +242,6 @@ void SInterCmd::Do(std::shared_ptr partition) { res_.AppendStringLen(member.size()); res_.AppendContent(member); } - return; } void SInterstoreCmd::DoInitial() { @@ -267,10 +250,9 @@ void SInterstoreCmd::DoInitial() { return; } dest_key_ = argv_[1]; - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); iter++; keys_.assign(++iter, argv_.end()); - return; } void SInterstoreCmd::Do(std::shared_ptr partition) { @@ -281,7 +263,6 @@ void SInterstoreCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void SIsmemberCmd::DoInitial() { @@ -291,13 +272,12 @@ void SIsmemberCmd::DoInitial() { } key_ = argv_[1]; member_ = argv_[2]; - return; } void SIsmemberCmd::Do(std::shared_ptr partition) { int32_t is_member = 0; partition->db()->SIsmember(key_, member_, &is_member); - if (is_member) { + if (is_member != 0) { res_.AppendContent(":1"); } else { res_.AppendContent(":0"); @@ -309,9 +289,8 @@ void SDiffCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNameSDiff); return; } - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); keys_.assign(++iter, argv_.end()); - return; } void SDiffCmd::Do(std::shared_ptr partition) { @@ -322,7 +301,6 @@ void SDiffCmd::Do(std::shared_ptr partition) { res_.AppendStringLen(member.size()); res_.AppendContent(member); } - return; } void SDiffstoreCmd::DoInitial() { @@ -331,10 +309,9 @@ void SDiffstoreCmd::DoInitial() { return; } dest_key_ = argv_[1]; - PikaCmdArgsType::iterator iter = argv_.begin(); + auto iter = argv_.begin(); iter++; keys_.assign(++iter, argv_.end()); - return; } void SDiffstoreCmd::Do(std::shared_ptr partition) { @@ -355,7 +332,6 @@ void SMoveCmd::DoInitial() { src_key_ = argv_[1]; dest_key_ = argv_[2]; member_ = argv_[3]; - return; } void SMoveCmd::Do(std::shared_ptr partition) { @@ -366,7 +342,6 @@ void SMoveCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void SRandmemberCmd::DoInitial() { @@ -379,21 +354,20 @@ void SRandmemberCmd::DoInitial() { res_.SetRes(CmdRes::kWrongNum, kCmdNameSRandmember); return; } else if (argv_.size() == 3) { - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &count_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &count_) == 0) { res_.SetRes(CmdRes::kInvalidInt); } else { reply_arr = true; ; } } - return; } void SRandmemberCmd::Do(std::shared_ptr partition) { std::vector members; rocksdb::Status s = partition->db()->SRandmember(key_, count_, &members); if (s.ok() || s.IsNotFound()) { - if (!reply_arr && members.size()) { + if (!reply_arr && (static_cast(!members.empty()) != 0U)) { res_.AppendStringLen(members[0].size()); res_.AppendContent(members[0]); } else { @@ -406,5 +380,4 @@ void SRandmemberCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } diff --git a/src/pika_slave_node.cc b/src/pika_slave_node.cc index 00ee3543d3..3e517b5bb2 100644 --- a/src/pika_slave_node.cc +++ b/src/pika_slave_node.cc @@ -7,6 +7,8 @@ #include "include/pika_conf.h" +using pstd::Status; + extern std::unique_ptr g_pika_conf; /* SyncWindow */ @@ -17,7 +19,8 @@ void SyncWindow::Push(const SyncWinItem& item) { } bool SyncWindow::Update(const SyncWinItem& start_item, const SyncWinItem& end_item, LogOffset* acked_offset) { - size_t start_pos = win_.size(), end_pos = win_.size(); + size_t start_pos = win_.size(); + size_t end_pos = win_.size(); for (size_t i = 0; i < win_.size(); ++i) { if (win_[i] == start_item) { start_pos = i; @@ -60,16 +63,15 @@ SlaveNode::SlaveNode(const std::string& ip, int port, const std::string& table_n int session_id) : RmNode(ip, port, table_name, partition_id, session_id), slave_state(kSlaveNotSync), - b_state(kNotSync), - sent_offset(), - acked_offset() {} + b_state(kNotSync) + {} -SlaveNode::~SlaveNode() {} +SlaveNode::~SlaveNode() = default; Status SlaveNode::InitBinlogFileReader(const std::shared_ptr& binlog, const BinlogOffset& offset) { binlog_reader = std::make_shared(); int res = binlog_reader->Seek(binlog, offset.filenum, offset.offset); - if (res) { + if (res != 0) { return Status::Corruption(ToString() + " binlog reader init failed"); } return Status::OK(); diff --git a/src/pika_stable_log.cc b/src/pika_stable_log.cc index 9476813d4c..1c51babe9c 100644 --- a/src/pika_stable_log.cc +++ b/src/pika_stable_log.cc @@ -7,18 +7,22 @@ #include +#include +#include + #include "include/pika_conf.h" #include "include/pika_rm.h" #include "include/pika_server.h" #include "pstd/include/env.h" -extern std::unique_ptr g_pika_conf; +using pstd::Status; + extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; -StableLog::StableLog(const std::string table_name, uint32_t partition_id, const std::string& log_path) - : purging_(false), table_name_(table_name), partition_id_(partition_id), log_path_(log_path) { +StableLog::StableLog(std::string table_name, uint32_t partition_id, std::string log_path) + : purging_(false), table_name_(std::move(table_name)), partition_id_(partition_id), log_path_(std::move(log_path)) { stable_logger_ = std::make_shared(log_path_, g_pika_conf->binlog_file_size()); std::map binlogs; if (!GetBinlogFiles(&binlogs)) { @@ -29,7 +33,7 @@ StableLog::StableLog(const std::string table_name, uint32_t partition_id, const } } -StableLog::~StableLog() {} +StableLog::~StableLog() = default; void StableLog::Leave() { Close(); @@ -44,7 +48,7 @@ void StableLog::RemoveStableLogDir() { logpath.erase(logpath.length() - 1); } logpath.append("_deleting/"); - if (pstd::RenameFile(log_path_, logpath.c_str())) { + if (pstd::RenameFile(log_path_, logpath) != 0) { LOG(WARNING) << "Failed to move log to trash, error: " << strerror(errno); return; } @@ -60,7 +64,7 @@ bool StableLog::PurgeStableLogs(uint32_t to, bool manual) { LOG(WARNING) << "purge process already exist"; return false; } - PurgeStableLogArg* arg = new PurgeStableLogArg(); + auto arg = new PurgeStableLogArg(); arg->to = to; arg->manual = manual; arg->logger = shared_from_this(); @@ -120,7 +124,7 @@ bool StableLog::PurgeFiles(uint32_t to, bool manual) { break; } } - if (delete_num) { + if (delete_num != 0) { std::map binlogs; if (!GetBinlogFiles(&binlogs)) { LOG(WARNING) << log_path_ << " Could not get binlog files!"; @@ -131,7 +135,7 @@ bool StableLog::PurgeFiles(uint32_t to, bool manual) { UpdateFirstOffset(it->first); } } - if (delete_num) { + if (delete_num != 0) { LOG(INFO) << log_path_ << " Success purge " << delete_num << " binlog file"; } return true; @@ -140,7 +144,7 @@ bool StableLog::PurgeFiles(uint32_t to, bool manual) { bool StableLog::GetBinlogFiles(std::map* binlogs) { std::vector children; int ret = pstd::GetChildren(log_path_, children); - if (ret != 0) { + if (ret) { LOG(WARNING) << log_path_ << " Get all files in log path failed! error:" << ret; return false; } @@ -163,14 +167,14 @@ bool StableLog::GetBinlogFiles(std::map* binlogs) { void StableLog::UpdateFirstOffset(uint32_t filenum) { PikaBinlogReader binlog_reader; int res = binlog_reader.Seek(stable_logger_, filenum, 0); - if (res) { + if (res != 0) { LOG(WARNING) << "Binlog reader init failed"; return; } BinlogItem item; BinlogOffset offset; - while (1) { + while (true) { std::string binlog; Status s = binlog_reader.Get(&binlog, &(offset.filenum), &(offset.offset)); if (s.IsEndFile()) { diff --git a/src/pika_statistic.cc b/src/pika_statistic.cc index 2a171c2c68..49cd037b5f 100644 --- a/src/pika_statistic.cc +++ b/src/pika_statistic.cc @@ -30,7 +30,7 @@ QpsStatistic::QpsStatistic(const QpsStatistic& other) { last_time_us = other.last_time_us.load(); } -QpsStatistic::~QpsStatistic() {} + void QpsStatistic::IncreaseQueryNum(bool is_write) { querynum++; @@ -68,9 +68,9 @@ void QpsStatistic::ResetLastSecQuerynum() { /* ServerStatistic */ -ServerStatistic::ServerStatistic() {} +ServerStatistic::ServerStatistic() = default; -ServerStatistic::~ServerStatistic() {} +ServerStatistic::~ServerStatistic() = default; /* Statistic */ diff --git a/src/pika_table.cc b/src/pika_table.cc index 519b331523..83cd26c50b 100644 --- a/src/pika_table.cc +++ b/src/pika_table.cc @@ -3,12 +3,15 @@ // 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/pika_table.h" #include "include/pika_cmd_table_manager.h" #include "include/pika_rm.h" #include "include/pika_server.h" +using pstd::Status; extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; extern std::unique_ptr g_pika_cmd_table_manager; @@ -19,9 +22,9 @@ std::string TablePath(const std::string& path, const std::string& table_name) { return path + buf; } -Table::Table(const std::string& table_name, uint32_t partition_num, const std::string& db_path, +Table::Table(std::string table_name, uint32_t partition_num, const std::string& db_path, const std::string& log_path) - : table_name_(table_name), partition_num_(partition_num) { + : table_name_(std::move(table_name)), partition_num_(partition_num) { db_path_ = TablePath(db_path, table_name_); log_path_ = TablePath(log_path, "log_" + table_name_); @@ -129,7 +132,7 @@ void Table::KeyScan() { key_scan_info_.key_scaning_ = true; key_scan_info_.duration = -2; // duration -2 mean the task in waiting status, // has not been scheduled for exec - BgTaskArg* bg_task_arg = new BgTaskArg(); + auto bg_task_arg = new BgTaskArg(); bg_task_arg->table = shared_from_this(); g_pika_server->KeyScanTaskSchedule(&DoKeyScan, reinterpret_cast(bg_task_arg)); } @@ -271,7 +274,7 @@ Status Table::MovetoToTrash(const std::string& path) { path_tmp.erase(path_tmp.length() - 1); } path_tmp += "_deleting/"; - if (pstd::RenameFile(path, path_tmp)) { + if (pstd::RenameFile(path, path_tmp) != 0) { LOG(WARNING) << "Failed to move " << path << " to trash, error: " << strerror(errno); return Status::Corruption("Failed to move %s to trash", path); } diff --git a/src/pika_zset.cc b/src/pika_zset.cc index ba4d927461..1c48fc552a 100644 --- a/src/pika_zset.cc +++ b/src/pika_zset.cc @@ -5,6 +5,8 @@ #include "include/pika_zset.h" +#include + #include "pstd/include/pstd_string.h" void ZAddCmd::DoInitial() { @@ -22,13 +24,12 @@ void ZAddCmd::DoInitial() { double score; size_t index = 2; for (; index < argc; index += 2) { - if (!pstd::string2d(argv_[index].data(), argv_[index].size(), &score)) { + if (pstd::string2d(argv_[index].data(), argv_[index].size(), &score) == 0) { res_.SetRes(CmdRes::kInvalidFloat); return; } score_members.push_back({score, argv_[index + 1]}); } - return; } void ZAddCmd::Do(std::shared_ptr partition) { @@ -39,7 +40,6 @@ void ZAddCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZCardCmd::DoInitial() { @@ -48,7 +48,6 @@ void ZCardCmd::DoInitial() { return; } key_ = argv_[1]; - return; } void ZCardCmd::Do(std::shared_ptr partition) { @@ -59,7 +58,6 @@ void ZCardCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, "zcard error"); } - return; } void ZScanCmd::DoInitial() { @@ -68,22 +66,23 @@ void ZScanCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &cursor_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &cursor_) == 0) { res_.SetRes(CmdRes::kWrongNum, kCmdNameZScan); return; } - size_t argc = argv_.size(), index = 3; + size_t argc = argv_.size(); + size_t index = 3; while (index < argc) { std::string opt = argv_[index]; - if (!strcasecmp(opt.data(), "match") || !strcasecmp(opt.data(), "count")) { + if ((strcasecmp(opt.data(), "match") == 0) || (strcasecmp(opt.data(), "count") == 0)) { index++; if (index >= argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(opt.data(), "match")) { + if (strcasecmp(opt.data(), "match") == 0) { pattern_ = argv_[index]; - } else if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &count_)) { + } else if (pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -97,7 +96,6 @@ void ZScanCmd::DoInitial() { res_.SetRes(CmdRes::kSyntaxErr); return; } - return; } void ZScanCmd::Do(std::shared_ptr partition) { @@ -122,7 +120,6 @@ void ZScanCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZIncrbyCmd::DoInitial() { @@ -131,12 +128,11 @@ void ZIncrbyCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2d(argv_[2].data(), argv_[2].size(), &by_)) { + if (pstd::string2d(argv_[2].data(), argv_[2].size(), &by_) == 0) { res_.SetRes(CmdRes::kInvalidFloat); return; } member_ = argv_[3]; - return; } void ZIncrbyCmd::Do(std::shared_ptr partition) { @@ -150,26 +146,24 @@ void ZIncrbyCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZsetRangeParentCmd::DoInitial() { - if (argv_.size() == 5 && !strcasecmp(argv_[4].data(), "withscores")) { + if (argv_.size() == 5 && (strcasecmp(argv_[4].data(), "withscores") == 0)) { is_ws_ = true; } else if (argv_.size() != 4) { res_.SetRes(CmdRes::kSyntaxErr); return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &start_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &start_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (!pstd::string2int(argv_[3].data(), argv_[3].size(), &stop_)) { + if (pstd::string2int(argv_[3].data(), argv_[3].size(), &stop_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - return; } void ZRangeCmd::DoInitial() { @@ -205,7 +199,6 @@ void ZRangeCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZRevrangeCmd::DoInitial() { @@ -241,12 +234,11 @@ void ZRevrangeCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } int32_t DoScoreStrRange(std::string begin_score, std::string end_score, bool* left_close, bool* right_close, double* min_score, double* max_score) { - if (begin_score.size() > 0 && begin_score.at(0) == '(') { + if (!begin_score.empty() && begin_score.at(0) == '(') { *left_close = false; begin_score.erase(begin_score.begin()); } @@ -254,11 +246,11 @@ int32_t DoScoreStrRange(std::string begin_score, std::string end_score, bool* le *min_score = storage::ZSET_SCORE_MIN; } else if (begin_score == "inf" || begin_score == "+inf") { *min_score = storage::ZSET_SCORE_MAX; - } else if (!pstd::string2d(begin_score.data(), begin_score.size(), min_score)) { + } else if (pstd::string2d(begin_score.data(), begin_score.size(), min_score) == 0) { return -1; } - if (end_score.size() > 0 && end_score.at(0) == '(') { + if (!end_score.empty() && end_score.at(0) == '(') { *right_close = false; end_score.erase(end_score.begin()); } @@ -266,7 +258,7 @@ int32_t DoScoreStrRange(std::string begin_score, std::string end_score, bool* le *max_score = storage::ZSET_SCORE_MAX; } else if (end_score == "-inf") { *max_score = storage::ZSET_SCORE_MIN; - } else if (!pstd::string2d(end_score.data(), end_score.size(), max_score)) { + } else if (pstd::string2d(end_score.data(), end_score.size(), max_score) == 0) { return -1; } return 0; @@ -291,20 +283,20 @@ void ZsetRangebyscoreParentCmd::DoInitial() { } size_t index = 4; while (index < argc) { - if (!strcasecmp(argv_[index].data(), "withscores")) { + if (strcasecmp(argv_[index].data(), "withscores") == 0) { with_scores_ = true; - } else if (!strcasecmp(argv_[index].data(), "limit")) { + } else if (strcasecmp(argv_[index].data(), "limit") == 0) { if (index + 3 > argc) { res_.SetRes(CmdRes::kSyntaxErr); return; } index++; - if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &offset_)) { + if (pstd::string2int(argv_[index].data(), argv_[index].size(), &offset_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } index++; - if (!pstd::string2int(argv_[index].data(), argv_[index].size(), &count_)) { + if (pstd::string2int(argv_[index].data(), argv_[index].size(), &count_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -337,7 +329,8 @@ void ZRangebyscoreCmd::Do(std::shared_ptr partition) { return; } FitLimit(count_, offset_, score_members.size()); - size_t index = offset_, end = offset_ + count_; + size_t index = offset_; + size_t end = offset_ + count_; if (with_scores_) { char buf[32]; int64_t len; @@ -356,7 +349,6 @@ void ZRangebyscoreCmd::Do(std::shared_ptr partition) { res_.AppendContent(score_members[index].member); } } - return; } void ZRevrangebyscoreCmd::DoInitial() { @@ -389,7 +381,8 @@ void ZRevrangebyscoreCmd::Do(std::shared_ptr partition) { return; } FitLimit(count_, offset_, score_members.size()); - int64_t index = offset_, end = offset_ + count_; + int64_t index = offset_; + int64_t end = offset_ + count_; if (with_scores_) { char buf[32]; int64_t len; @@ -408,7 +401,6 @@ void ZRevrangebyscoreCmd::Do(std::shared_ptr partition) { res_.AppendContent(score_members[index].member); } } - return; } void ZCountCmd::DoInitial() { @@ -422,7 +414,6 @@ void ZCountCmd::DoInitial() { res_.SetRes(CmdRes::kErrOther, "min or max is not a float"); return; } - return; } void ZCountCmd::Do(std::shared_ptr partition) { @@ -438,7 +429,6 @@ void ZCountCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZRemCmd::DoInitial() { @@ -447,9 +437,8 @@ void ZRemCmd::DoInitial() { return; } key_ = argv_[1]; - PikaCmdArgsType::iterator iter = argv_.begin() + 2; + auto iter = argv_.begin() + 2; members_.assign(iter, argv_.end()); - return; } void ZRemCmd::Do(std::shared_ptr partition) { @@ -460,12 +449,11 @@ void ZRemCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZsetUIstoreParentCmd::DoInitial() { dest_key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &num_keys_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &num_keys_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -482,7 +470,7 @@ void ZsetUIstoreParentCmd::DoInitial() { weights_.assign(num_keys_, 1); int index = num_keys_ + 3; while (index < argc) { - if (!strcasecmp(argv_[index].data(), "weights")) { + if (strcasecmp(argv_[index].data(), "weights") == 0) { index++; if (argc < index + num_keys_) { res_.SetRes(CmdRes::kSyntaxErr); @@ -491,23 +479,23 @@ void ZsetUIstoreParentCmd::DoInitial() { double weight; int base = index; for (; index < base + num_keys_; index++) { - if (!pstd::string2d(argv_[index].data(), argv_[index].size(), &weight)) { + if (pstd::string2d(argv_[index].data(), argv_[index].size(), &weight) == 0) { res_.SetRes(CmdRes::kErrOther, "weight value is not a float"); return; } weights_[index - base] = weight; } - } else if (!strcasecmp(argv_[index].data(), "aggregate")) { + } else if (strcasecmp(argv_[index].data(), "aggregate") == 0) { index++; if (argc < index + 1) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!strcasecmp(argv_[index].data(), "sum")) { + if (strcasecmp(argv_[index].data(), "sum") == 0) { aggregate_ = storage::SUM; - } else if (!strcasecmp(argv_[index].data(), "min")) { + } else if (strcasecmp(argv_[index].data(), "min") == 0) { aggregate_ = storage::MIN; - } else if (!strcasecmp(argv_[index].data(), "max")) { + } else if (strcasecmp(argv_[index].data(), "max") == 0) { aggregate_ = storage::MAX; } else { res_.SetRes(CmdRes::kSyntaxErr); @@ -519,7 +507,6 @@ void ZsetUIstoreParentCmd::DoInitial() { return; } } - return; } void ZUnionstoreCmd::DoInitial() { @@ -538,7 +525,6 @@ void ZUnionstoreCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZInterstoreCmd::DoInitial() { @@ -547,7 +533,6 @@ void ZInterstoreCmd::DoInitial() { return; } ZsetUIstoreParentCmd::DoInitial(); - return; } void ZInterstoreCmd::Do(std::shared_ptr partition) { @@ -558,13 +543,11 @@ void ZInterstoreCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZsetRankParentCmd::DoInitial() { key_ = argv_[1]; member_ = argv_[2]; - return; } void ZRankCmd::DoInitial() { @@ -629,7 +612,6 @@ void ZScoreCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } static int32_t DoMemberRange(const std::string& raw_min_member, const std::string& raw_max_member, bool* left_close, @@ -639,9 +621,9 @@ static int32_t DoMemberRange(const std::string& raw_min_member, const std::strin } else if (raw_min_member == "+") { *min_member = "+"; } else { - if (raw_min_member.size() > 0 && raw_min_member.at(0) == '(') { + if (!raw_min_member.empty() && raw_min_member.at(0) == '(') { *left_close = false; - } else if (raw_min_member.size() > 0 && raw_min_member.at(0) == '[') { + } else if (!raw_min_member.empty() && raw_min_member.at(0) == '[') { *left_close = true; } else { return -1; @@ -654,9 +636,9 @@ static int32_t DoMemberRange(const std::string& raw_min_member, const std::strin } else if (raw_max_member == "-") { *max_member = "-"; } else { - if (raw_max_member.size() > 0 && raw_max_member.at(0) == '(') { + if (!raw_max_member.empty() && raw_max_member.at(0) == '(') { *right_close = false; - } else if (raw_max_member.size() > 0 && raw_max_member.at(0) == '[') { + } else if (!raw_max_member.empty() && raw_max_member.at(0) == '[') { *right_close = true; } else { return -1; @@ -676,15 +658,15 @@ void ZsetRangebylexParentCmd::DoInitial() { size_t argc = argv_.size(); if (argc == 4) { return; - } else if (argc != 7 || strcasecmp(argv_[4].data(), "limit")) { + } else if (argc != 7 || strcasecmp(argv_[4].data(), "limit") != 0) { res_.SetRes(CmdRes::kSyntaxErr); return; } - if (!pstd::string2int(argv_[5].data(), argv_[5].size(), &offset_)) { + if (pstd::string2int(argv_[5].data(), argv_[5].size(), &offset_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (!pstd::string2int(argv_[6].data(), argv_[6].size(), &count_)) { + if (pstd::string2int(argv_[6].data(), argv_[6].size(), &count_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -712,12 +694,12 @@ void ZRangebylexCmd::Do(std::shared_ptr partition) { FitLimit(count_, offset_, members.size()); res_.AppendArrayLen(count_); - size_t index = offset_, end = offset_ + count_; + size_t index = offset_; + size_t end = offset_ + count_; for (; index < end; index++) { res_.AppendStringLen(members[index].size()); res_.AppendContent(members[index]); } - return; } void ZRevrangebylexCmd::DoInitial() { @@ -752,12 +734,12 @@ void ZRevrangebylexCmd::Do(std::shared_ptr partition) { FitLimit(count_, offset_, members.size()); res_.AppendArrayLen(count_); - int64_t index = members.size() - 1 - offset_, end = index - count_; + int64_t index = members.size() - 1 - offset_; + int64_t end = index - count_; for (; index > end; index--) { res_.AppendStringLen(members[index].size()); res_.AppendContent(members[index]); } - return; } void ZLexcountCmd::DoInitial() { @@ -785,7 +767,6 @@ void ZLexcountCmd::Do(std::shared_ptr partition) { return; } res_.AppendInteger(count); - return; } void ZRemrangebyrankCmd::DoInitial() { @@ -794,11 +775,11 @@ void ZRemrangebyrankCmd::DoInitial() { return; } key_ = argv_[1]; - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &start_rank_)) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), &start_rank_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } - if (!pstd::string2int(argv_[3].data(), argv_[3].size(), &stop_rank_)) { + if (pstd::string2int(argv_[3].data(), argv_[3].size(), &stop_rank_) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -812,7 +793,6 @@ void ZRemrangebyrankCmd::Do(std::shared_ptr partition) { } else { res_.SetRes(CmdRes::kErrOther, s.ToString()); } - return; } void ZRemrangebyscoreCmd::DoInitial() { @@ -826,7 +806,6 @@ void ZRemrangebyscoreCmd::DoInitial() { res_.SetRes(CmdRes::kErrOther, "min or max is not a float"); return; } - return; } void ZRemrangebyscoreCmd::Do(std::shared_ptr partition) { @@ -842,7 +821,6 @@ void ZRemrangebyscoreCmd::Do(std::shared_ptr partition) { return; } res_.AppendInteger(count); - return; } void ZRemrangebylexCmd::DoInitial() { @@ -856,7 +834,6 @@ void ZRemrangebylexCmd::DoInitial() { res_.SetRes(CmdRes::kErrOther, "min or max not valid string range item"); return; } - return; } void ZRemrangebylexCmd::Do(std::shared_ptr partition) { @@ -872,7 +849,6 @@ void ZRemrangebylexCmd::Do(std::shared_ptr partition) { return; } res_.AppendInteger(count); - return; } void ZPopmaxCmd::DoInitial() { @@ -885,7 +861,7 @@ void ZPopmaxCmd::DoInitial() { count_ = 1; return; } - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), (long long*)(&count_))) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), static_cast(&count_)) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } @@ -919,7 +895,7 @@ void ZPopminCmd::DoInitial() { count_ = 1; return; } - if (!pstd::string2int(argv_[2].data(), argv_[2].size(), (long long*)(&count_))) { + if (pstd::string2int(argv_[2].data(), argv_[2].size(), static_cast(&count_)) == 0) { res_.SetRes(CmdRes::kInvalidInt); return; } diff --git a/src/pstd/include/base_conf.h b/src/pstd/include/base_conf.h index 1a74b98c6c..779ab48bdf 100644 --- a/src/pstd/include/base_conf.h +++ b/src/pstd/include/base_conf.h @@ -6,18 +6,18 @@ #ifndef __PSTD_INCLUDE_BASE_CONF_H__ #define __PSTD_INCLUDE_BASE_CONF_H__ -#include -#include +#include +#include #include #include +#include #include + #include "pstd/include/pstd_define.h" namespace pstd { -class BaseConf; - class BaseConf { public: struct Rep { @@ -31,11 +31,11 @@ class BaseConf { ConfType type; // 0 means conf, 1 means comment std::string name; std::string value; - ConfItem(ConfType t, const std::string& v) : type(t), name(""), value(v) {} - ConfItem(ConfType t, const std::string& n, const std::string& v) : type(t), name(n), value(v) {} + ConfItem(ConfType t, std::string v) : type(t), value(std::move(v)) {} + ConfItem(ConfType t, std::string n, std::string v) : type(t), name(std::move(n)), value(std::move(v)) {} }; - explicit Rep(const std::string& p) : path(p) {} + explicit Rep(std::string p) : path(std::move(p)) {} std::vector item; }; @@ -56,13 +56,13 @@ class BaseConf { bool GetConfStrVec(const std::string& name, std::vector* value) const; bool GetConfDouble(const std::string& name, double* value) const; - bool SetConfInt(const std::string& name, const int value); - bool SetConfInt64(const std::string& name, const int64_t value); + bool SetConfInt(const std::string& name, int value); + bool SetConfInt64(const std::string& name, int64_t value); bool SetConfStr(const std::string& name, const std::string& value); - bool SetConfBool(const std::string& name, const bool value); + bool SetConfBool(const std::string& name, bool value); bool SetConfStrVec(const std::string& name, const std::vector& value); - bool SetConfDouble(const std::string& name, const double value); + bool SetConfDouble(const std::string& name, double value); bool CheckConfExist(const std::string& name) const; @@ -74,12 +74,6 @@ class BaseConf { private: std::unique_ptr rep_; - - /* - * No copy && no assign operator - */ - BaseConf(const BaseConf&); - void operator=(const BaseConf&); }; } // namespace pstd diff --git a/src/pstd/include/env.h b/src/pstd/include/env.h index 18decd15c3..da87801aeb 100644 --- a/src/pstd/include/env.h +++ b/src/pstd/include/env.h @@ -5,7 +5,9 @@ #include #include #include + #include "pstd/include/pstd_status.h" +#include "pstd/include/noncopyable.h" namespace pstd { @@ -34,7 +36,7 @@ int DeleteDir(const std::string& path); bool DeleteDirIfExist(const std::string& path); int CreateDir(const std::string& path); int CreatePath(const std::string& path, mode_t mode = 0755); -uint64_t Du(const std::string& path); +uint64_t Du(const std::string& filename); /* * Whether the file is exist @@ -46,18 +48,13 @@ Status DeleteFile(const std::string& fname); int RenameFile(const std::string& oldname, const std::string& newname); -class FileLock { +class FileLock : public pstd::noncopyable { public: - FileLock() {} - virtual ~FileLock(){}; + FileLock() = default; + virtual ~FileLock()= default;; int fd_ = -1; std::string name_; - - private: - // No copying allowed - FileLock(const FileLock&); - void operator=(const FileLock&); }; Status LockFile(const std::string& f, FileLock** l); @@ -84,9 +81,9 @@ Status NewRandomRWFile(const std::string& fname, std::unique_ptr& // A file abstraction for sequential writing. The implementation // must provide buffering since callers may append small fragments // at a time to the file. -class WritableFile { +class WritableFile : public pstd::noncopyable { public: - WritableFile() {} + WritableFile() = default; virtual ~WritableFile(); virtual Status Append(const Slice& data) = 0; @@ -95,17 +92,12 @@ class WritableFile { virtual Status Sync() = 0; virtual Status Trim(uint64_t offset) = 0; virtual uint64_t Filesize() = 0; - - private: - // No copying allowed - WritableFile(const WritableFile&); - void operator=(const WritableFile&); }; // A abstract for the sequential readable file class SequentialFile { public: - SequentialFile(){}; + SequentialFile()= default;; virtual ~SequentialFile(); // virtual Status Read(size_t n, char *&result, char *scratch) = 0; virtual Status Read(size_t n, Slice* result, char* scratch) = 0; @@ -114,23 +106,18 @@ class SequentialFile { virtual char* ReadLine(char* buf, int n) = 0; }; -class RWFile { +class RWFile : public pstd::noncopyable { public: - RWFile() {} + RWFile() = default; virtual ~RWFile(); virtual char* GetData() = 0; - - private: - // No copying allowed - RWFile(const RWFile&); - void operator=(const RWFile&); }; // A file abstraction for random reading and writing. -class RandomRWFile { +class RandomRWFile : public pstd::noncopyable { public: - RandomRWFile() {} - virtual ~RandomRWFile() {} + RandomRWFile() = default; + virtual ~RandomRWFile() = default; // Write data from Slice data to file starting from offset // Returns IOError on failure, but does not guarantee @@ -167,11 +154,6 @@ class RandomRWFile { (void)len; return Status::OK(); } - - private: - // No copying allowed - RandomRWFile(const RandomRWFile&); - void operator=(const RandomRWFile&); }; } // namespace pstd diff --git a/src/pstd/include/lock_mgr.h b/src/pstd/include/lock_mgr.h index 185bee6e17..8cbc9a588d 100644 --- a/src/pstd/include/lock_mgr.h +++ b/src/pstd/include/lock_mgr.h @@ -10,6 +10,7 @@ #include #include "pstd/include/mutex.h" +#include "pstd/include/noncopyable.h" namespace pstd { @@ -17,9 +18,9 @@ namespace lock { struct LockMap; struct LockMapStripe; -class LockMgr { +class LockMgr : public pstd::noncopyable { public: - LockMgr(size_t default_num_stripes, int64_t max_num_locks, std::shared_ptr factory); + LockMgr(size_t default_num_stripes, int64_t max_num_locks, const std::shared_ptr& factory); ~LockMgr(); @@ -32,7 +33,7 @@ class LockMgr { private: // Default number of lock map stripes - const size_t default_num_stripes_; + const size_t default_num_stripes_[[maybe_unused]]; // Limit on number of keys locked per column family const int64_t max_num_locks_; @@ -49,9 +50,6 @@ class LockMgr { void UnLockKey(const std::string& key, std::shared_ptr stripe); - // No copying allowed - LockMgr(const LockMgr&); - void operator=(const LockMgr&); }; } // namespace lock diff --git a/src/pstd/include/mutex.h b/src/pstd/include/mutex.h index b4f9123a28..3d67d426aa 100644 --- a/src/pstd/include/mutex.h +++ b/src/pstd/include/mutex.h @@ -16,7 +16,7 @@ using Status = pstd::Status; class Mutex { public: - virtual ~Mutex() {} + virtual ~Mutex() = default; // Attempt to acquire lock. Return OK on success, or other Status on failure. // If returned status is OK, Storage will eventually call UnLock(). @@ -36,7 +36,7 @@ class Mutex { class CondVar { public: - virtual ~CondVar() {} + virtual ~CondVar() = default; // Block current thread until condition variable is notified by a call to // Notify() or NotifyAll(). Wait() will be called with mutex locked. @@ -78,7 +78,7 @@ class MutexFactory { // Create a CondVar object. virtual std::shared_ptr AllocateCondVar() = 0; - virtual ~MutexFactory() {} + virtual ~MutexFactory() = default; }; } // namespace pstd::lock diff --git a/src/pstd/include/noncopyable.h b/src/pstd/include/noncopyable.h new file mode 100644 index 0000000000..4e24b0d52d --- /dev/null +++ b/src/pstd/include/noncopyable.h @@ -0,0 +1,23 @@ +// Copyright (c) 2023-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. + +#ifndef PIKA_NONCOPYABLE_H_ +#define PIKA_NONCOPYABLE_H_ + +namespace pstd { + +class noncopyable { + protected: + noncopyable() = default; + ~noncopyable() = default; + + private: + noncopyable(const noncopyable&) = delete; + void operator=(const noncopyable&) = delete; +}; + +} + +#endif diff --git a/src/pstd/include/posix.h b/src/pstd/include/posix.h index 0244bff839..3371432d8b 100644 --- a/src/pstd/include/posix.h +++ b/src/pstd/include/posix.h @@ -3,19 +3,11 @@ # define __CSAPP_H__ # include -# include -# include # include -# include # include # include # include # include -# include -# include -# include -# include -# include # include # include # include @@ -23,31 +15,38 @@ # include # include # include +# include +# include +# include +# include +# include +# include +# include +# include /* Default file permissions are DEF_MODE & ~DEF_UMASK */ /* $begin createmasks */ -# define DEF_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH -# define DEF_UMASK S_IWGRP | S_IWOTH +# define DEF_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) +# define DEF_UMASK (S_IWGRP | S_IWOTH) /* $end createmasks */ /* Simplifies calls to bind(), connect(), and accept() */ /* $begin sockaddrdef */ -typedef struct sockaddr SA; +using SA = struct sockaddr; /* $end sockaddrdef */ /* Persistent state for the robust I/O (Rio) package */ /* $begin rio_t */ # define RIO_BUFSIZE 8192 -typedef struct { +using rio_t = struct { int rio_fd; /* descriptor for this internal buf */ int rio_cnt; /* unread bytes in internal buf */ char* rio_bufptr; /* next unread byte in internal buf */ char rio_buf[RIO_BUFSIZE]; /* internal buffer */ -} rio_t; +}; /* $end rio_t */ /* External variables */ -extern int h_errno; /* defined by BIND for DNS errors */ extern char** environ; /* defined by libc */ /* Misc constants */ @@ -56,19 +55,19 @@ extern char** environ; /* defined by libc */ # define LISTENQ 1024 /* second argument to listen() */ /* Process control wrappers */ -pid_t Fork(void); +pid_t Fork(); void Execve(const char* filename, char* const argv[], char* const envp[]); pid_t Wait(int* status); pid_t Waitpid(pid_t pid, int* iptr, int options); void Kill(pid_t pid, int signum); unsigned int Sleep(unsigned int secs); -void Pause(void); +void Pause(); unsigned int Alarm(unsigned int seconds); void Setpgid(pid_t pid, pid_t pgid); pid_t Getpgrp(); /* Signal wrappers */ -typedef void handler_t(int); +using handler_t = void (int); handler_t* Signal(int signum, handler_t* handler); void Sigprocmask(int how, const sigset_t* set, sigset_t* oldset); void Sigemptyset(sigset_t* set); @@ -125,7 +124,7 @@ void Pthread_join(pthread_t tid, void** thread_return); void Pthread_cancel(pthread_t tid); void Pthread_detach(pthread_t tid); void Pthread_exit(void* retval); -pthread_t Pthread_self(void); +pthread_t Pthread_self(); void Pthread_once(pthread_once_t* once_control, void (*init_function)()); /* POSIX semaphore wrappers */ @@ -141,7 +140,7 @@ ssize_t rio_readnb(rio_t* rp, void* usrbuf, size_t n); ssize_t rio_readlineb(rio_t* rp, void* usrbuf, size_t maxlen); /* Wrappers for Rio package */ -ssize_t Rio_readn(int fd, void* usrbuf, size_t n); +ssize_t Rio_readn(int fd, void* ptr, size_t n); void Rio_writen(int fd, void* usrbuf, size_t n); void Rio_readinitb(rio_t* rp, int fd); ssize_t Rio_readnb(rio_t* rp, void* usrbuf, size_t n); diff --git a/src/pstd/include/pstd_coding.h b/src/pstd/include/pstd_coding.h index 0b786091ec..f601b5e337 100644 --- a/src/pstd/include/pstd_coding.h +++ b/src/pstd/include/pstd_coding.h @@ -10,8 +10,8 @@ #ifndef __PSTD_CODING_H__ #define __PSTD_CODING_H__ -#include -#include +#include +#include #include #include "pstd/include/pstd_slice.h" @@ -54,9 +54,9 @@ extern int VarintLength(uint64_t v); // Lower-level versions of Put... that write directly into a character buffer // REQUIRES: dst has enough space for the value being written -extern void EncodeFixed16(char* dst, uint16_t value); -extern void EncodeFixed32(char* dst, uint32_t value); -extern void EncodeFixed64(char* dst, uint64_t value); +extern void EncodeFixed16(char* buf, uint16_t value); +extern void EncodeFixed32(char* buf, uint32_t value); +extern void EncodeFixed64(char* buf, uint64_t value); // Lower-level versions of Put... that write directly into a character buffer // and return a pointer just past the last byte written. @@ -89,37 +89,49 @@ inline uint64_t DecodeFixed64(const char* ptr) { } inline void GetFixed16(std::string* dst, uint16_t* value) { - if (!dst || !value) return; + if (!dst || !value) { + return; + } *value = DecodeFixed16(dst->data()); dst->erase(0, sizeof(uint16_t)); } inline void GetFixed32(std::string* dst, uint32_t* value) { - if (!dst || !value) return; + if (!dst || !value) { + return; + } *value = DecodeFixed32(dst->data()); dst->erase(0, sizeof(uint32_t)); } inline void GetFixed64(std::string* dst, uint64_t* value) { - if (!dst || !value) return; + if (!dst || !value) { + return; + } *value = DecodeFixed64(dst->data()); dst->erase(0, sizeof(uint64_t)); } inline void GetFixed16(Slice* dst, uint16_t* value) { - if (!dst || !value) return; + if (!dst || !value) { + return; + } *value = DecodeFixed16(dst->data()); dst->remove_prefix(sizeof(uint16_t) / sizeof(char)); } inline void GetFixed32(Slice* dst, uint32_t* value) { - if (!dst || !value) return; + if (!dst || !value) { + return; + } *value = DecodeFixed32(dst->data()); dst->remove_prefix(sizeof(uint32_t) / sizeof(char)); } inline void GetFixed64(Slice* dst, uint64_t* value) { - if (!dst || !value) return; + if (!dst || !value) { + return; + } *value = DecodeFixed64(dst->data()); dst->remove_prefix(sizeof(uint64_t) / sizeof(char)); } diff --git a/src/pstd/include/pstd_mutex.h b/src/pstd/include/pstd_mutex.h index c97ddfaa88..b1ea9c8203 100644 --- a/src/pstd/include/pstd_mutex.h +++ b/src/pstd/include/pstd_mutex.h @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include "noncopyable.h" namespace pstd { @@ -23,7 +25,7 @@ void InitOnce(OnceType& once, F&& f, Args&&... args) { return std::call_once(once, std::forward(f), std::forward(args)...); } -class RefMutex { +class RefMutex : public pstd::noncopyable { public: RefMutex() = default; ~RefMutex() = default; @@ -40,15 +42,11 @@ class RefMutex { private: std::mutex mu_; int refs_ = 0; - - // No copying - RefMutex(const RefMutex&); - void operator=(const RefMutex&); }; -class RecordMutex { +class RecordMutex : public pstd::noncopyable { public: - RecordMutex(){}; + RecordMutex()= default;; ~RecordMutex(); void MultiLock(const std::vector& keys); @@ -60,24 +58,16 @@ class RecordMutex { Mutex mutex_; std::unordered_map records_; - - // No copying - RecordMutex(const RecordMutex&); - void operator=(const RecordMutex&); }; -class RecordLock { +class RecordLock : public pstd::noncopyable { public: - RecordLock(RecordMutex* mu, const std::string& key) : mu_(mu), key_(key) { mu_->Lock(key_); } + RecordLock(RecordMutex* mu, std::string key) : mu_(mu), key_(std::move(key)) { mu_->Lock(key_); } ~RecordLock() { mu_->Unlock(key_); } private: RecordMutex* const mu_; std::string key_; - - // No copying allowed - RecordLock(const RecordLock&); - void operator=(const RecordLock&); }; } // namespace pstd diff --git a/src/pstd/include/pstd_slice.h b/src/pstd/include/pstd_slice.h index 409fb49bd0..9b0402ceea 100644 --- a/src/pstd/include/pstd_slice.h +++ b/src/pstd/include/pstd_slice.h @@ -20,9 +20,9 @@ #ifndef __PSTD_SLICE_H__ #define __PSTD_SLICE_H__ -#include -#include -#include +#include +#include +#include #include namespace pstd { @@ -30,7 +30,7 @@ namespace pstd { class Slice { public: // Create an empty slice. - Slice() : data_(""), size_(0) {} + Slice() = default; // Create a slice that refers to d[0,n-1]. Slice(const char* d, size_t n) : data_(d), size_(n) {} @@ -83,7 +83,7 @@ class Slice { bool starts_with(const Slice& x) const { return ((size_ >= x.size_) && (memcmp(data_, x.data_, x.size_) == 0)); } private: - const char* data_; + const char* data_{""}; size_t size_ = 0; // Intentionally copyable @@ -99,11 +99,13 @@ inline int Slice::compare(const Slice& b) const { const size_t min_len = (size_ < b.size_) ? size_ : b.size_; int r = memcmp(data_, b.data_, min_len); if (r == 0) { - if (size_ < b.size_) + if (size_ < b.size_) { r = -1; - else if (size_ > b.size_) + } else if (size_ > b.size_) { r = +1; + } } + return r; } diff --git a/src/pstd/include/pstd_status.h b/src/pstd/include/pstd_status.h index 64e73e4367..a3f1dc189e 100644 --- a/src/pstd/include/pstd_status.h +++ b/src/pstd/include/pstd_status.h @@ -9,7 +9,7 @@ namespace pstd { class Status { public: // Create a success status. - Status() : state_(nullptr) {} + Status() = default; ~Status() { delete[] state_; } // Copy the specified status. @@ -17,14 +17,14 @@ class Status { void operator=(const Status& s); // Return a success status. - static Status OK() { return Status(); } + static Status OK() { return {}; } // Return error status of an appropriate type. static Status NotFound(const Slice& msg, const Slice& msg2 = Slice()) { return Status(kNotFound, msg, msg2); } static Status Corruption(const Slice& msg, const Slice& msg2 = Slice()) { return Status(kCorruption, msg, msg2); } static Status NotSupported(const Slice& msg, const Slice& msg2 = Slice()) { return Status(kNotSupported, msg, msg2); } static Status InvalidArgument(const Slice& msg, const Slice& msg2 = Slice()) { - return Status(kInvalidArgument, msg, msg2); + return {kInvalidArgument, msg, msg2}; } static Status IOError(const Slice& msg, const Slice& msg2 = Slice()) { return Status(kIOError, msg, msg2); } static Status EndFile(const Slice& msg, const Slice& msg2 = Slice()) { return Status(kEndFile, msg, msg2); } @@ -40,7 +40,7 @@ class Status { static Status Busy(const Slice& msg, const Slice& msg2 = Slice()) { return Status(kBusy, msg, msg2); } // Returns true if the status indicates success. - bool ok() const { return (state_ == nullptr); } + bool ok() const { return !state_; } // Returns true if the status indicates a NotFound error. bool IsNotFound() const { return code() == kNotFound; } @@ -85,7 +85,7 @@ class Status { // state_[0..3] == length of message // state_[4] == code // state_[5..] == message - const char* state_; + const char* state_{nullptr}; enum Code { kOk = 0, @@ -102,19 +102,19 @@ class Status { kBusy = 11 }; - Code code() const { return (state_ == nullptr) ? kOk : static_cast(state_[4]); } + Code code() const { return !state_ ? kOk : static_cast(state_[4]); } Status(Code code, const Slice& msg, const Slice& msg2); static const char* CopyState(const char* s); }; -inline Status::Status(const Status& s) { state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_); } +inline Status::Status(const Status& s) { state_ = !s.state_ ? nullptr : CopyState(s.state_); } inline void Status::operator=(const Status& s) { // The following condition catches both aliasing (when this == &s), // and the common case where both s and *this are ok. if (state_ != s.state_) { delete[] state_; - state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_); + state_ = !s.state_ ? nullptr : CopyState(s.state_); } } diff --git a/src/pstd/include/pstd_string.h b/src/pstd/include/pstd_string.h index d4d5934b7c..7db8c257e6 100644 --- a/src/pstd/include/pstd_string.h +++ b/src/pstd/include/pstd_string.h @@ -40,15 +40,15 @@ namespace pstd { -int stringmatchlen(const char* p, int plen, const char* s, int slen, int nocase); +int stringmatchlen(const char* pattern, int patternLen, const char* string, int stringLen, int nocase); int stringmatch(const char* p, const char* s, int nocase); long long memtoll(const char* p, int* err); -int ll2string(char* s, size_t len, long long value); +int ll2string(char* dst, size_t dstlen, long long svalue); int string2int(const char* s, size_t slen, long long* value); -int string2int(const char* s, size_t slen, long* value); -int string2int(const char* s, size_t slen, unsigned long* value); +int string2int(const char* s, size_t slen, long* lval); +int string2int(const char* s, size_t slen, unsigned long* lval); int d2string(char* buf, size_t len, double value); -int string2d(const char* buf, size_t len, double* value); +int string2d(const char* s, size_t slen, double* dval); std::vector& StringSplit(const std::string& s, char delim, std::vector& elems); std::string StringConcat(const std::vector& elems, char delim); std::string& StringToLower(std::string& ori); diff --git a/src/pstd/include/random.h b/src/pstd/include/random.h index 6e74330130..6c8adc6fe4 100644 --- a/src/pstd/include/random.h +++ b/src/pstd/include/random.h @@ -1,7 +1,7 @@ #ifndef __PSTD_INCLUDE_RANDOM_H__ #define __PSTD_INCLUDE_RANDOM_H__ -#include +#include namespace pstd { diff --git a/src/pstd/include/rsync.h b/src/pstd/include/rsync.h index 5204e28eb4..386ddf2d44 100644 --- a/src/pstd/include/rsync.h +++ b/src/pstd/include/rsync.h @@ -2,6 +2,7 @@ #define __PSTD_RSYNC_H__ #include +#include namespace pstd { const std::string kRsyncSecretFile = "pstd_rsync.secret"; @@ -16,11 +17,11 @@ struct RsyncRemote { int port; std::string module; int kbps; // speed limit - RsyncRemote(const std::string& _host, const int _port, const std::string& _module, const int _kbps) - : host(_host), port(_port), module(_module), kbps(_kbps) {} + RsyncRemote(std::string _host, const int _port, std::string _module, const int _kbps) + : host(std::move(_host)), port(_port), module(std::move(_module)), kbps(_kbps) {} }; -int StartRsync(const std::string& rsync_path, const std::string& module, const std::string& ip, const int port, +int StartRsync(const std::string& raw_path, const std::string& module, const std::string& ip, int port, const std::string& passwd); int StopRsync(const std::string& path); int RsyncSendFile(const std::string& local_file_path, const std::string& remote_file_path, diff --git a/src/pstd/include/scope_record_lock.h b/src/pstd/include/scope_record_lock.h index d827d9509a..882964c178 100644 --- a/src/pstd/include/scope_record_lock.h +++ b/src/pstd/include/scope_record_lock.h @@ -10,16 +10,15 @@ #include #include +#include "pstd/include/noncopyable.h" #include "pstd/include/lock_mgr.h" #include "rocksdb/slice.h" -namespace pstd { - -namespace lock { +namespace pstd::lock { using Slice = rocksdb::Slice; -class ScopeRecordLock { +class ScopeRecordLock final : public pstd::noncopyable { public: ScopeRecordLock(std::shared_ptr lock_mgr, const Slice& key) : lock_mgr_(lock_mgr), key_(key) { lock_mgr_->TryLock(key_.ToString()); @@ -29,11 +28,9 @@ class ScopeRecordLock { private: std::shared_ptr const lock_mgr_; Slice key_; - ScopeRecordLock(const ScopeRecordLock&); - void operator=(const ScopeRecordLock&); }; -class MultiScopeRecordLock { +class MultiScopeRecordLock final : public pstd::noncopyable { public: MultiScopeRecordLock(std::shared_ptr lock_mgr, const std::vector& keys); ~MultiScopeRecordLock(); @@ -41,23 +38,18 @@ class MultiScopeRecordLock { private: std::shared_ptr const lock_mgr_; std::vector keys_; - MultiScopeRecordLock(const MultiScopeRecordLock&); - void operator=(const MultiScopeRecordLock&); }; -class MultiRecordLock { +class MultiRecordLock : public noncopyable { public: explicit MultiRecordLock(std::shared_ptr lock_mgr) : lock_mgr_(lock_mgr) {} - ~MultiRecordLock() {} + ~MultiRecordLock() = default; + void Lock(const std::vector& keys); void Unlock(const std::vector& keys); - private: std::shared_ptr const lock_mgr_; - MultiRecordLock(const MultiRecordLock&); - void operator=(const MultiRecordLock&); }; -} // namespace lock -} // namespace pstd +} // namespace pstd::lock #endif // __SRC_SCOPE_RECORD_LOCK_H__ diff --git a/src/pstd/include/xdebug.h b/src/pstd/include/xdebug.h index 9e6eb4b8cb..bee6243efa 100644 --- a/src/pstd/include/xdebug.h +++ b/src/pstd/include/xdebug.h @@ -8,11 +8,11 @@ #ifndef __XDEBUG_H__ # define __XDEBUG_H__ -# include -# include -# include -# include # include +# include +# include +# include +# include # ifdef __XDEBUG__ # define pint(x) qf_debug("%s = %d", #x, x) diff --git a/src/pstd/src/base_conf.cc b/src/pstd/src/base_conf.cc index 5cf21b9ce1..14f01c4080 100644 --- a/src/pstd/src/base_conf.cc +++ b/src/pstd/src/base_conf.cc @@ -21,7 +21,7 @@ static const int kConfItemLen = 1024 * 1024; BaseConf::BaseConf(const std::string& path) : rep_(std::make_unique(path)) {} -BaseConf::~BaseConf() {} +BaseConf::~BaseConf() = default; int BaseConf::LoadConf() { if (!FileExists(rep_->path)) { @@ -32,9 +32,11 @@ int BaseConf::LoadConf() { // read conf items char line[kConfItemLen]; - char name[kConfItemLen], value[kConfItemLen]; + char name[kConfItemLen]; + char value[kConfItemLen]; int line_len = 0; - int name_len = 0, value_len = 0; + int name_len = 0; + int value_len = 0; int sep_sign = 0; Rep::ConfType type = Rep::kConf; @@ -55,7 +57,7 @@ int BaseConf::LoadConf() { case '\n': break; case COLON: - if (!sep_sign) { + if (sep_sign == 0) { type = Rep::kConf; sep_sign = 1; break; @@ -70,9 +72,9 @@ int BaseConf::LoadConf() { } if (type == Rep::kConf) { - rep_->item.push_back(Rep::ConfItem(Rep::kConf, std::string(name, name_len), std::string(value, value_len))); + rep_->item.emplace_back(Rep::kConf, std::string(name, name_len), std::string(value, value_len)); } else { - rep_->item.push_back(Rep::ConfItem(Rep::kComment, std::string(line, line_len))); + rep_->item.emplace_back(Rep::kComment, std::string(line, line_len)); } } @@ -91,12 +93,12 @@ int BaseConf::ReloadConf() { } bool BaseConf::GetConfInt(const std::string& name, int* value) const { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - (*value) = atoi(rep_->item[i].value.c_str()); + if (name == i.name) { + (*value) = atoi(i.value.c_str()); return true; } } @@ -104,14 +106,14 @@ bool BaseConf::GetConfInt(const std::string& name, int* value) const { } bool BaseConf::GetConfIntHuman(const std::string& name, int* value) const { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - auto c_str = rep_->item[i].value.c_str(); + if (name == i.name) { + auto c_str = i.value.c_str(); (*value) = strtoll(c_str, nullptr, 10); - char last = c_str[rep_->item[i].value.size() - 1]; + char last = c_str[i.value.size() - 1]; if (last == 'K' || last == 'k') { (*value) *= (1 << 10); } else if (last == 'M' || last == 'm') { @@ -126,14 +128,14 @@ bool BaseConf::GetConfIntHuman(const std::string& name, int* value) const { } bool BaseConf::GetConfInt64Human(const std::string& name, int64_t* value) const { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - auto c_str = rep_->item[i].value.c_str(); + if (name == i.name) { + auto c_str = i.value.c_str(); (*value) = strtoll(c_str, nullptr, 10); - char last = c_str[rep_->item[i].value.size() - 1]; + char last = c_str[i.value.size() - 1]; if (last == 'K' || last == 'k') { (*value) *= (1 << 10); } else if (last == 'M' || last == 'm') { @@ -148,12 +150,12 @@ bool BaseConf::GetConfInt64Human(const std::string& name, int64_t* value) const } bool BaseConf::GetConfInt64(const std::string& name, int64_t* value) const { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - (*value) = strtoll(rep_->item[i].value.c_str(), nullptr, 10); + if (name == i.name) { + (*value) = strtoll(i.value.c_str(), nullptr, 10); return true; } } @@ -161,12 +163,12 @@ bool BaseConf::GetConfInt64(const std::string& name, int64_t* value) const { } bool BaseConf::GetConfStr(const std::string& name, std::string* val) const { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == 1) { + for (auto & i : rep_->item) { + if (i.type == 1) { continue; } - if (name == rep_->item[i].name) { - (*val) = rep_->item[i].value; + if (name == i.name) { + (*val) = i.value; return true; } } @@ -174,15 +176,15 @@ bool BaseConf::GetConfStr(const std::string& name, std::string* val) const { } bool BaseConf::GetConfStrVec(const std::string& name, std::vector* value) const { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - std::string val_str = rep_->item[i].value; + if (name == i.name) { + std::string val_str = i.value; std::string::size_type pos; while (true) { - pos = val_str.find(","); + pos = val_str.find(','); if (pos == std::string::npos) { value->push_back(StringTrim(val_str)); break; @@ -197,14 +199,14 @@ bool BaseConf::GetConfStrVec(const std::string& name, std::vector* } bool BaseConf::GetConfBool(const std::string& name, bool* value) const { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - if (rep_->item[i].value == "true" || rep_->item[i].value == "1" || rep_->item[i].value == "yes") { + if (name == i.name) { + if (i.value == "true" || i.value == "1" || i.value == "yes") { (*value) = true; - } else if (rep_->item[i].value == "false" || rep_->item[i].value == "0" || rep_->item[i].value == "no") { + } else if (i.value == "false" || i.value == "0" || i.value == "no") { (*value) = false; } return true; @@ -227,12 +229,12 @@ bool BaseConf::GetConfDouble(const std::string& name, double* value) const { } bool BaseConf::SetConfInt(const std::string& name, const int value) { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - rep_->item[i].value = std::to_string(value); + if (name == i.name) { + i.value = std::to_string(value); return true; } } @@ -240,12 +242,12 @@ bool BaseConf::SetConfInt(const std::string& name, const int value) { } bool BaseConf::SetConfInt64(const std::string& name, const int64_t value) { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - rep_->item[i].value = std::to_string(value); + if (name == i.name) { + i.value = std::to_string(value); return true; } } @@ -253,12 +255,12 @@ bool BaseConf::SetConfInt64(const std::string& name, const int64_t value) { } bool BaseConf::SetConfStr(const std::string& name, const std::string& value) { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - rep_->item[i].value = value; + if (name == i.name) { + i.value = value; return true; } } @@ -266,15 +268,15 @@ bool BaseConf::SetConfStr(const std::string& name, const std::string& value) { } bool BaseConf::SetConfBool(const std::string& name, const bool value) { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - if (value == true) { - rep_->item[i].value = "true"; + if (name == i.name) { + if (value) { + i.value = "true"; } else { - rep_->item[i].value = "false"; + i.value = "false"; } return true; } @@ -288,12 +290,12 @@ bool BaseConf::SetConfStrVec(const std::string& name, const std::vectoritem.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { - rep_->item[i].value = std::to_string(value); + if (name == i.name) { + i.value = std::to_string(value); return true; } } @@ -301,11 +303,11 @@ bool BaseConf::SetConfDouble(const std::string& name, const double value) { } bool BaseConf::CheckConfExist(const std::string& name) const { - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kComment) { + for (auto & i : rep_->item) { + if (i.type == Rep::kComment) { continue; } - if (name == rep_->item[i].name) { + if (name == i.name) { return true; } } @@ -314,9 +316,9 @@ bool BaseConf::CheckConfExist(const std::string& name) const { void BaseConf::DumpConf() const { int cnt = 1; - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kConf) { - LOG(INFO) << fmt::format("{:2} {} {}", cnt++, rep_->item[i].name, rep_->item[i].value); + for (auto & i : rep_->item) { + if (i.type == Rep::kConf) { + LOG(INFO) << fmt::format("{:2} {} {}", cnt++, i.name, i.value); } } } @@ -330,12 +332,12 @@ bool BaseConf::WriteBack() { return false; } std::string tmp; - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kConf) { - tmp = rep_->item[i].name + " : " + rep_->item[i].value + "\n"; + for (auto & i : rep_->item) { + if (i.type == Rep::kConf) { + tmp = i.name + " : " + i.value + "\n"; write_file->Append(tmp); } else { - write_file->Append(rep_->item[i].value); + write_file->Append(i.value); } } DeleteFile(rep_->path); @@ -348,15 +350,14 @@ void BaseConf::WriteSampleConf() const { std::string sample_path = rep_->path + ".sample"; Status ret = NewWritableFile(sample_path, write_file); std::string tmp; - for (size_t i = 0; i < rep_->item.size(); i++) { - if (rep_->item[i].type == Rep::kConf) { - tmp = rep_->item[i].name + " :\n"; + for (auto & i : rep_->item) { + if (i.type == Rep::kConf) { + tmp = i.name + " :\n"; write_file->Append(tmp); } else { - write_file->Append(rep_->item[i].value); + write_file->Append(i.value); } } - return; } void BaseConf::PushConfItem(const Rep::ConfItem& item) { rep_->item.push_back(item); } diff --git a/src/pstd/src/env.cc b/src/pstd/src/env.cc index f30e5f4374..d6cf3b3ae9 100644 --- a/src/pstd/src/env.cc +++ b/src/pstd/src/env.cc @@ -1,15 +1,16 @@ #include "pstd/include/env.h" -#include #include #include #include #include #include #include +#include #include #include +#include #include #include @@ -33,7 +34,7 @@ int SetMaxFileDescriptorNum(int64_t max_file_descriptor_num) { // Try to Set the number of file descriptor struct rlimit limit; if (getrlimit(RLIMIT_NOFILE, &limit) != -1) { - if (limit.rlim_cur < (rlim_t)max_file_descriptor_num) { + if (limit.rlim_cur < static_cast(max_file_descriptor_num)) { // rlim_cur could be set by any user while rlim_max are // changeable only by root. limit.rlim_cur = max_file_descriptor_num; @@ -90,7 +91,8 @@ int DoCreatePath(const char* path, mode_t mode) { if (stat(path, &st) != 0) { /* Directory does not exist. EEXIST for race * condition */ - if (mkdir(path, mode) != 0 && errno != EEXIST) status = -1; + if (mkdir(path, mode) != 0 && errno != EEXIST) { status = -1; +} } else if (!S_ISDIR(st.st_mode)) { errno = ENOTDIR; status = -1; @@ -113,7 +115,7 @@ int CreatePath(const std::string& path, mode_t mode) { status = 0; pp = copypath; - while (status == 0 && (sp = strchr(pp, '/')) != 0) { + while (status == 0 && (sp = strchr(pp, '/')) != nullptr) { if (sp != pp) { /* Neither root nor double pstd in path */ *sp = '\0'; @@ -122,7 +124,9 @@ int CreatePath(const std::string& path, mode_t mode) { } pp = sp + 1; } - if (status == 0) status = DoCreatePath(path.c_str(), mode); + if (status == 0) { + status = DoCreatePath(path.c_str(), mode); + } free(copypath); return (status); } @@ -148,7 +152,7 @@ Status LockFile(const std::string& fname, FileLock** lock) { result = IOError("lock " + fname, errno); close(fd); } else { - FileLock* my_lock = new FileLock; + auto my_lock = new FileLock; my_lock->fd_ = fd; my_lock->name_ = fname; *lock = my_lock; @@ -170,7 +174,7 @@ int GetChildren(const std::string& dir, std::vector& result) { int res = 0; result.clear(); DIR* d = opendir(dir.c_str()); - if (d == nullptr) { + if (!d) { return errno; } struct dirent* entry; @@ -178,7 +182,7 @@ int GetChildren(const std::string& dir, std::vector& result) { if (strcmp(entry->d_name, "..") == 0 || strcmp(entry->d_name, ".") == 0) { continue; } - result.push_back(entry->d_name); + result.emplace_back(entry->d_name); } closedir(d); return res; @@ -186,7 +190,7 @@ int GetChildren(const std::string& dir, std::vector& result) { bool GetDescendant(const std::string& dir, std::vector& result) { DIR* d = opendir(dir.c_str()); - if (d == nullptr) { + if (!d) { return false; } struct dirent* entry; @@ -216,7 +220,7 @@ int IsDir(const std::string& path) { struct stat buf; int ret = stat(path.c_str(), &buf); if (0 == ret) { - if (buf.st_mode & S_IFDIR) { + if ((buf.st_mode & S_IFDIR) != 0) { // folder return 0; } else { @@ -270,10 +274,7 @@ int DeleteDir(const std::string& path) { } bool DeleteDirIfExist(const std::string& path) { - if (IsDir(path) == 0 && DeleteDir(path) != 0) { - return false; - } - return true; + return !(IsDir(path) == 0 && DeleteDir(path) != 0); } uint64_t Du(const std::string& filename) { @@ -295,7 +296,7 @@ uint64_t Du(const std::string& filename) { if (!dir) { return sum; } - while ((entry = readdir(dir))) { + while ((entry = readdir(dir)) != nullptr) { if (strcmp(entry->d_name, "..") == 0 || strcmp(entry->d_name, ".") == 0) { continue; } @@ -315,7 +316,7 @@ uint64_t NowMicros() { void SleepForMicroseconds(int micros) { usleep(micros); } -SequentialFile::~SequentialFile() {} +SequentialFile::~SequentialFile() = default; class PosixSequentialFile : public SequentialFile { private: @@ -325,22 +326,22 @@ class PosixSequentialFile : public SequentialFile { public: virtual void setUnBuffer() { setbuf(file_, nullptr); } - PosixSequentialFile(const std::string& fname, FILE* f) : filename_(fname), file_(f) { setbuf(file_, nullptr); } + PosixSequentialFile(std::string fname, FILE* f) : filename_(std::move(fname)), file_(f) { setbuf(file_, nullptr); } - virtual ~PosixSequentialFile() { + ~PosixSequentialFile() override { if (file_) { fclose(file_); } } - virtual Status Read(size_t n, Slice* result, char* scratch) override { + Status Read(size_t n, Slice* result, char* scratch) override { Status s; size_t r = fread(scratch, 1, n, file_); *result = Slice(scratch, r); if (r < n) { - if (feof(file_)) { + if (feof(file_) != 0) { s = Status::EndFile(filename_, "end file"); // We leave status as ok if we hit the end of the file } else { @@ -351,14 +352,14 @@ class PosixSequentialFile : public SequentialFile { return s; } - virtual Status Skip(uint64_t n) override { - if (fseek(file_, n, SEEK_CUR)) { + Status Skip(uint64_t n) override { + if (fseek(file_, n, SEEK_CUR) != 0) { return IOError(filename_, errno); } return Status::OK(); } - virtual char* ReadLine(char* buf, int n) override { return fgets(buf, n, file_); } + char* ReadLine(char* buf, int n) override { return fgets(buf, n, file_); } virtual Status Close() { if (fclose(file_) != 0) { @@ -369,7 +370,7 @@ class PosixSequentialFile : public SequentialFile { } }; -WritableFile::~WritableFile() {} +WritableFile::~WritableFile() = default; // We preallocate up to an extra megabyte and use memcpy to append new // data to the file. This is safe since we either properly close the @@ -403,7 +404,7 @@ class PosixMmapFile : public WritableFile { bool UnmapCurrentRegion() { bool result = true; - if (base_ != nullptr) { + if (base_) { if (last_sync_ < limit_) { // Defer syncing this data until next Sync() call, if any pending_sync_ = true; @@ -436,7 +437,7 @@ class PosixMmapFile : public WritableFile { return false; } void* ptr = mmap(nullptr, map_size_, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, file_offset_); - if (ptr == MAP_FAILED) { + if (ptr == MAP_FAILED) { // NOLINT LOG(WARNING) << "mmap failed"; return false; } @@ -449,18 +450,14 @@ class PosixMmapFile : public WritableFile { } public: - PosixMmapFile(const std::string& fname, int fd, size_t page_size, uint64_t write_len = 0) - : filename_(fname), + PosixMmapFile(std::string fname, int fd, size_t page_size, uint64_t write_len = 0) + : filename_(std::move(fname)), fd_(fd), page_size_(page_size), map_size_(Roundup(kMmapBoundSize, page_size)), - base_(nullptr), - limit_(nullptr), - dst_(nullptr), - last_sync_(nullptr), - file_offset_(0), - write_len_(write_len), - pending_sync_(false) { + + write_len_(write_len) + { if (write_len_ != 0) { while (map_size_ < write_len_) { map_size_ += (1024 * 1024); @@ -469,20 +466,20 @@ class PosixMmapFile : public WritableFile { assert((page_size & (page_size - 1)) == 0); } - ~PosixMmapFile() { + ~PosixMmapFile() override { if (fd_ >= 0) { PosixMmapFile::Close(); } } - virtual Status Append(const Slice& data) { + Status Append(const Slice& data) override { const char* src = data.data(); size_t left = data.size(); while (left > 0) { assert(base_ <= dst_); assert(dst_ <= limit_); size_t avail = limit_ - dst_; - if (avail == 0) { + if (!avail) { if (!UnmapCurrentRegion() || !MapNewRegion()) { return IOError(filename_, errno); } @@ -496,7 +493,7 @@ class PosixMmapFile : public WritableFile { return Status::OK(); } - virtual Status Close() { + Status Close() override { Status s; size_t unused = limit_ - dst_; if (!UnmapCurrentRegion()) { @@ -520,9 +517,9 @@ class PosixMmapFile : public WritableFile { return s; } - virtual Status Flush() { return Status::OK(); } + Status Flush() override { return Status::OK(); } - virtual Status Sync() { + Status Sync() override { Status s; if (pending_sync_) { @@ -551,7 +548,7 @@ class PosixMmapFile : public WritableFile { return s; } - virtual Status Trim(uint64_t target) { + Status Trim(uint64_t target) override { if (!UnmapCurrentRegion()) { return IOError(filename_, errno); } @@ -564,19 +561,19 @@ class PosixMmapFile : public WritableFile { return Status::OK(); } - virtual uint64_t Filesize() { return write_len_ + file_offset_ + (dst_ - base_); } + uint64_t Filesize() override { return write_len_ + file_offset_ + (dst_ - base_); } }; -RWFile::~RWFile() {} +RWFile::~RWFile() = default; class MmapRWFile : public RWFile { public: - MmapRWFile(const std::string& fname, int fd, size_t page_size) - : filename_(fname), fd_(fd), page_size_(page_size), map_size_(Roundup(65536, page_size)), base_(nullptr) { + MmapRWFile(std::string fname, int fd, size_t page_size) + : filename_(std::move(fname)), fd_(fd), page_size_(page_size), map_size_(Roundup(65536, page_size)) { DoMapRegion(); } - ~MmapRWFile() { + ~MmapRWFile() override { if (fd_ >= 0) { munmap(base_, map_size_); } @@ -591,21 +588,21 @@ class MmapRWFile : public RWFile { return false; } void* ptr = mmap(nullptr, map_size_, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0); - if (ptr == MAP_FAILED) { + if (ptr == MAP_FAILED) { // NOLINT return false; } base_ = reinterpret_cast(ptr); return true; } - char* GetData() { return base_; } + char* GetData() override { return base_; } char* base() { return base_; } private: static size_t Roundup(size_t x, size_t y) { return ((x + y - 1) / y) * y; } std::string filename_; int fd_ = -1; - size_t page_size_ = 0; + size_t page_size_[[maybe_unused]] = 0; size_t map_size_ = 0; char* base_ = nullptr; }; @@ -619,18 +616,20 @@ class PosixRandomRWFile : public RandomRWFile { // bool fallocate_with_keep_size_; public: - PosixRandomRWFile(const std::string& fname, int fd) - : filename_(fname), fd_(fd), pending_sync_(false), pending_fsync_(false) { + PosixRandomRWFile(std::string fname, int fd) + : filename_(std::move(fname)), fd_(fd) { // fallocate_with_keep_size_ = options.fallocate_with_keep_size; } - ~PosixRandomRWFile() { + ~PosixRandomRWFile() override { if (fd_ >= 0) { - Close(); + // TODO(clang-tidy): Call virtual method during destruction bypasses virtual dispatch + // So I disabled next line clang-tidy check simply temporarily. + Close(); // NOLINT } } - virtual Status Write(uint64_t offset, const Slice& data) override { + Status Write(uint64_t offset, const Slice& data) override { const char* src = data.data(); size_t left = data.size(); Status s; @@ -654,7 +653,7 @@ class PosixRandomRWFile : public RandomRWFile { return Status::OK(); } - virtual Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const override { + Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const override { Status s; ssize_t r = -1; size_t left = n; @@ -678,7 +677,7 @@ class PosixRandomRWFile : public RandomRWFile { return s; } - virtual Status Close() override { + Status Close() override { Status s = Status::OK(); if (fd_ >= 0 && close(fd_) < 0) { s = IOError(filename_, errno); @@ -687,7 +686,7 @@ class PosixRandomRWFile : public RandomRWFile { return s; } - virtual Status Sync() override { + Status Sync() override { #if defined(__APPLE__) if (pending_sync_ && fsync(fd_) < 0) { #else @@ -699,7 +698,7 @@ class PosixRandomRWFile : public RandomRWFile { return Status::OK(); } - virtual Status Fsync() override { + Status Fsync() override { if (pending_fsync_ && fsync(fd_) < 0) { return IOError(filename_, errno); } @@ -722,7 +721,7 @@ class PosixRandomRWFile : public RandomRWFile { Status NewSequentialFile(const std::string& fname, std::unique_ptr& result) { FILE* f = fopen(fname.c_str(), "r"); - if (f == nullptr) { + if (!f) { return IOError(fname, errno); } else { result = std::make_unique(fname, f); diff --git a/src/pstd/src/lock_mgr.cc b/src/pstd/src/lock_mgr.cc index e067d48f52..12ef090674 100644 --- a/src/pstd/src/lock_mgr.cc +++ b/src/pstd/src/lock_mgr.cc @@ -17,12 +17,10 @@ #include "pstd/include/mutex.h" -namespace pstd { - -namespace lock { +namespace pstd::lock { struct LockMapStripe { - explicit LockMapStripe(std::shared_ptr factory) { + explicit LockMapStripe(const std::shared_ptr& factory) { stripe_mutex = factory->AllocateMutex(); stripe_cv = factory->AllocateCondVar(); assert(stripe_mutex); @@ -41,7 +39,7 @@ struct LockMapStripe { // Map of #num_stripes LockMapStripes struct LockMap { - explicit LockMap(size_t num_stripes, std::shared_ptr factory) : num_stripes_(num_stripes) { + explicit LockMap(size_t num_stripes, const std::shared_ptr& factory) : num_stripes_(num_stripes) { lock_map_stripes_.reserve(num_stripes); for (size_t i = 0; i < num_stripes; i++) { auto stripe = std::make_shared(factory); @@ -49,7 +47,7 @@ struct LockMap { } } - ~LockMap() {} + ~LockMap() = default; // Number of sepearate LockMapStripes to create, each with their own Mutex const size_t num_stripes_; @@ -69,13 +67,13 @@ size_t LockMap::GetStripe(const std::string& key) const { return stripe; } -LockMgr::LockMgr(size_t default_num_stripes, int64_t max_num_locks, std::shared_ptr mutex_factory) +LockMgr::LockMgr(size_t default_num_stripes, int64_t max_num_locks, const std::shared_ptr& mutex_factory) : default_num_stripes_(default_num_stripes), max_num_locks_(max_num_locks), mutex_factory_(mutex_factory), lock_map_(std::make_shared(default_num_stripes, mutex_factory)) {} -LockMgr::~LockMgr() {} +LockMgr::~LockMgr() = default; Status LockMgr::TryLock(const std::string& key) { #ifdef LOCKLESS @@ -136,7 +134,7 @@ Status LockMgr::AcquireLocked(std::shared_ptr stripe, const std:: stripe->keys.insert(key); // Maintain lock count if there is a limit on the number of locks - if (max_num_locks_) { + if (max_num_locks_ != 0) { lock_map_->lock_cnt++; } } @@ -176,5 +174,4 @@ void LockMgr::UnLock(const std::string& key) { // Signal waiting threads to retry locking stripe->stripe_cv->NotifyAll(); } -} // namespace lock -} // namespace pstd +} // namespace pstd::lock diff --git a/src/pstd/src/mutex_impl.cc b/src/pstd/src/mutex_impl.cc index 68e1573771..987760d94d 100644 --- a/src/pstd/src/mutex_impl.cc +++ b/src/pstd/src/mutex_impl.cc @@ -9,13 +9,12 @@ #include "pstd/include/mutex.h" #include "pstd/include/mutex_impl.h" -namespace pstd { -namespace lock { +namespace pstd::lock { class MutexImpl : public Mutex { public: - MutexImpl() {} - ~MutexImpl() {} + MutexImpl() = default; + ~MutexImpl() override = default; Status Lock() override; @@ -31,8 +30,8 @@ class MutexImpl : public Mutex { class CondVarImpl : public CondVar { public: - CondVarImpl() {} - ~CondVarImpl() {} + CondVarImpl() = default; + ~CondVarImpl() override = default; Status Wait(std::shared_ptr mutex) override; @@ -116,5 +115,4 @@ Status CondVarImpl::WaitFor(std::shared_ptr mutex, int64_t timeout_time) // CV was signaled, or we spuriously woke up (but didn't time out) return s; } -} // namespace lock -} // namespace pstd +} // namespace pstd::lock diff --git a/src/pstd/src/posix.cc b/src/pstd/src/posix.cc index ffe4b488f9..390c33a182 100644 --- a/src/pstd/src/posix.cc +++ b/src/pstd/src/posix.cc @@ -2,12 +2,14 @@ #include "pstd/include/xdebug.h" #include +#include +#include /********************************************* * Wrappers for Unix process control functions ********************************************/ /* $begin forkwrapper */ -pid_t Fork(void) { +pid_t Fork() { pid_t pid; if ((pid = fork()) < 0) { @@ -55,7 +57,6 @@ void Kill(pid_t pid, int signum) { void Pause() { (void)pause(); - return; } unsigned int Sleep(unsigned int secs) { return sleep(secs); } @@ -68,10 +69,9 @@ void Setpgid(pid_t pid, pid_t pgid) { if ((rc = setpgid(pid, pgid)) < 0) { LOG(ERROR) << "Setpgid error: " << strerror(errno); } - return; } -pid_t Getpgrp(void) { return getpgrp(); } +pid_t Getpgrp() { return getpgrp(); } /************************************ * Wrappers for Unix signal functions @@ -79,7 +79,8 @@ pid_t Getpgrp(void) { return getpgrp(); } /* $begin sigaction */ handler_t* Signal(int signum, handler_t* handler) { - struct sigaction action, old_action; + struct sigaction action; + struct sigaction old_action; action.sa_handler = handler; sigemptyset(&action.sa_mask); /* block sigs of type being handled */ @@ -96,40 +97,35 @@ void Sigprocmask(int how, const sigset_t* set, sigset_t* oldset) { if (sigprocmask(how, set, oldset) < 0) { LOG(ERROR) << "Sigprocmask error: " << strerror(errno); } - return; } void Sigemptyset(sigset_t* set) { if (sigemptyset(set) < 0) { LOG(ERROR) << "Sigemptyset error: " << strerror(errno); } - return; } void Sigfillset(sigset_t* set) { if (sigfillset(set) < 0) { LOG(ERROR) << "Sigfillset error: " << strerror(errno); } - return; } void Sigaddset(sigset_t* set, int signum) { if (sigaddset(set, signum) < 0) { LOG(ERROR) << "Sigaddset error: " << strerror(errno); } - return; } void Sigdelset(sigset_t* set, int signum) { if (sigdelset(set, signum) < 0) { LOG(ERROR) << "Sigdelset error: " << strerror(errno); } - return; } int Sigismember(const sigset_t* set, int signum) { int rc; - if ((rc = sigismember(set, signum)) < 0) { + if (rc = sigismember(set, signum); rc < 0) { LOG(ERROR) << "Sigismember error: " << strerror(errno); } return rc; @@ -219,7 +215,7 @@ void Fstat(int fd, struct stat* buf) { void* Mmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset) { void* ptr; - if ((ptr = mmap(addr, len, prot, flags, fd, offset)) == ((void*)-1)) { + if ((ptr = mmap(addr, len, prot, flags, fd, offset)) == ((void*)-1)) { // NOLINT LOG(ERROR) << "mmap error: " << strerror(errno); } return (ptr); @@ -238,7 +234,7 @@ void Munmap(void* start, size_t length) { void* Malloc(size_t size) { void* p; - if ((p = malloc(size)) == nullptr) { + if (!(p = malloc(size))) { LOG(ERROR) << "Malloc error: " << strerror(errno); } return p; @@ -247,7 +243,7 @@ void* Malloc(size_t size) { void* Realloc(void* ptr, size_t size) { void* p; - if ((p = realloc(ptr, size)) == nullptr) { + if (!(p = realloc(ptr, size))) { LOG(ERROR) << "Realloc error: " << strerror(errno); } return p; @@ -256,7 +252,7 @@ void* Realloc(void* ptr, size_t size) { void* Calloc(size_t nmemb, size_t size) { void* p; - if ((p = calloc(nmemb, size)) == nullptr) { + if (!(p = calloc(nmemb, size))) { LOG(ERROR) << "Calloc error: " << strerror(errno); } return p; @@ -276,7 +272,7 @@ void Fclose(FILE* fp) { FILE* Fdopen(int fd, const char* type) { FILE* fp; - if ((fp = fdopen(fd, type)) == nullptr) { + if (!(fp = fdopen(fd, type))) { LOG(ERROR) << "Fdopen error: " << strerror(errno); } @@ -286,7 +282,7 @@ FILE* Fdopen(int fd, const char* type) { char* Fgets(char* ptr, int n, FILE* stream) { char* rptr; - if (((rptr = fgets(ptr, n, stream)) == nullptr) && ferror(stream)) { + if (!(rptr = fgets(ptr, n, stream)) && ferror(stream)) { LOG(ERROR) << "Fgets error"; } @@ -296,7 +292,7 @@ char* Fgets(char* ptr, int n, FILE* stream) { FILE* Fopen(const char* filename, const char* mode) { FILE* fp; - if ((fp = fopen(filename, mode)) == nullptr) { + if (!(fp = fopen(filename, mode))) { LOG(ERROR) << "Fopen error: " << strerror(errno); } @@ -312,7 +308,7 @@ void Fputs(const char* ptr, FILE* stream) { size_t Fread(void* ptr, size_t size, size_t nmemb, FILE* stream) { size_t n; - if (((n = fread(ptr, size, nmemb, stream)) < nmemb) && ferror(stream)) { + if (((n = fread(ptr, size, nmemb, stream)) < nmemb) && (ferror(stream) != 0)) { LOG(ERROR) << "Fread error: " << strerror(errno); } return n; @@ -338,25 +334,19 @@ int Socket(int domain, int type, int protocol) { } void Setsockopt(int s, int level, int optname, const void* optval, int optlen) { - int rc; - - if ((rc = setsockopt(s, level, optname, optval, optlen)) < 0) { + if (setsockopt(s, level, optname, optval, optlen) < 0) { LOG(ERROR) << "Setsockopt error: " << strerror(errno); } } void Bind(int sockfd, struct sockaddr* my_addr, int addrlen) { - int rc; - - if ((rc = bind(sockfd, my_addr, addrlen)) < 0) { + if (bind(sockfd, my_addr, addrlen) < 0) { LOG(ERROR) << "Bind error: " << strerror(errno); } } void Listen(int s, int backlog) { - int rc; - - if ((rc = listen(s, backlog)) < 0) { + if (listen(s, backlog) < 0) { LOG(ERROR) << "Listen error: " << strerror(errno); } } @@ -364,16 +354,14 @@ void Listen(int s, int backlog) { int Accept(int s, struct sockaddr* addr, socklen_t* addrlen) { int rc; - if ((rc = accept(s, addr, addrlen)) < 0) { + if (rc = accept(s, addr, addrlen); rc < 0) { LOG(ERROR) << "Accept error: " << strerror(errno); } return rc; } void Connect(int sockfd, struct sockaddr* serv_addr, int addrlen) { - int rc; - - if ((rc = connect(sockfd, serv_addr, addrlen)) < 0) { + if (connect(sockfd, serv_addr, addrlen) < 0) { LOG(ERROR) << "Connect error: " << strerror(errno); } } @@ -386,7 +374,7 @@ void Connect(int sockfd, struct sockaddr* serv_addr, int addrlen) { struct hostent* Gethostbyname(const char* name) { struct hostent* p; - if ((p = gethostbyname(name)) == nullptr) { + if (!(p = gethostbyname(name))) { LOG(ERROR) << "Gethostbyname error: DNS error " << h_errno; } return p; @@ -396,7 +384,7 @@ struct hostent* Gethostbyname(const char* name) { struct hostent* Gethostbyaddr(const char* addr, int len, int type) { struct hostent* p; - if ((p = gethostbyaddr(addr, len, type)) == nullptr) { + if (!(p = gethostbyaddr(addr, len, type))) { LOG(ERROR) << "Gethostbyaddr error: DNS error " << h_errno; } return p; @@ -409,7 +397,7 @@ struct hostent* Gethostbyaddr(const char* addr, int len, int type) { void Pthread_create(pthread_t* tidp, pthread_attr_t* attrp, void* (*routine)(void*), void* argp) { int rc; - if ((rc = pthread_create(tidp, attrp, routine, argp)) != 0) { + if (rc = pthread_create(tidp, attrp, routine, argp); rc != 0) { LOG(ERROR) << "Pthread_create error: " << strerror(rc); } } @@ -417,7 +405,7 @@ void Pthread_create(pthread_t* tidp, pthread_attr_t* attrp, void* (*routine)(voi void Pthread_cancel(pthread_t tid) { int rc; - if ((rc = pthread_cancel(tid)) != 0) { + if (rc = pthread_cancel(tid); rc != 0) { LOG(ERROR) << "Pthread_cancel error: " << strerror(rc); } } @@ -442,7 +430,7 @@ void Pthread_detach(pthread_t tid) { void Pthread_exit(void* retval) { pthread_exit(retval); } -pthread_t Pthread_self(void) { return pthread_self(); } +pthread_t Pthread_self() { return pthread_self(); } void Pthread_once(pthread_once_t* once_control, void (*init_function)()) { pthread_once(once_control, init_function); } @@ -451,7 +439,8 @@ void Pthread_once(pthread_once_t* once_control, void (*init_function)()) { pthre *******************************/ void Sem_init(sem_t* sem, int pshared, unsigned int value) { - if (sem_init(sem, pshared, value) < 0) { +// TODO(clang-tidy) : should use c11 cond or mutex instead of Posix sem + if (sem_init(sem, pshared, value) < 0) { // NOLINT LOG(ERROR) << "Sem_init error: " << strerror(errno); } } @@ -478,16 +467,18 @@ void V(sem_t* sem) { ssize_t rio_readn(int fd, void* usrbuf, size_t n) { size_t nleft = n; ssize_t nread; - char* bufp = (char*)usrbuf; + char* bufp = static_cast(usrbuf); while (nleft > 0) { if ((nread = read(fd, bufp, nleft)) < 0) { - if (errno == EINTR) /* interrupted by sig handler return */ + if (errno == EINTR) { /* interrupted by sig handler return */ nread = 0; /* and call read() again */ - else + } else { return -1; /* errno set by read() */ - } else if (nread == 0) +} + } else if (nread == 0) { break; /* EOF */ +} nleft -= nread; bufp += nread; } @@ -502,14 +493,15 @@ ssize_t rio_readn(int fd, void* usrbuf, size_t n) { ssize_t rio_writen(int fd, void* usrbuf, size_t n) { size_t nleft = n; ssize_t nwritten; - char* bufp = (char*)usrbuf; + char* bufp = static_cast(usrbuf); while (nleft > 0) { if ((nwritten = write(fd, bufp, nleft)) <= 0) { - if (errno == EINTR) /* interrupted by sig handler return */ + if (errno == EINTR) { /* interrupted by sig handler return */ nwritten = 0; /* and call write() again */ - else + } else { return -1; /* errorno set by write() */ +} } nleft -= nwritten; bufp += nwritten; @@ -533,17 +525,21 @@ static ssize_t rio_read(rio_t* rp, char* usrbuf, size_t n) { while (rp->rio_cnt <= 0) { /* refill if buf is empty */ rp->rio_cnt = read(rp->rio_fd, rp->rio_buf, sizeof(rp->rio_buf)); if (rp->rio_cnt < 0) { - if (errno != EINTR) /* interrupted by sig handler return */ + if (errno != EINTR) { /* interrupted by sig handler return */ return -1; - } else if (rp->rio_cnt == 0) /* EOF */ +} + } else if (rp->rio_cnt == 0) { /* EOF */ return 0; - else + } else { rp->rio_bufptr = rp->rio_buf; /* reset buffer ptr */ +} } /* Copy min(n, rp->rio_cnt) bytes from internal buf to user buf */ cnt = n; - if (rp->rio_cnt < (int)n) cnt = rp->rio_cnt; + if (rp->rio_cnt < static_cast(n)) { + cnt = rp->rio_cnt; + } memcpy(usrbuf, rp->rio_bufptr, cnt); rp->rio_bufptr += cnt; rp->rio_cnt -= cnt; @@ -569,16 +565,18 @@ void rio_readinitb(rio_t* rp, int fd) { ssize_t rio_readnb(rio_t* rp, void* usrbuf, size_t n) { size_t nleft = n; ssize_t nread; - char* bufp = (char*)usrbuf; + char* bufp = static_cast(usrbuf); while (nleft > 0) { if ((nread = rio_read(rp, bufp, nleft)) < 0) { - if (errno == EINTR) /* interrupted by sig handler return */ + if (errno == EINTR) { /* interrupted by sig handler return */ nread = 0; /* call read() again */ - else + } else { return -1; /* errno set by read() */ - } else if (nread == 0) + } + } else if (nread == 0) { break; /* EOF */ + } nleft -= nread; bufp += nread; } @@ -593,19 +591,23 @@ ssize_t rio_readnb(rio_t* rp, void* usrbuf, size_t n) { ssize_t rio_readlineb(rio_t* rp, void* usrbuf, size_t maxlen) { size_t n; int rc; - char c, *bufp = (char*)usrbuf; + char c; + char *bufp = static_cast(usrbuf); for (n = 1; n < maxlen; n++) { if ((rc = rio_read(rp, &c, 1)) == 1) { *bufp++ = c; - if (c == '\n') break; + if (c == '\n') { break; +} } else if (rc == 0) { - if (n == 1) + if (n == 1) { return 0; /* EOF, no data read */ - else + } else { break; /* EOF, some data was read */ - } else +} + } else { return -1; /* error */ +} } *bufp = 0; return n; @@ -625,7 +627,7 @@ ssize_t Rio_readn(int fd, void* ptr, size_t nbytes) { } void Rio_writen(int fd, void* usrbuf, size_t n) { - if (rio_writen(fd, usrbuf, n) != (ssize_t)n) { + if (rio_writen(fd, usrbuf, n) != static_cast(n)) { LOG(ERROR) << "Rio_writen error: " << strerror(errno); } } @@ -665,17 +667,23 @@ int open_clientfd(char* hostname, int port) { struct hostent* hp; struct sockaddr_in serveraddr; - if ((clientfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return -1; /* check errno for cause of error */ + if ((clientfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + return -1; /* check errno for cause of error */ + } /* Fill in the server's IP address and port */ - if ((hp = gethostbyname(hostname)) == nullptr) return -2; /* check h_errno for cause of error */ - bzero((char*)&serveraddr, sizeof(serveraddr)); + if (!(hp = gethostbyname(hostname))) { + return -2; /* check h_errno for cause of error */ + } + memset(&serveraddr, 0, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; - bcopy((char*)hp->h_addr_list[0], (char*)&serveraddr.sin_addr.s_addr, hp->h_length); + memmove(&serveraddr.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length); serveraddr.sin_port = htons(port); /* Establish a connection with the server */ - if (connect(clientfd, (SA*)&serveraddr, sizeof(serveraddr)) < 0) return -1; + if (connect(clientfd, reinterpret_cast(&serveraddr), sizeof(serveraddr)) < 0) { + return -1; + } return clientfd; } /* $end open_clientfd */ @@ -686,25 +694,34 @@ int open_clientfd(char* hostname, int port) { */ /* $begin open_listenfd */ int open_listenfd(int port) { - int listenfd, optval = 1; + int listenfd; + int optval = 1; struct sockaddr_in serveraddr; /* Create a socket descriptor */ - if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return -1; + if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + return -1; + } /* Eliminates "Address already in use" error from bind. */ - if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const void*)&optval, sizeof(int)) < 0) return -1; + if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)) < 0) { + return -1; + } /* Listenfd will be an endpoint for all requests to port on any IP address for this host */ - bzero((char*)&serveraddr, sizeof(serveraddr)); + memset(&serveraddr, 0, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); serveraddr.sin_port = htons((unsigned short)port); - if (bind(listenfd, (SA*)&serveraddr, sizeof(serveraddr)) < 0) return -1; + if (bind(listenfd, reinterpret_cast(&serveraddr), sizeof(serveraddr)) < 0) { + return -1; + } /* Make it a listening socket ready to accept connection requests */ - if (listen(listenfd, LISTENQ) < 0) return -1; + if (listen(listenfd, LISTENQ) < 0) { + return -1; +} return listenfd; } /* $end open_listenfd */ diff --git a/src/pstd/src/pstd_coding.cc b/src/pstd/src/pstd_coding.cc index b6ef74f860..8d2b0e67f3 100644 --- a/src/pstd/src/pstd_coding.cc +++ b/src/pstd/src/pstd_coding.cc @@ -33,7 +33,7 @@ void PutFixed64(std::string* dst, uint64_t value) { char* EncodeVarint32(char* dst, uint32_t v) { // Operate on characters as unsigneds - unsigned char* ptr = reinterpret_cast(dst); + auto ptr = reinterpret_cast(dst); static const int B = 128; if (v < (1 << 7)) { *(ptr++) = v; @@ -67,7 +67,7 @@ void PutVarint32(std::string* dst, uint32_t v) { char* EncodeVarint64(char* dst, uint64_t v) { static const int B = 128; - unsigned char* ptr = reinterpret_cast(dst); + auto ptr = reinterpret_cast(dst); while (v >= B) { *(ptr++) = (v & (B - 1)) | B; v >>= 7; @@ -101,7 +101,7 @@ const char* GetVarint32PtrFallback(const char* p, const char* limit, uint32_t* v for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) { uint32_t byte = *(reinterpret_cast(p)); p++; - if (byte & 128) { + if ((byte & 128) != 0U) { // More bytes are present result |= ((byte & 127) << shift); } else { @@ -117,7 +117,7 @@ bool GetVarint32(std::string* input, uint32_t* value) { const char* p = input->data(); const char* limit = p + input->size(); const char* q = GetVarint32Ptr(p, limit, value); - if (q == nullptr) { + if (!q) { return false; } else { (*input).erase(0, q - p); @@ -129,7 +129,7 @@ bool GetVarint32(Slice* input, uint32_t* value) { const char* p = input->data(); const char* limit = p + input->size(); const char* q = GetVarint32Ptr(p, limit, value); - if (q == nullptr) { + if (!q) { return false; } else { *input = Slice(q, limit - q); @@ -142,7 +142,7 @@ const char* GetVarint64Ptr(const char* p, const char* limit, uint64_t* value) { for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) { uint64_t byte = *(reinterpret_cast(p)); p++; - if (byte & 128) { + if ((byte & 128) != 0U) { // More bytes are present result |= ((byte & 127) << shift); } else { @@ -158,7 +158,7 @@ bool GetVarint64(Slice* input, uint64_t* value) { const char* p = input->data(); const char* limit = p + input->size(); const char* q = GetVarint64Ptr(p, limit, value); - if (q == nullptr) { + if (!q) { return false; } else { *input = Slice(q, limit - q); @@ -169,8 +169,12 @@ bool GetVarint64(Slice* input, uint64_t* value) { const char* GetLengthPrefixedSlice(const char* p, const char* limit, Slice* result) { uint32_t len; p = GetVarint32Ptr(p, limit, &len); - if (p == nullptr) return nullptr; - if (p + len > limit) return nullptr; + if (!p) { + return nullptr; + } + if (p + len > limit) { + return nullptr; + } *result = Slice(p, len); return p + len; } diff --git a/src/pstd/src/pstd_hash.cc b/src/pstd/src/pstd_hash.cc index 5f1698d31c..120da79c01 100644 --- a/src/pstd/src/pstd_hash.cc +++ b/src/pstd/src/pstd_hash.cc @@ -72,6 +72,7 @@ // of patent rights can be found in the PATENTS file in the same directory. #include "pstd/include/pstd_hash.h" +#include #include #include #include @@ -80,9 +81,9 @@ namespace pstd { class SHA256 { protected: - typedef unsigned char uint8; - typedef unsigned int uint32; - typedef unsigned long long uint64; + using uint8 = unsigned char; + using uint32 = unsigned int; + using uint64 = uint64_t; const static uint32 sha256_k[]; static const unsigned int SHA224_256_BLOCK_SIZE = (512 / 8); @@ -101,11 +102,11 @@ class SHA256 { uint32 m_h[8]; }; -#define SHA2_SHFR(x, n) (x >> n) -#define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) -#define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) -#define SHA2_CH(x, y, z) ((x & y) ^ (~x & z)) -#define SHA2_MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) +#define SHA2_SHFR(x, n) ((x) >> (n)) +#define SHA2_ROTR(x, n) (((x) >> (n)) | ((x) << ((sizeof(x) << 3) - (n)))) +#define SHA2_ROTL(x, n) (((x) << (n)) | ((x) >> ((sizeof(x) << 3) - (n)))) +#define SHA2_CH(x, y, z) (((x) & (y)) ^ (~(x) & (z))) +#define SHA2_MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) #define SHA256_F1(x) (SHA2_ROTR(x, 2) ^ SHA2_ROTR(x, 13) ^ SHA2_ROTR(x, 22)) #define SHA256_F2(x) (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25)) #define SHA256_F3(x) (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3)) @@ -135,21 +136,21 @@ class SHA256 { // assumes that char is 8 bit and int is 32 bit class MD5 { public: - typedef unsigned int size_type; // must be 32bit + using size_type = unsigned int; // must be 32bit MD5(); MD5(const std::string& text); - void update(const unsigned char* buf, size_type length); - void update(const char* buf, size_type length); + void update(const unsigned char* input, size_type length); + void update(const char* input, size_type length); MD5& finalize(); std::string hexdigest() const; std::string rawdigest() const; - friend std::ostream& operator<<(std::ostream&, MD5 md5); + friend std::ostream& operator<<(std::ostream& /*out*/, MD5 md5); private: void init(); - typedef unsigned char uint1; // 8bit - typedef unsigned int uint4; // 32bit + using uint1 = unsigned char; // 8bit + using uint4 = unsigned int; // 32bit enum { blocksize = 64 }; // VC6 won't eat a const static int here void transform(const uint1 block[blocksize]); @@ -187,11 +188,12 @@ const unsigned int SHA256::sha256_k[64] = { // UL = uint32 void SHA256::transform(const unsigned char* message, unsigned int block_nb) { uint32 w[64]; uint32 wv[8]; - uint32 t1, t2; + uint32 t1; + uint32 t2; const unsigned char* sub_block; int i; int j; - for (i = 0; i < (int)block_nb; i++) { + for (i = 0; i < static_cast(block_nb); i++) { sub_block = message + (i << 6); for (j = 0; j < 16; j++) { SHA2_PACK32(&sub_block[j << 2], &w[j]); @@ -235,7 +237,9 @@ void SHA256::init() { void SHA256::update(const unsigned char* message, unsigned int len) { unsigned int block_nb; - unsigned int new_len, rem_len, tmp_len; + unsigned int new_len; + unsigned int rem_len; + unsigned int tmp_len; const unsigned char* shifted_message; tmp_len = SHA224_256_BLOCK_SIZE - m_len; rem_len = len < tmp_len ? len : tmp_len; @@ -260,7 +264,7 @@ void SHA256::final(unsigned char* digest) { unsigned int pm_len; unsigned int len_b; int i; - block_nb = (1 + ((SHA224_256_BLOCK_SIZE - 9) < (m_len % SHA224_256_BLOCK_SIZE))); + block_nb = (1 + static_cast((SHA224_256_BLOCK_SIZE - 9) < (m_len % SHA224_256_BLOCK_SIZE))); len_b = (m_tot_len + m_len) << 3; pm_len = block_nb << 6; memset(m_block + m_len, 0, pm_len - m_len); @@ -278,20 +282,22 @@ std::string sha256(const std::string& input, bool raw) { SHA256 ctx = SHA256(); ctx.init(); - ctx.update((unsigned char*)input.c_str(), input.length()); + ctx.update((unsigned char*)input.c_str(), input.length()); // NOLINT ctx.final(digest); if (raw) { std::string res; - for (unsigned int i = 0; i < SHA256::DIGEST_SIZE; ++i) { - res.append(1, digest[i]); + for (unsigned char i : digest) { + res.append(1, i); } return res; } char buf[2 * SHA256::DIGEST_SIZE + 1]; buf[2 * SHA256::DIGEST_SIZE] = 0; - for (size_t i = 0; i < SHA256::DIGEST_SIZE; i++) sprintf(buf + i * 2, "%02x", digest[i]); - return std::string(buf); + for (size_t i = 0; i < SHA256::DIGEST_SIZE; i++) { + sprintf(buf + i * 2, "%02x", digest[i]); + } + return {buf}; } // MD5 hash function @@ -379,9 +385,10 @@ void MD5::init() { // decodes input (unsigned char) into output (uint4). Assumes len is a multiple of 4. void MD5::decode(uint4 output[], const uint1 input[], size_type len) { - for (unsigned int i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((uint4)input[j]) | (((uint4)input[j + 1]) << 8) | (((uint4)input[j + 2]) << 16) | - (((uint4)input[j + 3]) << 24); + for (unsigned int i = 0, j = 0; j < len; i++, j += 4) { + output[i] = (static_cast(input[j])) | ((static_cast(input[j + 1])) << 8) | + ((static_cast(input[j + 2])) << 16) | ((static_cast(input[j + 3])) << 24); + } } ////////////////////////////// @@ -401,7 +408,11 @@ void MD5::encode(uint1 output[], const uint4 input[], size_type len) { // apply MD5 algo on a block void MD5::transform(const uint1 block[blocksize]) { - uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + uint4 a = state[0]; + uint4 b = state[1]; + uint4 c = state[2]; + uint4 d = state[3]; + uint4 x[16]; decode(x, block, blocksize); /* Round 1 */ @@ -494,7 +505,9 @@ void MD5::update(const unsigned char input[], size_type length) { size_type index = count[0] / 8 % blocksize; // Update number of bits - if ((count[0] += (length << 3)) < (length << 3)) count[1]++; + if ((count[0] += (length << 3)) < (length << 3)) { + count[1]++; + } count[1] += (length >> 29); // number of bytes we need to fill in buffer @@ -509,11 +522,14 @@ void MD5::update(const unsigned char input[], size_type length) { transform(buffer); // transform chunks of blocksize (64 bytes) - for (i = firstpart; i + blocksize <= length; i += blocksize) transform(&input[i]); + for (i = firstpart; i + blocksize <= length; i += blocksize) { + transform(&input[i]); + } index = 0; - } else + } else { i = 0; + } // buffer remaining input memcpy(&buffer[index], &input[i], length - i); @@ -522,7 +538,9 @@ void MD5::update(const unsigned char input[], size_type length) { ////////////////////////////// // for convenience provide a verson with signed char -void MD5::update(const char input[], size_type length) { update((const unsigned char*)input, length); } +void MD5::update(const char input[], size_type length) { + update(reinterpret_cast(input), length); +} ////////////////////////////// @@ -563,20 +581,26 @@ MD5& MD5::finalize() { // return hex representation of digest as string std::string MD5::hexdigest() const { - if (!finalized) return ""; + if (!finalized) { + return ""; + } char buf[33]; - for (int i = 0; i < 16; i++) sprintf(buf + i * 2, "%02x", digest[i]); + for (int i = 0; i < 16; i++) { + sprintf(buf + i * 2, "%02x", digest[i]); + } buf[32] = 0; - return std::string(buf); + return {buf}; } std::string MD5::rawdigest() const { - if (!finalized) return ""; + if (!finalized) { + return ""; + } std::string res; - for (unsigned int i = 0; i < 16; ++i) { - res.append(1, digest[i]); + for (unsigned char i : digest) { + res.append(1, i); } return res; } diff --git a/src/pstd/src/pstd_mutex.cc b/src/pstd/src/pstd_mutex.cc index 6de1a7b6a3..1734c6eedb 100644 --- a/src/pstd/src/pstd_mutex.cc +++ b/src/pstd/src/pstd_mutex.cc @@ -44,7 +44,7 @@ void RecordMutex::Lock(const std::string& key) { ref_mutex->Lock(); } else { - RefMutex* ref_mutex = new RefMutex(); + auto ref_mutex = new RefMutex(); records_.emplace(key, ref_mutex); ref_mutex->Ref(); diff --git a/src/pstd/src/pstd_status.cc b/src/pstd/src/pstd_status.cc index 2d30b42b8a..850b6219a8 100644 --- a/src/pstd/src/pstd_status.cc +++ b/src/pstd/src/pstd_status.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. See the AUTHORS file for names of contributors. #include "pstd/include/pstd_status.h" -#include +#include namespace pstd { @@ -19,12 +19,12 @@ Status::Status(Code code, const Slice& msg, const Slice& msg2) { assert(code != kOk); const uint32_t len1 = static_cast(msg.size()); const uint32_t len2 = static_cast(msg2.size()); - const uint32_t size = len1 + (len2 ? (2 + len2) : 0); + const uint32_t size = len1 + (len2 != 0U ? (2 + len2) : 0); char* result = new char[size + 5]; memcpy(result, &size, sizeof(size)); result[4] = static_cast(code); memcpy(result + 5, msg.data(), len1); - if (len2) { + if (len2 != 0U) { result[5 + len1] = ':'; result[6 + len1] = ' '; memcpy(result + 7 + len1, msg2.data(), len2); @@ -33,7 +33,7 @@ Status::Status(Code code, const Slice& msg, const Slice& msg2) { } std::string Status::ToString() const { - if (state_ == nullptr) { + if (!state_) { return "OK"; } else { char tmp[30]; diff --git a/src/pstd/src/pstd_string.cc b/src/pstd/src/pstd_string.cc index bcc925e4a4..613951dd8b 100644 --- a/src/pstd/src/pstd_string.cc +++ b/src/pstd/src/pstd_string.cc @@ -34,22 +34,21 @@ #include "pstd/include/pstd_string.h" #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include #include #include +#include +#include +#include +#include #include +#include +#include +#include +#include #include #include @@ -60,23 +59,29 @@ namespace pstd { /* Glob-style pattern matching. */ int stringmatchlen(const char* pattern, int patternLen, const char* string, int stringLen, int nocase) { - while (patternLen) { + while (patternLen != 0) { switch (pattern[0]) { case '*': while (pattern[1] == '*') { pattern++; patternLen--; } - if (patternLen == 1) return 1; /* match */ - while (stringLen) { - if (stringmatchlen(pattern + 1, patternLen - 1, string, stringLen, nocase)) return 1; /* match */ + if (patternLen == 1) { + return 1; /* match */ + } + while (stringLen != 0) { + if (stringmatchlen(pattern + 1, patternLen - 1, string, stringLen, nocase) != 0) { + return 1; /* match */ + } string++; stringLen--; } return 0; /* no match */ break; case '?': - if (stringLen == 0) return 0; /* no match */ + if (stringLen == 0) { + return 0; /* no match */ + } string++; stringLen--; break; @@ -86,17 +91,19 @@ int stringmatchlen(const char* pattern, int patternLen, const char* string, int pattern++; patternLen--; - nott = pattern[0] == '^'; - if (nott) { + nott = static_cast(pattern[0] == '^'); + if (nott != 0) { pattern++; patternLen--; } match = 0; - while (1) { + while (true) { if (pattern[0] == '\\') { pattern++; patternLen--; - if (pattern[0] == string[0]) match = 1; + if (pattern[0] == string[0]) { + match = 1; + } } else if (pattern[0] == ']') { break; } else if (patternLen == 0) { @@ -112,26 +119,36 @@ int stringmatchlen(const char* pattern, int patternLen, const char* string, int start = end; end = t; } - if (nocase) { + if (nocase != 0) { start = tolower(start); end = tolower(end); c = tolower(c); } pattern += 2; patternLen -= 2; - if (c >= start && c <= end) match = 1; + if (c >= start && c <= end) { + match = 1; + } } else { - if (!nocase) { - if (pattern[0] == string[0]) match = 1; + if (nocase == 0) { + if (pattern[0] == string[0]) { + match = 1; + } } else { - if (tolower((int)pattern[0]) == tolower((int)string[0])) match = 1; + if (tolower(static_cast(pattern[0])) == tolower(static_cast(string[0]))) { + match = 1; + } } } pattern++; patternLen--; } - if (nott) match = !match; - if (!match) return 0; /* no match */ + if (nott != 0) { + match = static_cast(match == 0); + } + if (match == 0) { + return 0; /* no match */ + } string++; stringLen--; break; @@ -143,10 +160,14 @@ int stringmatchlen(const char* pattern, int patternLen, const char* string, int } /* fall through */ default: - if (!nocase) { - if (pattern[0] != string[0]) return 0; /* no match */ + if (nocase == 0) { + if (pattern[0] != string[0]) { + return 0; /* no match */ + } } else { - if (tolower((int)pattern[0]) != tolower((int)string[0])) return 0; /* no match */ + if (tolower(static_cast(pattern[0])) != tolower(static_cast(string[0]))) { + return 0; /* no match */ + } } string++; stringLen--; @@ -162,7 +183,9 @@ int stringmatchlen(const char* pattern, int patternLen, const char* string, int break; } } - if (patternLen == 0 && stringLen == 0) return 1; + if (patternLen == 0 && stringLen == 0) { + return 1; + } return 0; } @@ -183,32 +206,42 @@ long long memtoll(const char* p, int* err) { long long val; unsigned int digits; - if (err) *err = 0; + if (err) { + *err = 0; + } /* Search the first non digit character. */ u = p; - if (*u == '-') u++; - while (*u && isdigit(*u)) u++; - if (*u == '\0' || !strcasecmp(u, "b")) { + if (*u == '-') { + u++; + } + while ((*u != 0) && (isdigit(*u) != 0)) { + u++; + } + if (*u == '\0' || (strcasecmp(u, "b") == 0)) { mul = 1; - } else if (!strcasecmp(u, "k")) { + } else if (strcasecmp(u, "k") == 0) { mul = 1000; - } else if (!strcasecmp(u, "kb")) { + } else if (strcasecmp(u, "kb") == 0) { mul = 1024; - } else if (!strcasecmp(u, "m")) { + } else if (strcasecmp(u, "m") == 0) { mul = 1000 * 1000; - } else if (!strcasecmp(u, "mb")) { + } else if (strcasecmp(u, "mb") == 0) { mul = 1024 * 1024; - } else if (!strcasecmp(u, "g")) { + } else if (strcasecmp(u, "g") == 0) { mul = 1000L * 1000 * 1000; - } else if (!strcasecmp(u, "gb")) { + } else if (strcasecmp(u, "gb") == 0) { mul = 1024L * 1024 * 1024; } else { - if (err) *err = 1; + if (err) { + *err = 1; + } mul = 1; } digits = u - p; if (digits >= sizeof(buf)) { - if (err) *err = 1; + if (err) { + *err = 1; + } return LLONG_MAX; } memcpy(buf, p, digits); @@ -220,21 +253,29 @@ long long memtoll(const char* p, int* err) { /* Return the number of digits of 'v' when converted to string in radix 10. * See ll2string() for more information. */ uint32_t digits10(uint64_t v) { - if (v < 10) return 1; - if (v < 100) return 2; - if (v < 1000) return 3; + if (v < 10) { + return 1; + } + if (v < 100) { + return 2; + } + if (v < 1000) { + return 3; + } if (v < 1000000000000UL) { if (v < 100000000UL) { if (v < 1000000) { - if (v < 10000) return 4; - return 5 + (v >= 100000); + if (v < 10000) { + return 4; + } + return 5 + static_cast(v >= 100000); } - return 7 + (v >= 10000000UL); + return 7 + static_cast(v >= 10000000UL); } if (v < 10000000000UL) { - return 9 + (v >= 1000000000UL); + return 9 + static_cast(v >= 1000000000UL); } - return 11 + (v >= 100000000000UL); + return 11 + static_cast(v >= 100000000000UL); } return 12 + digits10(v / 1000000000000UL); } @@ -266,7 +307,7 @@ int ll2string(char* dst, size_t dstlen, long long svalue) { if (svalue != LLONG_MIN) { value = -svalue; } else { - value = ((unsigned long long)LLONG_MAX) + 1; + value = (static_cast(LLONG_MAX) + 1); } negative = 1; } else { @@ -276,7 +317,9 @@ int ll2string(char* dst, size_t dstlen, long long svalue) { /* Check length. */ uint32_t const length = digits10(value) + negative; - if (length >= dstlen) return 0; + if (length >= dstlen) { + return 0; + } /* Null term. */ uint32_t next = length; @@ -292,15 +335,17 @@ int ll2string(char* dst, size_t dstlen, long long svalue) { /* Handle last 1-2 digits. */ if (value < 10) { - dst[next] = '0' + (uint32_t)value; + dst[next] = '0' + static_cast(value); } else { - int i = (uint32_t)value * 2; + int i = static_cast(value) * 2; dst[next] = digits[i + 1]; dst[next - 1] = digits[i]; } /* Add sign. */ - if (negative) dst[0] = '-'; + if (negative != 0) { + dst[0] = '-'; + } return length; } @@ -313,11 +358,15 @@ int string2int(const char* s, size_t slen, long long* value) { int negative = 0; unsigned long long v; - if (plen == slen) return 0; + if (plen == slen) { + return 0; + } /* Special case: first and only digit is 0. */ if (slen == 1 && p[0] == '0') { - if (value != nullptr) *value = 0; + if (value) { + *value = 0; + } return 1; } @@ -327,7 +376,9 @@ int string2int(const char* s, size_t slen, long long* value) { plen++; /* Abort on only a negative sign. */ - if (plen == slen) return 0; + if (plen == slen) { + return 0; + } } while (plen < slen && p[0] == '0') { @@ -336,7 +387,9 @@ int string2int(const char* s, size_t slen, long long* value) { } if (plen == slen) { - if (value != nullptr) *value = 0; + if (value) { + *value = 0; + } return 1; } @@ -353,12 +406,14 @@ int string2int(const char* s, size_t slen, long long* value) { } while (plen < slen && p[0] >= '0' && p[0] <= '9') { - if (v > (ULLONG_MAX / 10)) /* Overflow. */ + if (v > (ULLONG_MAX / 10)) { /* Overflow. */ return 0; + } v *= 10; - if (v > (ULLONG_MAX - (p[0] - '0'))) /* Overflow. */ + if (v > (ULLONG_MAX - (p[0] - '0'))) { /* Overflow. */ return 0; + } v += p[0] - '0'; p++; @@ -366,16 +421,24 @@ int string2int(const char* s, size_t slen, long long* value) { } /* Return if not all bytes were used. */ - if (plen < slen) return 0; + if (plen < slen) { + return 0; + } - if (negative) { - if (v > ((unsigned long long)(-(LLONG_MIN + 1)) + 1)) /* Overflow. */ + if (negative != 0) { + if (v > (static_cast(-(LLONG_MIN + 1)) + 1)) { /* Overflow. */ return 0; - if (value != nullptr) *value = -v; + } + if (value) { + *value = -v; + } } else { - if (v > LLONG_MAX) /* Overflow. */ + if (v > LLONG_MAX) { /* Overflow. */ return 0; - if (value != nullptr) *value = v; + } + if (value) { + *value = v; + } } return 1; } @@ -386,11 +449,15 @@ int string2int(const char* s, size_t slen, long long* value) { int string2int(const char* s, size_t slen, long* lval) { long long llval; - if (!string2int(s, slen, &llval)) return 0; + if (string2int(s, slen, &llval) == 0) { + return 0; + } - if (llval < LONG_MIN || llval > LONG_MAX) return 0; + if (llval < LONG_MIN || llval > LONG_MAX) { + return 0; + } - *lval = (long)llval; + *lval = static_cast(llval); return 1; } @@ -400,11 +467,15 @@ int string2int(const char* s, size_t slen, long* lval) { int string2int(const char* s, size_t slen, unsigned long* lval) { long long llval; - if (!string2int(s, slen, &llval)) return 0; + if (string2int(s, slen, &llval) == 0) { + return 0; + } - if (llval > (long long)(ULONG_MAX)) return 0; + if (llval > static_cast(ULONG_MAX)) { + return 0; + } - *lval = (unsigned long)llval; + *lval = static_cast(llval); return 1; } @@ -414,16 +485,18 @@ int d2string(char* buf, size_t len, double value) { if (std::isnan(value)) { len = snprintf(buf, len, "nan"); } else if (std::isinf(value)) { - if (value < 0) + if (value < 0) { len = snprintf(buf, len, "-inf"); - else + } else { len = snprintf(buf, len, "inf"); + } } else if (value == 0) { /* See: http://en.wikipedia.org/wiki/Signed_zero, "Comparisons". */ - if (1.0 / value < 0) + if (1.0 / value < 0) { len = snprintf(buf, len, "-0"); - else + } else { len = snprintf(buf, len, "0"); + } } else { #if (DBL_MANT_DIG >= 52) && (LLONG_MAX == 0x7fffffffffffffffLL) /* Check if the float is in a safe range to be casted into a @@ -437,9 +510,9 @@ int d2string(char* buf, size_t len, double value) { * integer printing function that is much faster. */ double min = -4503599627370495; /* (2^52)-1 */ double max = 4503599627370496; /* -(2^52) */ - if (value > min && value < max && value == ((double)((long long)value))) - len = ll2string(buf, len, (long long)value); - else + if (value > min && value < max && value == (static_cast(static_cast(value)))) { + len = ll2string(buf, len, static_cast(value)); + } else // NOLINT #endif len = snprintf(buf, len, "%.17g", value); } @@ -450,9 +523,13 @@ int d2string(char* buf, size_t len, double value) { int string2d(const char* s, size_t slen, double* dval) { char* pEnd; double d = strtod(s, &pEnd); - if (pEnd != s + slen) return 0; + if (pEnd != s + slen) { + return 0; + } - if (dval != nullptr) *dval = d; + if (dval) { + *dval = d; + } return 1; } @@ -465,7 +542,7 @@ void getRandomHexChars(char* p, unsigned int len) { char charset[] = "0123456789abcdef"; unsigned int j; - if (fp == nullptr || fread(p, len, 1, fp) == 0) { + if (!fp || !fread(p, len, 1, fp)) { /* If we can't read from /dev/urandom, do some reasonable effort * in order to create some entropy, since this function is used to * generate run_id and cluster instance IDs */ @@ -493,11 +570,17 @@ void getRandomHexChars(char* p, unsigned int len) { } /* Finally xor it with rand() output, that was already seeded with * time() at startup. */ - for (j = 0; j < len; j++) p[j] ^= rand(); + for (j = 0; j < len; j++) { + p[j] ^= rand(); + } } /* Turn it into hex digits taking just 4 bits out of 8 for every byte. */ - for (j = 0; j < len; j++) p[j] = charset[p[j] & 0x0F]; - if (fp) fclose(fp); + for (j = 0; j < len; j++) { + p[j] = charset[p[j] & 0x0F]; + } + if (fp) { + fclose(fp); + } } std::vector& StringSplit(const std::string& s, char delim, std::vector& elems) { @@ -505,14 +588,16 @@ std::vector& StringSplit(const std::string& s, char delim, std::vec std::stringstream ss(s); std::string item; while (std::getline(ss, item, delim)) { - if (!item.empty()) elems.push_back(item); + if (!item.empty()) { + elems.push_back(item); + } } return elems; } std::string StringConcat(const std::vector& elems, char delim) { std::string result; - std::vector::const_iterator it = elems.begin(); + auto it = elems.begin(); while (it != elems.end()) { result.append(*it); result.append(1, delim); @@ -536,11 +621,11 @@ std::string& StringToUpper(std::string& ori) { std::string IpPortString(const std::string& ip, int port) { if (ip.empty()) { - return std::string(); + return {}; } char buf[10]; if (ll2string(buf, sizeof(buf), port) <= 0) { - return std::string(); + return {}; } return (ip + ":" + buf); } @@ -576,7 +661,7 @@ std::string ToRead(const std::string& str) { read.append("\\b"); break; default: - if (isprint(*iter)) { + if (isprint(*iter) != 0) { read.append(1, *iter); } else { snprintf(buf, sizeof(buf), "\\x%02x", static_cast(*iter)); @@ -604,34 +689,42 @@ bool ParseIpPortString(const std::string& ip_port, std::string& ip, int& port) { if (1 != string2int(port_str.data(), port_str.size(), &lport)) { return false; } - port = (int)lport; + port = static_cast(lport); return true; } // Trim charlist std::string StringTrim(const std::string& ori, const std::string& charlist) { - if (ori.empty()) return ori; + if (ori.empty()) { + return ori; + } size_t pos = 0; int rpos = ori.size() - 1; while (pos < ori.size()) { bool meet = false; - for (char c : charlist) + for (char c : charlist) { if (ori.at(pos) == c) { meet = true; break; } - if (!meet) break; + } + if (!meet) { + break; + } ++pos; } while (rpos >= 0) { bool meet = false; - for (char c : charlist) + for (char c : charlist) { if (ori.at(rpos) == c) { meet = true; break; } - if (!meet) break; + } + if (!meet) { + break; + } --rpos; } return ori.substr(pos, rpos - pos + 1); diff --git a/src/pstd/src/rsync.cc b/src/pstd/src/rsync.cc index 1a40644ae2..42c73c587a 100644 --- a/src/pstd/src/rsync.cc +++ b/src/pstd/src/rsync.cc @@ -102,7 +102,7 @@ int StopRsync(const std::string& raw_path) { }; char line[32]; - if (sequential_file->ReadLine(line, 32) == nullptr) { + if (!(sequential_file->ReadLine(line, 32))) { LOG(WARNING) << "read rsync pid file err"; return 0; }; @@ -146,7 +146,8 @@ int RsyncSendClearTarget(const std::string& local_dir_path, const std::string& r if (local_dir_path.empty() || remote_dir_path.empty()) { return -2; } - std::string local_dir(local_dir_path), remote_dir(remote_dir_path); + std::string local_dir(local_dir_path); + std::string remote_dir(remote_dir_path); if (local_dir_path.back() != '/') { local_dir.append("/"); } diff --git a/src/pstd/src/scope_record_lock.cc b/src/pstd/src/scope_record_lock.cc index 5f4a84f91c..de6d23c0be 100644 --- a/src/pstd/src/scope_record_lock.cc +++ b/src/pstd/src/scope_record_lock.cc @@ -3,11 +3,11 @@ // 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/include/scope_record_lock.h" +#include -namespace pstd { +#include "pstd/include/scope_record_lock.h" -namespace lock { +namespace pstd::lock { MultiScopeRecordLock::MultiScopeRecordLock(std::shared_ptr lock_mgr, const std::vector& keys) : lock_mgr_(lock_mgr), keys_(keys) { @@ -73,5 +73,4 @@ void MultiRecordLock::Unlock(const std::vector& keys) { } } } -} // namespace lock -} // namespace pstd +} // namespace pstd::lock diff --git a/src/pstd/src/testutil.cc b/src/pstd/src/testutil.cc index 2aef3a5d20..1618fa4bf4 100644 --- a/src/pstd/src/testutil.cc +++ b/src/pstd/src/testutil.cc @@ -14,7 +14,7 @@ void current_time_str(char * str, size_t max_len) struct timeval tv; struct tm tmm; - gettimeofday(&tv, 0); + gettimeofday(&tv, nullptr); localtime_r(&(tv.tv_sec), &tmm); snprintf(str, max_len, "%04d-%02d-%02dT%02d:%02d:%02d.%06ld", @@ -24,7 +24,7 @@ void current_time_str(char * str, size_t max_len) tmm.tm_hour, tmm.tm_min, tmm.tm_sec, - tv.tv_usec); + tv.tv_usec); // NOLINT cause different between macOS and ubuntu } int GetTestDirectory(std::string* result) { @@ -33,7 +33,7 @@ int GetTestDirectory(std::string* result) { *result = env; } else { char buf[100]; - snprintf(buf, sizeof(buf), "/tmp/pstdtest-%d", int(geteuid())); + snprintf(buf, sizeof(buf), "/tmp/pstdtest-%d", static_cast(geteuid())); *result = buf; } return 0; diff --git a/src/pstd/tests/base_conf_test.cc b/src/pstd/tests/base_conf_test.cc index 22b787748e..865883e736 100644 --- a/src/pstd/tests/base_conf_test.cc +++ b/src/pstd/tests/base_conf_test.cc @@ -33,7 +33,9 @@ class BaseConfTest : public ::testing::Test { std::unique_ptr write_file; Status ret = NewWritableFile(test_conf_, write_file); - if (!ret.ok()) return ret; + if (!ret.ok()) { + return ret; + } for (std::string& item : sample_conf) { write_file->Append(item); } diff --git a/src/pstd/tests/slash_coding_test.cc b/src/pstd/tests/slash_coding_test.cc index b46c2afd14..1ddbedd341 100644 --- a/src/pstd/tests/slash_coding_test.cc +++ b/src/pstd/tests/slash_coding_test.cc @@ -72,7 +72,7 @@ TEST_F(Coding, EncodingOutput) { ASSERT_EQ(0x04, static_cast(dst[3])); dst.clear(); - PutFixed64(&dst, 0x0807060504030201ull); + PutFixed64(&dst, 0x0807060504030201ULL); ASSERT_EQ(8, dst.size()); ASSERT_EQ(0x01, static_cast(dst[0])); ASSERT_EQ(0x02, static_cast(dst[1])); @@ -115,26 +115,26 @@ TEST_F(Coding, Varint64) { values.push_back(~static_cast(0) - 1); for (uint32_t k = 0; k < 64; k++) { // Test values near powers of two - const uint64_t power = 1ull << k; + const uint64_t power = 1ULL << k; values.push_back(power); values.push_back(power - 1); values.push_back(power + 1); } std::string s; - for (size_t i = 0; i < values.size(); i++) { - PutVarint64(&s, values[i]); + for (auto value : values) { + PutVarint64(&s, value); } const char* p = s.data(); const char* limit = p + s.size(); - for (size_t i = 0; i < values.size(); i++) { + for (auto & value : values) { ASSERT_TRUE(p < limit); uint64_t actual; const char* start = p; p = GetVarint64Ptr(p, limit, &actual); ASSERT_TRUE(p != nullptr); - ASSERT_EQ(values[i], actual); + ASSERT_EQ(value, actual); ASSERT_EQ(VarintLength(actual), p - start); } ASSERT_EQ(p, limit); @@ -147,7 +147,7 @@ TEST_F(Coding, Varint32Overflow) { } TEST_F(Coding, Varint32Truncation) { - uint32_t large_value = (1u << 31) + 100; + uint32_t large_value = (1U << 31) + 100; std::string s; PutVarint32(&s, large_value); uint32_t result; @@ -165,7 +165,7 @@ TEST_F(Coding, Varint64Overflow) { } TEST_F(Coding, Varint64Truncation) { - uint64_t large_value = (1ull << 63) + 100ull; + uint64_t large_value = (1ULL << 63) + 100ULL; std::string s; PutVarint64(&s, large_value); uint64_t result; diff --git a/src/pstd/tests/slash_string_test.cc b/src/pstd/tests/slash_string_test.cc index b5e833c9a6..de9217839e 100644 --- a/src/pstd/tests/slash_string_test.cc +++ b/src/pstd/tests/slash_string_test.cc @@ -7,7 +7,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. -#include +#include #include "gtest/gtest.h" #include "pstd/include/pstd_string.h" diff --git a/src/storage/include/storage/backupable.h b/src/storage/include/storage/backupable.h index 1de1dce890..c5462a14b1 100644 --- a/src/storage/include/storage/backupable.h +++ b/src/storage/include/storage/backupable.h @@ -6,6 +6,8 @@ #ifndef SRC_BACKUPABLE_H_ #define SRC_BACKUPABLE_H_ +#include + #include "rocksdb/db.h" #include "db_checkpoint.h" @@ -27,8 +29,8 @@ struct BackupSaveArgs { const std::string key_type; Status res; - BackupSaveArgs(void* _p_engine, const std::string& _backup_dir, const std::string& _key_type) - : p_engine(_p_engine), backup_dir(_backup_dir), key_type(_key_type) {} + BackupSaveArgs(void* _p_engine, std::string _backup_dir, std::string _key_type) + : p_engine(_p_engine), backup_dir(std::move(_backup_dir)), key_type(std::move(_key_type)) {} }; struct BackupContent { @@ -52,14 +54,14 @@ class BackupEngine { Status CreateNewBackupSpecify(const std::string& dir, const std::string& type); private: - BackupEngine() {} + BackupEngine() = default; std::map> engines_; std::map backup_content_; std::map backup_pthread_ts_; Status NewCheckpoint(rocksdb::DB* rocksdb_db, const std::string& type); - std::string GetSaveDirByType(const std::string _dir, const std::string& _type) const { + std::string GetSaveDirByType(const std::string& _dir, const std::string& _type) const { std::string backup_dir = _dir.empty() ? DEFAULT_BK_PATH : _dir; return backup_dir + ((backup_dir.back() != '/') ? "/" : "") + _type; } diff --git a/src/storage/include/storage/db_checkpoint.h b/src/storage/include/storage/db_checkpoint.h index ecd7984afb..100081052e 100644 --- a/src/storage/include/storage/db_checkpoint.h +++ b/src/storage/include/storage/db_checkpoint.h @@ -36,7 +36,7 @@ class DBCheckpoint { VectorLogPtr& live_wal_files, uint64_t manifest_file_size, uint64_t sequence_number) = 0; - virtual ~DBCheckpoint() {} + virtual ~DBCheckpoint() = default; }; } // namespace rocksdb diff --git a/src/storage/include/storage/storage.h b/src/storage/include/storage/storage.h index fceebb854f..21cb1484af 100644 --- a/src/storage/include/storage/storage.h +++ b/src/storage/include/storage/storage.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "rocksdb/convenience.h" @@ -131,8 +132,8 @@ struct BGTask { std::string argv; BGTask(const DataType& _type = DataType::kAll, const Operation& _opeation = Operation::kNone, - const std::string& _argv = "") - : type(_type), operation(_opeation), argv(_argv) {} + std::string _argv = "") + : type(_type), operation(_opeation), argv(std::move(_argv)) {} }; class Storage { @@ -153,7 +154,7 @@ class Storage { Status Set(const Slice& key, const Slice& value); // Set key to hold the string value. if key exist - Status Setxx(const Slice& key, const Slice& value, int32_t* ret, const int32_t ttl = 0); + Status Setxx(const Slice& key, const Slice& value, int32_t* ret, int32_t ttl = 0); // Get the value of key. If the key does not exist // the special value nil is returned @@ -181,7 +182,7 @@ class Storage { // Set key to hold string value if key does not exist // return 1 if the key was set // return 0 if the key was not set - Status Setnx(const Slice& key, const Slice& value, int32_t* ret, const int32_t ttl = 0); + Status Setnx(const Slice& key, const Slice& value, int32_t* ret, int32_t ttl = 0); // Sets the given keys to their respective values. // MSETNX will not perform any operation at all even @@ -192,7 +193,7 @@ class Storage { // return 1 if the key currently hold the give value And override success // return 0 if the key doesn't exist And override fail // return -1 if the key currently does not hold the given value And override fail - Status Setvx(const Slice& key, const Slice& value, const Slice& new_value, int32_t* ret, const int32_t ttl = 0); + Status Setvx(const Slice& key, const Slice& value, const Slice& new_value, int32_t* ret, int32_t ttl = 0); // delete the key that holds a given value // return 1 if the key currently hold the give value And delete success @@ -216,7 +217,7 @@ class Storage { // Count the number of set bits (population counting) in a string. // return the number of bits set to 1 // note: if need to specified offset, set have_range to true - Status BitCount(const Slice& key, int64_t start_offset, int64_t end_offset, int32_t* ret, bool have_offset); + Status BitCount(const Slice& key, int64_t start_offset, int64_t end_offset, int32_t* ret, bool have_range); // Perform a bitwise operation between multiple keys // and store the result in the destination key @@ -340,7 +341,7 @@ class Storage { // Iterate over a Hash table of fields // return next_field that the user need to use as the start_field argument // in the next call - Status HScanx(const Slice& key, const std::string start_field, const std::string& pattern, int64_t count, + Status HScanx(const Slice& key, const std::string& start_field, const std::string& pattern, int64_t count, std::vector* field_values, std::string* next_field); // Iterate over a Hash table of fields by specified range @@ -570,14 +571,14 @@ class Storage { // set less than count, it will pop out the total number of sorted set. If two // ScoreMember's score were the same, the lexicographic predominant elements will // be pop out. - Status ZPopMax(const Slice& key, const int64_t count, std::vector* score_members); + Status ZPopMax(const Slice& key, int64_t count, std::vector* score_members); // Pop the minimum count score_members which have less score in the sorted set. // And return the result in the score_members,If the total number of the sorted // set less than count, it will pop out the total number of sorted set. If two // ScoreMember's score were the same, the lexicographic predominant elements will // not be pop out. - Status ZPopMin(const Slice& key, const int64_t count, std::vector* score_members); + Status ZPopMin(const Slice& key, int64_t count, std::vector* score_members); // Adds all the specified members with the specified scores to the sorted set // stored at key. It is possible to specify multiple score / member pairs. If @@ -737,7 +738,7 @@ class Storage { // existing members are ignored. // // An error is returned when key exists and does not hold a sorted set. - Status ZRem(const Slice& key, std::vector members, int32_t* ret); + Status ZRem(const Slice& key, const std::vector& members, int32_t* ret); // Removes all elements in the sorted set stored at key with rank between // start and stop. Both start and stop are 0 -based indexes with 0 being the @@ -818,7 +819,7 @@ class Storage { // // If destination already exists, it is overwritten. Status ZUnionstore(const Slice& destination, const std::vector& keys, const std::vector& weights, - const AGGREGATE agg, int32_t* ret); + AGGREGATE agg, int32_t* ret); // Computes the intersection of numkeys sorted sets given by the specified // keys, and stores the result in destination. It is mandatory to provide the @@ -835,7 +836,7 @@ class Storage { // // If destination already exists, it is overwritten. Status ZInterstore(const Slice& destination, const std::vector& keys, const std::vector& weights, - const AGGREGATE agg, int32_t* ret); + AGGREGATE agg, int32_t* ret); // When all the elements in a sorted set are inserted with the same score, in // order to force lexicographical ordering, this command returns all the @@ -1007,8 +1008,8 @@ class Storage { Status SetSmallCompactionThreshold(uint32_t small_compaction_threshold); std::string GetCurrentTaskType(); - Status GetUsage(const std::string& property, uint64_t* const result); - Status GetUsage(const std::string& property, std::map* const type_result); + Status GetUsage(const std::string& property, uint64_t* result); + Status GetUsage(const std::string& property, std::map* type_result); uint64_t GetProperty(const std::string& db_type, const std::string& property); Status GetKeyNum(std::vector* key_infos); diff --git a/src/storage/src/backupable.cc b/src/storage/src/backupable.cc index 9a1c92ba43..3de6ae2ac6 100644 --- a/src/storage/src/backupable.cc +++ b/src/storage/src/backupable.cc @@ -38,7 +38,7 @@ Status BackupEngine::Open(storage::Storage* storage, std::shared_ptrGetDBByType(type)) == nullptr) { + if (!(rocksdb_db = storage->GetDBByType(type))) { s = Status::Corruption("Error db type"); } @@ -91,8 +91,8 @@ Status BackupEngine::CreateNewBackupSpecify(const std::string& backup_dir, const } void* ThreadFuncSaveSpecify(void* arg) { - BackupSaveArgs* arg_ptr = static_cast(arg); - BackupEngine* p = static_cast(arg_ptr->p_engine); + auto arg_ptr = static_cast(arg); + auto p = static_cast(arg_ptr->p_engine); arg_ptr->res = p->CreateNewBackupSpecify(arg_ptr->backup_dir, arg_ptr->key_type); pthread_exit(&(arg_ptr->res)); } @@ -102,7 +102,7 @@ Status BackupEngine::WaitBackupPthread() { Status s = Status::OK(); for (auto& pthread : backup_pthread_ts_) { void* res; - if ((ret = pthread_join(pthread.second, &res)) != 0) { + if (pthread_join(pthread.second, &res) != 0) { } Status cur_s = *(static_cast(res)); if (!cur_s.ok()) { diff --git a/src/storage/src/base_data_key_format.h b/src/storage/src/base_data_key_format.h index b8ce19af5b..316f473070 100644 --- a/src/storage/src/base_data_key_format.h +++ b/src/storage/src/base_data_key_format.h @@ -12,7 +12,7 @@ namespace storage { class BaseDataKey { public: BaseDataKey(const Slice& key, int32_t version, const Slice& data) - : start_(nullptr), key_(key), version_(version), data_(data) {} + : key_(key), version_(version), data_(data) {} ~BaseDataKey() { if (start_ != space_) { @@ -20,7 +20,7 @@ class BaseDataKey { } } - const Slice Encode() { + Slice Encode() { size_t usize = key_.size() + data_.size(); size_t needed = usize + sizeof(int32_t) * 2; char* dst; @@ -113,9 +113,9 @@ class ParsedZSetsMemberKey : public ParsedBaseDataKey { Slice member() { return data_; } }; -typedef BaseDataKey HashesDataKey; -typedef BaseDataKey SetsMemberKey; -typedef BaseDataKey ZSetsMemberKey; +using HashesDataKey = BaseDataKey; +using SetsMemberKey = BaseDataKey; +using ZSetsMemberKey = BaseDataKey; } // namespace storage #endif // SRC_BASE_DATA_KEY_FORMAT_H_ diff --git a/src/storage/src/base_filter.h b/src/storage/src/base_filter.h index 0ced1b5e8f..1bbae2f8ca 100644 --- a/src/storage/src/base_filter.h +++ b/src/storage/src/base_filter.h @@ -24,7 +24,7 @@ class BaseMetaFilter : public rocksdb::CompactionFilter { bool* value_changed) const override { int64_t unix_time; rocksdb::Env::Default()->GetCurrentTime(&unix_time); - int32_t cur_time = static_cast(unix_time); + auto cur_time = static_cast(unix_time); ParsedBaseMetaValue parsed_base_meta_value(value); TRACE("==========================START=========================="); TRACE("[MetaFilter], key: %s, count = %d, timestamp: %d, cur_time: %d, version: %d", key.ToString().c_str(), @@ -61,11 +61,8 @@ class BaseDataFilter : public rocksdb::CompactionFilter { public: BaseDataFilter(rocksdb::DB* db, std::vector* cf_handles_ptr) : db_(db), - cf_handles_ptr_(cf_handles_ptr), - cur_key_(""), - meta_not_found_(false), - cur_meta_version_(0), - cur_meta_timestamp_(0) {} + cf_handles_ptr_(cf_handles_ptr) + {} bool Filter(int level, const Slice& key, const rocksdb::Slice& value, std::string* new_value, bool* value_changed) const override { @@ -78,7 +75,7 @@ class BaseDataFilter : public rocksdb::CompactionFilter { cur_key_ = parsed_base_data_key.key().ToString(); std::string meta_value; // destroyed when close the database, Reserve Current key value - if (cf_handles_ptr_->size() == 0) { + if (cf_handles_ptr_->empty()) { return false; } Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value); @@ -144,20 +141,20 @@ class BaseDataFilterFactory : public rocksdb::CompactionFilterFactory { std::vector* cf_handles_ptr_ = nullptr; }; -typedef BaseMetaFilter HashesMetaFilter; -typedef BaseMetaFilterFactory HashesMetaFilterFactory; -typedef BaseDataFilter HashesDataFilter; -typedef BaseDataFilterFactory HashesDataFilterFactory; +using HashesMetaFilter = BaseMetaFilter; +using HashesMetaFilterFactory = BaseMetaFilterFactory; +using HashesDataFilter = BaseDataFilter; +using HashesDataFilterFactory = BaseDataFilterFactory; -typedef BaseMetaFilter SetsMetaFilter; -typedef BaseMetaFilterFactory SetsMetaFilterFactory; -typedef BaseDataFilter SetsMemberFilter; -typedef BaseDataFilterFactory SetsMemberFilterFactory; +using SetsMetaFilter = BaseMetaFilter; +using SetsMetaFilterFactory = BaseMetaFilterFactory; +using SetsMemberFilter = BaseDataFilter; +using SetsMemberFilterFactory = BaseDataFilterFactory; -typedef BaseMetaFilter ZSetsMetaFilter; -typedef BaseMetaFilterFactory ZSetsMetaFilterFactory; -typedef BaseDataFilter ZSetsDataFilter; -typedef BaseDataFilterFactory ZSetsDataFilterFactory; +using ZSetsMetaFilter = BaseMetaFilter; +using ZSetsMetaFilterFactory = BaseMetaFilterFactory; +using ZSetsDataFilter = BaseDataFilter; +using ZSetsDataFilterFactory = BaseDataFilterFactory; } // namespace storage #endif // SRC_BASE_FILTER_H_ diff --git a/src/storage/src/base_meta_value_format.h b/src/storage/src/base_meta_value_format.h index a9bf7a23d1..e940456242 100644 --- a/src/storage/src/base_meta_value_format.h +++ b/src/storage/src/base_meta_value_format.h @@ -61,20 +61,20 @@ class ParsedBaseMetaValue : public ParsedInternalValue { } void StripSuffix() override { - if (value_ != nullptr) { + if (value_) { value_->erase(value_->size() - kBaseMetaValueSuffixLength, kBaseMetaValueSuffixLength); } } void SetVersionToValue() override { - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - kBaseMetaValueSuffixLength; EncodeFixed32(dst, version_); } } void SetTimestampToValue() override { - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - sizeof(int32_t); EncodeFixed32(dst, timestamp_); } @@ -91,7 +91,7 @@ class ParsedBaseMetaValue : public ParsedInternalValue { void set_count(int32_t count) { count_ = count; - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()); EncodeFixed32(dst, count_); } @@ -99,7 +99,7 @@ class ParsedBaseMetaValue : public ParsedInternalValue { void ModifyCount(int32_t delta) { count_ += delta; - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()); EncodeFixed32(dst, count_); } @@ -121,12 +121,12 @@ class ParsedBaseMetaValue : public ParsedInternalValue { int32_t count_ = 0; }; -typedef BaseMetaValue HashesMetaValue; -typedef ParsedBaseMetaValue ParsedHashesMetaValue; -typedef BaseMetaValue SetsMetaValue; -typedef ParsedBaseMetaValue ParsedSetsMetaValue; -typedef BaseMetaValue ZSetsMetaValue; -typedef ParsedBaseMetaValue ParsedZSetsMetaValue; +using HashesMetaValue = BaseMetaValue; +using ParsedHashesMetaValue = ParsedBaseMetaValue; +using SetsMetaValue = BaseMetaValue; +using ParsedSetsMetaValue = ParsedBaseMetaValue; +using ZSetsMetaValue = BaseMetaValue; +using ParsedZSetsMetaValue = ParsedBaseMetaValue; } // namespace storage #endif // SRC_BASE_META_VALUE_FORMAT_H_ diff --git a/src/storage/src/base_value_format.h b/src/storage/src/base_value_format.h index f2146d6c9b..c819f786d8 100644 --- a/src/storage/src/base_value_format.h +++ b/src/storage/src/base_value_format.h @@ -18,7 +18,7 @@ namespace storage { class InternalValue { public: explicit InternalValue(const rocksdb::Slice& user_value) - : start_(nullptr), user_value_(user_value), version_(0), timestamp_(0) {} + : user_value_(user_value) {} virtual ~InternalValue() { if (start_ != space_) { delete[] start_; @@ -36,7 +36,7 @@ class InternalValue { } void set_version(int32_t version = 0) { version_ = version; } static const size_t kDefaultValueSuffixLength = sizeof(int32_t) * 2; - virtual const rocksdb::Slice Encode() { + virtual rocksdb::Slice Encode() { size_t usize = user_value_.size(); size_t needed = usize + kDefaultValueSuffixLength; char* dst; @@ -69,13 +69,13 @@ class ParsedInternalValue { // Use this constructor after rocksdb::DB::Get(), since we use this in // the implement of user interfaces and may need to modify the // original value suffix, so the value_ must point to the string - explicit ParsedInternalValue(std::string* value) : value_(value), version_(0), timestamp_(0) {} + explicit ParsedInternalValue(std::string* value) : value_(value) {} // Use this constructor in rocksdb::CompactionFilter::Filter(), // since we use this in Compaction process, all we need to do is parsing // the rocksdb::Slice, so don't need to modify the original value, value_ can be // set to nullptr - explicit ParsedInternalValue(const rocksdb::Slice& value) : value_(nullptr), version_(0), timestamp_(0) {} + explicit ParsedInternalValue(const rocksdb::Slice& value) {} virtual ~ParsedInternalValue() = default; diff --git a/src/storage/src/coding.h b/src/storage/src/coding.h index 37825edb11..001e9d76ee 100644 --- a/src/storage/src/coding.h +++ b/src/storage/src/coding.h @@ -20,7 +20,7 @@ #ifndef STORAGE_PLATFORM_IS_LITTLE_ENDIAN # define STORAGE_PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN) #endif -#include +#include namespace storage { static const bool kLittleEndian = STORAGE_PLATFORM_IS_LITTLE_ENDIAN; diff --git a/src/storage/src/custom_comparator.h b/src/storage/src/custom_comparator.h index 1369b5556f..07648ef8d2 100644 --- a/src/storage/src/custom_comparator.h +++ b/src/storage/src/custom_comparator.h @@ -16,7 +16,7 @@ namespace storage { class ListsDataKeyComparatorImpl : public rocksdb::Comparator { public: - ListsDataKeyComparatorImpl() {} + ListsDataKeyComparatorImpl() = default; // keep compatible with blackwidow const char* Name() const override { return "blackwidow.ListsDataKeyComparator"; } @@ -25,8 +25,8 @@ class ListsDataKeyComparatorImpl : public rocksdb::Comparator { assert(!a.empty() && !b.empty()); const char* ptr_a = a.data(); const char* ptr_b = b.data(); - int32_t a_size = static_cast(a.size()); - int32_t b_size = static_cast(b.size()); + auto a_size = static_cast(a.size()); + auto b_size = static_cast(b.size()); int32_t key_a_len = DecodeFixed32(ptr_a); int32_t key_b_len = DecodeFixed32(ptr_b); ptr_a += sizeof(int32_t); @@ -72,7 +72,7 @@ class ListsDataKeyComparatorImpl : public rocksdb::Comparator { } } - bool Equal(const rocksdb::Slice& a, const rocksdb::Slice& b) const override { return !Compare(a, b); } + bool Equal(const rocksdb::Slice& a, const rocksdb::Slice& b) const override { return Compare(a, b) == 0; } void FindShortestSeparator(std::string* start, const rocksdb::Slice& limit) const override {} @@ -95,8 +95,8 @@ class ZSetsScoreKeyComparatorImpl : public rocksdb::Comparator { const char* ptr_a = a.data(); const char* ptr_b = b.data(); - int32_t a_size = static_cast(a.size()); - int32_t b_size = static_cast(b.size()); + auto a_size = static_cast(a.size()); + auto b_size = static_cast(b.size()); int32_t key_a_len = DecodeFixed32(ptr_a); int32_t key_b_len = DecodeFixed32(ptr_b); rocksdb::Slice key_a_prefix(ptr_a, key_a_len + 2 * sizeof(int32_t)); @@ -104,7 +104,7 @@ class ZSetsScoreKeyComparatorImpl : public rocksdb::Comparator { ptr_a += key_a_len + 2 * sizeof(int32_t); ptr_b += key_b_len + 2 * sizeof(int32_t); int ret = key_a_prefix.compare(key_b_prefix); - if (ret) { + if (ret) { return ret; } @@ -129,7 +129,7 @@ class ZSetsScoreKeyComparatorImpl : public rocksdb::Comparator { rocksdb::Slice key_a_member(ptr_a, a_size - (ptr_a - a.data())); rocksdb::Slice key_b_member(ptr_b, b_size - (ptr_b - b.data())); ret = key_a_member.compare(key_b_member); - if (ret) { + if (ret) { return ret; } } @@ -137,7 +137,7 @@ class ZSetsScoreKeyComparatorImpl : public rocksdb::Comparator { return 0; } - bool Equal(const rocksdb::Slice& a, const rocksdb::Slice& b) const override { return !Compare(a, b); } + bool Equal(const rocksdb::Slice& a, const rocksdb::Slice& b) const override { return Compare(a, b) == 0; } void ParseAndPrintZSetsScoreKey(const std::string& from, const std::string& str) { const char* ptr = str.data(); @@ -181,7 +181,7 @@ class ZSetsScoreKeyComparatorImpl : public rocksdb::Comparator { rocksdb::Slice key_limit_prefix(ptr_limit, key_limit_len + 2 * sizeof(int32_t)); ptr_start += key_start_len + 2 * sizeof(int32_t); ptr_limit += key_limit_len + 2 * sizeof(int32_t); - if (key_start_prefix.compare(key_limit_prefix)) { + if (key_start_prefix.compare(key_limit_prefix) != 0) { return; } @@ -217,8 +217,8 @@ class ZSetsScoreKeyComparatorImpl : public rocksdb::Comparator { if (diff_index >= min_length) { // Do not shorten if one string is a prefix of the other } else { - uint8_t key_start_member_byte = static_cast(key_start_member[diff_index]); - uint8_t key_limit_member_byte = static_cast(key_limit_member[diff_index]); + auto key_start_member_byte = static_cast(key_start_member[diff_index]); + auto key_limit_member_byte = static_cast(key_limit_member[diff_index]); if (key_start_member_byte >= key_limit_member_byte) { // Cannot shorten since limit is smaller than start or start is // already the shortest possible. diff --git a/src/storage/src/db_checkpoint.cc b/src/storage/src/db_checkpoint.cc index d81c18a708..0490d62a41 100644 --- a/src/storage/src/db_checkpoint.cc +++ b/src/storage/src/db_checkpoint.cc @@ -15,7 +15,7 @@ # define __STDC_FORMAT_MACROS # endif -# include +# include #include # include "file/file_util.h" @@ -63,7 +63,8 @@ Status DBCheckpoint::CreateCheckpoint(const std::string& checkpoint_dir) { retur Status DBCheckpointImpl::CreateCheckpoint(const std::string& checkpoint_dir) { std::vector live_files; VectorLogPtr live_wal_files; - uint64_t manifest_file_size, sequence_number; + uint64_t manifest_file_size; + uint64_t sequence_number; Status s = GetCheckpointFiles(live_files, live_wal_files, manifest_file_size, sequence_number); if (s.ok()) { s = CreateCheckpointWithFiles(checkpoint_dir, live_files, live_wal_files, manifest_file_size, sequence_number); @@ -124,7 +125,8 @@ Status DBCheckpointImpl::CreateCheckpointWithFiles(const std::string& checkpoint s = db_->GetEnv()->CreateDir(full_private_path); // copy/hard link live_files - std::string manifest_fname, current_fname; + std::string manifest_fname; + std::string current_fname; for (size_t i = 0; s.ok() && i < live_files.size(); ++i) { uint64_t number; FileType type; @@ -135,7 +137,7 @@ Status DBCheckpointImpl::CreateCheckpointWithFiles(const std::string& checkpoint } // we should only get sst, options, manifest and current files here assert(type == kTableFile || type == kDescriptorFile || type == kCurrentFile || type == kOptionsFile); - assert(live_files[i].size() > 0 && live_files[i][0] == '/'); + assert(!live_files[i].empty() && live_files[i][0] == '/'); if (type == kCurrentFile) { // We will craft the current file manually to ensure it's consistent with // the manifest number. This is necessary because current's file contents @@ -230,7 +232,7 @@ Status DBCheckpointImpl::CreateCheckpointWithFiles(const std::string& checkpoint if (s.ok()) { std::unique_ptr checkpoint_directory; db_->GetEnv()->NewDirectory(checkpoint_dir, &checkpoint_directory); - if (checkpoint_directory != nullptr) { + if (checkpoint_directory) { s = checkpoint_directory->Fsync(); } } @@ -242,7 +244,7 @@ Status DBCheckpointImpl::CreateCheckpointWithFiles(const std::string& checkpoint std::vector subchildren; db_->GetEnv()->GetChildren(full_private_path, &subchildren); for (auto& subchild : subchildren) { - std::string subchild_path = full_private_path + "/" + subchild; + std::string subchild_path = full_private_path.append("/" + subchild); Status s1 = db_->GetEnv()->DeleteFile(subchild_path); Log(db_->GetOptions().info_log, "Delete file %s -- %s", subchild_path.c_str(), s1.ToString().c_str()); } diff --git a/src/storage/src/lists_data_key_format.h b/src/storage/src/lists_data_key_format.h index 448d1e2ad8..b25a70a2a8 100644 --- a/src/storage/src/lists_data_key_format.h +++ b/src/storage/src/lists_data_key_format.h @@ -14,7 +14,7 @@ namespace storage { class ListsDataKey { public: ListsDataKey(const rocksdb::Slice& key, int32_t version, uint64_t index) - : start_(nullptr), key_(key), version_(version), index_(index) {} + : key_(key), version_(version), index_(index) {} ~ListsDataKey() { if (start_ != space_) { @@ -22,7 +22,7 @@ class ListsDataKey { } } - const rocksdb::Slice Encode() { + rocksdb::Slice Encode() { size_t usize = key_.size(); size_t needed = usize + sizeof(int32_t) * 2 + sizeof(uint64_t); char* dst; diff --git a/src/storage/src/lists_filter.h b/src/storage/src/lists_filter.h index d8a596d709..77ec977776 100644 --- a/src/storage/src/lists_filter.h +++ b/src/storage/src/lists_filter.h @@ -25,10 +25,10 @@ class ListsMetaFilter : public rocksdb::CompactionFilter { bool* value_changed) const override { int64_t unix_time; rocksdb::Env::Default()->GetCurrentTime(&unix_time); - int32_t cur_time = static_cast(unix_time); + auto cur_time = static_cast(unix_time); ParsedListsMetaValue parsed_lists_meta_value(value); TRACE("==========================START=========================="); - TRACE("[ListMetaFilter], key: %s, count = %lu, timestamp: %d, cur_time: %d, version: %d", key.ToString().c_str(), + TRACE("[ListMetaFilter], key: %s, count = %llu, timestamp: %d, cur_time: %d, version: %d", key.ToString().c_str(), parsed_lists_meta_value.count(), parsed_lists_meta_value.timestamp(), cur_time, parsed_lists_meta_value.version()); @@ -62,23 +62,21 @@ class ListsDataFilter : public rocksdb::CompactionFilter { public: ListsDataFilter(rocksdb::DB* db, std::vector* cf_handles_ptr) : db_(db), - cf_handles_ptr_(cf_handles_ptr), - meta_not_found_(false), - cur_meta_version_(0), - cur_meta_timestamp_(0) {} + cf_handles_ptr_(cf_handles_ptr) + {} bool Filter(int level, const rocksdb::Slice& key, const rocksdb::Slice& value, std::string* new_value, bool* value_changed) const override { ParsedListsDataKey parsed_lists_data_key(key); TRACE("==========================START=========================="); - TRACE("[DataFilter], key: %s, index = %lu, data = %s, version = %d", parsed_lists_data_key.key().ToString().c_str(), + TRACE("[DataFilter], key: %s, index = %llu, data = %s, version = %d", parsed_lists_data_key.key().ToString().c_str(), parsed_lists_data_key.index(), value.ToString().c_str(), parsed_lists_data_key.version()); if (parsed_lists_data_key.key().ToString() != cur_key_) { cur_key_ = parsed_lists_data_key.key().ToString(); std::string meta_value; // destroyed when close the database, Reserve Current key value - if (cf_handles_ptr_->size() == 0) { + if (cf_handles_ptr_->empty()) { return false; } rocksdb::Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value); diff --git a/src/storage/src/lists_meta_value_format.h b/src/storage/src/lists_meta_value_format.h index 5d3b962746..3ef993cbb7 100644 --- a/src/storage/src/lists_meta_value_format.h +++ b/src/storage/src/lists_meta_value_format.h @@ -42,7 +42,7 @@ class ListsMetaValue : public InternalValue { static const size_t kDefaultValueSuffixLength = sizeof(int32_t) * 2 + sizeof(int64_t) * 2; - const rocksdb::Slice Encode() override { + rocksdb::Slice Encode() override { size_t usize = user_value_.size(); size_t needed = usize + kDefaultValueSuffixLength; char* dst; @@ -84,7 +84,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { public: // Use this constructor after rocksdb::DB::Get(); explicit ParsedListsMetaValue(std::string* internal_value_str) - : ParsedInternalValue(internal_value_str), count_(0), left_index_(0), right_index_(0) { + : ParsedInternalValue(internal_value_str) { assert(internal_value_str->size() >= kListsMetaValueSuffixLength); if (internal_value_str->size() >= kListsMetaValueSuffixLength) { user_value_ = rocksdb::Slice(internal_value_str->data(), internal_value_str->size() - kListsMetaValueSuffixLength); @@ -100,7 +100,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { // Use this constructor in rocksdb::CompactionFilter::Filter(); explicit ParsedListsMetaValue(const rocksdb::Slice& internal_value_slice) - : ParsedInternalValue(internal_value_slice), count_(0), left_index_(0), right_index_(0) { + : ParsedInternalValue(internal_value_slice) { assert(internal_value_slice.size() >= kListsMetaValueSuffixLength); if (internal_value_slice.size() >= kListsMetaValueSuffixLength) { user_value_ = rocksdb::Slice(internal_value_slice.data(), internal_value_slice.size() - kListsMetaValueSuffixLength); @@ -115,27 +115,27 @@ class ParsedListsMetaValue : public ParsedInternalValue { } void StripSuffix() override { - if (value_ != nullptr) { + if (value_) { value_->erase(value_->size() - kListsMetaValueSuffixLength, kListsMetaValueSuffixLength); } } void SetVersionToValue() override { - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - kListsMetaValueSuffixLength; EncodeFixed32(dst, version_); } } void SetTimestampToValue() override { - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - sizeof(int32_t) - 2 * sizeof(int64_t); EncodeFixed32(dst, timestamp_); } } void SetIndexToValue() { - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - 2 * sizeof(int64_t); EncodeFixed64(dst, left_index_); dst += sizeof(int64_t); @@ -157,7 +157,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { void set_count(uint64_t count) { count_ = count; - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()); EncodeFixed64(dst, count_); } @@ -165,7 +165,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { void ModifyCount(uint64_t delta) { count_ += delta; - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()); EncodeFixed64(dst, count_); } @@ -187,7 +187,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { void set_left_index(uint64_t index) { left_index_ = index; - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - 2 * sizeof(int64_t); EncodeFixed64(dst, left_index_); } @@ -195,7 +195,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { void ModifyLeftIndex(uint64_t index) { left_index_ -= index; - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - 2 * sizeof(int64_t); EncodeFixed64(dst, left_index_); } @@ -205,7 +205,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { void set_right_index(uint64_t index) { right_index_ = index; - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - sizeof(int64_t); EncodeFixed64(dst, right_index_); } @@ -213,7 +213,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { void ModifyRightIndex(uint64_t index) { right_index_ += index; - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - sizeof(int64_t); EncodeFixed64(dst, right_index_); } diff --git a/src/storage/src/lru_cache.h b/src/storage/src/lru_cache.h index fb931c196c..f2634e752c 100644 --- a/src/storage/src/lru_cache.h +++ b/src/storage/src/lru_cache.h @@ -6,8 +6,8 @@ #ifndef SRC_LRU_CACHE_H_ #define SRC_LRU_CACHE_H_ -#include -#include +#include +#include #include #include "rocksdb/status.h" @@ -34,17 +34,17 @@ class HandleTable { size_t TableSize(); LRUHandle* Lookup(const T1& key); LRUHandle* Remove(const T1& key); - LRUHandle* Insert(const T1& key, LRUHandle* const handle); + LRUHandle* Insert(const T1& key, LRUHandle* handle); private: std::unordered_map*> table_; }; template -HandleTable::HandleTable() {} +HandleTable::HandleTable() = default; template -HandleTable::~HandleTable() {} +HandleTable::~HandleTable() = default; template size_t HandleTable::TableSize() { @@ -103,10 +103,10 @@ class LRUCache { private: void LRU_Trim(); - void LRU_Remove(LRUHandle* const e); - void LRU_Append(LRUHandle* const e); - void LRU_MoveToHead(LRUHandle* const e); - bool FinishErase(LRUHandle* const e); + void LRU_Remove(LRUHandle* e); + void LRU_Append(LRUHandle* e); + void LRU_MoveToHead(LRUHandle* e); + bool FinishErase(LRUHandle* e); // Initialized before use. size_t capacity_ = 0; @@ -123,7 +123,7 @@ class LRUCache { }; template -LRUCache::LRUCache() : capacity_(0), usage_(0), size_(0) { +LRUCache::LRUCache() { // Make empty circular linked lists. lru_.next = &lru_; lru_.prev = &lru_; @@ -163,11 +163,11 @@ template rocksdb::Status LRUCache::Lookup(const T1& key, T2* const value) { std::lock_guard l(mutex_); LRUHandle* handle = handle_table_.Lookup(key); - if (handle != nullptr) { + if (handle) { LRU_MoveToHead(handle); *value = handle->value; } - return (handle == nullptr) ? rocksdb::Status::NotFound() : rocksdb::Status::OK(); + return (!handle) ? rocksdb::Status::NotFound() : rocksdb::Status::OK(); } template @@ -176,7 +176,7 @@ rocksdb::Status LRUCache::Insert(const T1& key, const T2& value, size_t if (capacity_ == 0) { return rocksdb::Status::Corruption("capacity is empty"); } else { - LRUHandle* handle = new LRUHandle(); + auto handle = new LRUHandle(); handle->key = key; handle->value = value; handle->charge = charge; @@ -218,7 +218,7 @@ bool LRUCache::LRUAndHandleTableConsistent() { LRUHandle* current = lru_.prev; while (current != &lru_) { handle = handle_table_.Lookup(current->key); - if (handle == nullptr || handle != current) { + if (!handle || handle != current) { return false; } else { count++; @@ -283,7 +283,7 @@ void LRUCache::LRU_MoveToHead(LRUHandle* const e) { template bool LRUCache::FinishErase(LRUHandle* const e) { bool erased = false; - if (e != nullptr) { + if (e) { LRU_Remove(e); size_--; usage_ -= e->charge; diff --git a/src/storage/src/murmurhash.cc b/src/storage/src/murmurhash.cc index 851a5ec264..9c42fcb4ed 100644 --- a/src/storage/src/murmurhash.cc +++ b/src/storage/src/murmurhash.cc @@ -26,8 +26,8 @@ uint64_t MurmurHash64A(const void* key, int len, unsigned int seed) { uint64_t h = seed ^ (len * m); - const uint64_t* data = (const uint64_t*)key; - const uint64_t* end = data + (len / 8); + auto data = static_cast(key); + auto end = data + (len / 8); while (data != end) { uint64_t k = *data++; @@ -40,23 +40,29 @@ uint64_t MurmurHash64A(const void* key, int len, unsigned int seed) { h *= m; } - const unsigned char* data2 = (const unsigned char*)data; + auto data2 = reinterpret_cast(data); switch (len & 7) { case 7: - h ^= ((uint64_t)data2[6]) << 48; // fallthrough + h ^= (static_cast(data2[6])) << 48; + [[fallthrough]]; case 6: - h ^= ((uint64_t)data2[5]) << 40; // fallthrough + h ^= (static_cast(data2[5])) << 40; + [[fallthrough]]; case 5: - h ^= ((uint64_t)data2[4]) << 32; // fallthrough + h ^= (static_cast(data2[4])) << 32; + [[fallthrough]]; case 4: - h ^= ((uint64_t)data2[3]) << 24; // fallthrough + h ^= (static_cast(data2[3])) << 24; + [[fallthrough]]; case 3: - h ^= ((uint64_t)data2[2]) << 16; // fallthrough + h ^= (static_cast(data2[2])) << 16; + [[fallthrough]]; case 2: - h ^= ((uint64_t)data2[1]) << 8; // fallthrough + h ^= (static_cast(data2[1])) << 8; + [[fallthrough]]; case 1: - h ^= ((uint64_t)data2[0]); + h ^= (static_cast(data2[0])); h *= m; } @@ -95,7 +101,7 @@ unsigned int MurmurHash2(const void* key, int len, unsigned int seed) { // Mix 4 bytes at a time into the hash - const unsigned char* data = (const unsigned char*)key; + auto data = (const unsigned char*)key; while (len >= 4) { unsigned int k = *(unsigned int*)data; @@ -115,9 +121,11 @@ unsigned int MurmurHash2(const void* key, int len, unsigned int seed) { switch (len) { case 3: - h ^= data[2] << 16; // fallthrough + h ^= data[2] << 16; + [[fallthrough]]; case 2: - h ^= data[1] << 8; // fallthrough + h ^= data[1] << 8; + [[fallthrough]]; case 1: h ^= data[0]; h *= m; @@ -146,7 +154,7 @@ unsigned int MurmurHashNeutral2(const void* key, int len, unsigned int seed) { unsigned int h = seed ^ len; - const unsigned char* data = (const unsigned char*)key; + auto data = static_cast(key); while (len >= 4) { unsigned int k; @@ -169,9 +177,11 @@ unsigned int MurmurHashNeutral2(const void* key, int len, unsigned int seed) { switch (len) { case 3: - h ^= data[2] << 16; // fallthrough + h ^= data[2] << 16; + [[fallthrough]]; case 2: - h ^= data[1] << 8; // fallthrough + h ^= data[1] << 8; + [[fallthrough]]; case 1: h ^= data[0]; h *= m; diff --git a/src/storage/src/murmurhash.h b/src/storage/src/murmurhash.h index 2a14711adb..3b33d69017 100644 --- a/src/storage/src/murmurhash.h +++ b/src/storage/src/murmurhash.h @@ -12,7 +12,7 @@ #ifndef SRC_MURMURHASH_H_ #define SRC_MURMURHASH_H_ -#include +#include #include "rocksdb/slice.h" #if defined(__x86_64__) @@ -31,7 +31,7 @@ typedef unsigned int murmur_t; # define MURMUR_HASH MurmurHashNeutral2 unsigned int MurmurHashNeutral2(const void* key, int len, unsigned int seed); # define MurmurHash MurmurHashNeutral2 -typedef unsigned int murmur_t; +using murmur_t = unsigned int; #endif // Allow slice to be hashable by murmur hash. diff --git a/src/storage/src/options_helper.cc b/src/storage/src/options_helper.cc index 43e1ac4d99..b0783c35d8 100644 --- a/src/storage/src/options_helper.cc +++ b/src/storage/src/options_helper.cc @@ -13,14 +13,14 @@ namespace storage { static bool strToInt(const std::string& value, int* num, int base = 10) { size_t end; *num = std::stoi(value, &end, base); - return end < value.size() ? false : true; + return end >= value.size(); } // strToUint64 may throw exception static bool strToUint64(const std::string& value, uint64_t* num, int base = 10) { size_t end; *num = std::stoull(value, &end, base); - return end < value.size() ? false : true; + return end >= value.size(); } // strToUint32 may throw exception @@ -41,25 +41,33 @@ bool ParseOptionMember(const MemberType& member_type, const std::string& value, switch (member_type) { case MemberType::kInt: { int intVal; - if (!strToInt(value, &intVal)) return false; + if (!strToInt(value, &intVal)) { + return false; + } *reinterpret_cast(member_address) = intVal; break; } case MemberType::kUint: { uint32_t uint32Val; - if (!strToUint32(value, &uint32Val)) return false; + if (!strToUint32(value, &uint32Val)) { + return false; + } *reinterpret_cast(member_address) = static_cast(uint32Val); break; } case MemberType::kUint64T: { uint64_t uint64Val; - if (!strToUint64(value, &uint64Val)) return false; + if (!strToUint64(value, &uint64Val)) { + return false; + } *reinterpret_cast(member_address) = uint64Val; break; } case MemberType::kSizeT: { uint64_t uint64Val; - if (!strToUint64(value, &uint64Val)) return false; + if (!strToUint64(value, &uint64Val)) { + return false; + } *reinterpret_cast(member_address) = static_cast(uint64Val); break; } diff --git a/src/storage/src/redis.cc b/src/storage/src/redis.cc index 338d505887..3691293912 100644 --- a/src/storage/src/redis.cc +++ b/src/storage/src/redis.cc @@ -11,7 +11,6 @@ Redis::Redis(Storage* const s, const DataType& type) : storage_(s), type_(type), lock_mgr_(std::make_shared(1000, 0, std::make_shared())), - db_(nullptr), small_compaction_threshold_(5000) { statistics_store_ = std::make_unique>(); scan_cursors_store_ = std::make_unique>(); @@ -52,7 +51,7 @@ Status Redis::SetSmallCompactionThreshold(size_t small_compaction_threshold) { } Status Redis::UpdateSpecificKeyStatistics(const std::string& key, size_t count) { - if (statistics_store_->Capacity() && count) { + if ((statistics_store_->Capacity() != 0U) && (count != 0U)) { size_t total = 0; statistics_store_->Lookup(key, &total); statistics_store_->Insert(key, total + count); @@ -75,13 +74,15 @@ Status Redis::SetOptions(const OptionType& option_type, const std::unordered_map if (option_type == OptionType::kDB) { return db_->SetDBOptions(options); } - if (handles_.size() == 0) { + if (handles_.empty()) { return db_->SetOptions(db_->DefaultColumnFamily(), options); } Status s; for (auto handle : handles_) { s = db_->SetOptions(handle, options); - if (!s.ok()) break; + if (!s.ok()) { + break; + } } return s; } diff --git a/src/storage/src/redis.h b/src/storage/src/redis.h index a21a341108..5dbff22a25 100644 --- a/src/storage/src/redis.h +++ b/src/storage/src/redis.h @@ -25,7 +25,7 @@ using Slice = rocksdb::Slice; class Redis { public: - Redis(Storage* const storage, const DataType& type); + Redis(Storage* storage, const DataType& type); virtual ~Redis(); rocksdb::DB* GetDB() { return db_; } diff --git a/src/storage/src/redis_hashes.cc b/src/storage/src/redis_hashes.cc index 0fef3c2a93..1dfd556cb4 100644 --- a/src/storage/src/redis_hashes.cc +++ b/src/storage/src/redis_hashes.cc @@ -58,9 +58,9 @@ Status RedisHashes::Open(const StorageOptions& storage_options, const std::strin std::vector column_families; // Meta CF - column_families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, meta_cf_ops)); + column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops); // Data CF - column_families.push_back(rocksdb::ColumnFamilyDescriptor("data_cf", data_cf_ops)); + column_families.emplace_back("data_cf", data_cf_ops); return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_); } @@ -133,7 +133,7 @@ Status RedisHashes::ScanKeys(const std::string& pattern, std::vectorvalue()); if (!parsed_hashes_meta_value.IsStale() && parsed_hashes_meta_value.count() != 0) { key = iter->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } } @@ -160,8 +160,8 @@ Status RedisHashes::PKPatternMatchDel(const std::string& pattern, int32_t* ret) key = iter->key().ToString(); meta_value = iter->value().ToString(); ParsedHashesMetaValue parsed_hashes_meta_value(&meta_value); - if (!parsed_hashes_meta_value.IsStale() && parsed_hashes_meta_value.count() && - StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (!parsed_hashes_meta_value.IsStale() && (parsed_hashes_meta_value.count() != 0) && + (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0)) { parsed_hashes_meta_value.InitialMetaValue(); batch.Put(handles_[0], key, meta_value); } @@ -177,7 +177,7 @@ Status RedisHashes::PKPatternMatchDel(const std::string& pattern, int32_t* ret) } iter->Next(); } - if (batch.Count()) { + if (batch.Count() != 0U) { s = db_->Write(default_write_options_, &batch); if (s.ok()) { total_delete += batch.Count(); @@ -193,11 +193,11 @@ Status RedisHashes::HDel(const Slice& key, const std::vector& field uint32_t statistic = 0; std::vector filtered_fields; std::unordered_set field_set; - for (auto iter = fields.begin(); iter != fields.end(); ++iter) { - std::string field = *iter; + for (const auto & iter : fields) { + const std::string& field = iter; if (field_set.find(field) == field_set.end()) { field_set.insert(field); - filtered_fields.push_back(*iter); + filtered_fields.push_back(iter); } } @@ -335,7 +335,7 @@ Status RedisHashes::HIncrby(const Slice& key, const Slice& field, int64_t value, s = db_->Get(default_read_options_, handles_[1], hashes_data_key.Encode(), &old_value); if (s.ok()) { int64_t ival = 0; - if (!StrToInt64(old_value.data(), old_value.size(), &ival)) { + if (StrToInt64(old_value.data(), old_value.size(), &ival) == 0) { return Status::Corruption("hash value is not an integer"); } if ((value >= 0 && LLONG_MAX - value < ival) || (value < 0 && LLONG_MIN - value > ival)) { @@ -794,7 +794,7 @@ Status RedisHashes::HScan(const Slice& key, int64_t cursor, const std::string& p iter->Next()) { ParsedHashesDataKey parsed_hashes_data_key(iter->key()); std::string field = parsed_hashes_data_key.field().ToString(); - if (StringMatch(pattern.data(), pattern.size(), field.data(), field.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), field.data(), field.size(), 0) != 0) { field_values->push_back({field, iter->value().ToString()}); } rest--; @@ -817,7 +817,7 @@ Status RedisHashes::HScan(const Slice& key, int64_t cursor, const std::string& p return Status::OK(); } -Status RedisHashes::HScanx(const Slice& key, const std::string start_field, const std::string& pattern, int64_t count, +Status RedisHashes::HScanx(const Slice& key, const std::string& start_field, const std::string& pattern, int64_t count, std::vector* field_values, std::string* next_field) { next_field->clear(); field_values->clear(); @@ -844,7 +844,7 @@ Status RedisHashes::HScanx(const Slice& key, const std::string start_field, cons iter->Next()) { ParsedHashesDataKey parsed_hashes_data_key(iter->key()); std::string field = parsed_hashes_data_key.field().ToString(); - if (StringMatch(pattern.data(), pattern.size(), field.data(), field.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), field.data(), field.size(), 0) != 0) { field_values->push_back({field, iter->value().ToString()}); } rest--; @@ -878,8 +878,8 @@ Status RedisHashes::PKHScanRange(const Slice& key, const Slice& field_start, con ScopeSnapshot ss(db_, &snapshot); read_options.snapshot = snapshot; - bool start_no_limit = !field_start.compare(""); - bool end_no_limit = !field_end.compare(""); + bool start_no_limit = field_start.compare("") == 0; + bool end_no_limit = field_end.empty(); if (!start_no_limit && !end_no_limit && (field_start.compare(field_end) > 0)) { return Status::InvalidArgument("error in given range"); @@ -903,7 +903,7 @@ Status RedisHashes::PKHScanRange(const Slice& key, const Slice& field_start, con if (!end_no_limit && field.compare(field_end) > 0) { break; } - if (StringMatch(pattern.data(), pattern.size(), field.data(), field.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), field.data(), field.size(), 0) != 0) { field_values->push_back({field, iter->value().ToString()}); } remain--; @@ -936,8 +936,8 @@ Status RedisHashes::PKHRScanRange(const Slice& key, const Slice& field_start, co ScopeSnapshot ss(db_, &snapshot); read_options.snapshot = snapshot; - bool start_no_limit = !field_start.compare(""); - bool end_no_limit = !field_end.compare(""); + bool start_no_limit = field_start.compare("") == 0; + bool end_no_limit = field_end.empty(); if (!start_no_limit && !end_no_limit && (field_start.compare(field_end) < 0)) { return Status::InvalidArgument("error in given range"); @@ -963,7 +963,7 @@ Status RedisHashes::PKHRScanRange(const Slice& key, const Slice& field_start, co if (!end_no_limit && field.compare(field_end) < 0) { break; } - if (StringMatch(pattern.data(), pattern.size(), field.data(), field.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), field.data(), field.size(), 0) != 0) { field_values->push_back({field, iter->value().ToString()}); } remain--; @@ -995,8 +995,8 @@ Status RedisHashes::PKScanRange(const Slice& key_start, const Slice& key_end, co iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) > 0)) { return Status::InvalidArgument("error in given range"); @@ -1015,7 +1015,7 @@ Status RedisHashes::PKScanRange(const Slice& key_start, const Slice& key_end, co it->Next(); } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } remain--; @@ -1048,8 +1048,8 @@ Status RedisHashes::PKRScanRange(const Slice& key_start, const Slice& key_end, c iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) < 0)) { return Status::InvalidArgument("error in given range"); @@ -1068,7 +1068,7 @@ Status RedisHashes::PKRScanRange(const Slice& key_start, const Slice& key_end, c it->Prev(); } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } remain--; @@ -1152,7 +1152,7 @@ bool RedisHashes::Scan(const std::string& start_key, const std::string& pattern, continue; } else { meta_key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), meta_key.data(), meta_key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), meta_key.data(), meta_key.size(), 0) != 0) { keys->push_back(meta_key); } (*count)--; diff --git a/src/storage/src/redis_hashes.h b/src/storage/src/redis_hashes.h index e86eca570c..c778f625f8 100644 --- a/src/storage/src/redis_hashes.h +++ b/src/storage/src/redis_hashes.h @@ -16,8 +16,8 @@ namespace storage { class RedisHashes : public Redis { public: - RedisHashes(Storage* const s, const DataType& type); - ~RedisHashes() = default; + RedisHashes(Storage* s, const DataType& type); + ~RedisHashes() override = default; // Common Commands Status Open(const StorageOptions& storage_options, const std::string& db_path) override; @@ -39,13 +39,13 @@ class RedisHashes : public Redis { Status HLen(const Slice& key, int32_t* ret); Status HMGet(const Slice& key, const std::vector& fields, std::vector* vss); Status HMSet(const Slice& key, const std::vector& fvs); - Status HSet(const Slice& key, const Slice& field, const Slice& value, int32_t* ret); + Status HSet(const Slice& key, const Slice& field, const Slice& value, int32_t* res); Status HSetnx(const Slice& key, const Slice& field, const Slice& value, int32_t* ret); Status HVals(const Slice& key, std::vector* values); Status HStrlen(const Slice& key, const Slice& field, int32_t* len); Status HScan(const Slice& key, int64_t cursor, const std::string& pattern, int64_t count, std::vector* field_values, int64_t* next_cursor); - Status HScanx(const Slice& key, const std::string start_field, const std::string& pattern, int64_t count, + Status HScanx(const Slice& key, const std::string& start_field, const std::string& pattern, int64_t count, std::vector* field_values, std::string* next_field); Status PKHScanRange(const Slice& key, const Slice& field_start, const std::string& field_end, const Slice& pattern, int32_t limit, std::vector* field_values, std::string* next_field); diff --git a/src/storage/src/redis_hyperloglog.cc b/src/storage/src/redis_hyperloglog.cc index 5b2e7d3c14..34abe6a1d7 100644 --- a/src/storage/src/redis_hyperloglog.cc +++ b/src/storage/src/redis_hyperloglog.cc @@ -21,7 +21,7 @@ HyperLogLog::HyperLogLog(uint8_t precision, std::string origin_register) { for (uint32_t i = 0; i < m_; ++i) { register_[i] = 0; } - if (origin_register != "") { + if (!origin_register.empty()) { for (uint32_t i = 0; i < m_; ++i) { register_[i] = origin_register[i]; } @@ -35,7 +35,8 @@ std::string HyperLogLog::Add(const char* value, uint32_t len) { MurmurHash3_x86_32(value, len, HLL_HASH_SEED, static_cast(&hash_value)); int32_t index = hash_value & ((1 << b_) - 1); uint8_t rank = Nctz((hash_value >> b_), 32 - b_); - if (rank > register_[index]) register_[index] = rank; + if (rank > register_[index]) { register_[index] = rank; +} std::string result(m_, 0); for (uint32_t i = 0; i < m_; ++i) { result[i] = register_[i]; @@ -57,7 +58,8 @@ double HyperLogLog::Estimate() const { } double HyperLogLog::FirstEstimate() const { - double estimate, sum = 0.0; + double estimate; + double sum = 0.0; for (uint32_t i = 0; i < m_; i++) { sum += 1.0 / (1 << register_[i]); } @@ -107,6 +109,6 @@ std::string HyperLogLog::Merge(const HyperLogLog& hll) { } // ::__builtin_ctz(x): 返回右起第一个‘1’之后的0的个数 -uint8_t HyperLogLog::Nctz(uint32_t x, int b) { return (uint8_t)std::min(b, ::__builtin_ctz(x)) + 1; } +uint8_t HyperLogLog::Nctz(uint32_t x, int b) { return static_cast(std::min(b, ::__builtin_ctz(x))) + 1; } } // namespace storage diff --git a/src/storage/src/redis_hyperloglog.h b/src/storage/src/redis_hyperloglog.h index cd55293176..8e9bfadd3e 100644 --- a/src/storage/src/redis_hyperloglog.h +++ b/src/storage/src/redis_hyperloglog.h @@ -14,7 +14,7 @@ namespace storage { class HyperLogLog { public: - HyperLogLog(uint8_t precision, std::string origin_resiter); + HyperLogLog(uint8_t precision, std::string origin_register); ~HyperLogLog(); double Estimate() const; @@ -23,7 +23,7 @@ class HyperLogLog { double Alpha() const; uint8_t Nctz(uint32_t x, int b); - std::string Add(const char* str, uint32_t len); + std::string Add(const char* value, uint32_t len); std::string Merge(const HyperLogLog& hll); protected: diff --git a/src/storage/src/redis_lists.cc b/src/storage/src/redis_lists.cc index 406ac5106c..158003281f 100644 --- a/src/storage/src/redis_lists.cc +++ b/src/storage/src/redis_lists.cc @@ -65,9 +65,9 @@ Status RedisLists::Open(const StorageOptions& storage_options, const std::string std::vector column_families; // Meta CF - column_families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, meta_cf_ops)); + column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops); // Data CF - column_families.push_back(rocksdb::ColumnFamilyDescriptor("data_cf", data_cf_ops)); + column_families.emplace_back("data_cf", data_cf_ops); return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_); } @@ -140,7 +140,7 @@ Status RedisLists::ScanKeys(const std::string& pattern, std::vector ParsedListsMetaValue parsed_lists_meta_value(iter->value()); if (!parsed_lists_meta_value.IsStale() && parsed_lists_meta_value.count() != 0) { key = iter->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } } @@ -167,8 +167,8 @@ Status RedisLists::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { key = iter->key().ToString(); meta_value = iter->value().ToString(); ParsedListsMetaValue parsed_lists_meta_value(&meta_value); - if (!parsed_lists_meta_value.IsStale() && parsed_lists_meta_value.count() && - StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (!parsed_lists_meta_value.IsStale() && (parsed_lists_meta_value.count() != 0U) && + (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0)) { parsed_lists_meta_value.InitialMetaValue(); batch.Put(handles_[0], key, meta_value); } @@ -184,7 +184,7 @@ Status RedisLists::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { } iter->Next(); } - if (batch.Count()) { + if (batch.Count() != 0U) { s = db_->Write(default_write_options_, &batch); if (s.ok()) { total_delete += batch.Count(); @@ -522,7 +522,7 @@ Status RedisLists::LRem(const Slice& key, int64_t count, const Slice& value, uin if (count >= 0) { current_index = start_index; rocksdb::Iterator* iter = db_->NewIterator(default_read_options_, handles_[1]); - for (iter->Seek(start_data_key.Encode()); iter->Valid() && current_index <= stop_index && (!count || rest != 0); + for (iter->Seek(start_data_key.Encode()); iter->Valid() && current_index <= stop_index && ((count == 0) || rest != 0); iter->Next(), current_index++) { if (strcmp(iter->value().ToString().data(), value.data()) == 0) { target_index.push_back(current_index); @@ -535,7 +535,7 @@ Status RedisLists::LRem(const Slice& key, int64_t count, const Slice& value, uin } else { current_index = stop_index; rocksdb::Iterator* iter = db_->NewIterator(default_read_options_, handles_[1]); - for (iter->Seek(stop_data_key.Encode()); iter->Valid() && current_index >= start_index && (!count || rest != 0); + for (iter->Seek(stop_data_key.Encode()); iter->Valid() && current_index >= start_index && ((count == 0) || rest != 0); iter->Prev(), current_index--) { if (strcmp(iter->value().ToString().data(), value.data()) == 0) { target_index.push_back(current_index); @@ -562,7 +562,7 @@ Status RedisLists::LRem(const Slice& key, int64_t count, const Slice& value, uin rocksdb::Iterator* iter = db_->NewIterator(default_read_options_, handles_[1]); for (iter->Seek(sublist_right_key.Encode()); iter->Valid() && current_index >= start_index; iter->Prev(), current_index--) { - if (!strcmp(iter->value().ToString().data(), value.data()) && rest > 0) { + if ((strcmp(iter->value().ToString().data(), value.data()) == 0) && rest > 0) { rest--; } else { ListsDataKey lists_data_key(key, version, left--); @@ -582,7 +582,7 @@ Status RedisLists::LRem(const Slice& key, int64_t count, const Slice& value, uin rocksdb::Iterator* iter = db_->NewIterator(default_read_options_, handles_[1]); for (iter->Seek(sublist_left_key.Encode()); iter->Valid() && current_index <= stop_index; iter->Next(), current_index++) { - if (!strcmp(iter->value().ToString().data(), value.data()) && rest > 0) { + if ((strcmp(iter->value().ToString().data(), value.data()) == 0) && rest > 0) { rest--; } else { ListsDataKey lists_data_key(key, version, right++); @@ -741,7 +741,7 @@ Status RedisLists::RPoplpush(const Slice& source, const Slice& destination, std: Status s; rocksdb::WriteBatch batch; MultiScopeRecordLock l(lock_mgr_, {source.ToString(), destination.ToString()}); - if (!source.compare(destination)) { + if (source.compare(destination) == 0) { std::string meta_value; s = db_->Get(default_read_options_, handles_[0], source, &meta_value); if (s.ok()) { @@ -877,7 +877,7 @@ Status RedisLists::RPush(const Slice& key, const std::vector& value EncodeFixed64(str, values.size()); ListsMetaValue lists_meta_value(Slice(str, sizeof(uint64_t))); version = lists_meta_value.UpdateVersion(); - for (auto value : values) { + for (const auto& value : values) { index = lists_meta_value.right_index(); lists_meta_value.ModifyRightIndex(1); ListsDataKey lists_data_key(key, version, index); @@ -931,8 +931,8 @@ Status RedisLists::PKScanRange(const Slice& key_start, const Slice& key_end, con iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) > 0)) { return Status::InvalidArgument("error in given range"); @@ -951,7 +951,7 @@ Status RedisLists::PKScanRange(const Slice& key_start, const Slice& key_end, con it->Next(); } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } remain--; @@ -984,8 +984,8 @@ Status RedisLists::PKRScanRange(const Slice& key_start, const Slice& key_end, co iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) < 0)) { return Status::InvalidArgument("error in given range"); @@ -1004,7 +1004,7 @@ Status RedisLists::PKRScanRange(const Slice& key_start, const Slice& key_end, co it->Prev(); } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } remain--; @@ -1088,7 +1088,7 @@ bool RedisLists::Scan(const std::string& start_key, const std::string& pattern, continue; } else { meta_key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), meta_key.data(), meta_key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), meta_key.data(), meta_key.size(), 0) != 0) { keys->push_back(meta_key); } (*count)--; diff --git a/src/storage/src/redis_lists.h b/src/storage/src/redis_lists.h index cf5a2305a9..280f14ddd3 100644 --- a/src/storage/src/redis_lists.h +++ b/src/storage/src/redis_lists.h @@ -17,8 +17,8 @@ namespace storage { class RedisLists : public Redis { public: - RedisLists(Storage* const s, const DataType& type); - ~RedisLists() = default; + RedisLists(Storage* s, const DataType& type); + ~RedisLists() override = default; // Common commands Status Open(const StorageOptions& storage_options, const std::string& db_path) override; diff --git a/src/storage/src/redis_sets.cc b/src/storage/src/redis_sets.cc index 3c4ebd6074..e0a2e3eefb 100644 --- a/src/storage/src/redis_sets.cc +++ b/src/storage/src/redis_sets.cc @@ -25,7 +25,7 @@ RedisSets::RedisSets(Storage* const s, const DataType& type) : Redis(s, type) { spop_counts_store_->SetCapacity(1000); } -RedisSets::~RedisSets() {} +RedisSets::~RedisSets() = default; rocksdb::Status RedisSets::Open(const StorageOptions& storage_options, const std::string& db_path) { statistics_store_->SetCapacity(storage_options.statistics_max_size); @@ -67,9 +67,9 @@ rocksdb::Status RedisSets::Open(const StorageOptions& storage_options, const std std::vector column_families; // Meta CF - column_families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, meta_cf_ops)); + column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops); // Member CF - column_families.push_back(rocksdb::ColumnFamilyDescriptor("member_cf", member_cf_ops)); + column_families.emplace_back("member_cf", member_cf_ops); return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_); } @@ -142,7 +142,7 @@ rocksdb::Status RedisSets::ScanKeys(const std::string& pattern, std::vectorvalue()); if (!parsed_sets_meta_value.IsStale() && parsed_sets_meta_value.count() != 0) { key = iter->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } } @@ -169,8 +169,8 @@ rocksdb::Status RedisSets::PKPatternMatchDel(const std::string& pattern, int32_t key = iter->key().ToString(); meta_value = iter->value().ToString(); ParsedSetsMetaValue parsed_sets_meta_value(&meta_value); - if (!parsed_sets_meta_value.IsStale() && parsed_sets_meta_value.count() && - StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (!parsed_sets_meta_value.IsStale() && (parsed_sets_meta_value.count() != 0) && + (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0)) { parsed_sets_meta_value.InitialMetaValue(); batch.Put(handles_[0], key, meta_value); } @@ -186,7 +186,7 @@ rocksdb::Status RedisSets::PKPatternMatchDel(const std::string& pattern, int32_t } iter->Next(); } - if (batch.Count()) { + if (batch.Count() != 0U) { s = db_->Write(default_write_options_, &batch); if (s.ok()) { total_delete += batch.Count(); @@ -283,7 +283,7 @@ rocksdb::Status RedisSets::SCard(const Slice& key, int32_t* ret) { } rocksdb::Status RedisSets::SDiff(const std::vector& keys, std::vector* members) { - if (keys.size() <= 0) { + if (keys.empty()) { return rocksdb::Status::Corruption("SDiff invalid parameter, no keys"); } @@ -349,7 +349,7 @@ rocksdb::Status RedisSets::SDiff(const std::vector& keys, std::vect } rocksdb::Status RedisSets::SDiffstore(const Slice& destination, const std::vector& keys, int32_t* ret) { - if (keys.size() <= 0) { + if (keys.empty()) { return rocksdb::Status::Corruption("SDiffsotre invalid parameter, no keys"); } @@ -442,7 +442,7 @@ rocksdb::Status RedisSets::SDiffstore(const Slice& destination, const std::vecto } rocksdb::Status RedisSets::SInter(const std::vector& keys, std::vector* members) { - if (keys.size() <= 0) { + if (keys.empty()) { return rocksdb::Status::Corruption("SInter invalid parameter, no keys"); } @@ -517,7 +517,7 @@ rocksdb::Status RedisSets::SInter(const std::vector& keys, std::vec } rocksdb::Status RedisSets::SInterstore(const Slice& destination, const std::vector& keys, int32_t* ret) { - if (keys.size() <= 0) { + if (keys.empty()) { return rocksdb::Status::Corruption("SInterstore invalid parameter, no keys"); } @@ -918,7 +918,8 @@ rocksdb::Status RedisSets::SRandmember(const Slice& key, int32_t count, std::vec } std::sort(targets.begin(), targets.end()); - int32_t cur_index = 0, idx = 0; + int32_t cur_index = 0; + int32_t idx = 0; SetsMemberKey sets_member_key(key, version, Slice()); auto iter = db_->NewIterator(default_read_options_, handles_[1]); for (iter->Seek(sets_member_key.Encode()); iter->Valid() && cur_index < size; iter->Next(), cur_index++) { @@ -986,7 +987,7 @@ rocksdb::Status RedisSets::SRem(const Slice& key, const std::vector } rocksdb::Status RedisSets::SUnion(const std::vector& keys, std::vector* members) { - if (keys.size() <= 0) { + if (keys.empty()) { return rocksdb::Status::Corruption("SUnion invalid parameter, no keys"); } @@ -999,12 +1000,12 @@ rocksdb::Status RedisSets::SUnion(const std::vector& keys, std::vec std::vector vaild_sets; rocksdb::Status s; - for (uint32_t idx = 0; idx < keys.size(); ++idx) { - s = db_->Get(read_options, handles_[0], keys[idx], &meta_value); + for (const auto & key : keys) { + s = db_->Get(read_options, handles_[0], key, &meta_value); if (s.ok()) { ParsedSetsMetaValue parsed_sets_meta_value(&meta_value); if (!parsed_sets_meta_value.IsStale() && parsed_sets_meta_value.count() != 0) { - vaild_sets.push_back({keys[idx], parsed_sets_meta_value.version()}); + vaild_sets.push_back({key, parsed_sets_meta_value.version()}); } } else if (!s.IsNotFound()) { return s; @@ -1031,7 +1032,7 @@ rocksdb::Status RedisSets::SUnion(const std::vector& keys, std::vec } rocksdb::Status RedisSets::SUnionstore(const Slice& destination, const std::vector& keys, int32_t* ret) { - if (keys.size() <= 0) { + if (keys.empty()) { return rocksdb::Status::Corruption("SUnionstore invalid parameter, no keys"); } @@ -1047,12 +1048,12 @@ rocksdb::Status RedisSets::SUnionstore(const Slice& destination, const std::vect std::vector vaild_sets; rocksdb::Status s; - for (uint32_t idx = 0; idx < keys.size(); ++idx) { - s = db_->Get(read_options, handles_[0], keys[idx], &meta_value); + for (const auto & key : keys) { + s = db_->Get(read_options, handles_[0], key, &meta_value); if (s.ok()) { ParsedSetsMetaValue parsed_sets_meta_value(&meta_value); if (!parsed_sets_meta_value.IsStale() && parsed_sets_meta_value.count() != 0) { - vaild_sets.push_back({keys[idx], parsed_sets_meta_value.version()}); + vaild_sets.push_back({key, parsed_sets_meta_value.version()}); } } else if (!s.IsNotFound()) { return s; @@ -1150,7 +1151,7 @@ rocksdb::Status RedisSets::SScan(const Slice& key, int64_t cursor, const std::st iter->Next()) { ParsedSetsMemberKey parsed_sets_member_key(iter->key()); std::string member = parsed_sets_member_key.member().ToString(); - if (StringMatch(pattern.data(), pattern.size(), member.data(), member.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), member.data(), member.size(), 0) != 0) { members->push_back(member); } rest--; @@ -1185,8 +1186,8 @@ rocksdb::Status RedisSets::PKScanRange(const Slice& key_start, const Slice& key_ iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) > 0)) { return rocksdb::Status::InvalidArgument("error in given range"); @@ -1205,7 +1206,7 @@ rocksdb::Status RedisSets::PKScanRange(const Slice& key_start, const Slice& key_ it->Next(); } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } remain--; @@ -1238,8 +1239,8 @@ rocksdb::Status RedisSets::PKRScanRange(const Slice& key_start, const Slice& key iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) < 0)) { return rocksdb::Status::InvalidArgument("error in given range"); @@ -1258,7 +1259,7 @@ rocksdb::Status RedisSets::PKRScanRange(const Slice& key_start, const Slice& key it->Prev(); } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } remain--; @@ -1342,7 +1343,7 @@ bool RedisSets::Scan(const std::string& start_key, const std::string& pattern, s continue; } else { meta_key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), meta_key.data(), meta_key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), meta_key.data(), meta_key.size(), 0) != 0) { keys->push_back(meta_key); } (*count)--; diff --git a/src/storage/src/redis_sets.h b/src/storage/src/redis_sets.h index 4043f43876..2e2834e422 100644 --- a/src/storage/src/redis_sets.h +++ b/src/storage/src/redis_sets.h @@ -17,14 +17,14 @@ #include "src/redis.h" #define SPOP_COMPACT_THRESHOLD_COUNT 500 -#define SPOP_COMPACT_THRESHOLD_DURATION 1000 * 1000 // 1000ms +#define SPOP_COMPACT_THRESHOLD_DURATION (1000 * 1000) // 1000ms namespace storage { class RedisSets : public Redis { public: - RedisSets(Storage* const s, const DataType& type); - ~RedisSets(); + RedisSets(Storage* s, const DataType& type); + ~RedisSets() override; // Common Commands Status Open(const StorageOptions& storage_options, const std::string& db_path) override; diff --git a/src/storage/src/redis_strings.cc b/src/storage/src/redis_strings.cc index 565fb5fbed..09b5cdfb38 100644 --- a/src/storage/src/redis_strings.cc +++ b/src/storage/src/redis_strings.cc @@ -103,7 +103,7 @@ Status RedisStrings::ScanKeys(const std::string& pattern, std::vectorvalue()); if (!parsed_strings_value.IsStale()) { key = iter->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } } @@ -130,7 +130,7 @@ Status RedisStrings::PKPatternMatchDel(const std::string& pattern, int32_t* ret) key = iter->key().ToString(); value = iter->value().ToString(); ParsedStringsValue parsed_strings_value(&value); - if (!parsed_strings_value.IsStale() && StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (!parsed_strings_value.IsStale() && (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0)) { batch.Delete(key); } // In order to be more efficient, we use batch deletion here @@ -146,7 +146,7 @@ Status RedisStrings::PKPatternMatchDel(const std::string& pattern, int32_t* ret) } iter->Next(); } - if (batch.Count()) { + if (batch.Count() != 0U) { s = db_->Write(default_write_options_, &batch); if (s.ok()) { total_delete += batch.Count(); @@ -213,7 +213,7 @@ Status RedisStrings::BitCount(const Slice& key, int64_t start_offset, int64_t en return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); - const unsigned char* bit_value = reinterpret_cast(value.data()); + const auto bit_value = reinterpret_cast(value.data()); int64_t value_length = value.length(); if (have_range) { if (start_offset < 0) { @@ -248,8 +248,9 @@ Status RedisStrings::BitCount(const Slice& key, int64_t start_offset, int64_t en } std::string BitOpOperate(BitOpType op, const std::vector& src_values, int64_t max_len) { + char byte; + char output; auto dest_value = std::make_unique(max_len); - char byte, output; for (int64_t j = 0; j < max_len; j++) { if (j < static_cast(src_values[0].size())) { output = src_values[0][j]; @@ -292,19 +293,20 @@ Status RedisStrings::BitOp(BitOpType op, const std::string& dest_key, const std: Status s; if (op == kBitOpNot && src_keys.size() != 1) { return Status::InvalidArgument("the number of source keys is not right"); - } else if (src_keys.size() < 1) { + } else if (src_keys.empty()) { return Status::InvalidArgument("the number of source keys is not right"); } - int64_t max_len = 0, value_len = 0; + int64_t max_len = 0; + int64_t value_len = 0; std::vector src_values; - for (size_t i = 0; i < src_keys.size(); i++) { + for (const auto & src_key : src_keys) { std::string value; - s = db_->Get(default_read_options_, src_keys[i], &value); + s = db_->Get(default_read_options_, src_key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { - src_values.push_back(std::string("")); + src_values.emplace_back(""); value_len = 0; } else { parsed_strings_value.StripSuffix(); @@ -312,7 +314,7 @@ Status RedisStrings::BitOp(BitOpType op, const std::string& dest_key, const std: value_len = value.size(); } } else if (s.IsNotFound()) { - src_values.push_back(std::string("")); + src_values.emplace_back(""); value_len = 0; } else { return s; @@ -501,7 +503,8 @@ Status RedisStrings::Incrby(const Slice& key, int64_t value, int64_t* ret) { } Status RedisStrings::Incrbyfloat(const Slice& key, const Slice& value, std::string* ret) { - std::string old_value, new_value; + std::string old_value; + std::string new_value; long double long_double_by; if (StrToLongDouble(value.data(), value.size(), &long_double_by) == -1) { return Status::Corruption("Value is not a vaild float"); @@ -518,7 +521,8 @@ Status RedisStrings::Incrbyfloat(const Slice& key, const Slice& value, std::stri } else { int32_t timestamp = parsed_strings_value.timestamp(); std::string old_user_value = parsed_strings_value.value().ToString(); - long double total, old_number; + long double total; + long double old_number; if (StrToLongDouble(old_user_value.data(), old_user_value.size(), &old_number) == -1) { return Status::Corruption("Value is not a vaild float"); } @@ -571,7 +575,8 @@ Status RedisStrings::MGet(const std::vector& keys, std::vector& kvs) { std::vector keys; - for (const auto& kv : kvs) { + keys.reserve(kvs.size()); +for (const auto& kv : kvs) { keys.push_back(kv.key); } @@ -589,8 +594,8 @@ Status RedisStrings::MSetnx(const std::vector& kvs, int32_t* ret) { bool exists = false; *ret = 0; std::string value; - for (size_t i = 0; i < kvs.size(); i++) { - s = db_->Get(default_read_options_, kvs[i].key, &value); + for (const auto & kv : kvs) { + s = db_->Get(default_read_options_, kv.key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (!parsed_strings_value.IsStale()) { @@ -740,7 +745,7 @@ Status RedisStrings::Setvx(const Slice& key, const Slice& value, const Slice& ne if (parsed_strings_value.IsStale()) { *ret = 0; } else { - if (!value.compare(parsed_strings_value.value())) { + if (value.compare(parsed_strings_value.value()) == 0) { StringsValue strings_value(new_value); if (ttl > 0) { strings_value.SetRelativeTimestamp(ttl); @@ -773,7 +778,7 @@ Status RedisStrings::Delvx(const Slice& key, const Slice& value, int32_t* ret) { *ret = 0; return Status::NotFound("Stale"); } else { - if (!value.compare(parsed_strings_value.value())) { + if (value.compare(parsed_strings_value.value()) == 0) { *ret = 1; return db_->Delete(default_write_options_, key); } else { @@ -842,8 +847,8 @@ Status RedisStrings::Strlen(const Slice& key, int32_t* len) { int32_t GetBitPos(const unsigned char* s, unsigned int bytes, int bit) { uint64_t word = 0; uint64_t skip_val = 0; - unsigned char* value = const_cast(s); - uint64_t* l = reinterpret_cast(value); + auto value = const_cast(s); + auto l = reinterpret_cast(value); int pos = 0; if (bit == 0) { skip_val = std::numeric_limits::max(); @@ -859,10 +864,10 @@ int32_t GetBitPos(const unsigned char* s, unsigned int bytes, int bit) { bytes = bytes - sizeof(*l); pos = pos + 8 * sizeof(*l); } - unsigned char* c = reinterpret_cast(l); + auto c = reinterpret_cast(l); for (size_t j = 0; j < sizeof(*l); j++) { word = word << 8; - if (bytes) { + if (bytes != 0U) { word = word | *c; c++; bytes--; @@ -875,8 +880,8 @@ int32_t GetBitPos(const unsigned char* s, unsigned int bytes, int bit) { uint64_t mask = std::numeric_limits::max(); mask = mask >> 1; mask = ~(mask); - while (mask) { - if (((word & mask) != 0) == bit) { + while (mask != 0U) { + if (static_cast((word & mask) != 0) == bit) { return pos; } pos++; @@ -900,7 +905,7 @@ Status RedisStrings::BitPos(const Slice& key, int32_t bit, int64_t* ret) { return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); - const unsigned char* bit_value = reinterpret_cast(value.data()); + const auto bit_value = reinterpret_cast(value.data()); int64_t value_length = value.length(); int64_t start_offset = 0; int64_t end_offset = std::max(value_length - 1, static_cast(0)); @@ -935,7 +940,7 @@ Status RedisStrings::BitPos(const Slice& key, int32_t bit, int64_t start_offset, return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); - const unsigned char* bit_value = reinterpret_cast(value.data()); + const auto bit_value = reinterpret_cast(value.data()); int64_t value_length = value.length(); int64_t end_offset = std::max(value_length - 1, static_cast(0)); if (start_offset < 0) { @@ -983,7 +988,7 @@ Status RedisStrings::BitPos(const Slice& key, int32_t bit, int64_t start_offset, return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); - const unsigned char* bit_value = reinterpret_cast(value.data()); + const auto bit_value = reinterpret_cast(value.data()); int64_t value_length = value.length(); if (start_offset < 0) { start_offset = start_offset + value_length; @@ -1036,7 +1041,8 @@ Status RedisStrings::PKScanRange(const Slice& key_start, const Slice& key_end, c std::vector* kvs, std::string* next_key) { next_key->clear(); - std::string key, value; + std::string key; + std::string value; int32_t remain = limit; rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; @@ -1044,8 +1050,8 @@ Status RedisStrings::PKScanRange(const Slice& key_start, const Slice& key_end, c iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) > 0)) { return Status::InvalidArgument("error in given range"); @@ -1067,7 +1073,7 @@ Status RedisStrings::PKScanRange(const Slice& key_start, const Slice& key_end, c } else { key = it->key().ToString(); value = parsed_strings_value.value().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { kvs->push_back({key, value}); } remain--; @@ -1090,7 +1096,8 @@ Status RedisStrings::PKScanRange(const Slice& key_start, const Slice& key_end, c Status RedisStrings::PKRScanRange(const Slice& key_start, const Slice& key_end, const Slice& pattern, int32_t limit, std::vector* kvs, std::string* next_key) { - std::string key, value; + std::string key; + std::string value; int32_t remain = limit; rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; @@ -1098,8 +1105,8 @@ Status RedisStrings::PKRScanRange(const Slice& key_start, const Slice& key_end, iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) < 0)) { return Status::InvalidArgument("error in given range"); @@ -1121,7 +1128,7 @@ Status RedisStrings::PKRScanRange(const Slice& key_start, const Slice& key_end, } else { key = it->key().ToString(); value = parsed_strings_value.value().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { kvs->push_back({key, value}); } remain--; @@ -1197,7 +1204,7 @@ bool RedisStrings::Scan(const std::string& start_key, const std::string& pattern continue; } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } (*count)--; diff --git a/src/storage/src/redis_strings.h b/src/storage/src/redis_strings.h index e7449e877c..a6d9143c1d 100644 --- a/src/storage/src/redis_strings.h +++ b/src/storage/src/redis_strings.h @@ -16,8 +16,8 @@ namespace storage { class RedisStrings : public Redis { public: - RedisStrings(Storage* const s, const DataType& type); - ~RedisStrings() = default; + RedisStrings(Storage* s, const DataType& type); + ~RedisStrings() override = default; // Common Commands Status Open(const StorageOptions& storage_options, const std::string& db_path) override; @@ -30,7 +30,7 @@ class RedisStrings : public Redis { // Strings Commands Status Append(const Slice& key, const Slice& value, int32_t* ret); - Status BitCount(const Slice& key, int64_t start_offset, int64_t end_offset, int32_t* ret, bool have_offset); + Status BitCount(const Slice& key, int64_t start_offset, int64_t end_offset, int32_t* ret, bool have_range); Status BitOp(BitOpType op, const std::string& dest_key, const std::vector& src_keys, int64_t* ret); Status Decrby(const Slice& key, int64_t value, int64_t* ret); Status Get(const Slice& key, std::string* value); @@ -43,11 +43,11 @@ class RedisStrings : public Redis { Status MSet(const std::vector& kvs); Status MSetnx(const std::vector& kvs, int32_t* ret); Status Set(const Slice& key, const Slice& value); - Status Setxx(const Slice& key, const Slice& value, int32_t* ret, const int32_t ttl = 0); + Status Setxx(const Slice& key, const Slice& value, int32_t* ret, int32_t ttl = 0); Status SetBit(const Slice& key, int64_t offset, int32_t value, int32_t* ret); Status Setex(const Slice& key, const Slice& value, int32_t ttl); - Status Setnx(const Slice& key, const Slice& value, int32_t* ret, const int32_t ttl = 0); - Status Setvx(const Slice& key, const Slice& value, const Slice& new_value, int32_t* ret, const int32_t ttl = 0); + Status Setnx(const Slice& key, const Slice& value, int32_t* ret, int32_t ttl = 0); + Status Setvx(const Slice& key, const Slice& value, const Slice& new_value, int32_t* ret, int32_t ttl = 0); Status Delvx(const Slice& key, const Slice& value, int32_t* ret); Status Setrange(const Slice& key, int64_t start_offset, const Slice& value, int32_t* ret); Status Strlen(const Slice& key, int32_t* len); diff --git a/src/storage/src/redis_zsets.cc b/src/storage/src/redis_zsets.cc index b1905e6588..921a50233b 100644 --- a/src/storage/src/redis_zsets.cc +++ b/src/storage/src/redis_zsets.cc @@ -35,7 +35,8 @@ Status RedisZSets::Open(const StorageOptions& storage_options, const std::string rocksdb::Options ops(storage_options.options); Status s = rocksdb::DB::Open(ops, db_path, &db_); if (s.ok()) { - rocksdb::ColumnFamilyHandle *dcf = nullptr, *scf = nullptr; + rocksdb::ColumnFamilyHandle *dcf = nullptr; + rocksdb::ColumnFamilyHandle *scf = nullptr; s = db_->CreateColumnFamily(rocksdb::ColumnFamilyOptions(), "data_cf", &dcf); if (!s.ok()) { return s; @@ -76,9 +77,9 @@ Status RedisZSets::Open(const StorageOptions& storage_options, const std::string score_cf_ops.table_factory.reset(rocksdb::NewBlockBasedTableFactory(score_cf_table_ops)); std::vector column_families; - column_families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, meta_cf_ops)); - column_families.push_back(rocksdb::ColumnFamilyDescriptor("data_cf", data_cf_ops)); - column_families.push_back(rocksdb::ColumnFamilyDescriptor("score_cf", score_cf_ops)); + column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops); + column_families.emplace_back("data_cf", data_cf_ops); + column_families.emplace_back("score_cf", score_cf_ops); return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_); } @@ -154,7 +155,7 @@ Status RedisZSets::ScanKeys(const std::string& pattern, std::vector ParsedZSetsMetaValue parsed_zsets_meta_value(iter->value()); if (!parsed_zsets_meta_value.IsStale() && parsed_zsets_meta_value.count() != 0) { key = iter->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } } @@ -181,8 +182,8 @@ Status RedisZSets::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { key = iter->key().ToString(); meta_value = iter->value().ToString(); ParsedZSetsMetaValue parsed_zsets_meta_value(&meta_value); - if (!parsed_zsets_meta_value.IsStale() && parsed_zsets_meta_value.count() && - StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (!parsed_zsets_meta_value.IsStale() && (parsed_zsets_meta_value.count() != 0) && + (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0)) { parsed_zsets_meta_value.InitialMetaValue(); batch.Put(handles_[0], key, meta_value); } @@ -198,7 +199,7 @@ Status RedisZSets::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { } iter->Next(); } - if (batch.Count()) { + if (batch.Count() != 0U) { s = db_->Write(default_write_options_, &batch); if (s.ok()) { total_delete += batch.Count(); @@ -655,7 +656,7 @@ Status RedisZSets::ZRank(const Slice& key, const Slice& member, int32_t* rank) { rocksdb::Iterator* iter = db_->NewIterator(read_options, handles_[2]); for (iter->Seek(zsets_score_key.Encode()); iter->Valid() && index <= stop_index; iter->Next(), ++index) { ParsedZSetsScoreKey parsed_zsets_score_key(iter->key()); - if (!parsed_zsets_score_key.member().compare(member)) { + if (parsed_zsets_score_key.member().compare(member) == 0) { found = true; break; } @@ -672,7 +673,7 @@ Status RedisZSets::ZRank(const Slice& key, const Slice& member, int32_t* rank) { return s; } -Status RedisZSets::ZRem(const Slice& key, std::vector members, int32_t* ret) { +Status RedisZSets::ZRem(const Slice& key, const std::vector& members, int32_t* ret) { *ret = 0; uint32_t statistic = 0; std::unordered_set unique; @@ -976,7 +977,7 @@ Status RedisZSets::ZRevrank(const Slice& key, const Slice& member, int32_t* rank rocksdb::Iterator* iter = db_->NewIterator(read_options, handles_[2]); for (iter->SeekForPrev(zsets_score_key.Encode()); iter->Valid() && left >= 0; iter->Prev(), --left, ++rev_index) { ParsedZSetsScoreKey parsed_zsets_score_key(iter->key()); - if (!parsed_zsets_score_key.member().compare(member)) { + if (parsed_zsets_score_key.member().compare(member) == 0) { found = true; break; } @@ -1121,7 +1122,7 @@ Status RedisZSets::ZUnionstore(const Slice& destination, const std::vector& keys, const std::vector& weights, const AGGREGATE agg, int32_t* ret) { - if (keys.size() <= 0) { + if (keys.empty()) { return Status::Corruption("ZInterstore invalid parameter, no keys"); } @@ -1180,7 +1181,7 @@ Status RedisZSets::ZInterstore(const Slice& destination, const std::vector 0 ? weights[0] : 1); + item.score = sm.score * (!weights.empty() ? weights[0] : 1); for (size_t idx = 1; idx < vaild_zsets.size(); ++idx) { double weight = idx < weights.size() ? weights[idx] : 1; ZSetsMemberKey zsets_member_key(vaild_zsets[idx].key, vaild_zsets[idx].version, item.member); @@ -1254,8 +1255,8 @@ Status RedisZSets::ZRangebylex(const Slice& key, const Slice& min, const Slice& ScopeSnapshot ss(db_, &snapshot); read_options.snapshot = snapshot; - bool left_no_limit = !min.compare("-"); - bool right_not_limit = !max.compare("+"); + bool left_no_limit = min.compare("-") == 0; + bool right_not_limit = max.compare("+") == 0; Status s = db_->Get(read_options, handles_[0], key, &meta_value); if (s.ok()) { @@ -1312,8 +1313,8 @@ Status RedisZSets::ZRemrangebylex(const Slice& key, const Slice& min, const Slic read_options.snapshot = snapshot; ScopeRecordLock l(lock_mgr_, key); - bool left_no_limit = !min.compare("-"); - bool right_not_limit = !max.compare("+"); + bool left_no_limit = min.compare("-") == 0; + bool right_not_limit = max.compare("+") == 0; int32_t del_cnt = 0; std::string meta_value; @@ -1431,7 +1432,7 @@ bool RedisZSets::Scan(const std::string& start_key, const std::string& pattern, continue; } else { meta_key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), meta_key.data(), meta_key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), meta_key.data(), meta_key.size(), 0) != 0) { keys->push_back(meta_key); } (*count)--; @@ -1553,7 +1554,7 @@ Status RedisZSets::ZScan(const Slice& key, int64_t cursor, const std::string& pa iter->Next()) { ParsedZSetsMemberKey parsed_zsets_member_key(iter->key()); std::string member = parsed_zsets_member_key.member().ToString(); - if (StringMatch(pattern.data(), pattern.size(), member.data(), member.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), member.data(), member.size(), 0) != 0) { uint64_t tmp = DecodeFixed64(iter->value().data()); const void* ptr_tmp = reinterpret_cast(&tmp); double score = *reinterpret_cast(ptr_tmp); @@ -1591,8 +1592,8 @@ Status RedisZSets::PKScanRange(const Slice& key_start, const Slice& key_end, con iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) > 0)) { return Status::InvalidArgument("error in given range"); @@ -1611,7 +1612,7 @@ Status RedisZSets::PKScanRange(const Slice& key_start, const Slice& key_end, con it->Next(); } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } remain--; @@ -1644,8 +1645,8 @@ Status RedisZSets::PKRScanRange(const Slice& key_start, const Slice& key_end, co iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; - bool start_no_limit = !key_start.compare(""); - bool end_no_limit = !key_end.compare(""); + bool start_no_limit = key_start.compare("") == 0; + bool end_no_limit = key_end.compare("") == 0; if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) < 0)) { return Status::InvalidArgument("error in given range"); @@ -1664,7 +1665,7 @@ Status RedisZSets::PKRScanRange(const Slice& key_start, const Slice& key_end, co it->Prev(); } else { key = it->key().ToString(); - if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { + if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0) { keys->push_back(key); } remain--; diff --git a/src/storage/src/redis_zsets.h b/src/storage/src/redis_zsets.h index b40cc0d80a..841f50a156 100644 --- a/src/storage/src/redis_zsets.h +++ b/src/storage/src/redis_zsets.h @@ -17,8 +17,8 @@ namespace storage { class RedisZSets : public Redis { public: - RedisZSets(Storage* const s, const DataType& type); - ~RedisZSets() = default; + RedisZSets(Storage* s, const DataType& type); + ~RedisZSets() override = default; // Common Commands Status Open(const StorageOptions& storage_options, const std::string& db_path) override; @@ -38,7 +38,7 @@ class RedisZSets : public Redis { Status ZRangebyscore(const Slice& key, double min, double max, bool left_close, bool right_close, int64_t count, int64_t offset, std::vector* score_members); Status ZRank(const Slice& key, const Slice& member, int32_t* rank); - Status ZRem(const Slice& key, std::vector members, int32_t* ret); + Status ZRem(const Slice& key, const std::vector& members, int32_t* ret); Status ZRemrangebyrank(const Slice& key, int32_t start, int32_t stop, int32_t* ret); Status ZRemrangebyscore(const Slice& key, double min, double max, bool left_close, bool right_close, int32_t* ret); Status ZRevrange(const Slice& key, int32_t start, int32_t stop, std::vector* score_members); @@ -47,9 +47,9 @@ class RedisZSets : public Redis { Status ZRevrank(const Slice& key, const Slice& member, int32_t* rank); Status ZScore(const Slice& key, const Slice& member, double* score); Status ZUnionstore(const Slice& destination, const std::vector& keys, const std::vector& weights, - const AGGREGATE agg, int32_t* ret); + AGGREGATE agg, int32_t* ret); Status ZInterstore(const Slice& destination, const std::vector& keys, const std::vector& weights, - const AGGREGATE agg, int32_t* ret); + AGGREGATE agg, int32_t* ret); Status ZRangebylex(const Slice& key, const Slice& min, const Slice& max, bool left_close, bool right_close, std::vector* members); Status ZLexcount(const Slice& key, const Slice& min, const Slice& max, bool left_close, bool right_close, @@ -62,8 +62,8 @@ class RedisZSets : public Redis { std::vector* keys, std::string* next_key); Status PKRScanRange(const Slice& key_start, const Slice& key_end, const Slice& pattern, int32_t limit, std::vector* keys, std::string* next_key); - Status ZPopMax(const Slice& key, const int64_t count, std::vector* score_members); - Status ZPopMin(const Slice& key, const int64_t count, std::vector* score_members); + Status ZPopMax(const Slice& key, int64_t count, std::vector* score_members); + Status ZPopMin(const Slice& key, int64_t count, std::vector* score_members); // Keys Commands Status Expire(const Slice& key, int32_t ttl) override; diff --git a/src/storage/src/scope_record_lock.h b/src/storage/src/scope_record_lock.h index 788240c666..37c14b3076 100644 --- a/src/storage/src/scope_record_lock.h +++ b/src/storage/src/scope_record_lock.h @@ -8,10 +8,12 @@ #include #include +#include #include #include "pstd/include/scope_record_lock.h" #include "src/lock_mgr.h" +#include "storage/storage.h" namespace storage { diff --git a/src/storage/src/scope_snapshot.h b/src/storage/src/scope_snapshot.h index a50d520516..8fecfc6985 100644 --- a/src/storage/src/scope_snapshot.h +++ b/src/storage/src/scope_snapshot.h @@ -8,8 +8,10 @@ #include "rocksdb/db.h" +#include "pstd/include/noncopyable.h" + namespace storage { -class ScopeSnapshot { +class ScopeSnapshot : public pstd::noncopyable { public: ScopeSnapshot(rocksdb::DB* db, const rocksdb::Snapshot** snapshot) : db_(db), snapshot_(snapshot) { *snapshot_ = db_->GetSnapshot(); @@ -19,8 +21,6 @@ class ScopeSnapshot { private: rocksdb::DB* const db_; const rocksdb::Snapshot** snapshot_; - ScopeSnapshot(const ScopeSnapshot&); - void operator=(const ScopeSnapshot&); }; } // namespace storage diff --git a/src/storage/src/storage.cc b/src/storage/src/storage.cc index 93695da395..e08cb1dd3a 100644 --- a/src/storage/src/storage.cc +++ b/src/storage/src/storage.cc @@ -8,6 +8,8 @@ #include +#include + #include "src/lru_cache.h" #include "src/mutex_impl.h" #include "src/options_helper.h" @@ -47,11 +49,7 @@ Status StorageOptions::ResetOptions(const OptionType& option_type, } Storage::Storage() - : strings_db_(nullptr), - hashes_db_(nullptr), - sets_db_(nullptr), - zsets_db_(nullptr), - lists_db_(nullptr), + : is_opened_(false), current_task_type_(kNone), bg_tasks_should_exit_(false), @@ -273,7 +271,7 @@ Status Storage::HScan(const Slice& key, int64_t cursor, const std::string& patte return hashes_db_->HScan(key, cursor, pattern, count, field_values, next_cursor); } -Status Storage::HScanx(const Slice& key, const std::string start_field, const std::string& pattern, int64_t count, +Status Storage::HScanx(const Slice& key, const std::string& start_field, const std::string& pattern, int64_t count, std::vector* field_values, std::string* next_field) { return hashes_db_->HScanx(key, start_field, pattern, count, field_values, next_field); } @@ -444,7 +442,7 @@ Status Storage::ZRank(const Slice& key, const Slice& member, int32_t* rank) { return zsets_db_->ZRank(key, member, rank); } -Status Storage::ZRem(const Slice& key, std::vector members, int32_t* ret) { +Status Storage::ZRem(const Slice& key, const std::vector& members, int32_t* ret) { return zsets_db_->ZRem(key, members, ret); } @@ -759,8 +757,11 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& keys->clear(); bool is_finish; int64_t leftover_visits = count; - int64_t step_length = count, cursor_ret = 0; - std::string start_key, next_key, prefix; + int64_t step_length = count; + int64_t cursor_ret = 0; + std::string start_key; + std::string next_key; + std::string prefix; prefix = isTailWildcard(pattern) ? pattern.substr(0, pattern.size() - 1) : ""; @@ -780,7 +781,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& switch (key_type) { case 'k': is_finish = strings_db_->Scan(start_key, pattern, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("k") + next_key); break; @@ -788,7 +789,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& if (DataType::kStrings == dtype) { cursor_ret = 0; break; - } else if (!leftover_visits) { + } else if (leftover_visits == 0) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("h") + prefix); break; @@ -797,7 +798,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& start_key = prefix; case 'h': is_finish = hashes_db_->Scan(start_key, pattern, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("h") + next_key); break; @@ -805,7 +806,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& if (DataType::kHashes == dtype) { cursor_ret = 0; break; - } else if (!leftover_visits) { + } else if (leftover_visits == 0) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("s") + prefix); break; @@ -814,7 +815,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& start_key = prefix; case 's': is_finish = sets_db_->Scan(start_key, pattern, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("s") + next_key); break; @@ -822,7 +823,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& if (DataType::kSets == dtype) { cursor_ret = 0; break; - } else if (!leftover_visits) { + } else if (leftover_visits == 0) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("l") + prefix); break; @@ -831,7 +832,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& start_key = prefix; case 'l': is_finish = lists_db_->Scan(start_key, pattern, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("l") + next_key); break; @@ -839,7 +840,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& if (DataType::kLists == dtype) { cursor_ret = 0; break; - } else if (!leftover_visits) { + } else if (leftover_visits == 0) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("z") + prefix); break; @@ -848,7 +849,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& start_key = prefix; case 'z': is_finish = zsets_db_->Scan(start_key, pattern, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("z") + next_key); break; @@ -865,8 +866,10 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min keys->clear(); bool is_finish; int64_t leftover_visits = count; - int64_t step_length = count, cursor_ret = 0; - std::string start_key, next_key; + int64_t step_length = count; + int64_t cursor_ret = 0; + std::string start_key; + std::string next_key; int64_t curtime; rocksdb::Env::Default()->GetCurrentTime(&curtime); @@ -888,7 +891,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min case 'k': is_finish = strings_db_->PKExpireScan(start_key, curtime + min_ttl, curtime + max_ttl, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("k") + next_key); break; @@ -896,7 +899,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min if (DataType::kStrings == dtype) { cursor_ret = 0; break; - } else if (!leftover_visits) { + } else if (leftover_visits == 0) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("h")); break; @@ -906,7 +909,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min case 'h': is_finish = hashes_db_->PKExpireScan(start_key, curtime + min_ttl, curtime + max_ttl, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("h") + next_key); break; @@ -914,7 +917,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min if (DataType::kHashes == dtype) { cursor_ret = 0; break; - } else if (!leftover_visits) { + } else if (leftover_visits == 0) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("s")); break; @@ -924,7 +927,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min case 's': is_finish = sets_db_->PKExpireScan(start_key, curtime + min_ttl, curtime + max_ttl, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("s") + next_key); break; @@ -932,7 +935,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min if (DataType::kSets == dtype) { cursor_ret = 0; break; - } else if (!leftover_visits) { + } else if (leftover_visits == 0) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("l")); break; @@ -942,7 +945,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min case 'l': is_finish = lists_db_->PKExpireScan(start_key, curtime + min_ttl, curtime + max_ttl, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("l") + next_key); break; @@ -950,7 +953,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min if (DataType::kLists == dtype) { cursor_ret = 0; break; - } else if (!leftover_visits) { + } else if (leftover_visits == 0) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("z")); break; @@ -960,7 +963,7 @@ int64_t Storage::PKExpireScan(const DataType& dtype, int64_t cursor, int32_t min case 'z': is_finish = zsets_db_->PKExpireScan(start_key, curtime + min_ttl, curtime + max_ttl, keys, &leftover_visits, &next_key); - if (!leftover_visits && !is_finish) { + if ((leftover_visits == 0) && !is_finish) { cursor_ret = cursor + step_length; StoreCursorStartKey(dtype, cursor_ret, std::string("z") + next_key); break; @@ -1292,30 +1295,50 @@ Status Storage::Keys(const DataType& data_type, const std::string& pattern, std: Status s; if (data_type == DataType::kStrings) { s = strings_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } else if (data_type == DataType::kHashes) { s = hashes_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } else if (data_type == DataType::kZSets) { s = zsets_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } else if (data_type == DataType::kSets) { s = sets_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } else if (data_type == DataType::kLists) { s = lists_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } else { s = strings_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } s = hashes_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } s = zsets_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } s = sets_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } s = lists_db_->ScanKeys(pattern, keys); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } return s; } @@ -1354,7 +1377,9 @@ Status Storage::PfAdd(const Slice& key, const std::vector& values, return Status::InvalidArgument("Invalid the number of key"); } - std::string value, registers, result = ""; + std::string value; + std::string registers; + std::string result; Status s = strings_db_->Get(key, &value); if (s.ok()) { registers = value; @@ -1364,13 +1389,13 @@ Status Storage::PfAdd(const Slice& key, const std::vector& values, return s; } HyperLogLog log(kPrecision, registers); - int32_t previous = static_cast(log.Estimate()); - for (size_t i = 0; i < values.size(); ++i) { - result = log.Add(values[i].data(), values[i].size()); + auto previous = static_cast(log.Estimate()); + for (const auto & value : values) { + result = log.Add(value.data(), value.size()); } HyperLogLog update_log(kPrecision, result); - int32_t now = static_cast(update_log.Estimate()); - if (previous != now || (s.IsNotFound() && values.size() == 0)) { + auto now = static_cast(update_log.Estimate()); + if (previous != now || (s.IsNotFound() && values.empty())) { *update = true; } s = strings_db_->Set(key, result); @@ -1378,11 +1403,12 @@ Status Storage::PfAdd(const Slice& key, const std::vector& values, } Status Storage::PfCount(const std::vector& keys, int64_t* result) { - if (keys.size() >= kMaxKeys || keys.size() <= 0) { + if (keys.size() >= kMaxKeys || keys.empty()) { return Status::InvalidArgument("Invalid the number of key"); } - std::string value, first_registers; + std::string value; + std::string first_registers; Status s = strings_db_->Get(keys[0], &value); if (s.ok()) { first_registers = std::string(value.data(), value.size()); @@ -1392,7 +1418,8 @@ Status Storage::PfCount(const std::vector& keys, int64_t* result) { HyperLogLog first_log(kPrecision, first_registers); for (size_t i = 1; i < keys.size(); ++i) { - std::string value, registers; + std::string value; + std::string registers; s = strings_db_->Get(keys[i], &value); if (s.ok()) { registers = value; @@ -1409,12 +1436,14 @@ Status Storage::PfCount(const std::vector& keys, int64_t* result) { } Status Storage::PfMerge(const std::vector& keys) { - if (keys.size() >= kMaxKeys || keys.size() <= 0) { + if (keys.size() >= kMaxKeys || keys.empty()) { return Status::InvalidArgument("Invalid the number of key"); } Status s; - std::string value, first_registers, result; + std::string value; + std::string first_registers; + std::string result; s = strings_db_->Get(keys[0], &value); if (s.ok()) { first_registers = std::string(value.data(), value.size()); @@ -1425,7 +1454,8 @@ Status Storage::PfMerge(const std::vector& keys) { result = first_registers; HyperLogLog first_log(kPrecision, first_registers); for (size_t i = 1; i < keys.size(); ++i) { - std::string value, registers; + std::string value; + std::string registers; s = strings_db_->Get(keys[i], &value); if (s.ok()) { registers = std::string(value.data(), value.size()); @@ -1442,7 +1472,7 @@ Status Storage::PfMerge(const std::vector& keys) { } static void* StartBGThreadWrapper(void* arg) { - Storage* s = reinterpret_cast(arg); + auto s = reinterpret_cast(arg); s->RunBGTask(); return nullptr; } @@ -1539,8 +1569,10 @@ Status Storage::DoCompact(const DataType& type) { } Status Storage::CompactKey(const DataType& type, const std::string& key) { - std::string meta_start_key, meta_end_key; - std::string data_start_key, data_end_key; + std::string meta_start_key; + std::string meta_end_key; + std::string data_start_key; + std::string data_end_key; CalculateMetaStartAndEndKey(key, &meta_start_key, &meta_end_key); CalculateDataStartAndEndKey(key, &data_start_key, &data_end_key); Slice slice_meta_begin(meta_start_key); @@ -1616,7 +1648,8 @@ Status Storage::GetUsage(const std::string& property, std::mapGetProperty(property, &out); result += out; @@ -1685,23 +1718,33 @@ Status Storage::SetOptions(const OptionType& option_type, const std::string& db_ Status s; if (db_type == ALL_DB || db_type == STRINGS_DB) { s = strings_db_->SetOptions(option_type, options); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } if (db_type == ALL_DB || db_type == HASHES_DB) { s = hashes_db_->SetOptions(option_type, options); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } if (db_type == ALL_DB || db_type == LISTS_DB) { s = lists_db_->SetOptions(option_type, options); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } if (db_type == ALL_DB || db_type == ZSETS_DB) { s = zsets_db_->SetOptions(option_type, options); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } if (db_type == ALL_DB || db_type == SETS_DB) { s = sets_db_->SetOptions(option_type, options); - if (!s.ok()) return s; + if (!s.ok()) { + return s; + } } return s; } diff --git a/src/storage/src/storage_murmur3.h b/src/storage/src/storage_murmur3.h index 25f95175c9..21868c9b0e 100644 --- a/src/storage/src/storage_murmur3.h +++ b/src/storage/src/storage_murmur3.h @@ -3,7 +3,7 @@ //----------------------------------------------------------------------------- // MurmurHash3 was written by Austin Appleby, and is placed in the public -// domain. The author hereby disclaims copyright to this source code. +// domain. The autohor hereby disclaims copyright to this source code. // Note - The x86 and x64 versions do _not_ produce the same results, as the // algorithms are optimized for their respective platforms. You can still @@ -27,7 +27,7 @@ typedef unsigned __int64 uint64_t; #else // defined(_MSC_VER) -# include +# include #endif // !defined(_MSC_VER) @@ -65,7 +65,7 @@ inline uint32_t rotl32(uint32_t x, uint8_t r) { return (x << r) | (x >> (32 - r) // Block read - if your platform needs to do endian-swapping or can only // handle aligned reads, do the conversion here -#define getblock(p, i) BYTESWAP(p[i]) +#define getblock(p, i) BYTESWAP((p)[i]) //----------------------------------------------------------------------------- // Finalization mix - force all bits of a hash block to avalanche @@ -89,7 +89,7 @@ extern #endif void MurmurHash3_x86_32(const void* key, int len, uint32_t seed, void* out) { - const uint8_t* data = (const uint8_t*)key; + const auto data = (const uint8_t*)key; const int nblocks = len / 4; int i; @@ -101,9 +101,9 @@ extern //---------- // body - const uint32_t* blocks = (const uint32_t*)(data + nblocks * 4); + const auto blocks = (const uint32_t*)(data + nblocks * 4); - for (i = -nblocks; i; i++) { + for (i = -nblocks; i != 0; i++) { uint32_t k1 = getblock(blocks, i); k1 *= c1; @@ -118,7 +118,7 @@ extern //---------- // tail { - const uint8_t* tail = (const uint8_t*)(data + nblocks * 4); + const auto tail = (data + nblocks * 4); uint32_t k1 = 0; diff --git a/src/storage/src/strings_filter.h b/src/storage/src/strings_filter.h index a7d89e1c43..28873456d2 100644 --- a/src/storage/src/strings_filter.h +++ b/src/storage/src/strings_filter.h @@ -22,7 +22,7 @@ class StringsFilter : public rocksdb::CompactionFilter { bool* value_changed) const override { int64_t unix_time; rocksdb::Env::Default()->GetCurrentTime(&unix_time); - int32_t cur_time = static_cast(unix_time); + auto cur_time = static_cast(unix_time); ParsedStringsValue parsed_strings_value(value); TRACE("==========================START=========================="); TRACE("[StringsFilter], key: %s, value = %s, timestamp: %d, cur_time: %d", key.ToString().c_str(), diff --git a/src/storage/src/strings_value_format.h b/src/storage/src/strings_value_format.h index f1e68da161..8717fe5c5f 100644 --- a/src/storage/src/strings_value_format.h +++ b/src/storage/src/strings_value_format.h @@ -44,7 +44,7 @@ class ParsedStringsValue : public ParsedInternalValue { } void StripSuffix() override { - if (value_ != nullptr) { + if (value_) { value_->erase(value_->size() - kStringsValueSuffixLength, kStringsValueSuffixLength); } } @@ -53,7 +53,7 @@ class ParsedStringsValue : public ParsedInternalValue { void SetVersionToValue() override {} void SetTimestampToValue() override { - if (value_ != nullptr) { + if (value_) { char* dst = const_cast(value_->data()) + value_->size() - kStringsValueSuffixLength; EncodeFixed32(dst, timestamp_); } diff --git a/src/storage/src/util.cc b/src/storage/src/util.cc index b5f55fc1bc..35089be4b3 100644 --- a/src/storage/src/util.cc +++ b/src/storage/src/util.cc @@ -3,11 +3,13 @@ // 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 #include +#include +#include +#include +#include #include + #include "pstd/include/pstd_string.h" #include "src/coding.h" @@ -45,13 +47,17 @@ int StringMatch(const char* pattern, int pattern_len, const char* str, int strin int StrToLongDouble(const char* s, size_t slen, long double* ldval) { char* pEnd; std::string t(s, slen); - if (t.find(" ") != std::string::npos) { + if (t.find(' ') != std::string::npos) { return -1; } long double d = strtold(s, &pEnd); - if (pEnd != s + slen) return -1; + if (pEnd != s + slen) { + return -1; + } - if (ldval != nullptr) *ldval = d; + if (ldval) { + *ldval = d; + } return 0; } @@ -64,10 +70,10 @@ int LongDoubleToStr(long double ldval, std::string* value) { /* Libc in odd systems (Hi Solaris!) will format infinite in a * different way, so better to handle it in an explicit way. */ if (ldval > 0) { - memcpy(buf, "inf", 3); + strcpy(buf, "inf"); len = 3; } else { - memcpy(buf, "-inf", 4); + strcpy(buf, "-inf"); len = 4; } return -1; @@ -79,13 +85,15 @@ int LongDoubleToStr(long double ldval, std::string* value) { * back into a string are exactly the same as what the user typed.) */ len = snprintf(buf, sizeof(buf), "%.17Lf", ldval); /* Now remove trailing zeroes after the '.' */ - if (strchr(buf, '.') != nullptr) { + if (strchr(buf, '.')) { char* p = buf + len - 1; while (*p == '0') { p--; len--; } - if (*p == '.') len--; + if (*p == '.') { + len--; + } } value->assign(buf, len); return 0; @@ -99,7 +107,9 @@ int do_mkdir(const char* path, mode_t mode) { if (stat(path, &st) != 0) { /* Directory does not exist. EEXIST for race * condition */ - if (mkdir(path, mode) != 0 && errno != EEXIST) status = -1; + if (mkdir(path, mode) != 0 && errno != EEXIST) { + status = -1; + } } else if (!S_ISDIR(st.st_mode)) { errno = ENOTDIR; status = -1; @@ -122,7 +132,7 @@ int mkpath(const char* path, mode_t mode) { status = 0; pp = copypath; - while (status == 0 && (sp = strchr(pp, '/')) != 0) { + while (status == 0 && (sp = strchr(pp, '/')) != nullptr) { if (sp != pp) { /* Neither root nor double slash in path */ *sp = '\0'; @@ -131,7 +141,9 @@ int mkpath(const char* path, mode_t mode) { } pp = sp + 1; } - if (status == 0) status = do_mkdir(path, mode); + if (status == 0) { + status = do_mkdir(path, mode); + } free(copypath); return (status); } @@ -182,7 +194,7 @@ int is_dir(const char* filename) { struct stat buf; int ret = stat(filename, &buf); if (0 == ret) { - if (buf.st_mode & S_IFDIR) { + if ((buf.st_mode & S_IFDIR) != 0) { // folder return 0; } else { @@ -197,7 +209,7 @@ int CalculateMetaStartAndEndKey(const std::string& key, std::string* meta_start_ size_t needed = key.size() + 1; auto dst = std::make_unique(needed); const char* start = dst.get(); - std::memcpy(dst.get(), key.data(), key.size()); + std::strncpy(dst.get(), key.data(), key.size()); char* dst_ptr = dst.get() + key.size(); meta_start_key->assign(start, key.size()); *dst_ptr = static_cast(0xff); @@ -210,16 +222,16 @@ int CalculateDataStartAndEndKey(const std::string& key, std::string* data_start_ auto dst = std::make_unique(needed); const char* start = dst.get(); char* dst_ptr = dst.get(); - + EncodeFixed32(dst_ptr, key.size()); dst_ptr += sizeof(int32_t); - std::memcpy(dst_ptr, key.data(), key.size()); + std::strncpy(dst_ptr, key.data(), key.size()); dst_ptr += key.size(); *dst_ptr = static_cast(0xff); - + data_start_key->assign(start, sizeof(int32_t) + key.size()); data_end_key->assign(start, sizeof(int32_t) + key.size() + 1); - + return 0; } @@ -241,9 +253,11 @@ bool isTailWildcard(const std::string& pattern) { } void GetFilepath(const char* path, const char* filename, char* filepath) { - strcpy(filepath, path); - if (filepath[strlen(path) - 1] != '/') strcat(filepath, "/"); - strcat(filepath, filename); + strcpy(filepath, path); // NOLINT + if (filepath[strlen(path) - 1] != '/') { + strcat(filepath, "/"); // NOLINT + } + strcat(filepath, filename); // NOLINT } bool DeleteFiles(const char* path) { @@ -258,17 +272,20 @@ bool DeleteFiles(const char* path) { remove(path); } else if (S_ISDIR(statbuf.st_mode)) // 判断是否是目录 { - if ((dir = opendir(path)) == nullptr) return 1; + if (!(dir = opendir(path))) { + return true; + } while ((dirinfo = readdir(dir)) != nullptr) { GetFilepath(path, dirinfo->d_name, filepath); - if (strcmp(dirinfo->d_name, ".") == 0 || strcmp(dirinfo->d_name, "..") == 0) // 判断是否是特殊目录 + if (strcmp(dirinfo->d_name, ".") == 0 || strcmp(dirinfo->d_name, "..") == 0) { // 判断是否是特殊目录 continue; + } DeleteFiles(filepath); rmdir(filepath); } closedir(dir); } - return 0; + return false; } } // namespace storage diff --git a/src/storage/src/zsets_data_key_format.h b/src/storage/src/zsets_data_key_format.h index e1b3cf1559..45352781f6 100644 --- a/src/storage/src/zsets_data_key_format.h +++ b/src/storage/src/zsets_data_key_format.h @@ -15,7 +15,7 @@ namespace storage { class ZSetsScoreKey { public: ZSetsScoreKey(const Slice& key, int32_t version, double score, const Slice& member) - : start_(nullptr), key_(key), version_(version), score_(score), member_(member) {} + : key_(key), version_(version), score_(score), member_(member) {} ~ZSetsScoreKey() { if (start_ != space_) { @@ -23,7 +23,7 @@ class ZSetsScoreKey { } } - const Slice Encode() { + Slice Encode() { size_t needed = key_.size() + member_.size() + sizeof(int32_t) * 2 + sizeof(uint64_t); char* dst = nullptr; if (needed <= sizeof(space_)) { diff --git a/src/storage/src/zsets_filter.h b/src/storage/src/zsets_filter.h index ca8b8ce498..51d58d94a9 100644 --- a/src/storage/src/zsets_filter.h +++ b/src/storage/src/zsets_filter.h @@ -21,7 +21,7 @@ namespace storage { class ZSetsScoreFilter : public rocksdb::CompactionFilter { public: ZSetsScoreFilter(rocksdb::DB* db, std::vector* handles_ptr) - : db_(db), cf_handles_ptr_(handles_ptr), meta_not_found_(false), cur_meta_version_(0), cur_meta_timestamp_(0) {} + : db_(db), cf_handles_ptr_(handles_ptr) {} bool Filter(int level, const rocksdb::Slice& key, const rocksdb::Slice& value, std::string* new_value, bool* value_changed) const override { @@ -35,7 +35,7 @@ class ZSetsScoreFilter : public rocksdb::CompactionFilter { cur_key_ = parsed_zsets_score_key.key().ToString(); std::string meta_value; // destroyed when close the database, Reserve Current key value - if (cf_handles_ptr_->size() == 0) { + if (cf_handles_ptr_->empty()) { return false; } Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value); diff --git a/src/storage/tests/hashes_test.cc b/src/storage/tests/hashes_test.cc index 74dcd6a991..ff3f1b4ac4 100644 --- a/src/storage/tests/hashes_test.cc +++ b/src/storage/tests/hashes_test.cc @@ -17,25 +17,25 @@ using namespace storage; class HashesTest : public ::testing::Test { public: - HashesTest() {} - virtual ~HashesTest() {} + HashesTest() = default; + ~HashesTest() override = default; - void SetUp() { + void SetUp() override { std::string path = "./db/hashes"; - if (access(path.c_str(), F_OK)) { + if (access(path.c_str(), F_OK) != 0) { mkdir(path.c_str(), 0755); } storage_options.options.create_if_missing = true; s = db.Open(storage_options, path); } - void TearDown() { + void TearDown() override { std::string path = "./db/hashes"; DeleteFiles(path.c_str()); } - static void SetUpTestCase() {} - static void TearDownTestCase() {} + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} StorageOptions storage_options; storage::Storage db; @@ -82,7 +82,7 @@ static bool size_match(storage::Storage* const db, const Slice& key, int32_t exp if (!s.ok() && !s.IsNotFound()) { return false; } - if (s.IsNotFound() && !expect_size) { + if (s.IsNotFound() && (expect_size == 0)) { return true; } return size == expect_size; @@ -91,7 +91,7 @@ static bool size_match(storage::Storage* const db, const Slice& key, int32_t exp static bool make_expired(storage::Storage* const db, const Slice& key) { std::map type_status; int ret = db->Expire(key, 1, &type_status); - if (!ret || !type_status[storage::DataType::kHashes].ok()) { + if ((ret == 0) || !type_status[storage::DataType::kHashes].ok()) { return false; } std::this_thread::sleep_for(std::chrono::milliseconds(2000)); @@ -979,8 +979,9 @@ TEST_F(HashesTest, HStrlenTest) { } // HScan -TEST_F(HashesTest, HScanTest) { - int64_t cursor = 0, next_cursor = 0; +TEST_F(HashesTest, HScanTest) { // NOLINT + int64_t cursor = 0; + int64_t next_cursor = 0; std::vector field_value_out; // ***************** Group 1 Test ***************** diff --git a/src/storage/tests/hyperloglog_test.cc b/src/storage/tests/hyperloglog_test.cc index ebc2e52bcf..854dcd4b7f 100644 --- a/src/storage/tests/hyperloglog_test.cc +++ b/src/storage/tests/hyperloglog_test.cc @@ -14,25 +14,25 @@ using namespace storage; class HyperLogLogTest : public ::testing::Test { public: - HyperLogLogTest() {} - virtual ~HyperLogLogTest() {} + HyperLogLogTest() = default; + ~HyperLogLogTest() override = default; - void SetUp() { + void SetUp() override { std::string path = "./db/hyperloglog"; - if (access(path.c_str(), F_OK)) { + if (access(path.c_str(), F_OK) != 0) { mkdir(path.c_str(), 0755); } storage_options.options.create_if_missing = true; s = db.Open(storage_options, path); } - void TearDown() { + void TearDown() override { std::string path = "./db/hyperloglog"; DeleteFiles(path.c_str()); } - static void SetUpTestCase() {} - static void TearDownTestCase() {} + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} StorageOptions storage_options; storage::Storage db; @@ -62,18 +62,18 @@ TEST_F(HyperLogLogTest, PfaddTest) { // PFADD the return value is true when at least 1 reg was modified values.clear(); - values.push_back("A"); - values.push_back("B"); - values.push_back("C"); + values.emplace_back("A"); + values.emplace_back("B"); + values.emplace_back("C"); s = db.PfAdd("HLL", values, &update); ASSERT_TRUE(s.ok()); ASSERT_TRUE(update); // PFADD the return value is false when no reg was modified values.clear(); - values.push_back("A"); - values.push_back("B"); - values.push_back("C"); + values.emplace_back("A"); + values.emplace_back("B"); + values.emplace_back("C"); update = false; s = db.PfAdd("HLL", values, &update); ASSERT_TRUE(s.ok()); @@ -83,7 +83,7 @@ TEST_F(HyperLogLogTest, PfaddTest) { // PFADD works with empty string (regression) values.clear(); - values.push_back(""); + values.emplace_back(""); s = db.PfAdd("HLL", values, &update); ASSERT_TRUE(s.ok()); ASSERT_TRUE(update); diff --git a/src/storage/tests/keys_test.cc b/src/storage/tests/keys_test.cc index 3bf455dc2a..46a78ab28b 100644 --- a/src/storage/tests/keys_test.cc +++ b/src/storage/tests/keys_test.cc @@ -10,31 +10,34 @@ #include "storage/storage.h" #include "storage/util.h" -using namespace storage; +// using namespace storage; +using storage::DataType; +using storage::Slice; +using storage::Status; class KeysTest : public ::testing::Test { public: - KeysTest() {} - virtual ~KeysTest() {} + KeysTest() = default; + ~KeysTest() override = default; - void SetUp() { + void SetUp() override { std::string path = "./db/keys"; - if (access(path.c_str(), F_OK)) { + if (access(path.c_str(), F_OK) != 0) { mkdir(path.c_str(), 0755); } storage_options.options.create_if_missing = true; s = db.Open(storage_options, path); } - void TearDown() { + void TearDown() override { std::string path = "./db/keys"; - DeleteFiles(path.c_str()); + storage::DeleteFiles(path.c_str()); } - static void SetUpTestCase() {} - static void TearDownTestCase() {} + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} - StorageOptions storage_options; + storage::StorageOptions storage_options; storage::Storage db; storage::Status s; }; @@ -42,7 +45,7 @@ class KeysTest : public ::testing::Test { static bool make_expired(storage::Storage* const db, const Slice& key) { std::map type_status; int ret = db->Expire(key, 1, &type_status); - if (!ret || !type_status[storage::DataType::kStrings].ok()) { + if ((ret == 0) || !type_status[storage::DataType::kStrings].ok()) { return false; } std::this_thread::sleep_for(std::chrono::milliseconds(2000)); @@ -52,13 +55,10 @@ static bool make_expired(storage::Storage* const db, const Slice& key) { static bool set_timeout(storage::Storage* const db, const Slice& key, int32_t ttl) { std::map type_status; int ret = db->Expire(key, ttl, &type_status); - if (!ret || !type_status[storage::DataType::kStrings].ok()) { - return false; - } - return true; + return !((ret == 0) || !type_status[storage::DataType::kStrings].ok()); } -static bool key_value_match(const std::vector& key_value_out, const std::vector& expect_key_value) { +static bool key_value_match(const std::vector& key_value_out, const std::vector& expect_key_value) { if (key_value_out.size() != expect_key_value.size()) { return false; } @@ -86,21 +86,22 @@ static bool key_match(const std::vector& keys_out, const std::vecto // PKScanRange // Note: This test needs to execute at first because all of the data is // predetermined. -TEST_F(KeysTest, PKScanRangeTest) { +TEST_F(KeysTest, PKScanRangeTest) { // NOLINT int32_t ret; uint64_t ret_u64; std::string next_key; std::vector keys_del; std::vector keys_out; std::vector expect_keys; - std::map type_status; + std::map type_status; std::vector kvs_out; std::vector expect_kvs; std::vector kvs{{"PKSCANRANGE_A", "VALUE"}, {"PKSCANRANGE_C", "VALUE"}, {"PKSCANRANGE_E", "VALUE"}, {"PKSCANRANGE_G", "VALUE"}, {"PKSCANRANGE_I", "VALUE"}, {"PKSCANRANGE_K", "VALUE"}, {"PKSCANRANGE_M", "VALUE"}, {"PKSCANRANGE_O", "VALUE"}, {"PKSCANRANGE_Q", "VALUE"}, {"PKSCANRANGE_S", "VALUE"}}; - for (const auto& kv : kvs) { + keys_del.reserve(kvs.size()); +for (const auto& kv : kvs) { keys_del.push_back(kv.key); } @@ -1034,7 +1035,7 @@ TEST_F(KeysTest, PKScanRangeTest) { // PKRScanRange // Note: This test needs to execute at first because all of the data is // predetermined. -TEST_F(KeysTest, PKRScanRangeTest) { +TEST_F(KeysTest, PKRScanRangeTest) { // NOLINT int32_t ret; uint64_t ret_u64; std::string next_key; @@ -1049,7 +1050,8 @@ TEST_F(KeysTest, PKRScanRangeTest) { {"PKRSCANRANGE_I", "VALUE"}, {"PKRSCANRANGE_K", "VALUE"}, {"PKRSCANRANGE_M", "VALUE"}, {"PKRSCANRANGE_O", "VALUE"}, {"PKRSCANRANGE_Q", "VALUE"}, {"PKRSCANRANGE_S", "VALUE"}}; - for (const auto& kv : kvs) { + keys_del.reserve(kvs.size()); +for (const auto& kv : kvs) { keys_del.push_back(kv.key); } @@ -2568,7 +2570,7 @@ TEST_F(KeysTest, PKRScanRangeTest) { // Scan // Note: This test needs to execute at first because all of the data is // predetermined. -TEST_F(KeysTest, ScanCaseAllTest) { +TEST_F(KeysTest, ScanCaseAllTest) { // NOLINT int64_t cursor; int64_t next_cursor; int64_t del_num; @@ -2890,9 +2892,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP5_SCAN_CASE_ALL_STRING_KEY1", "GP5_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP5_SCAN_CASE_ALL_STRING_KEY2", "GP5_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP5_SCAN_CASE_ALL_STRING_KEY3", "GP5_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP5_SCAN_CASE_ALL_HASH_KEY1", "GP5_SCAN_CASE_ALL_HASH_FIELD1", "GP5_SCAN_CASE_ALL_HASH_VALUE1", @@ -2901,33 +2903,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP5_SCAN_CASE_ALL_HASH_KEY3", "GP5_SCAN_CASE_ALL_HASH_FIELD3", "GP5_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP5_SCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP5_SCAN_CASE_ALL_SET_KEY1", {"GP5_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP5_SCAN_CASE_ALL_SET_KEY2", {"GP5_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP5_SCAN_CASE_ALL_SET_KEY3", {"GP5_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP5_SCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP5_SCAN_CASE_ALL_LIST_KEY1", {"GP5_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP5_SCAN_CASE_ALL_LIST_KEY2", {"GP5_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP5_SCAN_CASE_ALL_LIST_KEY3", {"GP5_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP5_SCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP5_SCAN_CASE_ALL_ZSET_KEY1", {{1, "GP5_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP5_SCAN_CASE_ALL_ZSET_KEY2", {{1, "GP5_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP5_SCAN_CASE_ALL_ZSET_KEY3", {{1, "GP5_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP5_SCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP5_SCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP5_SCAN_CASE_ALL_ZSET_KEY3"); cursor = 0; keys.clear(); @@ -2936,7 +2938,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "*_SET_*", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 3); ASSERT_EQ(total_keys[0], "GP5_SCAN_CASE_ALL_SET_KEY1"); ASSERT_EQ(total_keys[1], "GP5_SCAN_CASE_ALL_SET_KEY2"); @@ -2953,9 +2955,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP6_SCAN_CASE_ALL_STRING_KEY1", "GP6_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP6_SCAN_CASE_ALL_STRING_KEY2", "GP6_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP6_SCAN_CASE_ALL_STRING_KEY3", "GP6_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP6_SCAN_CASE_ALL_HASH_KEY1", "GP6_SCAN_CASE_ALL_HASH_FIELD1", "GP6_SCAN_CASE_ALL_HASH_VALUE1", @@ -2964,33 +2966,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP6_SCAN_CASE_ALL_HASH_KEY3", "GP6_SCAN_CASE_ALL_HASH_FIELD3", "GP6_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP6_SCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP6_SCAN_CASE_ALL_SET_KEY1", {"GP6_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP6_SCAN_CASE_ALL_SET_KEY2", {"GP6_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP6_SCAN_CASE_ALL_SET_KEY3", {"GP6_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP6_SCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP6_SCAN_CASE_ALL_LIST_KEY1", {"GP6_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP6_SCAN_CASE_ALL_LIST_KEY2", {"GP6_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP6_SCAN_CASE_ALL_LIST_KEY3", {"GP6_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP6_SCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP6_SCAN_CASE_ALL_ZSET_KEY1", {{1, "GP6_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP6_SCAN_CASE_ALL_ZSET_KEY2", {{1, "GP6_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP6_SCAN_CASE_ALL_ZSET_KEY3", {{1, "GP6_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP6_SCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP6_SCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP6_SCAN_CASE_ALL_ZSET_KEY3"); cursor = 0; keys.clear(); @@ -2999,7 +3001,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "*KEY1", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP6_SCAN_CASE_ALL_STRING_KEY1"); ASSERT_EQ(total_keys[1], "GP6_SCAN_CASE_ALL_HASH_KEY1"); @@ -3018,9 +3020,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP7_SCAN_CASE_ALL_STRING_KEY1", "GP7_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP7_SCAN_CASE_ALL_STRING_KEY2", "GP7_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP7_SCAN_CASE_ALL_STRING_KEY3", "GP7_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP7_SCAN_CASE_ALL_HASH_KEY1", "GP7_SCAN_CASE_ALL_HASH_FIELD1", "GP7_SCAN_CASE_ALL_HASH_VALUE1", @@ -3029,33 +3031,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP7_SCAN_CASE_ALL_HASH_KEY3", "GP7_SCAN_CASE_ALL_HASH_FIELD3", "GP7_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP7_SCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP7_SCAN_CASE_ALL_SET_KEY1", {"GP7_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP7_SCAN_CASE_ALL_SET_KEY2", {"GP7_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP7_SCAN_CASE_ALL_SET_KEY3", {"GP7_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP7_SCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP7_SCAN_CASE_ALL_LIST_KEY1", {"GP7_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP7_SCAN_CASE_ALL_LIST_KEY2", {"GP7_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP7_SCAN_CASE_ALL_LIST_KEY3", {"GP7_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP7_SCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP7_SCAN_CASE_ALL_ZSET_KEY1", {{1, "GP7_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP7_SCAN_CASE_ALL_ZSET_KEY2", {{1, "GP7_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP7_SCAN_CASE_ALL_ZSET_KEY3", {{1, "GP7_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP7_SCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP7_SCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP7_SCAN_CASE_ALL_ZSET_KEY3"); cursor = 0; keys.clear(); @@ -3064,7 +3066,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "*KEY2", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP7_SCAN_CASE_ALL_STRING_KEY2"); ASSERT_EQ(total_keys[1], "GP7_SCAN_CASE_ALL_HASH_KEY2"); @@ -3083,9 +3085,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP8_SCAN_CASE_ALL_STRING_KEY1", "GP8_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP8_SCAN_CASE_ALL_STRING_KEY2", "GP8_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP8_SCAN_CASE_ALL_STRING_KEY3", "GP8_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP8_SCAN_CASE_ALL_HASH_KEY1", "GP8_SCAN_CASE_ALL_HASH_FIELD1", "GP8_SCAN_CASE_ALL_HASH_VALUE1", @@ -3094,33 +3096,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP8_SCAN_CASE_ALL_HASH_KEY3", "GP8_SCAN_CASE_ALL_HASH_FIELD3", "GP8_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP8_SCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP8_SCAN_CASE_ALL_SET_KEY1", {"GP8_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP8_SCAN_CASE_ALL_SET_KEY2", {"GP8_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP8_SCAN_CASE_ALL_SET_KEY3", {"GP8_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP8_SCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP8_SCAN_CASE_ALL_LIST_KEY1", {"GP8_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP8_SCAN_CASE_ALL_LIST_KEY2", {"GP8_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP8_SCAN_CASE_ALL_LIST_KEY3", {"GP8_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP8_SCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP8_SCAN_CASE_ALL_ZSET_KEY1", {{1, "GP8_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP8_SCAN_CASE_ALL_ZSET_KEY2", {{1, "GP8_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP8_SCAN_CASE_ALL_ZSET_KEY3", {{1, "GP8_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP8_SCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP8_SCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP8_SCAN_CASE_ALL_ZSET_KEY3"); cursor = 0; keys.clear(); @@ -3129,7 +3131,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "*KEY3", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP8_SCAN_CASE_ALL_STRING_KEY3"); ASSERT_EQ(total_keys[1], "GP8_SCAN_CASE_ALL_HASH_KEY3"); @@ -3148,9 +3150,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP9_SCAN_CASE_ALL_STRING_KEY1", "GP9_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP9_SCAN_CASE_ALL_STRING_KEY2", "GP9_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP9_SCAN_CASE_ALL_STRING_KEY3", "GP9_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP9_SCAN_CASE_ALL_HASH_KEY1", "GP9_SCAN_CASE_ALL_HASH_FIELD1", "GP9_SCAN_CASE_ALL_HASH_VALUE1", @@ -3159,33 +3161,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP9_SCAN_CASE_ALL_HASH_KEY3", "GP9_SCAN_CASE_ALL_HASH_FIELD3", "GP9_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP9_SCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP9_SCAN_CASE_ALL_SET_KEY1", {"GP9_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP9_SCAN_CASE_ALL_SET_KEY2", {"GP9_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP9_SCAN_CASE_ALL_SET_KEY3", {"GP9_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP9_SCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP9_SCAN_CASE_ALL_LIST_KEY1", {"GP9_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP9_SCAN_CASE_ALL_LIST_KEY2", {"GP9_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP9_SCAN_CASE_ALL_LIST_KEY3", {"GP9_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP9_SCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP9_SCAN_CASE_ALL_ZSET_KEY1", {{1, "GP9_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP9_SCAN_CASE_ALL_ZSET_KEY2", {{1, "GP9_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP9_SCAN_CASE_ALL_ZSET_KEY3", {{1, "GP9_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP9_SCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP9_SCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP9_SCAN_CASE_ALL_ZSET_KEY3"); cursor = 0; keys.clear(); @@ -3194,7 +3196,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "GP9*", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 15); ASSERT_EQ(total_keys[0], "GP9_SCAN_CASE_ALL_STRING_KEY1"); ASSERT_EQ(total_keys[1], "GP9_SCAN_CASE_ALL_STRING_KEY2"); @@ -3223,9 +3225,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP10_SCAN_CASE_ALL_STRING_KEY1", "GP10_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP10_SCAN_CASE_ALL_STRING_KEY2", "GP10_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP10_SCAN_CASE_ALL_STRING_KEY3", "GP10_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP10_SCAN_CASE_ALL_HASH_KEY1", "GP10_SCAN_CASE_ALL_HASH_FIELD1", "GP10_SCAN_CASE_ALL_HASH_VALUE1", @@ -3234,33 +3236,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP10_SCAN_CASE_ALL_HASH_KEY3", "GP10_SCAN_CASE_ALL_HASH_FIELD3", "GP10_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP10_SCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP10_SCAN_CASE_ALL_SET_KEY1", {"GP10_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP10_SCAN_CASE_ALL_SET_KEY2", {"GP10_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP10_SCAN_CASE_ALL_SET_KEY3", {"GP10_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP10_SCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP10_SCAN_CASE_ALL_LIST_KEY1", {"GP10_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP10_SCAN_CASE_ALL_LIST_KEY2", {"GP10_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP10_SCAN_CASE_ALL_LIST_KEY3", {"GP10_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP10_SCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP10_SCAN_CASE_ALL_ZSET_KEY1", {{1, "GP10_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP10_SCAN_CASE_ALL_ZSET_KEY2", {{1, "GP10_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP10_SCAN_CASE_ALL_ZSET_KEY3", {{1, "GP10_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP10_SCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP10_SCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP10_SCAN_CASE_ALL_ZSET_KEY3"); cursor = 0; keys.clear(); @@ -3269,7 +3271,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "GP10_SCAN_CASE_ALL_STRING_*", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 3); ASSERT_EQ(total_keys[0], "GP10_SCAN_CASE_ALL_STRING_KEY1"); ASSERT_EQ(total_keys[1], "GP10_SCAN_CASE_ALL_STRING_KEY2"); @@ -3286,9 +3288,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP11_SCAN_CASE_ALL_STRING_KEY1", "GP11_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP11_SCAN_CASE_ALL_STRING_KEY2", "GP11_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP11_SCAN_CASE_ALL_STRING_KEY3", "GP11_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP11_SCAN_CASE_ALL_HASH_KEY1", "GP11_SCAN_CASE_ALL_HASH_FIELD1", "GP11_SCAN_CASE_ALL_HASH_VALUE1", @@ -3297,33 +3299,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP11_SCAN_CASE_ALL_HASH_KEY3", "GP11_SCAN_CASE_ALL_HASH_FIELD3", "GP11_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP11_SCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP11_SCAN_CASE_ALL_SET_KEY1", {"GP11_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP11_SCAN_CASE_ALL_SET_KEY2", {"GP11_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP11_SCAN_CASE_ALL_SET_KEY3", {"GP11_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP11_SCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP11_SCAN_CASE_ALL_LIST_KEY1", {"GP11_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP11_SCAN_CASE_ALL_LIST_KEY2", {"GP11_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP11_SCAN_CASE_ALL_LIST_KEY3", {"GP11_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP11_SCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP11_SCAN_CASE_ALL_ZSET_KEY1", {{1, "GP11_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP11_SCAN_CASE_ALL_ZSET_KEY2", {{1, "GP11_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP11_SCAN_CASE_ALL_ZSET_KEY3", {{1, "GP11_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP11_SCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP11_SCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP11_SCAN_CASE_ALL_ZSET_KEY3"); cursor = 0; keys.clear(); @@ -3332,7 +3334,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "GP11_SCAN_CASE_ALL_SET_*", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 3); ASSERT_EQ(total_keys[0], "GP11_SCAN_CASE_ALL_SET_KEY1"); ASSERT_EQ(total_keys[1], "GP11_SCAN_CASE_ALL_SET_KEY2"); @@ -3349,9 +3351,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP12_SCAN_CASE_ALL_STRING_KEY1", "GP12_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP12_SCAN_CASE_ALL_STRING_KEY2", "GP12_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP12_SCAN_CASE_ALL_STRING_KEY3", "GP12_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP12_SCAN_CASE_ALL_HASH_KEY1", "GP12_SCAN_CASE_ALL_HASH_FIELD1", "GP12_SCAN_CASE_ALL_HASH_VALUE1", @@ -3360,33 +3362,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP12_SCAN_CASE_ALL_HASH_KEY3", "GP12_SCAN_CASE_ALL_HASH_FIELD3", "GP12_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP12_SCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP12_SCAN_CASE_ALL_SET_KEY1", {"GP12_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP12_SCAN_CASE_ALL_SET_KEY2", {"GP12_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP12_SCAN_CASE_ALL_SET_KEY3", {"GP12_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP12_SCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP12_SCAN_CASE_ALL_LIST_KEY1", {"GP12_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP12_SCAN_CASE_ALL_LIST_KEY2", {"GP12_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP12_SCAN_CASE_ALL_LIST_KEY3", {"GP12_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP12_SCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP12_SCAN_CASE_ALL_ZSET_KEY1", {{1, "GP12_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP12_SCAN_CASE_ALL_ZSET_KEY2", {{1, "GP12_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP12_SCAN_CASE_ALL_ZSET_KEY3", {{1, "GP12_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP12_SCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP12_SCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP12_SCAN_CASE_ALL_ZSET_KEY3"); cursor = 0; keys.clear(); @@ -3395,7 +3397,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "GP12_SCAN_CASE_ALL_ZSET_*", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 3); ASSERT_EQ(total_keys[0], "GP12_SCAN_CASE_ALL_ZSET_KEY1"); ASSERT_EQ(total_keys[1], "GP12_SCAN_CASE_ALL_ZSET_KEY2"); @@ -3412,9 +3414,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP13_KEY1_SCAN_CASE_ALL_STRING", "GP13_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP13_KEY2_SCAN_CASE_ALL_STRING", "GP13_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP13_KEY3_SCAN_CASE_ALL_STRING", "GP13_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP13_KEY1_SCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP13_KEY2_SCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP13_KEY3_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP13_KEY1_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP13_KEY2_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP13_KEY3_SCAN_CASE_ALL_STRING"); // Hash s = db.HSet("GP13_KEY1_SCAN_CASE_ALL_HASH", "GP13_SCAN_CASE_ALL_HASH_FIELD1", "GP13_SCAN_CASE_ALL_HASH_VALUE1", @@ -3423,33 +3425,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP13_KEY3_SCAN_CASE_ALL_HASH", "GP13_SCAN_CASE_ALL_HASH_FIELD3", "GP13_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP13_KEY1_SCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP13_KEY2_SCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP13_KEY3_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP13_KEY1_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP13_KEY2_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP13_KEY3_SCAN_CASE_ALL_HASH"); // Set s = db.SAdd("GP13_KEY1_SCAN_CASE_ALL_SET", {"GP13_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP13_KEY2_SCAN_CASE_ALL_SET", {"GP13_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP13_KEY3_SCAN_CASE_ALL_SET", {"GP13_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP13_KEY1_SCAN_CASE_ALL_SET"); - delete_keys.push_back("GP13_KEY2_SCAN_CASE_ALL_SET"); - delete_keys.push_back("GP13_KEY3_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP13_KEY1_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP13_KEY2_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP13_KEY3_SCAN_CASE_ALL_SET"); // List s = db.LPush("GP13_KEY1_SCAN_CASE_ALL_LIST", {"GP13_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP13_KEY2_SCAN_CASE_ALL_LIST", {"GP13_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP13_KEY3_SCAN_CASE_ALL_LIST", {"GP13_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP13_KEY1_SCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP13_KEY2_SCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP13_KEY3_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP13_KEY1_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP13_KEY2_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP13_KEY3_SCAN_CASE_ALL_LIST"); // ZSet s = db.ZAdd("GP13_KEY1_SCAN_CASE_ALL_ZSET", {{1, "GP13_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP13_KEY2_SCAN_CASE_ALL_ZSET", {{1, "GP13_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP13_KEY3_SCAN_CASE_ALL_ZSET", {{1, "GP13_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP13_KEY1_SCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP13_KEY2_SCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP13_KEY3_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP13_KEY1_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP13_KEY2_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP13_KEY3_SCAN_CASE_ALL_ZSET"); cursor = 0; keys.clear(); @@ -3458,7 +3460,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "GP13_KEY1_SCAN_CASE_ALL_*", 1, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP13_KEY1_SCAN_CASE_ALL_STRING"); ASSERT_EQ(total_keys[1], "GP13_KEY1_SCAN_CASE_ALL_HASH"); @@ -3477,9 +3479,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP14_KEY1_SCAN_CASE_ALL_STRING", "GP14_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP14_KEY2_SCAN_CASE_ALL_STRING", "GP14_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP14_KEY3_SCAN_CASE_ALL_STRING", "GP14_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP14_KEY1_SCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP14_KEY2_SCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP14_KEY3_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP14_KEY1_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP14_KEY2_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP14_KEY3_SCAN_CASE_ALL_STRING"); // Hash s = db.HSet("GP14_KEY1_SCAN_CASE_ALL_HASH", "GP14_SCAN_CASE_ALL_HASH_FIELD1", "GP14_SCAN_CASE_ALL_HASH_VALUE1", @@ -3488,33 +3490,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP14_KEY3_SCAN_CASE_ALL_HASH", "GP14_SCAN_CASE_ALL_HASH_FIELD3", "GP14_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP14_KEY1_SCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP14_KEY2_SCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP14_KEY3_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP14_KEY1_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP14_KEY2_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP14_KEY3_SCAN_CASE_ALL_HASH"); // Set s = db.SAdd("GP14_KEY1_SCAN_CASE_ALL_SET", {"GP14_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP14_KEY2_SCAN_CASE_ALL_SET", {"GP14_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP14_KEY3_SCAN_CASE_ALL_SET", {"GP14_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP14_KEY1_SCAN_CASE_ALL_SET"); - delete_keys.push_back("GP14_KEY2_SCAN_CASE_ALL_SET"); - delete_keys.push_back("GP14_KEY3_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP14_KEY1_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP14_KEY2_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP14_KEY3_SCAN_CASE_ALL_SET"); // List s = db.LPush("GP14_KEY1_SCAN_CASE_ALL_LIST", {"GP14_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP14_KEY2_SCAN_CASE_ALL_LIST", {"GP14_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP14_KEY3_SCAN_CASE_ALL_LIST", {"GP14_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP14_KEY1_SCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP14_KEY2_SCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP14_KEY3_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP14_KEY1_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP14_KEY2_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP14_KEY3_SCAN_CASE_ALL_LIST"); // ZSet s = db.ZAdd("GP14_KEY1_SCAN_CASE_ALL_ZSET", {{1, "GP14_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP14_KEY2_SCAN_CASE_ALL_ZSET", {{1, "GP14_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP14_KEY3_SCAN_CASE_ALL_ZSET", {{1, "GP14_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP14_KEY1_SCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP14_KEY2_SCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP14_KEY3_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP14_KEY1_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP14_KEY2_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP14_KEY3_SCAN_CASE_ALL_ZSET"); cursor = 0; keys.clear(); @@ -3523,7 +3525,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "GP14_KEY1_SCAN_CASE_ALL_*", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP14_KEY1_SCAN_CASE_ALL_STRING"); ASSERT_EQ(total_keys[1], "GP14_KEY1_SCAN_CASE_ALL_HASH"); @@ -3542,9 +3544,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP15_KEY1_SCAN_CASE_ALL_STRING", "GP15_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP15_KEY2_SCAN_CASE_ALL_STRING", "GP15_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP15_KEY3_SCAN_CASE_ALL_STRING", "GP15_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP15_KEY1_SCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP15_KEY2_SCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP15_KEY3_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP15_KEY1_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP15_KEY2_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP15_KEY3_SCAN_CASE_ALL_STRING"); // Hash s = db.HSet("GP15_KEY1_SCAN_CASE_ALL_HASH", "GP15_SCAN_CASE_ALL_HASH_FIELD1", "GP15_SCAN_CASE_ALL_HASH_VALUE1", @@ -3553,33 +3555,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP15_KEY3_SCAN_CASE_ALL_HASH", "GP15_SCAN_CASE_ALL_HASH_FIELD3", "GP15_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP15_KEY1_SCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP15_KEY2_SCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP15_KEY3_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP15_KEY1_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP15_KEY2_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP15_KEY3_SCAN_CASE_ALL_HASH"); // Set s = db.SAdd("GP15_KEY1_SCAN_CASE_ALL_SET", {"GP15_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP15_KEY2_SCAN_CASE_ALL_SET", {"GP15_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP15_KEY3_SCAN_CASE_ALL_SET", {"GP15_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP15_KEY1_SCAN_CASE_ALL_SET"); - delete_keys.push_back("GP15_KEY2_SCAN_CASE_ALL_SET"); - delete_keys.push_back("GP15_KEY3_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP15_KEY1_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP15_KEY2_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP15_KEY3_SCAN_CASE_ALL_SET"); // List s = db.LPush("GP15_KEY1_SCAN_CASE_ALL_LIST", {"GP15_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP15_KEY2_SCAN_CASE_ALL_LIST", {"GP15_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP15_KEY3_SCAN_CASE_ALL_LIST", {"GP15_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP15_KEY1_SCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP15_KEY2_SCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP15_KEY3_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP15_KEY1_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP15_KEY2_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP15_KEY3_SCAN_CASE_ALL_LIST"); // ZSet s = db.ZAdd("GP15_KEY1_SCAN_CASE_ALL_ZSET", {{1, "GP15_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP15_KEY2_SCAN_CASE_ALL_ZSET", {{1, "GP15_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP15_KEY3_SCAN_CASE_ALL_ZSET", {{1, "GP15_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP15_KEY1_SCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP15_KEY2_SCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP15_KEY3_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP15_KEY1_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP15_KEY2_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP15_KEY3_SCAN_CASE_ALL_ZSET"); cursor = 0; keys.clear(); @@ -3588,7 +3590,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "GP15_KEY2_SCAN_CASE_ALL_*", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP15_KEY2_SCAN_CASE_ALL_STRING"); ASSERT_EQ(total_keys[1], "GP15_KEY2_SCAN_CASE_ALL_HASH"); @@ -3607,9 +3609,9 @@ TEST_F(KeysTest, ScanCaseAllTest) { s = db.Set("GP16_KEY1_SCAN_CASE_ALL_STRING", "GP16_SCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP16_KEY2_SCAN_CASE_ALL_STRING", "GP16_SCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP16_KEY3_SCAN_CASE_ALL_STRING", "GP16_SCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP16_KEY1_SCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP16_KEY2_SCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP16_KEY3_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP16_KEY1_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP16_KEY2_SCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP16_KEY3_SCAN_CASE_ALL_STRING"); // Hash s = db.HSet("GP16_KEY1_SCAN_CASE_ALL_HASH", "GP16_SCAN_CASE_ALL_HASH_FIELD1", "GP16_SCAN_CASE_ALL_HASH_VALUE1", @@ -3618,33 +3620,33 @@ TEST_F(KeysTest, ScanCaseAllTest) { &int32_ret); s = db.HSet("GP16_KEY3_SCAN_CASE_ALL_HASH", "GP16_SCAN_CASE_ALL_HASH_FIELD3", "GP16_SCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP16_KEY1_SCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP16_KEY2_SCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP16_KEY3_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP16_KEY1_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP16_KEY2_SCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP16_KEY3_SCAN_CASE_ALL_HASH"); // Set s = db.SAdd("GP16_KEY1_SCAN_CASE_ALL_SET", {"GP16_SCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP16_KEY2_SCAN_CASE_ALL_SET", {"GP16_SCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP16_KEY3_SCAN_CASE_ALL_SET", {"GP16_SCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP16_KEY1_SCAN_CASE_ALL_SET"); - delete_keys.push_back("GP16_KEY2_SCAN_CASE_ALL_SET"); - delete_keys.push_back("GP16_KEY3_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP16_KEY1_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP16_KEY2_SCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP16_KEY3_SCAN_CASE_ALL_SET"); // List s = db.LPush("GP16_KEY1_SCAN_CASE_ALL_LIST", {"GP16_SCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP16_KEY2_SCAN_CASE_ALL_LIST", {"GP16_SCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP16_KEY3_SCAN_CASE_ALL_LIST", {"GP16_SCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP16_KEY1_SCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP16_KEY2_SCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP16_KEY3_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP16_KEY1_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP16_KEY2_SCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP16_KEY3_SCAN_CASE_ALL_LIST"); // ZSet s = db.ZAdd("GP16_KEY1_SCAN_CASE_ALL_ZSET", {{1, "GP16_SCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP16_KEY2_SCAN_CASE_ALL_ZSET", {{1, "GP16_SCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP16_KEY3_SCAN_CASE_ALL_ZSET", {{1, "GP16_SCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP16_KEY1_SCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP16_KEY2_SCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP16_KEY3_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP16_KEY1_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP16_KEY2_SCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP16_KEY3_SCAN_CASE_ALL_ZSET"); cursor = 0; keys.clear(); @@ -3653,7 +3655,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { next_cursor = db.Scan(DataType::kAll, cursor, "GP16_KEY3_SCAN_CASE_ALL_*", 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP16_KEY3_SCAN_CASE_ALL_STRING"); ASSERT_EQ(total_keys[1], "GP16_KEY3_SCAN_CASE_ALL_HASH"); @@ -3670,7 +3672,7 @@ TEST_F(KeysTest, ScanCaseAllTest) { // Scan // Note: This test needs to execute at first because all of the data is // predetermined. -TEST_F(KeysTest, ScanCaseSingleTest) { +TEST_F(KeysTest, ScanCaseSingleTest) { // NOLINT int64_t cursor; int64_t next_cursor; int64_t del_num; @@ -3690,12 +3692,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP1_KEY4_SCAN_CASE_SINGLE_STRING", "GP1_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP1_KEY5_SCAN_CASE_SINGLE_STRING", "GP1_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP1_KEY6_SCAN_CASE_SINGLE_STRING", "GP1_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP1_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP1_KEY1_SCAN_CASE_SINGLE_HASH", "GP1_SCAN_CASE_SINGLE_HASH_FIELD1", "GP1_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -3710,12 +3712,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP1_KEY6_SCAN_CASE_SINGLE_HASH", "GP1_SCAN_CASE_SINGLE_HASH_FIELD6", "GP1_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP1_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP1_KEY1_SCAN_CASE_SINGLE_SET", {"GP1_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -3724,12 +3726,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP1_KEY4_SCAN_CASE_SINGLE_SET", {"GP1_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP1_KEY5_SCAN_CASE_SINGLE_SET", {"GP1_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP1_KEY6_SCAN_CASE_SINGLE_SET", {"GP1_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP1_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP1_KEY1_SCAN_CASE_SINGLE_LIST", {"GP1_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -3738,12 +3740,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP1_KEY4_SCAN_CASE_SINGLE_LIST", {"GP1_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP1_KEY5_SCAN_CASE_SINGLE_LIST", {"GP1_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP1_KEY6_SCAN_CASE_SINGLE_LIST", {"GP1_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP1_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP1_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP1_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -3752,12 +3754,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP1_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP1_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP1_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP1_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP1_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP1_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP1_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -3795,12 +3797,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP2_KEY4_SCAN_CASE_SINGLE_STRING", "GP2_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP2_KEY5_SCAN_CASE_SINGLE_STRING", "GP2_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP2_KEY6_SCAN_CASE_SINGLE_STRING", "GP2_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP2_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP2_KEY1_SCAN_CASE_SINGLE_HASH", "GP2_SCAN_CASE_SINGLE_HASH_FIELD1", "GP2_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -3815,12 +3817,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP2_KEY6_SCAN_CASE_SINGLE_HASH", "GP2_SCAN_CASE_SINGLE_HASH_FIELD6", "GP2_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP2_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP2_KEY1_SCAN_CASE_SINGLE_SET", {"GP2_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -3829,12 +3831,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP2_KEY4_SCAN_CASE_SINGLE_SET", {"GP2_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP2_KEY5_SCAN_CASE_SINGLE_SET", {"GP2_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP2_KEY6_SCAN_CASE_SINGLE_SET", {"GP2_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP2_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP2_KEY1_SCAN_CASE_SINGLE_LIST", {"GP2_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -3843,12 +3845,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP2_KEY4_SCAN_CASE_SINGLE_LIST", {"GP2_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP2_KEY5_SCAN_CASE_SINGLE_LIST", {"GP2_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP2_KEY6_SCAN_CASE_SINGLE_LIST", {"GP2_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP2_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP2_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP2_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -3857,12 +3859,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP2_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP2_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP2_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP2_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP2_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP2_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP2_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -3895,12 +3897,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP3_KEY4_SCAN_CASE_SINGLE_STRING", "GP3_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP3_KEY5_SCAN_CASE_SINGLE_STRING", "GP3_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP3_KEY6_SCAN_CASE_SINGLE_STRING", "GP3_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP3_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP3_KEY1_SCAN_CASE_SINGLE_HASH", "GP3_SCAN_CASE_SINGLE_HASH_FIELD1", "GP3_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -3915,12 +3917,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP3_KEY6_SCAN_CASE_SINGLE_HASH", "GP3_SCAN_CASE_SINGLE_HASH_FIELD6", "GP3_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP3_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP3_KEY1_SCAN_CASE_SINGLE_SET", {"GP3_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -3929,12 +3931,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP3_KEY4_SCAN_CASE_SINGLE_SET", {"GP3_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP3_KEY5_SCAN_CASE_SINGLE_SET", {"GP3_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP3_KEY6_SCAN_CASE_SINGLE_SET", {"GP3_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP3_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP3_KEY1_SCAN_CASE_SINGLE_LIST", {"GP3_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -3943,12 +3945,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP3_KEY4_SCAN_CASE_SINGLE_LIST", {"GP3_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP3_KEY5_SCAN_CASE_SINGLE_LIST", {"GP3_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP3_KEY6_SCAN_CASE_SINGLE_LIST", {"GP3_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP3_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP3_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP3_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -3957,12 +3959,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP3_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP3_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP3_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP3_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP3_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP3_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP3_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -3990,12 +3992,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP4_KEY4_SCAN_CASE_SINGLE_STRING", "GP4_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP4_KEY5_SCAN_CASE_SINGLE_STRING", "GP4_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP4_KEY6_SCAN_CASE_SINGLE_STRING", "GP4_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP4_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP4_KEY1_SCAN_CASE_SINGLE_HASH", "GP4_SCAN_CASE_SINGLE_HASH_FIELD1", "GP4_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -4010,12 +4012,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP4_KEY6_SCAN_CASE_SINGLE_HASH", "GP4_SCAN_CASE_SINGLE_HASH_FIELD6", "GP4_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP4_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP4_KEY1_SCAN_CASE_SINGLE_SET", {"GP4_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4024,12 +4026,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP4_KEY4_SCAN_CASE_SINGLE_SET", {"GP4_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP4_KEY5_SCAN_CASE_SINGLE_SET", {"GP4_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP4_KEY6_SCAN_CASE_SINGLE_SET", {"GP4_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP4_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP4_KEY1_SCAN_CASE_SINGLE_LIST", {"GP4_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4038,12 +4040,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP4_KEY4_SCAN_CASE_SINGLE_LIST", {"GP4_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP4_KEY5_SCAN_CASE_SINGLE_LIST", {"GP4_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP4_KEY6_SCAN_CASE_SINGLE_LIST", {"GP4_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP4_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP4_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP4_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4052,12 +4054,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP4_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP4_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP4_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP4_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP4_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP4_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP4_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4085,12 +4087,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP5_KEY4_SCAN_CASE_SINGLE_STRING", "GP5_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP5_KEY5_SCAN_CASE_SINGLE_STRING", "GP5_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP5_KEY6_SCAN_CASE_SINGLE_STRING", "GP5_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP5_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP5_KEY1_SCAN_CASE_SINGLE_HASH", "GP5_SCAN_CASE_SINGLE_HASH_FIELD1", "GP5_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -4105,12 +4107,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP5_KEY6_SCAN_CASE_SINGLE_HASH", "GP5_SCAN_CASE_SINGLE_HASH_FIELD6", "GP5_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP5_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP5_KEY1_SCAN_CASE_SINGLE_SET", {"GP5_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4119,12 +4121,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP5_KEY4_SCAN_CASE_SINGLE_SET", {"GP5_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP5_KEY5_SCAN_CASE_SINGLE_SET", {"GP5_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP5_KEY6_SCAN_CASE_SINGLE_SET", {"GP5_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP5_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP5_KEY1_SCAN_CASE_SINGLE_LIST", {"GP5_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4133,12 +4135,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP5_KEY4_SCAN_CASE_SINGLE_LIST", {"GP5_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP5_KEY5_SCAN_CASE_SINGLE_LIST", {"GP5_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP5_KEY6_SCAN_CASE_SINGLE_LIST", {"GP5_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP5_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP5_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP5_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4147,12 +4149,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP5_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP5_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP5_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP5_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP5_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP5_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP5_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4190,12 +4192,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP6_KEY4_SCAN_CASE_SINGLE_STRING", "GP6_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP6_KEY5_SCAN_CASE_SINGLE_STRING", "GP6_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP6_KEY6_SCAN_CASE_SINGLE_STRING", "GP6_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP6_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP6_KEY1_SCAN_CASE_SINGLE_HASH", "GP6_SCAN_CASE_SINGLE_HASH_FIELD1", "GP6_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -4210,12 +4212,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP6_KEY6_SCAN_CASE_SINGLE_HASH", "GP6_SCAN_CASE_SINGLE_HASH_FIELD6", "GP6_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP6_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP6_KEY1_SCAN_CASE_SINGLE_SET", {"GP6_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4224,12 +4226,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP6_KEY4_SCAN_CASE_SINGLE_SET", {"GP6_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP6_KEY5_SCAN_CASE_SINGLE_SET", {"GP6_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP6_KEY6_SCAN_CASE_SINGLE_SET", {"GP6_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP6_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP6_KEY1_SCAN_CASE_SINGLE_LIST", {"GP6_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4238,12 +4240,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP6_KEY4_SCAN_CASE_SINGLE_LIST", {"GP6_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP6_KEY5_SCAN_CASE_SINGLE_LIST", {"GP6_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP6_KEY6_SCAN_CASE_SINGLE_LIST", {"GP6_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP6_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP6_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP6_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4252,12 +4254,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP6_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP6_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP6_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP6_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP6_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP6_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP6_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4290,12 +4292,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP7_KEY4_SCAN_CASE_SINGLE_STRING", "GP7_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP7_KEY5_SCAN_CASE_SINGLE_STRING", "GP7_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP7_KEY6_SCAN_CASE_SINGLE_STRING", "GP7_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP7_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP7_KEY1_SCAN_CASE_SINGLE_HASH", "GP7_SCAN_CASE_SINGLE_HASH_FIELD1", "GP7_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -4310,12 +4312,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP7_KEY6_SCAN_CASE_SINGLE_HASH", "GP7_SCAN_CASE_SINGLE_HASH_FIELD6", "GP7_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP7_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP7_KEY1_SCAN_CASE_SINGLE_SET", {"GP7_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4324,12 +4326,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP7_KEY4_SCAN_CASE_SINGLE_SET", {"GP7_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP7_KEY5_SCAN_CASE_SINGLE_SET", {"GP7_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP7_KEY6_SCAN_CASE_SINGLE_SET", {"GP7_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP7_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP7_KEY1_SCAN_CASE_SINGLE_LIST", {"GP7_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4338,12 +4340,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP7_KEY4_SCAN_CASE_SINGLE_LIST", {"GP7_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP7_KEY5_SCAN_CASE_SINGLE_LIST", {"GP7_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP7_KEY6_SCAN_CASE_SINGLE_LIST", {"GP7_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP7_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP7_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP7_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4352,12 +4354,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP7_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP7_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP7_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP7_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP7_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP7_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP7_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4385,12 +4387,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP8_KEY4_SCAN_CASE_SINGLE_STRING", "GP8_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP8_KEY5_SCAN_CASE_SINGLE_STRING", "GP8_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP8_KEY6_SCAN_CASE_SINGLE_STRING", "GP8_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP8_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP8_KEY1_SCAN_CASE_SINGLE_HASH", "GP8_SCAN_CASE_SINGLE_HASH_FIELD1", "GP8_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -4405,12 +4407,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP8_KEY6_SCAN_CASE_SINGLE_HASH", "GP8_SCAN_CASE_SINGLE_HASH_FIELD6", "GP8_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP8_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP8_KEY1_SCAN_CASE_SINGLE_SET", {"GP8_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4419,12 +4421,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP8_KEY4_SCAN_CASE_SINGLE_SET", {"GP8_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP8_KEY5_SCAN_CASE_SINGLE_SET", {"GP8_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP8_KEY6_SCAN_CASE_SINGLE_SET", {"GP8_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP8_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP8_KEY1_SCAN_CASE_SINGLE_LIST", {"GP8_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4433,12 +4435,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP8_KEY4_SCAN_CASE_SINGLE_LIST", {"GP8_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP8_KEY5_SCAN_CASE_SINGLE_LIST", {"GP8_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP8_KEY6_SCAN_CASE_SINGLE_LIST", {"GP8_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP8_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP8_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP8_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4447,12 +4449,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP8_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP8_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP8_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP8_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP8_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP8_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP8_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4480,12 +4482,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP9_KEY4_SCAN_CASE_SINGLE_STRING", "GP9_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP9_KEY5_SCAN_CASE_SINGLE_STRING", "GP9_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP9_KEY6_SCAN_CASE_SINGLE_STRING", "GP9_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP9_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP9_KEY1_SCAN_CASE_SINGLE_HASH", "GP9_SCAN_CASE_SINGLE_HASH_FIELD1", "GP9_SCAN_CASE_SINGLE_HASH_VALUE1", @@ -4500,12 +4502,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { &int32_ret); s = db.HSet("GP9_KEY6_SCAN_CASE_SINGLE_HASH", "GP9_SCAN_CASE_SINGLE_HASH_FIELD6", "GP9_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP9_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP9_KEY1_SCAN_CASE_SINGLE_SET", {"GP9_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4514,12 +4516,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP9_KEY4_SCAN_CASE_SINGLE_SET", {"GP9_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP9_KEY5_SCAN_CASE_SINGLE_SET", {"GP9_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP9_KEY6_SCAN_CASE_SINGLE_SET", {"GP9_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP9_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP9_KEY1_SCAN_CASE_SINGLE_LIST", {"GP9_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4528,12 +4530,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP9_KEY4_SCAN_CASE_SINGLE_LIST", {"GP9_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP9_KEY5_SCAN_CASE_SINGLE_LIST", {"GP9_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP9_KEY6_SCAN_CASE_SINGLE_LIST", {"GP9_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP9_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP9_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP9_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4542,12 +4544,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP9_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP9_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP9_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP9_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP9_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP9_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP9_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4585,12 +4587,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP10_KEY4_SCAN_CASE_SINGLE_STRING", "GP10_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP10_KEY5_SCAN_CASE_SINGLE_STRING", "GP10_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP10_KEY6_SCAN_CASE_SINGLE_STRING", "GP10_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP10_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP10_KEY1_SCAN_CASE_SINGLE_HASH", "GP10_SCAN_CASE_SINGLE_HASH_FIELD1", @@ -4605,12 +4607,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { "GP10_SCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP10_KEY6_SCAN_CASE_SINGLE_HASH", "GP10_SCAN_CASE_SINGLE_HASH_FIELD6", "GP10_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP10_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP10_KEY1_SCAN_CASE_SINGLE_SET", {"GP10_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4619,12 +4621,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP10_KEY4_SCAN_CASE_SINGLE_SET", {"GP10_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP10_KEY5_SCAN_CASE_SINGLE_SET", {"GP10_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP10_KEY6_SCAN_CASE_SINGLE_SET", {"GP10_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP10_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP10_KEY1_SCAN_CASE_SINGLE_LIST", {"GP10_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4633,12 +4635,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP10_KEY4_SCAN_CASE_SINGLE_LIST", {"GP10_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP10_KEY5_SCAN_CASE_SINGLE_LIST", {"GP10_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP10_KEY6_SCAN_CASE_SINGLE_LIST", {"GP10_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP10_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP10_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP10_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4647,12 +4649,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP10_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP10_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP10_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP10_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP10_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP10_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP10_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4685,12 +4687,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP11_KEY4_SCAN_CASE_SINGLE_STRING", "GP11_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP11_KEY5_SCAN_CASE_SINGLE_STRING", "GP11_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP11_KEY6_SCAN_CASE_SINGLE_STRING", "GP11_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP11_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP11_KEY1_SCAN_CASE_SINGLE_HASH", "GP11_SCAN_CASE_SINGLE_HASH_FIELD1", @@ -4705,12 +4707,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { "GP11_SCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP11_KEY6_SCAN_CASE_SINGLE_HASH", "GP11_SCAN_CASE_SINGLE_HASH_FIELD6", "GP11_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP11_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP11_KEY1_SCAN_CASE_SINGLE_SET", {"GP11_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4719,12 +4721,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP11_KEY4_SCAN_CASE_SINGLE_SET", {"GP11_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP11_KEY5_SCAN_CASE_SINGLE_SET", {"GP11_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP11_KEY6_SCAN_CASE_SINGLE_SET", {"GP11_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP11_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP11_KEY1_SCAN_CASE_SINGLE_LIST", {"GP11_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4733,12 +4735,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP11_KEY4_SCAN_CASE_SINGLE_LIST", {"GP11_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP11_KEY5_SCAN_CASE_SINGLE_LIST", {"GP11_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP11_KEY6_SCAN_CASE_SINGLE_LIST", {"GP11_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP11_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP11_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP11_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4747,12 +4749,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP11_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP11_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP11_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP11_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP11_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP11_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP11_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4780,12 +4782,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.Set("GP12_KEY4_SCAN_CASE_SINGLE_STRING", "GP12_SCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP12_KEY5_SCAN_CASE_SINGLE_STRING", "GP12_SCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP12_KEY6_SCAN_CASE_SINGLE_STRING", "GP12_SCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP12_KEY1_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY2_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY3_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY4_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY5_SCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY6_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY1_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY2_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY3_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY4_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY5_SCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY6_SCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP12_KEY1_SCAN_CASE_SINGLE_HASH", "GP12_SCAN_CASE_SINGLE_HASH_FIELD1", @@ -4800,12 +4802,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { "GP12_SCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP12_KEY6_SCAN_CASE_SINGLE_HASH", "GP12_SCAN_CASE_SINGLE_HASH_FIELD6", "GP12_SCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP12_KEY1_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY2_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY3_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY4_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY5_SCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY6_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY1_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY2_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY3_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY4_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY5_SCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY6_SCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP12_KEY1_SCAN_CASE_SINGLE_SET", {"GP12_SCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -4814,12 +4816,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.SAdd("GP12_KEY4_SCAN_CASE_SINGLE_SET", {"GP12_SCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP12_KEY5_SCAN_CASE_SINGLE_SET", {"GP12_SCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP12_KEY6_SCAN_CASE_SINGLE_SET", {"GP12_SCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP12_KEY1_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY2_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY3_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY4_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY5_SCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY6_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY1_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY2_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY3_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY4_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY5_SCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY6_SCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP12_KEY1_SCAN_CASE_SINGLE_LIST", {"GP12_SCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -4828,12 +4830,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.LPush("GP12_KEY4_SCAN_CASE_SINGLE_LIST", {"GP12_SCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP12_KEY5_SCAN_CASE_SINGLE_LIST", {"GP12_SCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP12_KEY6_SCAN_CASE_SINGLE_LIST", {"GP12_SCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP12_KEY1_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY2_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY3_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY4_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY5_SCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY6_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY1_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY2_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY3_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY4_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY5_SCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY6_SCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP12_KEY1_SCAN_CASE_SINGLE_ZSET", {{1, "GP12_SCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -4842,12 +4844,12 @@ TEST_F(KeysTest, ScanCaseSingleTest) { s = db.ZAdd("GP12_KEY4_SCAN_CASE_SINGLE_ZSET", {{1, "GP12_SCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP12_KEY5_SCAN_CASE_SINGLE_ZSET", {{1, "GP12_SCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP12_KEY6_SCAN_CASE_SINGLE_ZSET", {{1, "GP12_SCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP12_KEY1_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY2_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY3_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY4_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY5_SCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY6_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY1_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY2_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY3_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY4_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY5_SCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY6_SCAN_CASE_SINGLE_ZSET"); keys.clear(); cursor = 0; @@ -4867,7 +4869,7 @@ TEST_F(KeysTest, ScanCaseSingleTest) { db.Compact(DataType::kAll, true); } -TEST_F(KeysTest, PKExpireScanCaseAllTest) { +TEST_F(KeysTest, PKExpireScanCaseAllTest) { // NOLINT int64_t cursor; int64_t next_cursor; int64_t del_num; @@ -5269,9 +5271,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", "GP5_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", "GP5_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY3", "GP5_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP5_PKEXPIRESCAN_CASE_ALL_HASH_KEY1", "GP5_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5280,33 +5282,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP5_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP5_PKEXPIRESCAN_CASE_ALL_HASH_KEY3", "GP5_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP5_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY1", {"GP5_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY2", {"GP5_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY3", {"GP5_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY1", {"GP5_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY2", {"GP5_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY3", {"GP5_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1", {{1, "GP5_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2", {{1, "GP5_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3", {{1, "GP5_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP5_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); ASSERT_TRUE(set_timeout(&db, "GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", 5)); ASSERT_TRUE(set_timeout(&db, "GP5_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", 5)); @@ -5335,7 +5337,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 3); ASSERT_EQ(total_keys[0], "GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); ASSERT_EQ(total_keys[1], "GP5_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); @@ -5352,9 +5354,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", "GP6_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", "GP6_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY3", "GP6_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY1", "GP6_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5363,33 +5365,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP6_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY3", "GP6_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP6_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY1", {"GP6_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY2", {"GP6_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY3", {"GP6_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY1", {"GP6_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY2", {"GP6_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY3", {"GP6_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1", {{1, "GP6_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2", {{1, "GP6_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3", {{1, "GP6_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP6_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); ASSERT_TRUE(set_timeout(&db, "GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", 15)); ASSERT_TRUE(set_timeout(&db, "GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", 5)); @@ -5418,7 +5420,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP6_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); ASSERT_EQ(total_keys[1], "GP6_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); @@ -5437,9 +5439,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", "GP7_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", "GP7_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY3", "GP7_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY1", "GP7_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5448,33 +5450,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP7_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY3", "GP7_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP7_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY1", {"GP7_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY2", {"GP7_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY3", {"GP7_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY1", {"GP7_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY2", {"GP7_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY3", {"GP7_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1", {{1, "GP7_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2", {{1, "GP7_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3", {{1, "GP7_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP7_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); ASSERT_TRUE(set_timeout(&db, "GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", 5)); ASSERT_TRUE(set_timeout(&db, "GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", 15)); @@ -5503,7 +5505,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP7_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); ASSERT_EQ(total_keys[1], "GP7_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); @@ -5522,9 +5524,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", "GP8_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", "GP8_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY3", "GP8_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY1", "GP8_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5533,33 +5535,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP8_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY3", "GP8_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP8_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY1", {"GP8_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY2", {"GP8_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY3", {"GP8_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY1", {"GP8_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY2", {"GP8_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY3", {"GP8_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1", {{1, "GP8_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2", {{1, "GP8_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3", {{1, "GP8_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP8_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); ASSERT_TRUE(set_timeout(&db, "GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", 5)); ASSERT_TRUE(set_timeout(&db, "GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", 25)); @@ -5588,7 +5590,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP8_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); ASSERT_EQ(total_keys[1], "GP8_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); @@ -5607,9 +5609,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", "GP9_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", "GP9_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY3", "GP9_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP9_PKEXPIRESCAN_CASE_ALL_HASH_KEY1", "GP9_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5618,33 +5620,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP9_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP9_PKEXPIRESCAN_CASE_ALL_HASH_KEY3", "GP9_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP9_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY1", {"GP9_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY2", {"GP9_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY3", {"GP9_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY1", {"GP9_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY2", {"GP9_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY3", {"GP9_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1", {{1, "GP9_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2", {{1, "GP9_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3", {{1, "GP9_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP9_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); ASSERT_TRUE(set_timeout(&db, "GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", 5)); ASSERT_TRUE(set_timeout(&db, "GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", 25)); @@ -5673,7 +5675,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 0, 30, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 15); ASSERT_EQ(total_keys[0], "GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); ASSERT_EQ(total_keys[1], "GP9_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); @@ -5702,9 +5704,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", "GP10_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", "GP10_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY3", "GP10_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP10_PKEXPIRESCAN_CASE_ALL_HASH_KEY1", "GP10_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5713,33 +5715,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP10_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP10_PKEXPIRESCAN_CASE_ALL_HASH_KEY3", "GP10_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP10_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY1", {"GP10_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY2", {"GP10_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY3", {"GP10_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY1", {"GP10_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY2", {"GP10_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY3", {"GP10_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1", {{1, "GP10_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2", {{1, "GP10_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3", {{1, "GP10_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP10_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); ASSERT_TRUE(set_timeout(&db, "GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", 15)); ASSERT_TRUE(set_timeout(&db, "GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", 15)); @@ -5768,7 +5770,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 3); ASSERT_EQ(total_keys[0], "GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); ASSERT_EQ(total_keys[1], "GP10_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); @@ -5785,9 +5787,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", "GP11_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", "GP11_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY3", "GP11_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP11_PKEXPIRESCAN_CASE_ALL_HASH_KEY1", "GP11_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5796,33 +5798,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP11_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP11_PKEXPIRESCAN_CASE_ALL_HASH_KEY3", "GP11_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP11_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY1", {"GP11_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY2", {"GP11_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY3", {"GP11_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY1", {"GP11_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY2", {"GP11_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY3", {"GP11_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1", {{1, "GP11_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2", {{1, "GP11_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3", {{1, "GP11_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP11_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); ASSERT_TRUE(set_timeout(&db, "GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", 5)); ASSERT_TRUE(set_timeout(&db, "GP11_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", 5)); @@ -5851,7 +5853,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 3); ASSERT_EQ(total_keys[0], "GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); ASSERT_EQ(total_keys[1], "GP11_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); @@ -5868,9 +5870,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", "GP12_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", "GP12_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY3", "GP12_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY1"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY2"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY3"); // Hash s = db.HSet("GP12_PKEXPIRESCAN_CASE_ALL_HASH_KEY1", "GP12_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5879,33 +5881,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP12_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP12_PKEXPIRESCAN_CASE_ALL_HASH_KEY3", "GP12_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP12_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_HASH_KEY1"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_HASH_KEY2"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_HASH_KEY3"); // Set s = db.SAdd("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY1", {"GP12_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY2", {"GP12_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY3", {"GP12_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY1"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY2"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_SET_KEY3"); // List s = db.LPush("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY1", {"GP12_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY2", {"GP12_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY3", {"GP12_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY1"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY2"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_LIST_KEY3"); // ZSet s = db.ZAdd("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1", {{1, "GP12_PKEXPIRESCAN_CASE_ALL_ZSET_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2", {{1, "GP12_PKEXPIRESCAN_CASE_ALL_ZSET_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3", {{1, "GP12_PKEXPIRESCAN_CASE_ALL_ZSET_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); - delete_keys.push_back("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); + delete_keys.emplace_back("GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY3"); ASSERT_TRUE(set_timeout(&db, "GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY1", 5)); ASSERT_TRUE(set_timeout(&db, "GP12_PKEXPIRESCAN_CASE_ALL_STRING_KEY2", 5)); @@ -5934,7 +5936,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 3); ASSERT_EQ(total_keys[0], "GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY1"); ASSERT_EQ(total_keys[1], "GP12_PKEXPIRESCAN_CASE_ALL_ZSET_KEY2"); @@ -5951,9 +5953,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_STRING", "GP13_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_STRING", "GP13_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_STRING", "GP13_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); // Hash s = db.HSet("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_HASH", "GP13_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -5962,33 +5964,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP13_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_HASH", "GP13_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP13_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); // Set s = db.SAdd("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_SET", {"GP13_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_SET", {"GP13_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_SET", {"GP13_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_SET"); - delete_keys.push_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_SET"); - delete_keys.push_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_SET"); // List s = db.LPush("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_LIST", {"GP13_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_LIST", {"GP13_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_LIST", {"GP13_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_LIST"); // ZSet s = db.ZAdd("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP13_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP13_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP13_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP13_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP13_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP13_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP13_KEY1_PKEXPIRESCAN_CASE_ALL_STRING", 15)); ASSERT_TRUE(set_timeout(&db, "GP13_KEY2_PKEXPIRESCAN_CASE_ALL_STRING", 5)); @@ -6017,7 +6019,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 1, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP13_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); ASSERT_EQ(total_keys[1], "GP13_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); @@ -6036,9 +6038,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_STRING", "GP14_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_STRING", "GP14_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_STRING", "GP14_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); // Hash s = db.HSet("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_HASH", "GP14_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -6047,33 +6049,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP14_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_HASH", "GP14_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP14_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); // Set s = db.SAdd("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_SET", {"GP14_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_SET", {"GP14_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_SET", {"GP14_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_SET"); - delete_keys.push_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_SET"); - delete_keys.push_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_SET"); // List s = db.LPush("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_LIST", {"GP14_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_LIST", {"GP14_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_LIST", {"GP14_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_LIST"); // ZSet s = db.ZAdd("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP14_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP14_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP14_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP14_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP14_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP14_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP14_KEY1_PKEXPIRESCAN_CASE_ALL_STRING", 15)); ASSERT_TRUE(set_timeout(&db, "GP14_KEY2_PKEXPIRESCAN_CASE_ALL_STRING", 5)); @@ -6102,7 +6104,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP14_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); ASSERT_EQ(total_keys[1], "GP14_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); @@ -6121,9 +6123,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_STRING", "GP15_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_STRING", "GP15_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_STRING", "GP15_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); // Hash s = db.HSet("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_HASH", "GP15_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -6132,33 +6134,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP15_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_HASH", "GP15_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP15_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); // Set s = db.SAdd("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_SET", {"GP15_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_SET", {"GP15_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_SET", {"GP15_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_SET"); - delete_keys.push_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_SET"); - delete_keys.push_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_SET"); // List s = db.LPush("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_LIST", {"GP15_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_LIST", {"GP15_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_LIST", {"GP15_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_LIST"); // ZSet s = db.ZAdd("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP15_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP15_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP15_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP15_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP15_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP15_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP15_KEY1_PKEXPIRESCAN_CASE_ALL_STRING", 5)); ASSERT_TRUE(set_timeout(&db, "GP15_KEY2_PKEXPIRESCAN_CASE_ALL_STRING", 15)); @@ -6187,7 +6189,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP15_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); ASSERT_EQ(total_keys[1], "GP15_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); @@ -6206,9 +6208,9 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { s = db.Set("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_STRING", "GP16_PKEXPIRESCAN_CASE_ALL_STRING_VALUE1"); s = db.Set("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_STRING", "GP16_PKEXPIRESCAN_CASE_ALL_STRING_VALUE2"); s = db.Set("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_STRING", "GP16_PKEXPIRESCAN_CASE_ALL_STRING_VALUE3"); - delete_keys.push_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); - delete_keys.push_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_STRING"); + delete_keys.emplace_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); // Hash s = db.HSet("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_HASH", "GP16_PKEXPIRESCAN_CASE_ALL_HASH_FIELD1", @@ -6217,33 +6219,33 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { "GP16_PKEXPIRESCAN_CASE_ALL_HASH_VALUE2", &int32_ret); s = db.HSet("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_HASH", "GP16_PKEXPIRESCAN_CASE_ALL_HASH_FIELD3", "GP16_PKEXPIRESCAN_CASE_ALL_HASH_VALUE3", &int32_ret); - delete_keys.push_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); - delete_keys.push_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_HASH"); + delete_keys.emplace_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); // Set s = db.SAdd("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_SET", {"GP16_PKEXPIRESCAN_CASE_ALL_SET_MEMBER1"}, &int32_ret); s = db.SAdd("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_SET", {"GP16_PKEXPIRESCAN_CASE_ALL_SET_MEMBER2"}, &int32_ret); s = db.SAdd("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_SET", {"GP16_PKEXPIRESCAN_CASE_ALL_SET_MEMBER3"}, &int32_ret); - delete_keys.push_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_SET"); - delete_keys.push_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_SET"); - delete_keys.push_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_SET"); + delete_keys.emplace_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_SET"); // List s = db.LPush("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_LIST", {"GP16_PKEXPIRESCAN_CASE_ALL_LIST_NODE1"}, &uint64_ret); s = db.LPush("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_LIST", {"GP16_PKEXPIRESCAN_CASE_ALL_LIST_NODE2"}, &uint64_ret); s = db.LPush("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_LIST", {"GP16_PKEXPIRESCAN_CASE_ALL_LIST_NODE3"}, &uint64_ret); - delete_keys.push_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_LIST"); - delete_keys.push_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_LIST"); + delete_keys.emplace_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_LIST"); // ZSet s = db.ZAdd("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP16_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER1"}}, &int32_ret); s = db.ZAdd("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP16_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER2"}}, &int32_ret); s = db.ZAdd("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET", {{1, "GP16_PKEXPIRESCAN_CASE_ALL_LIST_MEMBER3"}}, &int32_ret); - delete_keys.push_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET"); - delete_keys.push_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP16_KEY1_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP16_KEY2_PKEXPIRESCAN_CASE_ALL_ZSET"); + delete_keys.emplace_back("GP16_KEY3_PKEXPIRESCAN_CASE_ALL_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP16_KEY1_PKEXPIRESCAN_CASE_ALL_STRING", 5)); ASSERT_TRUE(set_timeout(&db, "GP16_KEY2_PKEXPIRESCAN_CASE_ALL_STRING", 25)); @@ -6272,7 +6274,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { next_cursor = db.PKExpireScan(DataType::kAll, cursor, 10, 20, 5, &keys); total_keys.insert(total_keys.end(), keys.begin(), keys.end()); cursor = next_cursor; - } while (cursor); + } while (cursor != 0); ASSERT_EQ(total_keys.size(), 5); ASSERT_EQ(total_keys[0], "GP16_KEY3_PKEXPIRESCAN_CASE_ALL_STRING"); ASSERT_EQ(total_keys[1], "GP16_KEY3_PKEXPIRESCAN_CASE_ALL_HASH"); @@ -6286,7 +6288,7 @@ TEST_F(KeysTest, PKExpireScanCaseAllTest) { db.Compact(DataType::kAll, true); } -TEST_F(KeysTest, PKExpireScanCaseSingleTest) { +TEST_F(KeysTest, PKExpireScanCaseSingleTest) { // NOLINT int64_t cursor; int64_t next_cursor; int64_t del_num; @@ -6306,12 +6308,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP1_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP1_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP1_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP1_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -6326,12 +6328,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP1_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP1_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP1_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP1_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -6340,12 +6342,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP1_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP1_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP1_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP1_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -6354,12 +6356,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP1_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP1_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP1_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP1_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -6368,12 +6370,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP1_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP1_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP1_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP1_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP1_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING", 15)); ASSERT_TRUE(set_timeout(&db, "GP1_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING", 15)); @@ -6418,12 +6420,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP2_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP2_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP2_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP2_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -6438,12 +6440,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP2_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP2_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP2_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP2_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -6452,12 +6454,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP2_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP2_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP2_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP2_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -6466,12 +6468,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP2_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP2_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP2_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP2_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -6480,12 +6482,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP2_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP2_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP2_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP2_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP2_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING", 15)); ASSERT_TRUE(set_timeout(&db, "GP2_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING", 15)); @@ -6525,12 +6527,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP3_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP3_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP3_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP3_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -6545,12 +6547,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP3_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP3_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP3_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP3_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -6559,12 +6561,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP3_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP3_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP3_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP3_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -6573,12 +6575,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP3_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP3_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP3_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP3_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -6587,12 +6589,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP3_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP3_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP3_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP3_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP3_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING", 15)); ASSERT_TRUE(set_timeout(&db, "GP3_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING", 15)); @@ -6627,12 +6629,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP4_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP4_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP4_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP4_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -6647,12 +6649,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP4_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP4_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP4_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP4_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -6661,12 +6663,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP4_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP4_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP4_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP4_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -6675,12 +6677,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP4_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP4_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP4_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP4_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -6689,12 +6691,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP4_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP4_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP4_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP4_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP4_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING", 15)); ASSERT_TRUE(set_timeout(&db, "GP4_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING", 15)); @@ -6729,12 +6731,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP5_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP5_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP5_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP5_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -6749,12 +6751,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP5_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP5_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP5_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP5_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -6763,12 +6765,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP5_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP5_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP5_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP5_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -6777,12 +6779,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP5_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP5_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP5_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP5_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -6791,12 +6793,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP5_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP5_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP5_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP5_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP5_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", 15)); ASSERT_TRUE(set_timeout(&db, "GP5_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET", 15)); @@ -6841,12 +6843,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP6_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP6_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP6_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP6_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -6861,12 +6863,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP6_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP6_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP6_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP6_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -6875,12 +6877,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP6_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP6_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP6_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP6_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -6889,12 +6891,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP6_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP6_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP6_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP6_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -6903,12 +6905,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP6_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP6_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP6_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP6_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP6_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", 15)); ASSERT_TRUE(set_timeout(&db, "GP6_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET", 15)); @@ -6948,12 +6950,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP7_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP7_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP7_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP7_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -6968,12 +6970,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP7_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP7_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP7_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP7_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -6982,12 +6984,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP7_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP7_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP7_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP7_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -6996,12 +6998,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP7_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP7_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP7_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP7_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -7010,12 +7012,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP7_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP7_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP7_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP7_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP7_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", 15)); ASSERT_TRUE(set_timeout(&db, "GP7_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET", 15)); @@ -7050,12 +7052,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP8_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP8_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP8_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP8_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -7070,12 +7072,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP8_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP8_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP8_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP8_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -7084,12 +7086,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP8_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP8_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP8_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP8_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -7098,12 +7100,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP8_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP8_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP8_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP8_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -7112,12 +7114,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP8_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP8_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP8_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP8_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP8_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", 15)); ASSERT_TRUE(set_timeout(&db, "GP8_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET", 15)); @@ -7152,12 +7154,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP9_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP9_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP9_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP9_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -7172,12 +7174,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP9_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP9_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP9_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP9_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -7186,12 +7188,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP9_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP9_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP9_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP9_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -7200,12 +7202,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP9_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP9_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP9_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP9_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, &int32_ret); @@ -7214,12 +7216,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.ZAdd("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP9_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER4"}}, &int32_ret); s = db.ZAdd("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP9_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER5"}}, &int32_ret); s = db.ZAdd("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP9_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP9_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP9_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", 15)); ASSERT_TRUE(set_timeout(&db, "GP9_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET", 15)); @@ -7264,12 +7266,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP10_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP10_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP10_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP10_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -7284,12 +7286,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP10_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP10_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP10_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP10_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -7298,12 +7300,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP10_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP10_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP10_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP10_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -7312,12 +7314,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP10_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP10_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP10_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP10_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, @@ -7332,12 +7334,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { &int32_ret); s = db.ZAdd("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP10_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP10_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP10_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", 15)); ASSERT_TRUE(set_timeout(&db, "GP10_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET", 15)); @@ -7377,12 +7379,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP11_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP11_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP11_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP11_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -7397,12 +7399,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP11_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP11_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP11_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP11_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -7411,12 +7413,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP11_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP11_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP11_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP11_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -7425,12 +7427,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP11_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP11_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP11_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP11_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, @@ -7445,12 +7447,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { &int32_ret); s = db.ZAdd("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP11_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP11_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP11_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", 15)); ASSERT_TRUE(set_timeout(&db, "GP11_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET", 15)); @@ -7485,12 +7487,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.Set("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP12_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE4"); s = db.Set("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP12_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE5"); s = db.Set("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING", "GP12_PKEXPIRESCAN_CASE_SINGLE_STRING_VALUE6"); - delete_keys.push_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); - delete_keys.push_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_STRING"); + delete_keys.emplace_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_STRING"); // Hash s = db.HSet("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP12_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD1", @@ -7505,12 +7507,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { "GP12_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE5", &int32_ret); s = db.HSet("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH", "GP12_PKEXPIRESCAN_CASE_SINGLE_HASH_FIELD6", "GP12_PKEXPIRESCAN_CASE_SINGLE_HASH_VALUE6", &int32_ret); - delete_keys.push_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); - delete_keys.push_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_HASH"); + delete_keys.emplace_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_HASH"); // Set s = db.SAdd("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP12_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER1"}, &int32_ret); @@ -7519,12 +7521,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.SAdd("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP12_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER4"}, &int32_ret); s = db.SAdd("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP12_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER5"}, &int32_ret); s = db.SAdd("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET", {"GP12_PKEXPIRESCAN_CASE_SINGLE_SET_MEMBER6"}, &int32_ret); - delete_keys.push_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); - delete_keys.push_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_SET"); + delete_keys.emplace_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_SET"); // List s = db.LPush("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP12_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE1"}, &uint64_ret); @@ -7533,12 +7535,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { s = db.LPush("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP12_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE4"}, &uint64_ret); s = db.LPush("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP12_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE5"}, &uint64_ret); s = db.LPush("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST", {"GP12_PKEXPIRESCAN_CASE_SINGLE_LIST_NODE6"}, &uint64_ret); - delete_keys.push_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); - delete_keys.push_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_LIST"); + delete_keys.emplace_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_LIST"); // ZSet s = db.ZAdd("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP12_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER1"}}, @@ -7553,12 +7555,12 @@ TEST_F(KeysTest, PKExpireScanCaseSingleTest) { &int32_ret); s = db.ZAdd("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET", {{1, "GP12_PKEXPIRESCAN_CASE_SINGLE_LIST_MEMBER6"}}, &int32_ret); - delete_keys.push_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); - delete_keys.push_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY3_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY4_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY5_PKEXPIRESCAN_CASE_SINGLE_ZSET"); + delete_keys.emplace_back("GP12_KEY6_PKEXPIRESCAN_CASE_SINGLE_ZSET"); ASSERT_TRUE(set_timeout(&db, "GP12_KEY1_PKEXPIRESCAN_CASE_SINGLE_ZSET", 15)); ASSERT_TRUE(set_timeout(&db, "GP12_KEY2_PKEXPIRESCAN_CASE_SINGLE_ZSET", 15)); diff --git a/src/storage/tests/lists_filter_test.cc b/src/storage/tests/lists_filter_test.cc index d7699fd8d0..23f2351001 100644 --- a/src/storage/tests/lists_filter_test.cc +++ b/src/storage/tests/lists_filter_test.cc @@ -11,13 +11,18 @@ #include "src/redis.h" #include "storage/storage.h" -using namespace storage; +using storage::Status; +using storage::Slice; +using storage::EncodeFixed64; +using storage::ListsMetaValue; +using storage::ListsDataFilter; +using storage::ListsDataKey; class ListsFilterTest : public ::testing::Test { public: ListsFilterTest() { std::string db_path = "./db/list_meta"; - if (access(db_path.c_str(), F_OK)) { + if (access(db_path.c_str(), F_OK) != 0) { mkdir(db_path.c_str(), 0755); } options.create_if_missing = true; @@ -34,16 +39,16 @@ class ListsFilterTest : public ::testing::Test { rocksdb::ColumnFamilyOptions data_cf_ops(options); // Meta CF - column_families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, meta_cf_ops)); + column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops); // Data CF - column_families.push_back(rocksdb::ColumnFamilyDescriptor("data_cf", data_cf_ops)); + column_families.emplace_back("data_cf", data_cf_ops); s = rocksdb::DB::Open(options, db_path, column_families, &handles, &meta_db); } - virtual ~ListsFilterTest() {} + ~ListsFilterTest() override = default; - virtual void SetUp() {} - virtual void TearDown() { + void SetUp() override {} + void TearDown() override { for (auto handle : handles) { delete handle; } @@ -67,7 +72,7 @@ TEST_F(ListsFilterTest, MetaFilterTest) { std::string new_value; // Test Meta Filter - auto lists_meta_filter = std::make_unique(); + auto lists_meta_filter = std::make_unique(); ASSERT_TRUE(lists_meta_filter != nullptr); // Timeout timestamp is not set, but it's an empty list. @@ -104,7 +109,7 @@ TEST_F(ListsFilterTest, MetaFilterTest) { lists_meta_value4.UpdateVersion(); lists_meta_value4.SetRelativeTimestamp(1); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); - ParsedListsMetaValue parsed_meta_value(lists_meta_value4.Encode()); + storage::ParsedListsMetaValue parsed_meta_value(lists_meta_value4.Encode()); filter_result = lists_meta_filter->Filter(0, "FILTER_TEST_KEY", lists_meta_value4.Encode(), &new_value, &value_changed); ASSERT_EQ(filter_result, true); diff --git a/src/storage/tests/lists_test.cc b/src/storage/tests/lists_test.cc index e4410f8d28..a5eb483524 100644 --- a/src/storage/tests/lists_test.cc +++ b/src/storage/tests/lists_test.cc @@ -26,7 +26,7 @@ static bool elements_match(storage::Storage* const db, const Slice& key, return true; } for (uint64_t idx = 0; idx < elements_out.size(); ++idx) { - if (strcmp(elements_out[idx].c_str(), expect_elements[idx].c_str())) { + if (strcmp(elements_out[idx].c_str(), expect_elements[idx].c_str()) != 0) { return false; } } @@ -39,7 +39,7 @@ static bool elements_match(const std::vector& elements_out, return false; } for (uint64_t idx = 0; idx < elements_out.size(); ++idx) { - if (strcmp(elements_out[idx].c_str(), expect_elements[idx].c_str())) { + if (static_cast(strcmp(elements_out[idx].c_str(), expect_elements[idx].c_str()) != 0) != 0) { return false; } } @@ -52,7 +52,7 @@ static bool len_match(storage::Storage* const db, const Slice& key, uint64_t exp if (!s.ok() && !s.IsNotFound()) { return false; } - if (s.IsNotFound() && !expect_len) { + if (s.IsNotFound() && (expect_len == 0U)) { return true; } return len == expect_len; @@ -61,7 +61,7 @@ static bool len_match(storage::Storage* const db, const Slice& key, uint64_t exp static bool make_expired(storage::Storage* const db, const Slice& key) { std::map type_status; int ret = db->Expire(key, 1, &type_status); - if (!ret || !type_status[storage::DataType::kLists].ok()) { + if ((ret == 0) || !type_status[storage::DataType::kLists].ok()) { return false; } std::this_thread::sleep_for(std::chrono::milliseconds(2000)); @@ -70,12 +70,12 @@ static bool make_expired(storage::Storage* const db, const Slice& key) { class ListsTest : public ::testing::Test { public: - ListsTest() {} - virtual ~ListsTest() {} + ListsTest() = default; + ~ListsTest() override = default; - void SetUp() { + void SetUp() override { std::string path = "./db/lists"; - if (access(path.c_str(), F_OK)) { + if (access(path.c_str(), F_OK) != 0) { mkdir(path.c_str(), 0755); } storage_options.options.create_if_missing = true; @@ -86,13 +86,13 @@ class ListsTest : public ::testing::Test { } } - void TearDown() { + void TearDown() override { std::string path = "./db/lists"; DeleteFiles(path.c_str()); } - static void SetUpTestCase() {} - static void TearDownTestCase() {} + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} StorageOptions storage_options; storage::Storage db; @@ -100,7 +100,7 @@ class ListsTest : public ::testing::Test { }; // LIndex -TEST_F(ListsTest, LIndexTest) { +TEST_F(ListsTest, LIndexTest) { // NOLINT uint64_t num; std::string element; @@ -263,7 +263,7 @@ TEST_F(ListsTest, LIndexTest) { } // LInsert -TEST_F(ListsTest, LInsertTest) { +TEST_F(ListsTest, LInsertTest) { // NOLINT int64_t ret; uint64_t num; @@ -455,7 +455,7 @@ TEST_F(ListsTest, LInsertTest) { } // LLen -TEST_F(ListsTest, LLenTest) { +TEST_F(ListsTest, LLenTest) { // NOLINT uint64_t num; // ***************** Group 1 Test ***************** @@ -489,7 +489,7 @@ TEST_F(ListsTest, LLenTest) { } // LPop -TEST_F(ListsTest, LPopTest) { +TEST_F(ListsTest, LPopTest) { // NOLINT uint64_t num; std::string element; @@ -560,7 +560,7 @@ TEST_F(ListsTest, LPopTest) { } // LPush -TEST_F(ListsTest, LPushTest) { +TEST_F(ListsTest, LPushTest) { // NOLINT int32_t ret; uint64_t num; std::string element; @@ -697,7 +697,7 @@ TEST_F(ListsTest, LPushTest) { } // LPushx -TEST_F(ListsTest, LPushxTest) { +TEST_F(ListsTest, LPushxTest) { // NOLINT int64_t ret; uint64_t num; @@ -777,7 +777,7 @@ TEST_F(ListsTest, LPushxTest) { } // LRange -TEST_F(ListsTest, LRangeTest) { +TEST_F(ListsTest, LRangeTest) { // NOLINT uint64_t num; // ***************** Group 1 Test ***************** @@ -1030,7 +1030,7 @@ TEST_F(ListsTest, LRangeTest) { } // LRem -TEST_F(ListsTest, LRemTest) { +TEST_F(ListsTest, LRemTest) { // NOLINT int64_t ret; uint64_t num; @@ -1402,7 +1402,7 @@ TEST_F(ListsTest, LRemTest) { } // LSet -TEST_F(ListsTest, LSetTest) { +TEST_F(ListsTest, LSetTest) { // NOLINT int64_t ret; uint64_t num; @@ -1499,7 +1499,7 @@ TEST_F(ListsTest, LSetTest) { } // LTrim -TEST_F(ListsTest, LTrimTest) { +TEST_F(ListsTest, LTrimTest) { // NOLINT uint64_t num; // ***************** Group 1 Test ***************** // "a" -> "b" -> "c" -> "d" -> "e" @@ -1997,7 +1997,7 @@ TEST_F(ListsTest, LTrimTest) { } // RPop -TEST_F(ListsTest, RPopTest) { +TEST_F(ListsTest, RPopTest) { // NOLINT uint64_t num; std::string element; @@ -2068,10 +2068,11 @@ TEST_F(ListsTest, RPopTest) { } // RPoplpush -TEST_F(ListsTest, RPoplpushTest) { +TEST_F(ListsTest, RPoplpushTest) { // NOLINT int64_t ret; uint64_t num; - std::string element, target; + std::string element; + std::string target; std::map type_ttl; std::map type_status; @@ -2420,7 +2421,7 @@ TEST_F(ListsTest, RPoplpushTest) { } // RPush -TEST_F(ListsTest, RPushTest) { +TEST_F(ListsTest, RPushTest) { // NOLINT int32_t ret; uint64_t num; std::string element; @@ -2557,7 +2558,7 @@ TEST_F(ListsTest, RPushTest) { } // RPushx -TEST_F(ListsTest, RPushxTest) { +TEST_F(ListsTest, RPushxTest) { // NOLINT int64_t ret; uint64_t num; diff --git a/src/storage/tests/options_test.cc b/src/storage/tests/options_test.cc index 1c030726ef..b33177ce2d 100644 --- a/src/storage/tests/options_test.cc +++ b/src/storage/tests/options_test.cc @@ -14,10 +14,10 @@ using namespace storage; class StorageOptionsTest : public ::testing::Test { public: StorageOptionsTest() = default; - virtual ~StorageOptionsTest() = default; + ~StorageOptionsTest() override = default; - static void SetUpTestCase() {} - static void TearDownTestCase() {} + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} StorageOptions storage_options; storage::Status s; diff --git a/src/storage/tests/sets_test.cc b/src/storage/tests/sets_test.cc index 8b2245b091..ab5a3651ce 100644 --- a/src/storage/tests/sets_test.cc +++ b/src/storage/tests/sets_test.cc @@ -14,12 +14,12 @@ using namespace storage; class SetsTest : public ::testing::Test { public: - SetsTest() {} - virtual ~SetsTest() {} + SetsTest() = default; + ~SetsTest() override = default; void SetUp() override { std::string path = "./db/sets"; - if (access(path.c_str(), F_OK)) { + if (access(path.c_str(), F_OK) != 0) { mkdir(path.c_str(), 0755); } storage_options.options.create_if_missing = true; @@ -31,8 +31,8 @@ class SetsTest : public ::testing::Test { DeleteFiles(path.c_str()); } - static void SetUpTestCase() {} - static void TearDownTestCase() {} + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} StorageOptions storage_options; storage::Storage db; @@ -98,7 +98,7 @@ static bool size_match(storage::Storage* const db, const Slice& key, int32_t exp if (!s.ok() && !s.IsNotFound()) { return false; } - if (s.IsNotFound() && !expect_size) { + if (s.IsNotFound() && (expect_size == 0)) { return true; } return size == expect_size; @@ -107,7 +107,7 @@ static bool size_match(storage::Storage* const db, const Slice& key, int32_t exp static bool make_expired(storage::Storage* const db, const Slice& key) { std::map type_status; int ret = db->Expire(key, 1, &type_status); - if (!ret || !type_status[storage::DataType::kSets].ok()) { + if ((ret == 0) || !type_status[storage::DataType::kSets].ok()) { return false; } std::this_thread::sleep_for(std::chrono::milliseconds(2000)); @@ -115,7 +115,7 @@ static bool make_expired(storage::Storage* const db, const Slice& key) { } // SAdd -TEST_F(SetsTest, SAddTest) { +TEST_F(SetsTest, SAddTest) { // NOLINT int32_t ret = 0; std::vector members1{"a", "b", "c", "b"}; s = db.SAdd("SADD_KEY", members1, &ret); @@ -166,7 +166,7 @@ TEST_F(SetsTest, SAddTest) { } // SCard -TEST_F(SetsTest, SCardTest) { +TEST_F(SetsTest, SCardTest) { // NOLINT int32_t ret = 0; std::vector members{"MM1", "MM2", "MM3"}; s = db.SAdd("SCARD_KEY", members, &ret); @@ -178,7 +178,7 @@ TEST_F(SetsTest, SCardTest) { } // SDiff -TEST_F(SetsTest, SDiffTest) { +TEST_F(SetsTest, SDiffTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** @@ -224,7 +224,7 @@ TEST_F(SetsTest, SDiffTest) { // key3 = {a, c, e} (expire key) // key4 = {} (not exist key) // SDIFF key1 key2 key3 key4 = {a, b, d} - gp1_keys.push_back("GP1_SDIFF_KEY4"); + gp1_keys.emplace_back("GP1_SDIFF_KEY4"); gp1_members_out.clear(); s = db.SDiff(gp1_keys, &gp1_members_out); ASSERT_TRUE(s.ok()); @@ -319,7 +319,7 @@ TEST_F(SetsTest, SDiffTest) { ASSERT_TRUE(members_match(gp5_members_out, {"b", "d"})); // double "GP5_SDIFF_KEY3" - gp5_keys.push_back("GP5_SDIFF_KEY3"); + gp5_keys.emplace_back("GP5_SDIFF_KEY3"); gp5_members_out.clear(); s = db.SDiff(gp5_keys, &gp5_members_out); ASSERT_TRUE(s.ok()); @@ -335,7 +335,7 @@ TEST_F(SetsTest, SDiffTest) { } // SDiffstore -TEST_F(SetsTest, SDiffstoreTest) { +TEST_F(SetsTest, SDiffstoreTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** @@ -391,7 +391,7 @@ TEST_F(SetsTest, SDiffstoreTest) { // key4 = {} (not exist key) // SDIFFSTORE destination key1 key2 key3 // destination = {a, b, d} - gp1_keys.push_back("GP1_SDIFFSTORE_KEY4"); + gp1_keys.emplace_back("GP1_SDIFFSTORE_KEY4"); gp1_members_out.clear(); s = db.SDiffstore("GP1_SDIFFSTORE_DESTINATION3", gp1_keys, &ret); ASSERT_TRUE(s.ok()); @@ -572,7 +572,7 @@ TEST_F(SetsTest, SDiffstoreTest) { } // SInter -TEST_F(SetsTest, SInterTest) { +TEST_F(SetsTest, SInterTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** @@ -730,7 +730,7 @@ TEST_F(SetsTest, SInterTest) { } // SInterstore -TEST_F(SetsTest, SInterstoreTest) { +TEST_F(SetsTest, SInterstoreTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** @@ -974,7 +974,7 @@ TEST_F(SetsTest, SInterstoreTest) { } // SIsmember -TEST_F(SetsTest, SIsmemberTest) { +TEST_F(SetsTest, SIsmemberTest) { // NOLINT int32_t ret = 0; std::vector members{"MEMBER"}; s = db.SAdd("SISMEMBER_KEY", members, &ret); @@ -1006,12 +1006,12 @@ TEST_F(SetsTest, SIsmemberTest) { } // SMembers -TEST_F(SetsTest, SMembersTest) { +TEST_F(SetsTest, SMembersTest) { // NOLINT int32_t ret = 0; std::vector mid_members_in; - mid_members_in.push_back("MID_MEMBER1"); - mid_members_in.push_back("MID_MEMBER2"); - mid_members_in.push_back("MID_MEMBER3"); + mid_members_in.emplace_back("MID_MEMBER1"); + mid_members_in.emplace_back("MID_MEMBER2"); + mid_members_in.emplace_back("MID_MEMBER3"); s = db.SAdd("B_SMEMBERS_KEY", mid_members_in, &ret); ASSERT_TRUE(s.ok()); ASSERT_EQ(ret, 3); @@ -1023,9 +1023,9 @@ TEST_F(SetsTest, SMembersTest) { // Insert some kv who's position above "mid kv" std::vector pre_members_in; - pre_members_in.push_back("PRE_MEMBER1"); - pre_members_in.push_back("PRE_MEMBER2"); - pre_members_in.push_back("PRE_MEMBER3"); + pre_members_in.emplace_back("PRE_MEMBER1"); + pre_members_in.emplace_back("PRE_MEMBER2"); + pre_members_in.emplace_back("PRE_MEMBER3"); s = db.SAdd("A_SMEMBERS_KEY", pre_members_in, &ret); ASSERT_TRUE(s.ok()); ASSERT_EQ(ret, 3); @@ -1036,9 +1036,9 @@ TEST_F(SetsTest, SMembersTest) { // Insert some kv who's position below "mid kv" std::vector suf_members_in; - suf_members_in.push_back("SUF_MEMBER1"); - suf_members_in.push_back("SUF_MEMBER2"); - suf_members_in.push_back("SUF_MEMBER3"); + suf_members_in.emplace_back("SUF_MEMBER1"); + suf_members_in.emplace_back("SUF_MEMBER2"); + suf_members_in.emplace_back("SUF_MEMBER3"); s = db.SAdd("C_SMEMBERS_KEY", suf_members_in, &ret); ASSERT_TRUE(s.ok()); ASSERT_EQ(ret, 3); @@ -1056,7 +1056,7 @@ TEST_F(SetsTest, SMembersTest) { } // SMove -TEST_F(SetsTest, SMoveTest) { +TEST_F(SetsTest, SMoveTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** // source = {a, b, c, d} @@ -1281,7 +1281,7 @@ TEST_F(SetsTest, SMoveTest) { } // SPop -TEST_F(SetsTest, SPopTest) { +TEST_F(SetsTest, SPopTest) { // NOLINT int32_t ret = 0; std::vector members; @@ -1433,7 +1433,7 @@ TEST_F(SetsTest, SPopTest) { } // SRandmember -TEST_F(SetsTest, SRanmemberTest) { +TEST_F(SetsTest, SRanmemberTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** @@ -1540,7 +1540,7 @@ TEST_F(SetsTest, SRanmemberTest) { } // SRem -TEST_F(SetsTest, SRemTest) { +TEST_F(SetsTest, SRemTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** @@ -1598,7 +1598,7 @@ TEST_F(SetsTest, SRemTest) { } // SUnion -TEST_F(SetsTest, SUnionTest) { +TEST_F(SetsTest, SUnionTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** @@ -1714,7 +1714,7 @@ TEST_F(SetsTest, SUnionTest) { } // SUnionstore -TEST_F(SetsTest, SUnionstoreTest) { +TEST_F(SetsTest, SUnionstoreTest) { // NOLINT int32_t ret = 0; // ***************** Group 1 Test ***************** @@ -1839,9 +1839,10 @@ TEST_F(SetsTest, SUnionstoreTest) { } // SScan -TEST_F(SetsTest, SScanTest) { +TEST_F(SetsTest, SScanTest) { // NOLINT int32_t ret = 0; - int64_t cursor = 0, next_cursor = 0; + int64_t cursor = 0; + int64_t next_cursor = 0; std::vector member_out; // ***************** Group 1 Test ***************** // a b c d e f g h diff --git a/src/storage/tests/strings_filter_test.cc b/src/storage/tests/strings_filter_test.cc index 6587576263..5bfa713b64 100644 --- a/src/storage/tests/strings_filter_test.cc +++ b/src/storage/tests/strings_filter_test.cc @@ -15,7 +15,8 @@ using namespace storage; // Filter TEST(StringsFilterTest, FilterTest) { std::string new_value; - bool is_stale, value_changed; + bool is_stale; + bool value_changed; auto filter = std::make_unique(); int32_t ttl = 1; diff --git a/src/storage/tests/strings_test.cc b/src/storage/tests/strings_test.cc index da161d1225..e1c2d011f8 100644 --- a/src/storage/tests/strings_test.cc +++ b/src/storage/tests/strings_test.cc @@ -14,12 +14,12 @@ using namespace storage; class StringsTest : public ::testing::Test { public: - StringsTest() {} - virtual ~StringsTest() {} + StringsTest() = default; + ~StringsTest() override = default; void SetUp() override { std::string path = "./db/strings"; - if (access(path.c_str(), F_OK)) { + if (access(path.c_str(), F_OK) != 0) { mkdir(path.c_str(), 0755); } storage_options.options.create_if_missing = true; @@ -31,8 +31,8 @@ class StringsTest : public ::testing::Test { DeleteFiles(path.c_str()); } - static void SetUpTestCase() {} - static void TearDownTestCase() {} + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} StorageOptions storage_options; storage::Storage db; @@ -42,7 +42,7 @@ class StringsTest : public ::testing::Test { static bool make_expired(storage::Storage* const db, const Slice& key) { std::map type_status; int ret = db->Expire(key, 1, &type_status); - if (!ret || !type_status[storage::DataType::kStrings].ok()) { + if ((ret == 0) || !type_status[storage::DataType::kStrings].ok()) { return false; } std::this_thread::sleep_for(std::chrono::milliseconds(2000)); @@ -691,7 +691,8 @@ TEST_F(StringsTest, SetnxTest) { // Setvx TEST_F(StringsTest, SetvxTest) { - int32_t ret, ttl; + int32_t ret; + int32_t ttl; std::string value; // ***************** Group 1 Test ***************** s = db.Set("GP1_SETVX_KEY", "GP1_SETVX_VALUE"); @@ -784,7 +785,8 @@ TEST_F(StringsTest, SetvxTest) { // Delvx TEST_F(StringsTest, DelvxTest) { - int32_t ret, ttl; + int32_t ret; + int32_t ttl; std::string value; // ***************** Group 1 Test ***************** s = db.Set("GP1_DELVX_KEY", "GP1_DELVX_VALUE"); diff --git a/src/storage/tests/zsets_test.cc b/src/storage/tests/zsets_test.cc index a8adf98e1f..5ab47130ed 100644 --- a/src/storage/tests/zsets_test.cc +++ b/src/storage/tests/zsets_test.cc @@ -10,16 +10,21 @@ #include "storage/storage.h" #include "storage/util.h" -using namespace storage; +// using namespace storage; +using storage::Status; +using storage::Slice; +using storage::ScoreMember; +using storage::kZSets; +using storage::DataType; class ZSetsTest : public ::testing::Test { public: - ZSetsTest() {} - virtual ~ZSetsTest() {} + ZSetsTest() = default; + ~ZSetsTest() override = default; void SetUp() override { std::string path = "./db/zsets"; - if (access(path.c_str(), F_OK)) { + if (access(path.c_str(), F_OK) != 0) { mkdir(path.c_str(), 0755); } storage_options.options.create_if_missing = true; @@ -32,13 +37,13 @@ class ZSetsTest : public ::testing::Test { void TearDown() override { std::string path = "./db/zsets"; - DeleteFiles(path.c_str()); + storage::DeleteFiles(path.c_str()); } - static void SetUpTestCase() {} - static void TearDownTestCase() {} + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} - StorageOptions storage_options; + storage::StorageOptions storage_options; storage::Storage db; storage::Status s; }; @@ -58,7 +63,7 @@ static bool members_match(const std::vector& mm_out, const std::vec static bool score_members_match(storage::Storage* const db, const Slice& key, const std::vector& expect_sm) { std::vector sm_out; - Status s = db->ZRange(key, 0, -1, &sm_out); + storage::Status s = db->ZRange(key, 0, -1, &sm_out); if (!s.ok() && !s.IsNotFound()) { return false; } @@ -91,27 +96,27 @@ static bool score_members_match(const std::vector& sm_out, static bool size_match(storage::Storage* const db, const Slice& key, int32_t expect_size) { int32_t size = 0; - Status s = db->ZCard(key, &size); + storage::Status s = db->ZCard(key, &size); if (!s.ok() && !s.IsNotFound()) { return false; } - if (s.IsNotFound() && !expect_size) { + if (s.IsNotFound() && (expect_size == 0)) { return true; } return size == expect_size; } -static bool make_expired(storage::Storage* const db, const Slice& key) { +static bool make_expired(storage::Storage* const db, const storage::Slice& key) { std::map type_status; int ret = db->Expire(key, 1, &type_status); - if (!ret || !type_status[storage::DataType::kZSets].ok()) { + if ((ret == 0) || !type_status[storage::DataType::kZSets].ok()) { return false; } std::this_thread::sleep_for(std::chrono::milliseconds(2000)); return true; } -static bool delete_key(storage::Storage* const db, const Slice& key) { +static bool delete_key(storage::Storage* const db, const storage::Slice& key) { std::vector del_keys = {key.ToString()}; std::map type_status; db->Del(del_keys, &type_status); @@ -119,9 +124,9 @@ static bool delete_key(storage::Storage* const db, const Slice& key) { } // ZPopMax -TEST_F(ZSetsTest, ZPopMaxTest) { +TEST_F(ZSetsTest, ZPopMaxTest) { // NOLINT int32_t ret; - std::map type_ttl; + std::map type_ttl; std::map type_status; // ***************** Group 1 Test ***************** @@ -130,7 +135,7 @@ TEST_F(ZSetsTest, ZPopMaxTest) { // [3.23, MM1] // [8.0004, MM3] std::vector gp1_sm{{3.23, "MM1"}, {0, "MM2"}, {8.0004, "MM3"}, {-0.54, "MM4"}}; - Status s = db.ZAdd("GP1_ZPOPMAX_KEY", gp1_sm, &ret); + storage::Status s = db.ZAdd("GP1_ZPOPMAX_KEY", gp1_sm, &ret); ASSERT_TRUE(s.ok()); ASSERT_EQ(4, ret); ASSERT_TRUE(size_match(&db, "GP1_ZPOPMAX_KEY", 4)); @@ -267,7 +272,7 @@ TEST_F(ZSetsTest, ZPopMaxTest) { } // ZPopMin -TEST_F(ZSetsTest, ZPopMinTest) { +TEST_F(ZSetsTest, ZPopMinTest) { // NOLINT int32_t ret; std::map type_ttl; std::map type_status; @@ -415,7 +420,7 @@ TEST_F(ZSetsTest, ZPopMinTest) { } // ZAdd -TEST_F(ZSetsTest, ZAddTest) { +TEST_F(ZSetsTest, ZAddTest) { // NOLINT int32_t ret; std::map type_ttl; std::map type_status; @@ -694,7 +699,7 @@ TEST_F(ZSetsTest, ZAddTest) { } // ZCard -TEST_F(ZSetsTest, ZCardTest) { +TEST_F(ZSetsTest, ZCardTest) { // NOLINT int32_t ret; double score; @@ -739,7 +744,7 @@ TEST_F(ZSetsTest, ZCardTest) { } // ZCount -TEST_F(ZSetsTest, ZCountTest) { +TEST_F(ZSetsTest, ZCountTest) { // NOLINT int32_t ret; // ***************** Group 1 Test ***************** @@ -926,7 +931,7 @@ TEST_F(ZSetsTest, ZCountTest) { } // ZIncrby -TEST_F(ZSetsTest, ZIncrbyTest) { +TEST_F(ZSetsTest, ZIncrbyTest) { // NOLINT int32_t ret; double score; std::map type_ttl; @@ -1076,7 +1081,7 @@ TEST_F(ZSetsTest, ZIncrbyTest) { } // ZRange -TEST_F(ZSetsTest, ZRangeTest) { +TEST_F(ZSetsTest, ZRangeTest) { // NOLINT int32_t ret; std::vector score_members; @@ -1261,7 +1266,7 @@ TEST_F(ZSetsTest, ZRangeTest) { } // ZRangebyscore -TEST_F(ZSetsTest, ZRangebyscoreTest) { +TEST_F(ZSetsTest, ZRangebyscoreTest) { // NOLINT int32_t ret; std::vector score_members; @@ -1672,7 +1677,7 @@ TEST_F(ZSetsTest, ZRangebyscoreTest) { // TODO(@tangruilin): 修复测试代码 // ZRank -// TEST_F(ZSetsTest, ZRankTest) { +// TEST_F(ZSetsTest, ZRankTest) { // NOLINT // int32_t ret, rank; // // ***************** Group 1 Test ***************** @@ -1717,7 +1722,7 @@ TEST_F(ZSetsTest, ZRangebyscoreTest) { // } // ZRem -TEST_F(ZSetsTest, ZRemTest) { +TEST_F(ZSetsTest, ZRemTest) { // NOLINT int32_t ret; // ***************** Group 1 Test ***************** @@ -1828,7 +1833,7 @@ TEST_F(ZSetsTest, ZRemTest) { } // ZRemrangebyrank -TEST_F(ZSetsTest, ZRemrangebyrankTest) { +TEST_F(ZSetsTest, ZRemrangebyrankTest) { // NOLINT int32_t ret; std::vector score_members; @@ -2429,7 +2434,7 @@ TEST_F(ZSetsTest, ZRemrangebyrankTest) { } // ZRemrangebyscore -TEST_F(ZSetsTest, ZRemrangebyscoreTest) { +TEST_F(ZSetsTest, ZRemrangebyscoreTest) { // NOLINT int32_t ret; // ***************** Group 1 Test ***************** @@ -3050,7 +3055,7 @@ TEST_F(ZSetsTest, ZRemrangebyscoreTest) { } // ZRevrange -TEST_F(ZSetsTest, ZRevrangeTest) { +TEST_F(ZSetsTest, ZRevrangeTest) { // NOLINT int32_t ret; std::vector score_members; @@ -3271,7 +3276,7 @@ TEST_F(ZSetsTest, ZRevrangeTest) { // TODO(@tangruilin): 修复测试代码 // ZRevrangebyscore -// TEST_F(ZSetsTest, ZRevrangebyscoreTest) { +// TEST_F(ZSetsTest, ZRevrangebyscoreTest) { // NOLINT // int32_t ret; // std::vector score_members; @@ -3566,8 +3571,9 @@ TEST_F(ZSetsTest, ZRevrangeTest) { // } // ZRevrank -TEST_F(ZSetsTest, ZRevrankTest) { - int32_t ret, rank; +TEST_F(ZSetsTest, ZRevrankTest) { // NOLINT + int32_t ret; + int32_t rank; // ***************** Group 1 Test ***************** // {-5, MM0} {-3, MM1} {-1, MM2} {0, MM3} {1, MM4} {3, MM5} {5, MM6} @@ -3617,7 +3623,7 @@ TEST_F(ZSetsTest, ZRevrankTest) { } // ZSCORE -TEST_F(ZSetsTest, ZScoreTest) { +TEST_F(ZSetsTest, ZScoreTest) { // NOLINT int32_t ret; double score; @@ -3682,7 +3688,7 @@ TEST_F(ZSetsTest, ZScoreTest) { } // ZUNIONSTORE -TEST_F(ZSetsTest, ZUnionstoreTest) { +TEST_F(ZSetsTest, ZUnionstoreTest) { // NOLINT int32_t ret; // ***************** Group 1 Test ***************** @@ -3927,7 +3933,7 @@ TEST_F(ZSetsTest, ZUnionstoreTest) { } // ZINTERSTORE -TEST_F(ZSetsTest, ZInterstoreTest) { +TEST_F(ZSetsTest, ZInterstoreTest) { // NOLINT int32_t ret; // ***************** Group 1 Test ***************** @@ -4155,7 +4161,7 @@ TEST_F(ZSetsTest, ZInterstoreTest) { } // ZRANGEBYLEX -TEST_F(ZSetsTest, ZRangebylexTest) { +TEST_F(ZSetsTest, ZRangebylexTest) { // NOLINT int32_t ret; std::vector members; @@ -4285,7 +4291,7 @@ TEST_F(ZSetsTest, ZRangebylexTest) { } // ZLEXCOUNT -TEST_F(ZSetsTest, ZLexcountTest) { +TEST_F(ZSetsTest, ZLexcountTest) { // NOLINT int32_t ret; std::vector members; @@ -4415,7 +4421,7 @@ TEST_F(ZSetsTest, ZLexcountTest) { } // ZREMRANGEBYLEX -TEST_F(ZSetsTest, ZRemrangebylexTest) { +TEST_F(ZSetsTest, ZRemrangebylexTest) { // NOLINT int32_t ret; std::vector members; @@ -4816,9 +4822,10 @@ TEST_F(ZSetsTest, ZRemrangebylexTest) { } // ZScan -TEST_F(ZSetsTest, ZScanTest) { +TEST_F(ZSetsTest, ZScanTest) { // NOLINT int32_t ret = 0; - int64_t cursor = 0, next_cursor = 0; + int64_t cursor = 0; + int64_t next_cursor = 0; std::vector score_member_out; // ***************** Group 1 Test ***************** diff --git a/tools/aof_to_pika/include/aof_sender.h b/tools/aof_to_pika/include/aof_sender.h index 28fb8b2ae2..d05ea55139 100644 --- a/tools/aof_to_pika/include/aof_sender.h +++ b/tools/aof_to_pika/include/aof_sender.h @@ -3,6 +3,7 @@ #include #include +#include #include "aof_info.h" #include "aof_lock.h" @@ -14,13 +15,14 @@ #define READ_BUF_MAX 100 #define MSG_BLOCK_MAX 512 * 1024 -typedef struct ConnInfo { - ConnInfo() {} - ConnInfo(const std::string& h, const std::string& p, const std::string& a) : host_(h), port_(p), auth_(a) {} +using ConnInfo = struct ConnInfo { + ConnInfo() = default; + ConnInfo(std::string h, std::string p, std::string a) + : host_(std::move(h)), port_(std::move(p)), auth_(std::move(a)) {} std::string host_; std::string port_; std::string auth_; -} ConnInfo; +}; class AOFSender { public: diff --git a/tools/aof_to_pika/src/aof_info.cc b/tools/aof_to_pika/src/aof_info.cc index bb635a79b2..dc13fc472c 100644 --- a/tools/aof_to_pika/src/aof_info.cc +++ b/tools/aof_to_pika/src/aof_info.cc @@ -1,4 +1,4 @@ -#include "aof_info.h" +#include "include/aof_info.h" #include short aof_info_level_ = AOF_LOG_INFO; @@ -6,11 +6,16 @@ short aof_info_level_ = AOF_LOG_INFO; void set_info_level(int l) { aof_info_level_ = l; } void info_print(int l, const std::string& content) { - if (l > AOF_LOG_FATAL || l < AOF_LOG_DEBUG || content.empty()) return; + if (l > AOF_LOG_FATAL || l < AOF_LOG_DEBUG || content.empty()) { + return; + } - if (l < aof_info_level_) return; - if (l >= AOF_LOG_ERR) + if (l < aof_info_level_) { + return; + } + if (l >= AOF_LOG_ERR) { std::cerr << content << std::endl; - else + } else { std::cout << content << std::endl; + } } diff --git a/tools/aof_to_pika/src/aof_lock.cc b/tools/aof_to_pika/src/aof_lock.cc index bb57ef2004..fab0559c94 100644 --- a/tools/aof_to_pika/src/aof_lock.cc +++ b/tools/aof_to_pika/src/aof_lock.cc @@ -3,7 +3,7 @@ #include #include -#include "aof_lock.h" +#include "include/aof_lock.h" static void PthreadCall(const std::string& label, int result) { if (result != 0) { diff --git a/tools/aof_to_pika/src/aof_reader.cc b/tools/aof_to_pika/src/aof_reader.cc index 0eaf850be8..5853b951a6 100644 --- a/tools/aof_to_pika/src/aof_reader.cc +++ b/tools/aof_to_pika/src/aof_reader.cc @@ -1,13 +1,13 @@ -#include -#include -#include -#include #include +#include +#include +#include +#include #include #include #include #include -#include "aof_sender.h" +#include "include/aof_sender.h" #define VERSION "1.0.0" #define EOFMSG "EOAOF" @@ -36,11 +36,13 @@ static void split_send(const std::string& line) { sender->message_add(str_block); pos += MSG_BLOCK_MAX; } - if (pos != 0) send_buf_.assign(send_buf_.substr(pos)); + if (pos != 0) { + send_buf_.assign(send_buf_.substr(pos)); + } } static void print_cur_time() { - std::time_t now = time(0); + std::time_t now = time(nullptr); struct tm* time = localtime(&now); std::stringstream ss; ss << (time->tm_mon + 1) << '-' << time->tm_mday << " " << time->tm_hour << ":" << time->tm_min << "." @@ -91,14 +93,14 @@ static int file_read(const std::string& path) { return 0; } -static void* msg_process(void* p) { +static void* msg_process(void* p) { // NOLINT sender->process(); pthread_exit(nullptr); } -void intHandler(int sig) { +void intHandler(int sig) { // NOLINT LOG_ERR("Catched"); - std::time_t current = time(0); + std::time_t current = time(nullptr); double diff = difftime(current, begin_time); std::stringstream ss; ss << "Elapse time(s): " << diff; @@ -121,7 +123,10 @@ static void usage() { int main(int argc, char** argv) { char c; - std::string path, host, port, auth; + std::string path; + std::string host; + std::string port; + std::string auth; bool verbose = false; while (-1 != (c = getopt(argc, argv, "i:h:p:a:v"))) { switch (c) { @@ -163,14 +168,14 @@ int main(int argc, char** argv) { ifs.close(); sender = new AOFSender(); - if (false == sender->rconnect(host, port, auth)) { + if (!sender->rconnect(host, port, auth)) { LOG_ERR("Failed to connect remote server! host: " + host + " port : " + port); delete sender; return -1; } // We need output something when ctrl c catched - begin_time = time(0); + begin_time = time(nullptr); signal(SIGINT, intHandler); int ret = 0; diff --git a/tools/aof_to_pika/src/aof_sender.cc b/tools/aof_to_pika/src/aof_sender.cc index eeee43beb4..0c9533a8df 100644 --- a/tools/aof_to_pika/src/aof_sender.cc +++ b/tools/aof_to_pika/src/aof_sender.cc @@ -1,22 +1,27 @@ -#include #include #include #include -#include -#include #include #include #include +#include +#include +#include #include #include -#include "aof_info.h" -#include "aof_sender.h" +#include "include/aof_info.h" +#include "include/aof_sender.h" bool AOFSender::rconnect(const std::string& host, const std::string& port, const std::string& auth) { - if (host.empty() || port.empty()) return false; - int s = -1, ret; - struct addrinfo hints, *servinfo, *p; + if (host.empty() || port.empty()) { + return false; + } + int s = -1; + int ret; + struct addrinfo hints; + struct addrinfo* servinfo; + struct addrinfo* p; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; @@ -26,7 +31,9 @@ bool AOFSender::rconnect(const std::string& host, const std::string& port, const } for (p = servinfo; p != nullptr; p = p->ai_next) { - if ((s = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) continue; + if ((s = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { + continue; + } // connect if (connect(s, p->ai_addr, p->ai_addrlen) < 0) { close(s); @@ -58,12 +65,14 @@ AOFSender::~AOFSender() { buf_rcond_.SignalAll(); buf_wcond_.SignalAll(); buf_mutex_.Unlock(); - if (conn_info_ != nullptr) delete conn_info_; + delete conn_info_; close(sockfd_); } bool AOFSender::message_add(const std::string& message) { - if (message.empty()) return false; + if (message.empty()) { + return false; + } buf_mutex_.Lock(); while (read_buffer_.size() >= READ_BUF_MAX) { @@ -81,11 +90,11 @@ bool AOFSender::message_add(const std::string& message) { bool AOFSender::message_get_() { buf_mutex_.Lock(); - while (read_buffer_.size() == 0) { + while (read_buffer_.empty()) { LOG_DEBUG("Sender waiting for read buffer."); buf_rcond_.Wait(); // awake when the the wait send queue not empty } - if (read_buffer_.size() > 0) { + if (!read_buffer_.empty()) { to_send_ = read_buffer_.front(); read_buffer_.pop_front(); buf_wcond_.SignalAll(); @@ -102,21 +111,23 @@ bool AOFSender::process() { } char ibuf[1024 * 16]; memset(&ibuf, 0, sizeof(ibuf)); - long nsucc = 0, nfail = 0, inter = 0; + long nsucc = 0; + long nfail = 0; + long inter = 0; ; while (true) { int mask = RM_READBLE | RM_WRITABLE; mask = mask_wait_(sockfd_, mask, 1000); - if (mask & RM_RECONN) { + if ((mask & RM_RECONN) != 0) { close(sockfd_); - if (false == rconnect(conn_info_->host_, conn_info_->port_, conn_info_->auth_)) { + if (!rconnect(conn_info_->host_, conn_info_->port_, conn_info_->auth_)) { LOG_ERR("Failed to reconnect remote server! host: " + conn_info_->host_ + " port : " + conn_info_->port_ + " try again 1 second later!"); usleep(1000000); } - } else if (mask & RM_READBLE) { + } else if ((mask & RM_READBLE) != 0) { // Read from socket ssize_t count; std::string reply; @@ -124,7 +135,7 @@ bool AOFSender::process() { count = read(sockfd_, ibuf, sizeof(ibuf)); if (count == -1 && errno != EAGAIN && errno != EINTR) { LOG_ERR("Error reading from the server."); - return -1; + return (-1) != 0; } if (count > 0) { std::string tmp(ibuf); @@ -155,7 +166,7 @@ bool AOFSender::process() { // return -1; } } - } else if (mask & RM_WRITABLE) { + } else if ((mask & RM_WRITABLE) != 0) { // Read from queue if (to_send_.empty()) { message_get_(); @@ -169,20 +180,24 @@ bool AOFSender::process() { ssize_t nwritten = write(sockfd_, to_send_.c_str() + total_nwritten, to_send_.size() - total_nwritten); if (nwritten == -1) { - if (errno == EAGAIN) break; - if (errno == EINTR) continue; + if (errno == EAGAIN) { + break; + } + if (errno == EINTR) { + continue; + } LOG_ERR("Error writing to the server"); - return -1; + return (-1) != 0; } total_nwritten += nwritten; - } while ((unsigned)total_nwritten < to_send_.size()); + } while (static_cast(total_nwritten) < to_send_.size()); to_send_.assign(to_send_.substr(total_nwritten)); } } } - return 0; + return false; } int AOFSender::mask_wait_(int fd, int mask, long long milliseconds) { @@ -191,20 +206,30 @@ int AOFSender::mask_wait_(int fd, int mask, long long milliseconds) { memset(&pfd, 0, sizeof(pfd)); pfd.fd = fd; - if (mask & RM_READBLE) pfd.events |= POLLIN; - if (mask & RM_WRITABLE) pfd.events |= POLLOUT; + if ((mask & RM_READBLE) != 0) { + pfd.events |= POLLIN; + } + if ((mask & RM_WRITABLE) != 0) { + pfd.events |= POLLOUT; + } pfd.events |= POLLERR; pfd.events |= POLLHUP; switch (poll(&pfd, 1, milliseconds)) { case 1: - if (pfd.revents & POLLIN) retmask |= RM_READBLE; - if (pfd.revents & POLLOUT) retmask |= RM_WRITABLE; - if (pfd.revents & POLLERR || pfd.revents & POLLHUP) { + if ((pfd.revents & POLLIN) != 0) { + retmask |= RM_READBLE; + } + if ((pfd.revents & POLLOUT) != 0) { + retmask |= RM_WRITABLE; + } + if (((pfd.revents & POLLERR) != 0) || ((pfd.revents & POLLHUP) != 0)) { retmask |= RM_RECONN; close(fd); } - if (pfd.revents & POLLNVAL) retmask |= RM_RECONN; + if ((pfd.revents & POLLNVAL) != 0) { + retmask |= RM_RECONN; + } break; case -1: retmask |= RM_RECONN; @@ -235,22 +260,25 @@ bool AOFSender::set_nonblock_(int fd) { } bool AOFSender::check_succ_(const std::string& reply, long& succ, long& fail) { - if (reply.empty()) return false; + if (reply.empty()) { + return false; + } std::string line; std::stringstream ss(reply); int tmp_fail = fail; while (std::getline(ss, line)) { - if (line.empty() || line[0] == '\r') continue; - if (line.find("ERR") != std::string::npos) + if (line.empty() || line[0] == '\r') { + continue; + } + if (line.find("ERR") != std::string::npos) { fail++; - else + } else { succ++; + } } // skip last empty line - if (tmp_fail != fail) return false; - - return true; + return tmp_fail == fail; } void AOFSender::print_result() { diff --git a/tools/benchmark_client/benchmark_client.cc b/tools/benchmark_client/benchmark_client.cc index f969743a3f..8edf2d483f 100644 --- a/tools/benchmark_client/benchmark_client.cc +++ b/tools/benchmark_client/benchmark_client.cc @@ -96,7 +96,7 @@ void* ThreadMain(void* arg) { struct timeval timeout = {1, 500000}; // 1.5 seconds c = redisConnectWithTimeout(hostname.data(), port, timeout); - if (c == nullptr || c->err) { + if (!c || c->err) { if (c) { printf("Thread %lu, Connection error: %s\n", ta->tid, c->errstr); redisFree(c); @@ -111,7 +111,7 @@ void* ThreadMain(void* arg) { size_t auth_argv_len[2] = {4, password.size()}; res = reinterpret_cast(redisCommandArgv(c, 2, reinterpret_cast(auth_argv), reinterpret_cast(auth_argv_len))); - if (res == nullptr) { + if (!res) { printf("Thread %lu Auth Failed, Get reply Error\n", ta->tid); freeReplyObject(res); redisFree(c); @@ -132,7 +132,7 @@ void* ThreadMain(void* arg) { size_t select_argv_len[2] = {6, ta->table_name.size()}; res = reinterpret_cast(redisCommandArgv(c, 2, reinterpret_cast(select_argv), reinterpret_cast(select_argv_len))); - if (res == nullptr) { + if (!res) { printf("Thread %lu Select Table %s Failed, Get reply Error\n", ta->tid, ta->table_name.data()); freeReplyObject(res); redisFree(c); @@ -202,7 +202,7 @@ Status RunSetCommandPipeline(redisContext* c) { if (redisGetReply(c, reinterpret_cast(&res)) == REDIS_ERR) { return Status::Corruption("Redis Pipeline Get Reply Error"); } else { - if (res == nullptr || strcasecmp(res->str, "OK")) { + if (!res || strcasecmp(res->str, "OK")) { std::string res_str = "Exec command error: " + (res != nullptr ? std::string(res->str) : ""); freeReplyObject(res); return Status::Corruption(res_str); @@ -238,7 +238,7 @@ Status RunSetCommand(redisContext* c) { res = reinterpret_cast( redisCommandArgv(c, 3, reinterpret_cast(set_argv), reinterpret_cast(set_argvlen))); - if (res == nullptr || strcasecmp(res->str, "OK")) { + if (!res || strcasecmp(res->str, "OK")) { std::string res_str = "Exec command error: " + (res != nullptr ? std::string(res->str) : ""); freeReplyObject(res); return Status::Corruption(res_str); @@ -272,7 +272,7 @@ Status RunZAddCommand(redisContext* c) { res = reinterpret_cast(redisCommandArgv(c, 4, reinterpret_cast(zadd_argv), reinterpret_cast(zadd_argvlen))); - if (res == nullptr || res->integer == 0) { + if (!res || !res->integer) { std::string res_str = "Exec command error: " + (res != nullptr ? std::string(res->str) : ""); freeReplyObject(res); return Status::Corruption(res_str); diff --git a/tools/binlog_sender/binlog_consumer.cc b/tools/binlog_sender/binlog_consumer.cc index 71e1955847..b34b3c9bad 100644 --- a/tools/binlog_sender/binlog_consumer.cc +++ b/tools/binlog_sender/binlog_consumer.cc @@ -21,7 +21,7 @@ BinlogConsumer::~BinlogConsumer() { std::string BinlogConsumer::NewFileName(const std::string& name, const uint32_t current) { char buf[256]; snprintf(buf, sizeof(buf), "%s%u", name.c_str(), current); - return std::string(buf); + return {buf}; } bool BinlogConsumer::Init() { @@ -37,11 +37,7 @@ bool BinlogConsumer::Init() { current_filenum_ = first_filenum_; profile = NewFileName(filename_, current_filenum_); pstd::Status s = pstd::NewSequentialFile(profile, queue_); - if (!s.ok()) { - return false; - } else { - return true; - } + return s.ok(); } bool BinlogConsumer::trim() { @@ -63,7 +59,7 @@ bool BinlogConsumer::trim() { break; } offset = get_next(&is_error); - if (is_error == true) { + if (is_error) { return false; } res += offset; diff --git a/tools/binlog_sender/binlog_sender.cc b/tools/binlog_sender/binlog_sender.cc index ce6fcb44dd..351923b60b 100644 --- a/tools/binlog_sender/binlog_sender.cc +++ b/tools/binlog_sender/binlog_sender.cc @@ -7,9 +7,9 @@ #include "ctime" #include "iostream" -#include "stdint.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include #include "unistd.h" #include "net/include/net_cli.h" @@ -68,7 +68,7 @@ void Usage() { void TryToCommunicate() { cli = net::NewRedisCli(); cli->set_connect_timeout(3000); - Status net_s = cli->Connect(ip, port, ""); + pstd::Status net_s = cli->Connect(ip, port, ""); if (!net_s.ok()) { std::cout << "Connect failed " << net_s.ToString().c_str() << ", exit..." << std::endl; exit(-1); @@ -86,7 +86,7 @@ void TryToCommunicate() { net_s = cli->Send(&auth_cmd); net_s = cli->Recv(&argv); - if (argv.size() == 1 && !strcasecmp(argv[0].c_str(), ok.c_str())) { + if (argv.size() == 1 && (strcasecmp(argv[0].c_str(), ok.c_str()) == 0)) { std::cout << "Try communicate success..." << std::endl; } else { std::cout << "Auth failed..." << std::endl; @@ -105,7 +105,7 @@ void TryToCommunicate() { net_s = cli->Send(&ping_cmd); net_s = cli->Recv(&argv); - if (argv.size() == 1 && !strcasecmp(argv[0].c_str(), pong.c_str())) { + if (argv.size() == 1 && (strcasecmp(argv[0].c_str(), pong.c_str()) == 0)) { std::cout << "Try communicate success..." << std::endl; } else { std::cout << "Ping failed..." << std::endl; @@ -167,7 +167,8 @@ int main(int argc, char* argv[]) { exit(-1); } - uint32_t tv_start, tv_end; + uint32_t tv_start; + uint32_t tv_end; struct tm tm; time_t timet; strptime(start_time_str.c_str(), "%Y-%m-%d %H:%M:%S", &tm); @@ -206,7 +207,7 @@ int main(int argc, char* argv[]) { if (PikaBinlogTransverter::BinlogDecode(TypeFirst, scratch, &binlog_item)) { std::string redis_cmd = binlog_item.content(); if (tv_start <= binlog_item.exec_time() && binlog_item.exec_time() <= tv_end) { - Status net_s = cli->Send(&redis_cmd); + pstd::Status net_s = cli->Send(&redis_cmd); if (net_s.ok()) { net_s = cli->Recv(nullptr); if (net_s.ok()) { diff --git a/tools/binlog_sender/binlog_transverter.cc b/tools/binlog_sender/binlog_transverter.cc index dae9dc1120..194282c025 100644 --- a/tools/binlog_sender/binlog_transverter.cc +++ b/tools/binlog_sender/binlog_transverter.cc @@ -35,13 +35,13 @@ std::string BinlogItem::ToString() const { str.append(",filenum: " + std::to_string(filenum_)); str.append(",offset: " + std::to_string(offset_)); str.append("\ncontent: "); - for (size_t idx = 0; idx < content_.size(); ++idx) { - if (content_[idx] == '\n') { + for (char idx : content_) { + if (idx == '\n') { str.append("\\n"); - } else if (content_[idx] == '\r') { + } else if (idx == '\r') { str.append("\\r"); } else { - str.append(1, content_[idx]); + str.append(1, idx); } } str.append("\n"); diff --git a/tools/binlog_sender/progress_thread.cc b/tools/binlog_sender/progress_thread.cc index 7698728652..a410f3e20c 100644 --- a/tools/binlog_sender/progress_thread.cc +++ b/tools/binlog_sender/progress_thread.cc @@ -9,8 +9,8 @@ ProgressThread::ProgressThread(BinlogConsumer* binlog_consumer) : binlog_consume void* ProgressThread::ThreadMain() { while (!should_stop_) { - printf("\rSending binlog, current file num: %d, offset: %9ld", binlog_consumer_->current_filenum(), - binlog_consumer_->current_offset()); + printf("\rSending binlog, current file num: %d, offset: %9lu", binlog_consumer_->current_filenum(), + binlog_consumer_->current_offset()); // NOLINT fflush(stdout); } printf("\n"); diff --git a/tools/binlog_sender/utils.cc b/tools/binlog_sender/utils.cc index 27eac19abd..ce7fc46994 100644 --- a/tools/binlog_sender/utils.cc +++ b/tools/binlog_sender/utils.cc @@ -8,17 +8,13 @@ bool Exists(const std::string& base, const std::string& pattern) { std::string::size_type n; n = base.find(pattern); - if (n == std::string::npos) { - return false; - } else { - return true; - } + return n != std::string::npos; } bool CheckFilesStr(const std::string& files_str) { int32_t neg_count = 0; for (const auto& c : files_str) { - if (isdigit(c)) { + if (isdigit(c) != 0) { continue; } else if (c == NEG_CHAR) { neg_count++; @@ -26,13 +22,13 @@ bool CheckFilesStr(const std::string& files_str) { return false; } } - return neg_count <= 1 ? true : false; + return neg_count <= 1; } bool GetFileList(const std::string& files_str, std::vector* files) { std::string::size_type pos; if (Exists(files_str, NEG_STR)) { - pos = files_str.find(NEG_STR); + pos = files_str.find('-'); uint32_t start_file = atoi(files_str.substr(0, pos).data()); uint32_t end_file = atoi(files_str.substr(pos + 1).data()); for (uint32_t file_num = start_file; file_num <= end_file; ++file_num) { @@ -46,8 +42,8 @@ bool GetFileList(const std::string& files_str, std::vector* files) { bool CheckBinlogExists(const std::string& binlog_path, const std::vector& files) { std::string filename = binlog_path + WRITE2FILE; - for (size_t idx = 0; idx < files.size(); ++idx) { - std::string binlog_file = filename + std::to_string(files[idx]); + for (unsigned int file : files) { + std::string binlog_file = filename + std::to_string(file); if (!pstd::FileExists(binlog_file)) { return false; } diff --git a/tools/manifest_generator/include/pika_binlog.h b/tools/manifest_generator/include/pika_binlog.h index 56186b7371..db8dfcf73c 100644 --- a/tools/manifest_generator/include/pika_binlog.h +++ b/tools/manifest_generator/include/pika_binlog.h @@ -15,7 +15,7 @@ using pstd::Slice; using pstd::Status; -std::string NewFileName(const std::string name, const uint32_t current); +std::string NewFileName(const std::string& name, const uint32_t current); class Version { public: @@ -48,7 +48,7 @@ class Version { class Binlog { public: - Binlog(const std::string& Binlog_path, const int file_size = 100 * 1024 * 1024); + Binlog(std::string Binlog_path, const int file_size = 100 * 1024 * 1024); ~Binlog(); void Lock() { mutex_.lock(); } @@ -61,7 +61,7 @@ class Binlog { /* * Set Producer pro_num and pro_offset with lock */ - Status SetProducerStatus(uint32_t filenum, uint64_t pro_offset); + Status SetProducerStatus(uint32_t pro_num, uint64_t pro_offset); static Status AppendBlank(pstd::WritableFile* file, uint64_t len); diff --git a/tools/manifest_generator/manifest_generator.cc b/tools/manifest_generator/manifest_generator.cc index c244498cab..40ccaf95fa 100644 --- a/tools/manifest_generator/manifest_generator.cc +++ b/tools/manifest_generator/manifest_generator.cc @@ -3,7 +3,7 @@ // 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 #include @@ -31,15 +31,19 @@ void ParseInfoFile(const std::string& path) { std::cout << "Failed to open info file " << info_file; exit(-1); } - std::string line, master_ip; + std::string line; + std::string master_ip; int lineno = 0; - int64_t filenum = 0, offset = 0, tmp = 0, master_port = 0; + int64_t filenum = 0; + int64_t offset = 0; + int64_t tmp = 0; + int64_t master_port = 0; while (std::getline(is, line)) { lineno++; if (lineno == 2) { master_ip = line; } else if (lineno > 2 && lineno < 6) { - if (!pstd::string2int(line.data(), line.size(), &tmp) || tmp < 0) { + if ((pstd::string2int(line.data(), line.size(), &tmp) == 0) || tmp < 0) { std::cout << "Format of info file " << info_file << " error, line : " << line; is.close(); exit(-1); diff --git a/tools/manifest_generator/pika_binlog.cc b/tools/manifest_generator/pika_binlog.cc index 8515ef25b4..e710e0d62d 100644 --- a/tools/manifest_generator/pika_binlog.cc +++ b/tools/manifest_generator/pika_binlog.cc @@ -4,15 +4,16 @@ // of patent rights can be found in the PATENTS file in the same directory. #include +#include #include "include/pika_binlog.h" #include -std::string NewFileName(const std::string name, const uint32_t current) { +std::string NewFileName(const std::string& name, const uint32_t current) { char buf[256]; snprintf(buf, sizeof(buf), "%s%u", name.c_str(), current); - return std::string(buf); + return {buf}; } /* @@ -35,10 +36,10 @@ Status Version::StableSave() { Status Version::Init() { Status s; - if (save_->GetData() != nullptr) { - memcpy((char*)(&pro_num_), save_->GetData(), sizeof(uint32_t)); - memcpy((char*)(&pro_offset_), save_->GetData() + 4, sizeof(uint64_t)); - memcpy((char*)(&logic_id_), save_->GetData() + 12, sizeof(uint64_t)); + if (save_->GetData()) { + memcpy(reinterpret_cast(&pro_num_), save_->GetData(), sizeof(uint32_t)); + memcpy(reinterpret_cast(&pro_offset_), save_->GetData() + 4, sizeof(uint64_t)); + memcpy(reinterpret_cast(&logic_id_), save_->GetData() + 12, sizeof(uint64_t)); return Status::OK(); } else { return Status::Corruption("version init error"); @@ -48,7 +49,7 @@ Status Version::Init() { /* * Binlog */ -Binlog::Binlog(const std::string& binlog_path, const int file_size) +Binlog::Binlog(std::string binlog_path, const int file_size) : consumer_num_(0), version_(nullptr), queue_(nullptr), @@ -56,7 +57,7 @@ Binlog::Binlog(const std::string& binlog_path, const int file_size) pro_num_(0), pool_(nullptr), exit_all_consume_(false), - binlog_path_(binlog_path), + binlog_path_(std::move(binlog_path)), file_size_(file_size) { // To intergrate with old version, we don't set mmap file size to 100M; // pstd::SetMmapBoundSize(file_size); @@ -132,7 +133,7 @@ Status Binlog::GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint64 *filenum = version_->pro_num_; *pro_offset = version_->pro_offset_; - if (logic_id != nullptr) { + if (logic_id) { *logic_id = version_->logic_id_; } @@ -272,7 +273,7 @@ Status Binlog::AppendBlank(pstd::WritableFile* file, uint64_t len) { if (len % kBlockSize < kHeaderSize) { n = 0; } else { - n = (uint32_t)((len % kBlockSize) - kHeaderSize); + n = static_cast((len % kBlockSize) - kHeaderSize); } char buf[kBlockSize]; diff --git a/tools/pika-port/pika_port_3/binlog_receiver_thread.cc b/tools/pika-port/pika_port_3/binlog_receiver_thread.cc index 5405a67f0f..5d69f47f81 100644 --- a/tools/pika-port/pika_port_3/binlog_receiver_thread.cc +++ b/tools/pika-port/pika_port_3/binlog_receiver_thread.cc @@ -14,7 +14,7 @@ extern PikaPort* g_pika_port; -BinlogReceiverThread::BinlogReceiverThread(std::string host, int port, int cron_interval) +BinlogReceiverThread::BinlogReceiverThread(const std::string& host, int port, int cron_interval) : conn_factory_(this), handles_(this) { // thread_rep_ = net::NewHolyThread(port, &conn_factory_, // cron_interval, &handles_); diff --git a/tools/pika-port/pika_port_3/binlog_receiver_thread.h b/tools/pika-port/pika_port_3/binlog_receiver_thread.h index 40560b5961..b567b633e8 100644 --- a/tools/pika-port/pika_port_3/binlog_receiver_thread.h +++ b/tools/pika-port/pika_port_3/binlog_receiver_thread.h @@ -16,7 +16,7 @@ class BinlogReceiverThread { public: - BinlogReceiverThread(std::string host, int port, int cron_interval = 0); + BinlogReceiverThread(const std::string& host, int port, int cron_interval = 0); virtual ~BinlogReceiverThread(); int StartThread(); diff --git a/tools/pika-port/pika_port_3/binlog_transverter.cc b/tools/pika-port/pika_port_3/binlog_transverter.cc index fc2a95e5c3..3500eaa9f6 100644 --- a/tools/pika-port/pika_port_3/binlog_transverter.cc +++ b/tools/pika-port/pika_port_3/binlog_transverter.cc @@ -36,13 +36,13 @@ std::string PortBinlogItem::ToString() const { str.append(",filenum: " + std::to_string(filenum_)); str.append(",offset: " + std::to_string(offset_)); str.append("\ncontent: "); - for (size_t idx = 0; idx < content_.size(); ++idx) { - if (content_[idx] == '\n') { + for (char idx : content_) { + if (idx == '\n') { str.append("\\n"); - } else if (content_[idx] == '\r') { + } else if (idx == '\r') { str.append("\\r"); } else { - str.append(1, content_[idx]); + str.append(1, idx); } } str.append("\n"); diff --git a/tools/pika-port/pika_port_3/const.cc b/tools/pika-port/pika_port_3/const.cc index 85d8ce0dbc..2f9a67ba54 100644 --- a/tools/pika-port/pika_port_3/const.cc +++ b/tools/pika-port/pika_port_3/const.cc @@ -58,23 +58,23 @@ std::string PikaRole(int role) { const char* GetDBTypeString(int type) { switch (type) { - case int(storage::kStrings): { + case static_cast(storage::kStrings): { return "storage::kStrings"; } - case int(storage::kLists): { + case static_cast(storage::kLists): { return "storage::kLists"; } - case int(storage::kHashes): { + case static_cast(storage::kHashes): { return "storage::kHashes"; } - case int(storage::kSets): { + case static_cast(storage::kSets): { return "storage::kSets"; } - case int(storage::kZSets): { + case static_cast(storage::kZSets): { return "storage::kZSets"; } diff --git a/tools/pika-port/pika_port_3/main.cc b/tools/pika-port/pika_port_3/main.cc index c4f137869d..268bc33f8e 100644 --- a/tools/pika-port/pika_port_3/main.cc +++ b/tools/pika-port/pika_port_3/main.cc @@ -5,10 +5,10 @@ // #include #include -#include #include #include #include +#include #include #include @@ -47,7 +47,8 @@ static void createPidFile(const char* file) { } static void daemonize() { - if (fork() != 0) exit(0); /* parent exits */ + if (fork() != 0) { exit(0); /* parent exits */ +} setsid(); /* create a new session */ } @@ -158,7 +159,7 @@ int main(int argc, char* argv[]) { case 'p': snprintf(buf, 1024, "%s", optarg); pstd::string2int(buf, strlen(buf), &(num)); - g_conf.local_port = int(num); + g_conf.local_port = static_cast(num); break; case 'i': snprintf(buf, 1024, "%s", optarg); @@ -167,7 +168,7 @@ int main(int argc, char* argv[]) { case 'o': snprintf(buf, 1024, "%s", optarg); pstd::string2int(buf, strlen(buf), &(num)); - g_conf.master_port = int(num); + g_conf.master_port = static_cast(num); break; case 'm': snprintf(buf, 1024, "%s", optarg); @@ -176,12 +177,12 @@ int main(int argc, char* argv[]) { case 'n': snprintf(buf, 1024, "%s", optarg); pstd::string2int(buf, strlen(buf), &(num)); - g_conf.forward_port = int(num); + g_conf.forward_port = static_cast(num); break; case 'x': snprintf(buf, 1024, "%s", optarg); pstd::string2int(buf, strlen(buf), &(num)); - g_conf.forward_thread_num = int(num); + g_conf.forward_thread_num = static_cast(num); break; case 'y': snprintf(buf, 1024, "%s", optarg); @@ -190,18 +191,18 @@ int main(int argc, char* argv[]) { case 'z': snprintf(buf, 1024, "%s", optarg); pstd::string2int(buf, strlen(buf), &(num)); - g_conf.wait_bgsave_timeout = time_t(num); + g_conf.wait_bgsave_timeout = static_cast(num); break; case 'f': snprintf(buf, 1024, "%s", optarg); pstd::string2int(buf, strlen(buf), &(num)); - g_conf.filenum = (size_t)(num); + g_conf.filenum = static_cast(num); break; case 's': snprintf(buf, 1024, "%s", optarg); pstd::string2int(buf, strlen(buf), &(num)); - g_conf.offset = (size_t)(num); + g_conf.offset = static_cast(num); break; case 'w': snprintf(buf, 1024, "%s", optarg); @@ -225,7 +226,7 @@ int main(int argc, char* argv[]) { case 'b': snprintf(buf, 1024, "%s", optarg); pstd::string2int(buf, strlen(buf), &(num)); - g_conf.sync_batch_num = (size_t)(num); + g_conf.sync_batch_num = static_cast(num); break; case 'e': g_conf.exit_if_dbsync = true; diff --git a/tools/pika-port/pika_port_3/master_conn.cc b/tools/pika-port/pika_port_3/master_conn.cc index ed3910d6ed..fbb7cb3c66 100644 --- a/tools/pika-port/pika_port_3/master_conn.cc +++ b/tools/pika-port/pika_port_3/master_conn.cc @@ -5,6 +5,8 @@ #include +#include + #include "pstd/include/pstd_coding.h" #include "pstd/include/pstd_string.h" @@ -17,7 +19,7 @@ extern PikaPort* g_pika_port; MasterConn::MasterConn(int fd, std::string ip_port, void* worker_specific_data) - : NetConn(fd, ip_port, nullptr), + : NetConn(fd, std::move(ip_port), nullptr), rbuf_(nullptr), rbuf_len_(0), rbuf_size_(REDIS_IOBUF_LEN), @@ -102,7 +104,7 @@ int32_t MasterConn::GetNextNum(const std::string& content, int32_t left_pos, int // 012 3 // num range [left_pos + 1, right_pos - 2] assert(left_pos < right_pos); - if (pstd::string2int(content.data() + left_pos + 1, right_pos - left_pos - 2, value)) { + if (pstd::string2int(content.data() + left_pos + 1, right_pos - left_pos - 2, value) != 0) { return 0; } return -1; @@ -113,7 +115,8 @@ net::ReadStatus MasterConn::ParseRedisRESPArray(const std::string& content, net: int32_t pos = 0; int32_t next_parse_pos = 0; int32_t content_len = content.size(); - long multibulk_len = 0, bulk_len = 0; + long multibulk_len = 0; + long bulk_len = 0; if (content.empty() || content[0] != '*') { LOG(INFO) << "Content empty() or the first character of the redis protocol string not equal '*'"; return net::kParseError; @@ -133,7 +136,7 @@ net::ReadStatus MasterConn::ParseRedisRESPArray(const std::string& content, net: // 012 3 4567 8 argv->clear(); - while (multibulk_len) { + while (multibulk_len != 0) { if (content[next_parse_pos] != '$') { LOG(INFO) << "The first charactor of the RESP type element not equal '$'"; return net::kParseError; diff --git a/tools/pika-port/pika_port_3/master_conn.h b/tools/pika-port/pika_port_3/master_conn.h index c0bf37e14f..52a74702ac 100644 --- a/tools/pika-port/pika_port_3/master_conn.h +++ b/tools/pika-port/pika_port_3/master_conn.h @@ -33,11 +33,11 @@ class MasterConn : public net::NetConn { net::ReadStatus ReadRaw(uint32_t count); net::ReadStatus ReadHeader(); - net::ReadStatus ReadBody(uint32_t body_lenth); + net::ReadStatus ReadBody(uint32_t body_length); void ResetStatus(); int32_t FindNextSeparators(const std::string& content, int32_t next_parse_pos); - int32_t GetNextNum(const std::string& content, int32_t next_parse_pos, int32_t pos, long* value); + int32_t GetNextNum(const std::string& content, int32_t left_pos, int32_t pos, long* value); net::ReadStatus ParseRedisRESPArray(const std::string& content, net::RedisCmdArgsType* argv); bool ProcessAuth(const net::RedisCmdArgsType& argv); diff --git a/tools/pika-port/pika_port_3/migrator_thread.cc b/tools/pika-port/pika_port_3/migrator_thread.cc index 050b15689f..f1bb206473 100644 --- a/tools/pika-port/pika_port_3/migrator_thread.cc +++ b/tools/pika-port/pika_port_3/migrator_thread.cc @@ -18,10 +18,10 @@ const int64_t MAX_BATCH_NUM = 30000; -MigratorThread::~MigratorThread() {} +MigratorThread::~MigratorThread() = default; void MigratorThread::MigrateStringsDB() { - storage::RedisStrings* db = (storage::RedisStrings*)(db_); + auto db = static_cast(db_); rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; @@ -39,7 +39,7 @@ void MigratorThread::MigrateStringsDB() { for (iter->SeekToFirst(); !should_exit_ && iter->Valid(); iter->Next()) { storage::ParsedStringsValue parsed_strings_value(iter->value()); int32_t ttl = 0; - int64_t ts = (int64_t)(parsed_strings_value.timestamp()); + auto ts = static_cast(parsed_strings_value.timestamp()); if (ts != 0) { int64_t diff = ts - curtime; ttl = diff > 0 ? diff : -1; @@ -76,7 +76,7 @@ void MigratorThread::MigrateStringsDB() { } void MigratorThread::MigrateListsDB() { - storage::RedisLists* db = (storage::RedisLists*)(db_); + auto db = static_cast(db_); std::string start_key; std::string next_key; @@ -97,12 +97,12 @@ void MigratorThread::MigrateListsDB() { fin = db->Scan(start_key, pattern, &keys, &count, &next_key); // LOG(INFO) << "batch count: " << count << ", fin: " << fin << ", keys.size(): " << keys.size() << ", next_key: " // << next_key; - if (fin && keys.size() == 0) { + if (fin && keys.empty()) { break; } start_key = next_key; - for (auto k : keys) { + for (const auto& k : keys) { if (should_exit_) { break; } @@ -122,7 +122,7 @@ void MigratorThread::MigrateListsDB() { argv.push_back("RPUSH"); argv.push_back(k); - for (auto e : list) { + for (const auto& e : list) { // PlusNum(); argv.push_back(e); } @@ -159,7 +159,7 @@ void MigratorThread::MigrateListsDB() { } void MigratorThread::MigrateHashesDB() { - storage::RedisHashes* db = (storage::RedisHashes*)(db_); + auto db = static_cast(db_); std::string start_key; std::string next_key; @@ -177,12 +177,12 @@ void MigratorThread::MigrateHashesDB() { int64_t count = batch_count; std::vector keys; fin = db->Scan(start_key, pattern, &keys, &count, &next_key); - if (fin && keys.size() == 0) { + if (fin && keys.empty()) { break; } start_key = next_key; - for (auto k : keys) { + for (const auto& k : keys) { if (should_exit_) { break; } @@ -230,7 +230,7 @@ void MigratorThread::MigrateHashesDB() { } void MigratorThread::MigrateSetsDB() { - storage::RedisSets* db = (storage::RedisSets*)(db_); + auto db = static_cast(db_); std::string start_key; std::string next_key; @@ -248,12 +248,12 @@ void MigratorThread::MigrateSetsDB() { int64_t count = batch_count; std::vector keys; fin = db->Scan(start_key, pattern, &keys, &count, &next_key); - if (fin && keys.size() == 0) { + if (fin && keys.empty()) { break; } start_key = next_key; - for (auto k : keys) { + for (const auto& k : keys) { if (should_exit_) { break; } @@ -298,7 +298,7 @@ void MigratorThread::MigrateSetsDB() { } void MigratorThread::MigrateZsetsDB() { - storage::RedisZSets* db = (storage::RedisZSets*)(db_); + auto db = static_cast(db_); std::string start_key; std::string next_key; @@ -316,12 +316,12 @@ void MigratorThread::MigrateZsetsDB() { int64_t count = batch_count; std::vector keys; fin = db->Scan(start_key, pattern, &keys, &count, &next_key); - if (fin && keys.size() == 0) { + if (fin && keys.empty()) { break; } start_key = next_key; - for (auto k : keys) { + for (const auto& k : keys) { if (should_exit_) { break; } @@ -368,28 +368,28 @@ void MigratorThread::MigrateZsetsDB() { } void MigratorThread::MigrateDB() { - switch (int(type_)) { - case int(storage::kStrings): { + switch (static_cast(type_)) { + case static_cast(storage::kStrings): { MigrateStringsDB(); break; } - case int(storage::kLists): { + case static_cast(storage::kLists): { MigrateListsDB(); break; } - case int(storage::kHashes): { + case static_cast(storage::kHashes): { MigrateHashesDB(); break; } - case int(storage::kSets): { + case static_cast(storage::kSets): { MigrateSetsDB(); break; } - case int(storage::kZSets): { + case static_cast(storage::kZSets): { MigrateZsetsDB(); break; } @@ -404,7 +404,7 @@ void MigratorThread::MigrateDB() { void MigratorThread::DispatchKey(const std::string& command, const std::string& key) { thread_index_ = (thread_index_ + 1) % thread_num_; size_t idx = thread_index_; - if (key.size()) { // no empty + if (!key.empty()) { // no empty idx = std::hash()(key) % thread_num_; } (*senders_)[idx]->LoadKey(command); diff --git a/tools/pika-port/pika_port_3/pika_binlog.cc b/tools/pika-port/pika_port_3/pika_binlog.cc index 4212acc436..37562c2591 100644 --- a/tools/pika-port/pika_port_3/pika_binlog.cc +++ b/tools/pika-port/pika_port_3/pika_binlog.cc @@ -5,21 +5,22 @@ #include "pika_binlog.h" -#include -#include #include #include +#include +#include #include #include +#include #include #include "pstd/include/pstd_mutex.h" -std::string NewFileName(const std::string name, const uint32_t current) { +std::string NewFileName(const std::string& name, const uint32_t current) { char buf[256]; snprintf(buf, sizeof(buf), "%s%u", name.c_str(), current); - return std::string(buf); + return {buf}; } /* @@ -46,10 +47,10 @@ Status Version::StableSave() { Status Version::Init() { Status s; - if (save_->GetData() != nullptr) { - memcpy((char*)(&pro_num_), save_->GetData(), sizeof(uint32_t)); - memcpy((char*)(&pro_offset_), save_->GetData() + 4, sizeof(uint64_t)); - memcpy((char*)(&logic_id_), save_->GetData() + 12, sizeof(uint64_t)); + if (save_->GetData()) { + memcpy(reinterpret_cast(&pro_num_), save_->GetData(), sizeof(uint32_t)); + memcpy(reinterpret_cast(&pro_offset_), save_->GetData() + 4, sizeof(uint64_t)); + memcpy(reinterpret_cast(&logic_id_), save_->GetData() + 12, sizeof(uint64_t)); // memcpy((char*)(&double_master_recv_num_), save_->GetData() + 20, sizeof(uint32_t)); // memcpy((char*)(&double_master_recv_offset_), save_->GetData() + 24, sizeof(uint64_t)); return Status::OK(); @@ -61,7 +62,7 @@ Status Version::Init() { /* * Binlog */ -Binlog::Binlog(const std::string& binlog_path, const int file_size) +Binlog::Binlog(std::string binlog_path, const int file_size) : consumer_num_(0), version_(nullptr), queue_(nullptr), @@ -69,7 +70,7 @@ Binlog::Binlog(const std::string& binlog_path, const int file_size) pro_num_(0), pool_(nullptr), exit_all_consume_(false), - binlog_path_(binlog_path), + binlog_path_(std::move(binlog_path)), file_size_(file_size) { // To intergrate with old version, we don't set mmap file size to 100M; // pstd::SetMmapBoundSize(file_size); @@ -146,7 +147,7 @@ Status Binlog::GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint64 *filenum = version_->pro_num_; *pro_offset = version_->pro_offset_; - if (logic_id != nullptr) { + if (logic_id) { *logic_id = version_->logic_id_; } @@ -286,7 +287,7 @@ Status Binlog::AppendBlank(pstd::WritableFile* file, uint64_t len) { if (len % kBlockSize < kHeaderSize) { n = 0; } else { - n = (uint32_t)((len % kBlockSize) - kHeaderSize); + n = static_cast((len % kBlockSize) - kHeaderSize); } char buf[kBlockSize]; diff --git a/tools/pika-port/pika_port_3/pika_binlog.h b/tools/pika-port/pika_port_3/pika_binlog.h index 098aafb04e..a6e5910d71 100644 --- a/tools/pika-port/pika_port_3/pika_binlog.h +++ b/tools/pika-port/pika_port_3/pika_binlog.h @@ -25,13 +25,13 @@ using pstd::Slice; using pstd::Status; -std::string NewFileName(const std::string name, const uint32_t current); +std::string NewFileName(const std::string& name, const uint32_t current); class Version; class Binlog { public: - Binlog(const std::string& Binlog_path, const int file_size = 100 * 1024 * 1024); + Binlog(std::string Binlog_path, const int file_size = 100 * 1024 * 1024); ~Binlog(); Status Put(const std::string& item); @@ -41,7 +41,7 @@ class Binlog { /* * Set Producer pro_num and pro_offset with lock */ - Status SetProducerStatus(uint32_t filenum, uint64_t pro_offset); + Status SetProducerStatus(uint32_t pro_num, uint64_t pro_offset); static Status AppendBlank(pstd::WritableFile* file, uint64_t len); diff --git a/tools/pika-port/pika_port_3/pika_port.cc b/tools/pika-port/pika_port_3/pika_port.cc index 60dd01561c..6604e4af8f 100644 --- a/tools/pika-port/pika_port_3/pika_port.cc +++ b/tools/pika-port/pika_port_3/pika_port.cc @@ -4,11 +4,11 @@ // of patent rights can be found in the PATENTS file in the same directory. #include -#include #include #include #include #include +#include #include #include @@ -38,7 +38,7 @@ PikaPort::PikaPort(std::string& master_ip, int master_port, std::string& passwd) // Create redis sender size_t thread_num = g_conf.forward_thread_num; for (size_t i = 0; i < thread_num; i++) { - senders_.emplace_back(new RedisSender(int(i), g_conf.forward_ip, g_conf.forward_port, g_conf.forward_passwd)); + senders_.emplace_back(new RedisSender(static_cast(i), g_conf.forward_ip, g_conf.forward_port, g_conf.forward_passwd)); } // Create thread @@ -127,7 +127,7 @@ int PikaPort::SendRedisCommand(const std::string& command, const std::string& ke bool PikaPort::SetMaster(std::string& master_ip, int master_port) { std::lock_guard l(state_protector_); - if ((role_ ^ PIKA_ROLE_SLAVE) && repl_state_ == PIKA_REPL_NO_CONNECT) { + if (((role_ ^ PIKA_ROLE_SLAVE) != 0) && repl_state_ == PIKA_REPL_NO_CONNECT) { master_ip_ = master_ip; master_port_ = master_port; // role_ |= PIKA_ROLE_SLAVE; @@ -145,10 +145,7 @@ bool PikaPort::ShouldConnectMaster() { // LOG(INFO) << "repl_state: " << PikaState(repl_state_) // << " role: " << PikaRole(role_) // << " master_connection: " << master_connection_; - if (repl_state_ == PIKA_REPL_CONNECT) { - return true; - } - return false; + return repl_state_ == PIKA_REPL_CONNECT; } void PikaPort::ConnectMasterDone() { @@ -162,11 +159,7 @@ bool PikaPort::ShouldStartPingMaster() { std::shared_lock l(state_protector_); LOG(INFO) << "ShouldStartPingMaster: master_connection " << master_connection_ << ", repl_state " << PikaState(repl_state_); - if (repl_state_ == PIKA_REPL_CONNECTING && master_connection_ < 2) { - return true; - } - - return false; + return repl_state_ == PIKA_REPL_CONNECTING && master_connection_ < 2; } void PikaPort::MinusMasterConnection() { @@ -174,7 +167,7 @@ void PikaPort::MinusMasterConnection() { if (master_connection_ > 0) { if ((--master_connection_) <= 0) { // two connection with master has been deleted - if ((role_ & PIKA_ROLE_SLAVE) || (role_ & PIKA_ROLE_PORT)) { + if (((role_ & PIKA_ROLE_SLAVE) != 0) || ((role_ & PIKA_ROLE_PORT) != 0)) { // not change by slaveof no one, so set repl_state = PIKA_REPL_CONNECT, continue to connect master repl_state_ = PIKA_REPL_CONNECT; } else { @@ -202,10 +195,7 @@ bool PikaPort::ShouldAccessConnAsMaster(const std::string& ip) { std::shared_lock l(state_protector_); LOG(INFO) << "ShouldAccessConnAsMaster, repl_state_: " << PikaState(repl_state_) << ", ip: " << ip << ", master_ip: " << master_ip_; - if (repl_state_ != PIKA_REPL_NO_CONNECT && ip == master_ip_) { - return true; - } - return false; + return repl_state_ != PIKA_REPL_NO_CONNECT && ip == master_ip_; } void PikaPort::RemoveMaster() { @@ -216,7 +206,7 @@ void PikaPort::RemoveMaster() { master_ip_ = ""; master_port_ = -1; } - if (ping_thread_ != nullptr) { + if (ping_thread_) { int err = ping_thread_->StopThread(); if (err != 0) { LOG(WARNING) << "can't join thread " << strerror(err); @@ -228,10 +218,7 @@ void PikaPort::RemoveMaster() { bool PikaPort::IsWaitingDBSync() { std::shared_lock l(state_protector_); - if (repl_state_ == PIKA_REPL_WAIT_DBSYNC) { - return true; - } - return false; + return repl_state_ == PIKA_REPL_WAIT_DBSYNC; } void PikaPort::NeedWaitDBSync() { diff --git a/tools/pika-port/pika_port_3/pika_sender.cc b/tools/pika-port/pika_port_3/pika_sender.cc index 50404c59be..d36568cf4e 100644 --- a/tools/pika-port/pika_port_3/pika_sender.cc +++ b/tools/pika-port/pika_port_3/pika_sender.cc @@ -1,14 +1,15 @@ #include #include +#include #include "const.h" #include "pika_sender.h" #include "pstd/include/xdebug.h" PikaSender::PikaSender(std::string ip, int64_t port, std::string password) - : cli_(nullptr), ip_(ip), port_(port), password_(password), should_exit_(false), cnt_(0), elements_(0) {} + : cli_(nullptr), ip_(std::move(ip)), port_(port), password_(std::move(password)), should_exit_(false), cnt_(0), elements_(0) {} -PikaSender::~PikaSender() {} +PikaSender::~PikaSender() = default; int PikaSender::QueueSize() { std::lock_guard l(keys_mutex_); @@ -21,7 +22,7 @@ void PikaSender::Stop() { } void PikaSender::ConnectRedis() { - while (cli_ == nullptr) { + while (!cli_) { // Connect to redis cli_ = net::NewRedisCli(); cli_->set_connect_timeout(1000); @@ -38,7 +39,8 @@ void PikaSender::ConnectRedis() { // Authentication if (!password_.empty()) { - net::RedisCmdArgsType argv, resp; + net::RedisCmdArgsType argv; + net::RedisCmdArgsType resp; std::string cmd; argv.push_back("AUTH"); @@ -65,7 +67,8 @@ void PikaSender::ConnectRedis() { } } else { // If forget to input password - net::RedisCmdArgsType argv, resp; + net::RedisCmdArgsType argv; + net::RedisCmdArgsType resp; std::string cmd; argv.push_back("PING"); @@ -128,7 +131,7 @@ void PikaSender::SendCommand(std::string& command, const std::string& key) { void* PikaSender::ThreadMain() { LOG(INFO) << "Start sender thread..."; - if (cli_ == nullptr) { + if (!cli_) { ConnectRedis(); } @@ -136,7 +139,7 @@ void* PikaSender::ThreadMain() { { std::unique_lock lock(keys_mutex_); signal_.wait_for(lock, std::chrono::milliseconds(200), - [this]() { return keys_queue_.size() != 0 || should_exit_; }); + [this]() { return !keys_queue_.empty() || should_exit_; }); } if (QueueSize() == 0 && should_exit_) { diff --git a/tools/pika-port/pika_port_3/pika_sender.h b/tools/pika-port/pika_port_3/pika_sender.h index fd1251eff1..851ae521c9 100644 --- a/tools/pika-port/pika_port_3/pika_sender.h +++ b/tools/pika-port/pika_port_3/pika_sender.h @@ -17,7 +17,7 @@ class PikaSender : public net::Thread { public: PikaSender(std::string ip, int64_t port, std::string password); virtual ~PikaSender(); - void LoadKey(const std::string& cmd); + void LoadKey(const std::string& key); void Stop(); int64_t elements() { return elements_; } diff --git a/tools/pika-port/pika_port_3/redis_sender.cc b/tools/pika-port/pika_port_3/redis_sender.cc index 191a60a33e..204a3d2362 100644 --- a/tools/pika-port/pika_port_3/redis_sender.cc +++ b/tools/pika-port/pika_port_3/redis_sender.cc @@ -1,24 +1,26 @@ #include "redis_sender.h" -#include #include +#include #include +#include + #include "pstd/include/xdebug.h" static time_t kCheckDiff = 1; RedisSender::RedisSender(int id, std::string ip, int64_t port, std::string password) - : id_(id), cli_(nullptr), ip_(ip), port_(port), password_(password), should_exit_(false), cnt_(0), elements_(0) { + : id_(id), cli_(nullptr), ip_(std::move(ip)), port_(port), password_(std::move(password)), should_exit_(false), cnt_(0), elements_(0) { last_write_time_ = ::time(nullptr); } RedisSender::~RedisSender() { LOG(INFO) << "RedisSender thread " << id_ << " exit!!!"; } void RedisSender::ConnectRedis() { - while (cli_ == nullptr) { + while (!cli_) { // Connect to redis cli_ = net::NewRedisCli(); cli_->set_connect_timeout(1000); @@ -37,7 +39,8 @@ void RedisSender::ConnectRedis() { // Authentication if (!password_.empty()) { - net::RedisCmdArgsType argv, resp; + net::RedisCmdArgsType argv; + net::RedisCmdArgsType resp; std::string cmd; argv.push_back("AUTH"); @@ -64,7 +67,8 @@ void RedisSender::ConnectRedis() { } } else { // If forget to input password - net::RedisCmdArgsType argv, resp; + net::RedisCmdArgsType argv; + net::RedisCmdArgsType resp; std::string cmd; argv.push_back("PING"); @@ -151,7 +155,7 @@ void* RedisSender::ThreadMain() { while (!should_exit_) { std::unique_lock lock(commands_mutex_); - while (commands_queue_.size() == 0 && !should_exit_) { + while (commands_queue_.empty() && !should_exit_) { rsignal_.wait_for(lock, std::chrono::milliseconds(100)); // rsignal_.Wait(); } @@ -160,7 +164,7 @@ void* RedisSender::ThreadMain() { break; } - if (commands_queue_.size() == 0) { + if (commands_queue_.empty()) { continue; } diff --git a/tools/pika-port/pika_port_3/trysync_thread.cc b/tools/pika-port/pika_port_3/trysync_thread.cc index a4ea056643..89ebc7899b 100644 --- a/tools/pika-port/pika_port_3/trysync_thread.cc +++ b/tools/pika-port/pika_port_3/trysync_thread.cc @@ -13,9 +13,9 @@ #include #include -#include #include #include +#include #include #include "pstd/include/rsync.h" @@ -25,7 +25,7 @@ #include "storage/storage.h" #include "pika_define.h" -extern Conf g_conf; + extern PikaPort* g_pika_port; TrysyncThread::~TrysyncThread() { @@ -64,11 +64,11 @@ void TrysyncThread::PrepareRsync() { pstd::CreatePath(db_sync_path + "zsets"); } -bool TrysyncThread::Send(std::string lip) { +bool TrysyncThread::Send(const std::string& lip) { net::RedisCmdArgsType argv; std::string wbuf_str; std::string requirepass = g_pika_port->requirepass(); - if (requirepass != "") { + if (!requirepass.empty()) { argv.push_back("auth"); argv.push_back(requirepass); net::SerializeRedisCommand(argv, &wbuf_str); @@ -106,13 +106,13 @@ bool TrysyncThread::Send(std::string lip) { // if send command {trysync slaveip slaveport 11 38709514}, the reply = "sid:. // it means that slave sid is allocated by master. bool TrysyncThread::RecvProc() { - bool should_auth = g_pika_port->requirepass() == "" ? false : true; + bool should_auth = !g_pika_port->requirepass().empty(); bool is_authed = false; pstd::Status s; std::string reply; net::RedisCmdArgsType argv; - while (1) { + while (true) { s = cli_->Recv(&argv); if (!s.ok()) { LOG(WARNING) << "Connect master, status: " << s.ToString() << ", Recv error"; @@ -128,7 +128,7 @@ bool TrysyncThread::RecvProc() { } is_authed = true; } else { - if (argv.size() == 1 && pstd::string2int(reply.data(), reply.size(), &sid_)) { + if (argv.size() == 1 && (pstd::string2int(reply.data(), reply.size(), &sid_) != 0)) { // Luckily, I got your point, the sync is comming LOG(INFO) << "Recv sid from master: " << sid_; g_pika_port->SetSid(sid_); @@ -181,15 +181,19 @@ bool TrysyncThread::TryUpdateMasterOffset() { LOG(WARNING) << "Failed to open info file after db sync"; return false; } - std::string line, master_ip; + std::string line; + std::string master_ip; int lineno = 0; - int64_t filenum = 0, offset = 0, tmp = 0, master_port = 0; + int64_t filenum = 0; + int64_t offset = 0; + int64_t tmp = 0; + int64_t master_port = 0; while (std::getline(is, line)) { lineno++; if (lineno == 2) { master_ip = line; } else if (lineno > 2 && lineno < 6) { - if (!pstd::string2int(line.data(), line.size(), &tmp) || tmp < 0) { + if ((pstd::string2int(line.data(), line.size(), &tmp) == 0) || tmp < 0) { LOG(WARNING) << "Format of info file after db sync error, line: " << line; is.close(); return false; @@ -285,7 +289,7 @@ int TrysyncThread::Retransmit() { s = stringsDB.Open(bwOptions, path); LOG(INFO) << "Open strings DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread((void*)(&stringsDB), &senders_, storage::kStrings, thread_num)); + migrators_.emplace_back(new MigratorThread(&stringsDB, &senders_, storage::kStrings, thread_num)); } storage::RedisLists listsDB(&bw, storage::kLists); @@ -293,7 +297,7 @@ int TrysyncThread::Retransmit() { s = listsDB.Open(bwOptions, path); LOG(INFO) << "Open lists DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread((void*)(&listsDB), &senders_, storage::kLists, thread_num)); + migrators_.emplace_back(new MigratorThread(&listsDB, &senders_, storage::kLists, thread_num)); } storage::RedisHashes hashesDB(&bw, storage::kHashes); @@ -301,7 +305,7 @@ int TrysyncThread::Retransmit() { s = hashesDB.Open(bwOptions, path); LOG(INFO) << "Open hashes DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread((void*)(&hashesDB), &senders_, storage::kHashes, thread_num)); + migrators_.emplace_back(new MigratorThread(&hashesDB, &senders_, storage::kHashes, thread_num)); } storage::RedisSets setsDB(&bw, storage::kSets); @@ -309,7 +313,7 @@ int TrysyncThread::Retransmit() { s = setsDB.Open(bwOptions, path); LOG(INFO) << "Open sets DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread((void*)(&setsDB), &senders_, storage::kSets, thread_num)); + migrators_.emplace_back(new MigratorThread(&setsDB, &senders_, storage::kSets, thread_num)); } storage::RedisZSets zsetsDB(&bw, storage::kZSets); @@ -317,7 +321,7 @@ int TrysyncThread::Retransmit() { s = zsetsDB.Open(bwOptions, path); LOG(INFO) << "Open zsets DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread((void*)(&zsetsDB), &senders_, storage::kZSets, thread_num)); + migrators_.emplace_back(new MigratorThread(&zsetsDB, &senders_, storage::kZSets, thread_num)); } retransmit_mutex_.lock(); @@ -352,7 +356,8 @@ int TrysyncThread::Retransmit() { retransmit_flag_ = false; retransmit_mutex_.unlock(); - int64_t replies = 0, records = 0; + int64_t replies = 0; + int64_t records = 0; size = migrators_.size(); for (size_t i = 0; i < size; i++) { records += migrators_[i]->num(); @@ -436,7 +441,9 @@ void* TrysyncThread::ThreadMain() { // We append the master ip port after module name // To make sure only data from current master is received int rsync_port = g_conf.local_port + 3000; - int ret = pstd::StartRsync(dbsync_path, kDBSyncModule + "_" + ip_port, lip, rsync_port, g_conf.passwd); + auto s = kDBSyncModule; + s.append("_" + ip_port); + int ret = pstd::StartRsync(dbsync_path, s, lip, rsync_port, g_conf.passwd); if (0 != ret) { LOG(WARNING) << "Failed to start rsync, path: " << dbsync_path << ", error: " << ret; } diff --git a/tools/pika-port/pika_port_3/trysync_thread.h b/tools/pika-port/pika_port_3/trysync_thread.h index 005b5bed34..db95b56c91 100644 --- a/tools/pika-port/pika_port_3/trysync_thread.h +++ b/tools/pika-port/pika_port_3/trysync_thread.h @@ -30,7 +30,7 @@ class TrysyncThread : public net::Thread { void Stop(); private: - bool Send(std::string lip); + bool Send(const std::string& lip); bool RecvProc(); void PrepareRsync(); bool TryUpdateMasterOffset(); diff --git a/tools/pika_to_txt/pika_to_txt.cc b/tools/pika_to_txt/pika_to_txt.cc index 5e156a46bb..0cffc6a0c6 100644 --- a/tools/pika_to_txt/pika_to_txt.cc +++ b/tools/pika_to_txt/pika_to_txt.cc @@ -64,8 +64,8 @@ int main(int argc, char** argv) { bw_option.options.create_if_missing = true; bw_option.options.write_buffer_size = 256 * 1024 * 1024; // 256M bw_option.options.target_file_size_base = 20 * 1024 * 1024; // 20M - storage::Storage* storage_db = new storage::Storage(); - if (storage_db != nullptr && (status = storage_db->Open(bw_option, storage_db_path)).ok()) { + auto storage_db = new storage::Storage(); + if (storage_db && (status = storage_db->Open(bw_option, storage_db_path)).ok()) { std::cout << "Open Storage db success..." << std::endl; } else { std::cout << "Open Storage db failed..." << std::endl; @@ -74,9 +74,9 @@ int main(int argc, char** argv) { std::cout << "Start migrating data from Blackwidow db to " << target_file << "..." << std::endl; - WriteThread* write_thread = new WriteThread(target_file); - ScanThread* scan_thread = new ScanThread(write_thread, storage_db); - ProgressThread* progress_thread = new ProgressThread(scan_thread); + auto write_thread = new WriteThread(target_file); + auto scan_thread = new ScanThread(write_thread, storage_db); + auto progress_thread = new ProgressThread(scan_thread); write_thread->StartThread(); // wait for write thread open file success diff --git a/tools/pika_to_txt/scan_thread.cc b/tools/pika_to_txt/scan_thread.cc index fbacac38d4..338270c78b 100644 --- a/tools/pika_to_txt/scan_thread.cc +++ b/tools/pika_to_txt/scan_thread.cc @@ -12,8 +12,8 @@ bool ScanThread::is_finish() { return is_finish_; } int32_t ScanThread::scan_number() { return scan_number_; } void* ScanThread::ThreadMain() { - std::string key_start = ""; - std::string key_end = ""; + std::string key_start; + std::string key_end; std::string pattern = "*"; std::string next_key; std::vector keys; @@ -35,7 +35,7 @@ void* ScanThread::ThreadMain() { key_start = next_key; write_thread_->Load(data); } - } while (strcmp(next_key.data(), "")); + } while (strcmp(next_key.data(), "") != 0); is_finish_ = true; return nullptr; } diff --git a/tools/pika_to_txt/write_thread.cc b/tools/pika_to_txt/write_thread.cc index b30dadda82..c7ffb66b61 100644 --- a/tools/pika_to_txt/write_thread.cc +++ b/tools/pika_to_txt/write_thread.cc @@ -4,13 +4,15 @@ // of patent rights can be found in the PATENTS file in the same directory. #include "write_thread.h" + +#include #include "fstream" #include "iostream" #include "string" #define MAX_QUEUE_SIZE 1024 -WriteThread::WriteThread(const std::string& file_name) : should_stop_(false), file_name_(file_name) {} +WriteThread::WriteThread(std::string file_name) : should_stop_(false), file_name_(std::move(file_name)) {} void WriteThread::Load(const std::string& data) { std::unique_lock lock(data_queue_mutex_); @@ -32,7 +34,7 @@ void WriteThread::Stop() { } void* WriteThread::ThreadMain() { - std::fstream s(file_name_, s.binary | s.out); + std::fstream s(file_name_, std::fstream::binary | std::fstream::out); if (!s.is_open()) { std::cout << "failed to open " << file_name_ << ", exit..." << std::endl; exit(-1); @@ -43,7 +45,7 @@ void* WriteThread::ThreadMain() { rsignal_.wait(lock, [this] { return !data_queue_.empty() || should_stop_; }); } - if (data_queue_.size() > 0) { + if (!data_queue_.empty()) { data_queue_mutex_.lock(); std::string data = data_queue_.front(); data_queue_.pop(); diff --git a/tools/pika_to_txt/write_thread.h b/tools/pika_to_txt/write_thread.h index 24e5f95b20..6a2532f9ce 100644 --- a/tools/pika_to_txt/write_thread.h +++ b/tools/pika_to_txt/write_thread.h @@ -13,7 +13,7 @@ class WriteThread : public net::Thread { public: - WriteThread(const std::string& file_name); + WriteThread(std::string file_name); void Load(const std::string& data); void Stop(); diff --git a/tools/rdb_to_pika/protocoltopika.cc b/tools/rdb_to_pika/protocoltopika.cc index f1c9ae9983..cb275ec7d6 100644 --- a/tools/rdb_to_pika/protocoltopika.cc +++ b/tools/rdb_to_pika/protocoltopika.cc @@ -29,7 +29,6 @@ int main(int argc, char** argv) { int port; ss >> port; redisContext* c = redisConnect(ip, port); - redisReply* reply; if (!c || c->err) { if (c) { redisFree(c); @@ -44,7 +43,7 @@ int main(int argc, char** argv) { redisReply* r; if (argc == 5) { const char* password = argv[4]; - r = (redisReply*)redisCommand(c, "AUTH %s", password); + r = static_cast(redisCommand(c, "AUTH %s", password)); if (r->type == REDIS_REPLY_ERROR) { std::cout << "authentication failed " << std::endl; freeReplyObject(r); @@ -68,7 +67,7 @@ int main(int argc, char** argv) { fin.getline(line, sizeof(line)); } // std::cout << command << std::endl; - r = (redisReply*)redisCommand(c, command.c_str()); + r = static_cast(redisCommand(c, command.c_str())); if (r) { freeReplyObject(r); } diff --git a/tools/txt_to_pika/CMakeLists.txt b/tools/txt_to_pika/CMakeLists.txt index 93110fbacc..d8c76fcba6 100644 --- a/tools/txt_to_pika/CMakeLists.txt +++ b/tools/txt_to_pika/CMakeLists.txt @@ -11,7 +11,8 @@ aux_source_directory(${SRC_DIR} BASE_OBJS) add_executable(txt_to_pika ${BASE_OBJS}) target_include_directories(txt_to_pika PRIVATE ${INSTALL_INCLUDEDIR} - PRIVATE ${PROJECT_SOURCE_DIR}) + PRIVATE ${PROJECT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(txt_to_pika storage net pstd ${ROCKSDB_LIBRARY} pthread ${SNAPPY_LIBRARY} ${ZLIB_LIBRARY} ${BZ2_LIBRARY} ${GLOG_LIBRARY} ${GFLAGS_LIBRARY} rt) diff --git a/tools/txt_to_pika/scan.cc b/tools/txt_to_pika/scan.cc index ce1416ea18..0695ecbd5b 100644 --- a/tools/txt_to_pika/scan.cc +++ b/tools/txt_to_pika/scan.cc @@ -2,7 +2,7 @@ #include #include -ScanThread::~ScanThread() {} +ScanThread::~ScanThread() = default; void ScanThread::ScanFile() { log_info("Start to scan"); @@ -14,7 +14,9 @@ void ScanThread::ScanFile() { uint64_t index = 0; while (index < filesize) { - std::string str_key, str_value, cmd; + std::string str_key; + std::string str_value; + std::string cmd; uint32_t key_len; fout.read(reinterpret_cast(&key_len), sizeof(uint32_t)); char* key = new char[key_len]; diff --git a/tools/txt_to_pika/sender.cc b/tools/txt_to_pika/sender.cc index 9e3b0be116..dfbcf676ac 100644 --- a/tools/txt_to_pika/sender.cc +++ b/tools/txt_to_pika/sender.cc @@ -1,12 +1,15 @@ #include "sender.h" +#include + + SenderThread::SenderThread(std::string ip, int64_t port, std::string password) - : cli_(nullptr), ip_(ip), port_(port), password_(password), should_exit_(false), elements_(0) {} + : cli_(nullptr), ip_(std::move(ip)), port_(port), password_(std::move(password)), should_exit_(false), elements_(0) {} -SenderThread::~SenderThread() {} +SenderThread::~SenderThread() = default; void SenderThread::ConnectPika() { - while (cli_ == nullptr) { + while (!cli_) { // Connect to redis cli_ = net::NewRedisCli(); cli_->set_connect_timeout(1000); @@ -21,7 +24,8 @@ void SenderThread::ConnectPika() { // Authentication if (!password_.empty()) { - net::RedisCmdArgsType argv, resp; + net::RedisCmdArgsType argv; + net::RedisCmdArgsType resp; std::string cmd; argv.push_back("AUTH"); @@ -48,7 +52,8 @@ void SenderThread::ConnectPika() { } } else { // If forget to input password - net::RedisCmdArgsType argv, resp; + net::RedisCmdArgsType argv; + net::RedisCmdArgsType resp; std::string cmd; argv.push_back("PING"); @@ -112,10 +117,10 @@ void* SenderThread::ThreadMain() { while (!should_exit_ || QueueSize() != 0) { { std::unique_lock lock(cmd_mutex_); - rsignal_.wait(lock, [this] { return !cmd_queue_.size() || should_exit_; }); + rsignal_.wait(lock, [this] { return cmd_queue_.empty() || should_exit_; }); } - if (cli_ == nullptr) { + if (!cli_) { ConnectPika(); continue; } diff --git a/tools/txt_to_pika/txt_to_pika.cc b/tools/txt_to_pika/txt_to_pika.cc index a4ee1d84b4..6529eb6ba1 100644 --- a/tools/txt_to_pika/txt_to_pika.cc +++ b/tools/txt_to_pika/txt_to_pika.cc @@ -59,11 +59,12 @@ int main(int argc, char** argv) { std::cout << "thread: " << thread_num << std::endl; std::cout << "password: " << password << std::endl; + senders.reserve(thread_num); for (int i = 0; i < thread_num; i++) { senders.push_back(new SenderThread(ip, port, password)); } - ScanThread* scan_thread = new ScanThread(filename, senders, ttl); + auto scan_thread = new ScanThread(filename, senders, ttl); for (int i = 0; i < thread_num; i++) { senders[i]->StartThread();