From 101441383767da3c4edffd2f290e03afccd854a0 Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Thu, 5 Sep 2024 23:43:50 +0800 Subject: [PATCH] init glog --- cmake_modules/BaseFunctions.cmake | 3 + src/aio/disk_engine.cpp | 10 +- src/aio/file_io.cpp | 2 +- src/aio/test/CMakeLists.txt | 4 +- src/base/meta_store.cpp | 8 +- src/base/pegasus_utils.cpp | 4 +- src/base/test/CMakeLists.txt | 4 +- src/base/value_schema_manager.cpp | 3 +- src/base/value_schema_v0.cpp | 6 +- src/base/value_schema_v1.cpp | 6 +- src/base/value_schema_v2.cpp | 6 +- src/block_service/block_service_manager.cpp | 12 +- src/block_service/local/local_service.cpp | 6 +- src/block_service/test/CMakeLists.txt | 4 +- src/block_service/test/hdfs_service_test.cpp | 4 +- src/client/partition_resolver.cpp | 8 +- src/client/replication_ddl_client.cpp | 10 +- src/client/test/CMakeLists.txt | 4 +- .../pegasus_client_factory_impl.cpp | 2 +- src/client_lib/pegasus_client_impl.cpp | 3 +- src/client_lib/pegasus_scanner_impl.cpp | 12 +- src/common/common.cpp | 2 +- src/common/duplication_common.cpp | 20 +- src/common/fs_manager.cpp | 26 +- src/common/json_helper.h | 4 +- src/common/replication_common.cpp | 11 +- .../serialization_helper/thrift_helper.h | 16 +- src/common/storage_serverlet.h | 27 +- src/common/test/CMakeLists.txt | 4 +- src/failure_detector/failure_detector.cpp | 2 +- .../failure_detector_multimaster.h | 4 +- src/failure_detector/test/CMakeLists.txt | 4 +- .../test/failure_detector.cpp | 2 +- src/geo/bench/CMakeLists.txt | 4 +- src/geo/bench/bench.cpp | 2 +- src/geo/lib/geo_client.cpp | 8 +- src/geo/test/CMakeLists.txt | 4 +- src/geo/test/geo_test.cpp | 6 +- src/gutil/map_util.h | 36 +-- src/gutil/test/CMakeLists.txt | 4 +- src/gutil/test/no_destructor_test.cpp | 2 +- src/http/http_client.cpp | 12 +- src/http/http_message_parser.cpp | 2 +- src/http/test/CMakeLists.txt | 4 +- src/meta/app_env_validator.cpp | 2 +- src/meta/backup_engine.cpp | 2 +- src/meta/dump_file.h | 4 +- .../duplication/meta_duplication_service.cpp | 2 +- .../duplication/meta_duplication_service.h | 4 +- src/meta/greedy_load_balancer.cpp | 2 +- src/meta/load_balance_policy.cpp | 23 +- src/meta/meta_backup_service.cpp | 110 +++---- src/meta/meta_data.cpp | 14 +- src/meta/meta_data.h | 2 +- src/meta/meta_server_failure_detector.cpp | 6 +- src/meta/meta_server_failure_detector.h | 4 +- src/meta/meta_service.cpp | 6 +- src/meta/meta_split_service.cpp | 24 +- src/meta/meta_state_service_simple.cpp | 28 +- src/meta/meta_state_service_utils.cpp | 4 +- src/meta/meta_state_service_utils_impl.h | 16 +- src/meta/partition_guardian.cpp | 20 +- src/meta/server_load_balancer.cpp | 12 +- src/meta/server_state.cpp | 273 +++++++++--------- src/meta/server_state_restore.cpp | 6 +- src/meta/table_metrics.cpp | 18 +- src/meta/test/CMakeLists.txt | 4 +- .../test/balancer_simulator/CMakeLists.txt | 4 +- src/meta/test/balancer_validator.cpp | 30 +- src/meta/test/meta_app_operation_test.cpp | 10 +- src/meta/test/meta_state/CMakeLists.txt | 4 +- src/meta/test/misc/misc.cpp | 106 +++---- src/nfs/nfs_client_impl.cpp | 2 +- src/nfs/nfs_server_impl.cpp | 4 +- src/nfs/test/CMakeLists.txt | 4 +- src/perf_counter/perf_counter_atomic.cpp | 2 +- src/perf_counter/perf_counter_atomic.h | 18 +- src/perf_counter/perf_counters.cpp | 4 +- src/perf_counter/test/CMakeLists.txt | 4 +- src/ranger/ranger_resource_policy.cpp | 36 ++- src/ranger/ranger_resource_policy_manager.cpp | 11 +- src/ranger/test/CMakeLists.txt | 4 +- src/redis_protocol/proxy/CMakeLists.txt | 4 +- src/redis_protocol/proxy_lib/proxy_layer.cpp | 2 +- src/redis_protocol/proxy_lib/redis_parser.cpp | 16 +- src/redis_protocol/proxy_ut/CMakeLists.txt | 4 +- src/replica/backup/cold_backup_context.cpp | 14 +- src/replica/backup/cold_backup_context.h | 6 +- src/replica/backup/test/CMakeLists.txt | 4 +- src/replica/bulk_load/test/CMakeLists.txt | 4 +- src/replica/disk_cleaner.cpp | 10 +- src/replica/duplication/replica_follower.cpp | 4 +- src/replica/duplication/test/CMakeLists.txt | 5 +- src/replica/log_block.h | 2 +- src/replica/log_file.cpp | 14 +- src/replica/mutation.cpp | 6 +- src/replica/mutation.h | 10 +- src/replica/mutation_log.cpp | 82 +++--- src/replica/mutation_log_replay.cpp | 5 +- src/replica/prepare_list.cpp | 4 +- src/replica/replica.cpp | 24 +- src/replica/replica_2pc.cpp | 27 +- src/replica/replica_backup.cpp | 22 +- src/replica/replica_base.h | 10 +- src/replica/replica_check.cpp | 8 +- src/replica/replica_chkpt.cpp | 2 +- src/replica/replica_config.cpp | 94 +++--- src/replica/replica_context.cpp | 2 +- src/replica/replica_context.h | 4 +- src/replica/replica_failover.cpp | 10 +- src/replica/replica_http_service.h | 2 +- src/replica/replica_init.cpp | 18 +- src/replica/replica_learn.cpp | 32 +- src/replica/replica_stub.cpp | 96 +++--- src/replica/replication_app_base.cpp | 7 +- src/replica/split/replica_split_manager.cpp | 6 +- src/replica/split/test/CMakeLists.txt | 4 +- src/replica/storage/simple_kv/CMakeLists.txt | 4 +- .../simple_kv/simple_kv.server.impl.cpp | 38 +-- .../storage/simple_kv/test/CMakeLists.txt | 4 +- src/replica/storage/simple_kv/test/case.cpp | 28 +- .../storage/simple_kv/test/checker.cpp | 2 +- src/replica/storage/simple_kv/test/common.cpp | 8 +- .../simple_kv/test/simple_kv.server.impl.cpp | 36 +-- src/replica/test/CMakeLists.txt | 4 +- src/replica/test/mock_utils.h | 6 +- src/replica/test/replica_learn_test.cpp | 2 +- src/runtime/fault_injector.cpp | 2 +- src/runtime/pipeline.h | 4 +- src/runtime/profiler.cpp | 57 ++-- src/runtime/rpc/asio_net_provider.cpp | 10 +- src/runtime/rpc/dns_resolver.cpp | 4 +- src/runtime/rpc/group_host_port.h | 6 +- src/runtime/rpc/network.cpp | 15 +- src/runtime/rpc/network.sim.cpp | 31 +- src/runtime/rpc/rpc_engine.cpp | 70 ++--- src/runtime/rpc/rpc_engine.h | 2 +- src/runtime/rpc/rpc_holder.h | 20 +- src/runtime/rpc/rpc_host_port.cpp | 4 +- src/runtime/rpc/rpc_host_port.h | 6 +- src/runtime/rpc/rpc_message.cpp | 38 +-- src/runtime/rpc/rpc_stream.h | 4 +- src/runtime/rpc/serialization.h | 4 +- src/runtime/rpc/thrift_message_parser.cpp | 8 +- src/runtime/scheduler.cpp | 2 +- src/runtime/service_api_c.cpp | 26 +- src/runtime/service_app.h | 2 +- src/runtime/service_engine.cpp | 20 +- src/runtime/task/simple_task_queue.cpp | 4 +- src/runtime/task/task.cpp | 66 ++--- src/runtime/task/task.h | 6 +- src/runtime/task/task_engine.cpp | 12 +- src/runtime/task/task_engine.sim.cpp | 8 +- src/runtime/task/task_queue.cpp | 8 +- src/runtime/task/task_spec.cpp | 8 +- src/runtime/task/task_tracker.h | 2 +- src/runtime/test/CMakeLists.txt | 4 +- src/runtime/test/rpc.cpp | 2 +- src/runtime/tracer.cpp | 2 +- src/sample/CMakeLists.txt | 4 +- src/security/access_controller.cpp | 4 +- src/security/kinit_context.cpp | 8 +- src/security/negotiation_manager.cpp | 8 +- src/security/sasl_init.cpp | 15 +- src/security/test/CMakeLists.txt | 4 +- src/server/CMakeLists.txt | 5 +- src/server/available_detector.cpp | 8 +- src/server/capacity_unit_calculator.cpp | 6 +- src/server/hotkey_collector.cpp | 2 +- src/server/info_collector.cpp | 6 +- src/server/pegasus_server_impl.cpp | 26 +- src/server/pegasus_server_impl_init.cpp | 16 +- src/server/pegasus_server_write.cpp | 2 +- src/server/pegasus_write_service.cpp | 2 +- src/server/pegasus_write_service_impl.h | 2 +- src/server/test/CMakeLists.txt | 4 +- src/server/test/pegasus_server_test_base.h | 8 +- src/server/test/rocksdb_wrapper_test.cpp | 2 +- src/shell/CMakeLists.txt | 5 +- src/shell/command_helper.h | 10 +- src/shell/commands/data_operations.cpp | 4 +- src/shell/commands/debugger.cpp | 2 +- src/shell/commands/local_partition_split.cpp | 8 +- src/shell/main.cpp | 2 +- src/test/bench_test/CMakeLists.txt | 4 +- src/test/bench_test/benchmark.cpp | 4 +- .../backup_restore/CMakeLists.txt | 4 +- .../function_test/base_api/CMakeLists.txt | 4 +- .../function_test/bulk_load/CMakeLists.txt | 6 +- .../detect_hotspot/CMakeLists.txt | 4 +- .../partition_split/CMakeLists.txt | 4 +- .../function_test/recovery/CMakeLists.txt | 4 +- src/test/function_test/restore/CMakeLists.txt | 4 +- .../function_test/security/CMakeLists.txt | 6 +- .../function_test/throttle/CMakeLists.txt | 4 +- src/test/function_test/utils/global_env.cpp | 2 +- src/test/kill_test/CMakeLists.txt | 4 +- src/test/kill_test/process_kill_testor.cpp | 4 +- src/test/pressure_test/CMakeLists.txt | 4 +- src/test/pressure_test/main.cpp | 28 +- src/utils/blob.h | 4 +- src/utils/builtin_metrics.cpp | 6 +- src/utils/casts.h | 2 +- src/utils/command_manager.cpp | 13 +- src/utils/env.cpp | 12 +- src/utils/errors.h | 6 +- src/utils/flags.cpp | 14 +- src/utils/fmt_logging.h | 72 ++--- src/utils/latency_tracer.cpp | 15 +- src/utils/logging.cpp | 6 + src/utils/long_adder_bench/CMakeLists.txt | 4 +- src/utils/metrics.cpp | 10 +- src/utils/metrics.h | 6 +- src/utils/nth_element.h | 8 +- src/utils/output_utils.cpp | 13 +- src/utils/simple_logger.cpp | 53 ++-- src/utils/strings.cpp | 6 +- src/utils/test/CMakeLists.txt | 4 +- src/utils/test/fmt_logging_test.cpp | 2 +- src/utils/test/logging.cpp | 2 +- src/utils/test/metrics_test.cpp | 10 +- .../test/nth_element_bench/CMakeLists.txt | 4 +- src/utils/test/nth_element_utils.h | 9 +- src/zookeeper/lock_struct.cpp | 2 +- src/zookeeper/test/CMakeLists.txt | 4 +- .../test/distributed_lock_zookeeper.cpp | 2 +- src/zookeeper/zookeeper_session.cpp | 16 +- thirdparty/CMakeLists.txt | 35 +++ 228 files changed, 1531 insertions(+), 1371 deletions(-) diff --git a/cmake_modules/BaseFunctions.cmake b/cmake_modules/BaseFunctions.cmake index 9b784dc441..015de522a5 100644 --- a/cmake_modules/BaseFunctions.cmake +++ b/cmake_modules/BaseFunctions.cmake @@ -333,6 +333,9 @@ function(dsn_setup_thirdparty_libs) set(Boost_NO_SYSTEM_PATHS ON) set(Boost_NO_BOOST_CMAKE ON) + add_definitions(-DGLOG_USE_GLOG_EXPORT) + add_definitions(-DS2_USE_GLOG=0) + set(CMAKE_PREFIX_PATH ${THIRDPARTY_INSTALL_DIR};${CMAKE_PREFIX_PATH}) message(STATUS "CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}") find_package(Boost COMPONENTS system filesystem REQUIRED) diff --git a/src/aio/disk_engine.cpp b/src/aio/disk_engine.cpp index 1b104be301..c44aa1d06e 100644 --- a/src/aio/disk_engine.cpp +++ b/src/aio/disk_engine.cpp @@ -107,22 +107,22 @@ disk_file::disk_file(std::unique_ptr wf) : _write_file(st aio_task *disk_file::read(aio_task *tsk) { - CHECK(_read_file, ""); + CHECK(_read_file); tsk->add_ref(); // release on completion, see `on_read_completed`. return _read_queue.add_work(tsk, nullptr); } aio_task *disk_file::write(aio_task *tsk, void *ctx) { - CHECK(_write_file, ""); + CHECK(_write_file); tsk->add_ref(); // release on completion return _write_queue.add_work(tsk, ctx); } aio_task *disk_file::on_read_completed(aio_task *wk, error_code err, size_t size) { - CHECK(_read_file, ""); - CHECK(wk->next == nullptr, ""); + CHECK(_read_file); + CHECK_EQ(wk->next, nullptr); auto ret = _read_queue.on_work_completed(wk, nullptr); wk->enqueue(err, size); wk->release_ref(); // added in above read @@ -132,7 +132,7 @@ aio_task *disk_file::on_read_completed(aio_task *wk, error_code err, size_t size aio_task *disk_file::on_write_completed(aio_task *wk, void *ctx, error_code err, size_t size) { - CHECK(_write_file, ""); + CHECK(_write_file); auto ret = _write_queue.on_work_completed(wk, ctx); while (wk) { diff --git a/src/aio/file_io.cpp b/src/aio/file_io.cpp index a4bf26ba85..41e3d86e1f 100644 --- a/src/aio/file_io.cpp +++ b/src/aio/file_io.cpp @@ -58,7 +58,7 @@ namespace file { return new disk_file(std::move(wf)); } default: - CHECK(false, ""); + CHECK(false); } return nullptr; } diff --git a/src/aio/test/CMakeLists.txt b/src/aio/test/CMakeLists.txt index cbc853d834..ca0c859830 100644 --- a/src/aio/test/CMakeLists.txt +++ b/src/aio/test/CMakeLists.txt @@ -36,7 +36,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES config.ini diff --git a/src/base/meta_store.cpp b/src/base/meta_store.cpp index f9ca38ab77..5fb93d7e63 100644 --- a/src/base/meta_store.cpp +++ b/src/base/meta_store.cpp @@ -111,10 +111,10 @@ ::dsn::error_code meta_store::get_value_from_meta_cf(rocksdb::DB *db, if (ec != ::dsn::ERR_OK) { return ec; } - CHECK(dsn::buf2uint64(data, *value), - "rocksdb {} get \"{}\" from meta column family failed to parse into uint64", - db->GetName(), - data); + PGSCHECK(dsn::buf2uint64(data, *value), + "rocksdb {} get \"{}\" from meta column family failed to parse into uint64", + db->GetName(), + data); return ::dsn::ERR_OK; } diff --git a/src/base/pegasus_utils.cpp b/src/base/pegasus_utils.cpp index d0cd360342..b8d71f3242 100644 --- a/src/base/pegasus_utils.cpp +++ b/src/base/pegasus_utils.cpp @@ -95,8 +95,8 @@ c_escape_string(const char *src, size_t src_len, char *dest, size_t dest_len, bo inline unsigned int hex_digit_to_int(char c) { /* Assume ASCII. */ - CHECK('0' == 0x30 && 'A' == 0x41 && 'a' == 0x61, ""); - CHECK(isxdigit(c), ""); + PGSCHECK('0' == 0x30 && 'A' == 0x41 && 'a' == 0x61, ""); + CHECK(isxdigit(c)); unsigned int x = static_cast(c); if (x > '9') { x += 9; diff --git a/src/base/test/CMakeLists.txt b/src/base/test/CMakeLists.txt index 4d33878fe9..6d7b4efaaa 100644 --- a/src/base/test/CMakeLists.txt +++ b/src/base/test/CMakeLists.txt @@ -35,7 +35,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy - gtest) + gtest + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/base/value_schema_manager.cpp b/src/base/value_schema_manager.cpp index 491230bdfa..09a00aa062 100644 --- a/src/base/value_schema_manager.cpp +++ b/src/base/value_schema_manager.cpp @@ -63,7 +63,8 @@ value_schema *value_schema_manager::get_value_schema(uint32_t meta_cf_data_versi return schema; } else { auto schema = get_value_schema(meta_cf_data_version); - CHECK_NOTNULL(schema, "data version({}) in meta cf is not supported", meta_cf_data_version); + PGSCHECK_NOTNULL( + schema, "data version({}) in meta cf is not supported", meta_cf_data_version); return schema; } } diff --git a/src/base/value_schema_v0.cpp b/src/base/value_schema_v0.cpp index 1d9d0433bc..ff97654ec4 100644 --- a/src/base/value_schema_v0.cpp +++ b/src/base/value_schema_v0.cpp @@ -41,7 +41,7 @@ std::unique_ptr value_schema_v0::extract_field(std::string_view val field = extract_timestamp(value); break; default: - CHECK(false, "Unsupported field type: {}", type); + PGSCHECK(false, "Unsupported field type: {}", type); } return field; } @@ -60,7 +60,7 @@ void value_schema_v0::update_field(std::string &value, std::unique_ptr(params.fields[value_field_type::USER_DATA].get()); if (dsn_unlikely(expire_ts_field == nullptr || data_field == nullptr)) { - CHECK(false, "USER_DATA or EXPIRE_TIMESTAMP is not provided"); + PGSCHECK(false, "USER_DATA or EXPIRE_TIMESTAMP is not provided"); return {nullptr, 0}; } diff --git a/src/base/value_schema_v1.cpp b/src/base/value_schema_v1.cpp index 50ac2ba5bd..b527295314 100644 --- a/src/base/value_schema_v1.cpp +++ b/src/base/value_schema_v1.cpp @@ -44,7 +44,7 @@ std::unique_ptr value_schema_v1::extract_field(std::string_view val field = extract_time_tag(value); break; default: - CHECK(false, "Unsupported field type: {}", type); + PGSCHECK(false, "Unsupported field type: {}", type); } return field; } @@ -63,7 +63,7 @@ void value_schema_v1::update_field(std::string &value, std::unique_ptr(params.fields[value_field_type::USER_DATA].get()); if (dsn_unlikely(expire_ts_field == nullptr || data_field == nullptr || timetag_field == nullptr)) { - CHECK(false, "USER_DATA or EXPIRE_TIMESTAMP or TIME_TAG is not provided"); + PGSCHECK(false, "USER_DATA or EXPIRE_TIMESTAMP or TIME_TAG is not provided"); return {nullptr, 0}; } diff --git a/src/base/value_schema_v2.cpp b/src/base/value_schema_v2.cpp index 82f4942a74..0b3145b64b 100644 --- a/src/base/value_schema_v2.cpp +++ b/src/base/value_schema_v2.cpp @@ -45,7 +45,7 @@ std::unique_ptr value_schema_v2::extract_field(std::string_view val field = extract_time_tag(value); break; default: - CHECK(false, "Unsupported field type: {}", type); + PGSCHECK(false, "Unsupported field type: {}", type); } return field; } @@ -65,7 +65,7 @@ void value_schema_v2::update_field(std::string &value, std::unique_ptr(params.fields[value_field_type::USER_DATA].get()); if (dsn_unlikely(expire_ts_field == nullptr || data_field == nullptr || timetag_field == nullptr)) { - CHECK(false, "USER_DATA or EXPIRE_TIMESTAMP or TIME_TAG is not provided"); + PGSCHECK(false, "USER_DATA or EXPIRE_TIMESTAMP or TIME_TAG is not provided"); return {nullptr, 0}; } diff --git a/src/block_service/block_service_manager.cpp b/src/block_service/block_service_manager.cpp index 1d0cd45f95..e5577aa973 100644 --- a/src/block_service/block_service_manager.cpp +++ b/src/block_service/block_service_manager.cpp @@ -39,13 +39,13 @@ namespace block_service { block_service_registry::block_service_registry() { - CHECK(utils::factory_store::register_factory( - "hdfs_service", block_filesystem::create, PROVIDER_TYPE_MAIN), - "register hdfs_service failed"); + PGSCHECK(utils::factory_store::register_factory( + "hdfs_service", block_filesystem::create, PROVIDER_TYPE_MAIN), + "register hdfs_service failed"); - CHECK(utils::factory_store::register_factory( - "local_service", block_filesystem::create, PROVIDER_TYPE_MAIN), - "register local_service failed"); + PGSCHECK(utils::factory_store::register_factory( + "local_service", block_filesystem::create, PROVIDER_TYPE_MAIN), + "register local_service failed"); } block_service_manager::block_service_manager() diff --git a/src/block_service/local/local_service.cpp b/src/block_service/local/local_service.cpp index 0069a03773..239670cc63 100644 --- a/src/block_service/local/local_service.cpp +++ b/src/block_service/local/local_service.cpp @@ -77,9 +77,9 @@ error_code local_service::initialize(const std::vector &args) if (::dsn::utils::filesystem::directory_exists(_root)) { LOG_WARNING("old local block service root dir has already exist, path({})", _root); } else { - CHECK(::dsn::utils::filesystem::create_directory(_root), - "local block service create directory({}) fail", - _root); + PGSCHECK(::dsn::utils::filesystem::create_directory(_root), + "local block service create directory({}) fail", + _root); } LOG_INFO("local block service initialize succeed with root({})", _root); } diff --git a/src/block_service/test/CMakeLists.txt b/src/block_service/test/CMakeLists.txt index b8aaad6520..d5e64a04b0 100644 --- a/src/block_service/test/CMakeLists.txt +++ b/src/block_service/test/CMakeLists.txt @@ -35,7 +35,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/block_service/test/hdfs_service_test.cpp b/src/block_service/test/hdfs_service_test.cpp index b0880de2a3..f5cd973b6d 100644 --- a/src/block_service/test/hdfs_service_test.cpp +++ b/src/block_service/test/hdfs_service_test.cpp @@ -115,11 +115,11 @@ void HDFSClientTest::write_test_files_async(const std::string &local_test_path, if (s.ok()) { ++(*success_count); } else { - CHECK(s.IsIOError(), "{}", s.ToString()); + PGSCHECK(s.IsIOError(), "{}", s.ToString()); auto pos1 = s.ToString().find( "IO error: No such file or directory: While open a file for appending: "); auto pos2 = s.ToString().find("IO error: While appending to file: "); - CHECK(pos1 == 0 || pos2 == 0, "{}", s.ToString()); + PGSCHECK(pos1 == 0 || pos2 == 0, "{}", s.ToString()); } }); } diff --git a/src/client/partition_resolver.cpp b/src/client/partition_resolver.cpp index 7cc5b00e9c..c6797cc8c2 100644 --- a/src/client/partition_resolver.cpp +++ b/src/client/partition_resolver.cpp @@ -84,11 +84,11 @@ void partition_resolver::call_task(const rpc_response_task_ptr &t) dynamic_cast(task::get_current_task()); partition_resolver_ptr r(this); - CHECK_NOTNULL(ctask, "current task must be rpc_response_task"); + PGSCHECK_NOTNULL(ctask, "current task must be rpc_response_task"); ctask->replace_callback(std::move(oc)); - CHECK(ctask->set_retry(false), - "rpc_response_task set retry failed, state = {}", - enum_to_string(ctask->state())); + PGSCHECK(ctask->set_retry(false), + "rpc_response_task set retry failed, state = {}", + enum_to_string(ctask->state())); // sleep gap milliseconds before retry tasking::enqueue( diff --git a/src/client/replication_ddl_client.cpp b/src/client/replication_ddl_client.cpp index 27bfb2df0a..521e3dfccc 100644 --- a/src/client/replication_ddl_client.cpp +++ b/src/client/replication_ddl_client.cpp @@ -913,13 +913,13 @@ dsn::error_code replication_ddl_client::do_recovery(const std::vector } } if (req->hp_recovery_nodes.empty()) { - CHECK(req->recovery_nodes.empty(), - "recovery_nodes should be set together with hp_recovery_nodes"); + PGSCHECK(req->recovery_nodes.empty(), + "recovery_nodes should be set together with hp_recovery_nodes"); out << "node set for recovery it empty" << std::endl; return ERR_INVALID_PARAMETERS; } - CHECK(!req->recovery_nodes.empty(), - "recovery_nodes should be set together with hp_recovery_nodes"); + PGSCHECK(!req->recovery_nodes.empty(), + "recovery_nodes should be set together with hp_recovery_nodes"); req->skip_bad_nodes = skip_bad_nodes; req->skip_lost_partitions = skip_lost_partitions; @@ -1534,7 +1534,7 @@ ::dsn::error_code replication_ddl_client::clear_app_envs(const std::string &app_ if (clear_all) { req->__set_clear_prefix(""); } else { - CHECK(!prefix.empty(), "prefix can not be empty"); + PGSCHECK(!prefix.empty(), "prefix can not be empty"); req->__set_clear_prefix(prefix); } diff --git a/src/client/test/CMakeLists.txt b/src/client/test/CMakeLists.txt index 60f3762760..a23b0e4034 100644 --- a/src/client/test/CMakeLists.txt +++ b/src/client/test/CMakeLists.txt @@ -30,7 +30,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/client_lib/pegasus_client_factory_impl.cpp b/src/client_lib/pegasus_client_factory_impl.cpp index b98cb139a1..29feb44a15 100644 --- a/src/client_lib/pegasus_client_factory_impl.cpp +++ b/src/client_lib/pegasus_client_factory_impl.cpp @@ -42,7 +42,7 @@ bool pegasus_client_factory_impl::initialize(const char *config_file) { bool is_initialized = ::dsn::tools::is_engine_ready(); if (config_file == nullptr) { - CHECK(is_initialized, "rdsn engine not started, please specify a valid config file"); + PGSCHECK(is_initialized, "rdsn engine not started, please specify a valid config file"); } else { if (is_initialized) { LOG_WARNING("rdsn engine already started, ignore the config file '{}'", config_file); diff --git a/src/client_lib/pegasus_client_impl.cpp b/src/client_lib/pegasus_client_impl.cpp index 4ab09425bb..cf14b879fd 100644 --- a/src/client_lib/pegasus_client_impl.cpp +++ b/src/client_lib/pegasus_client_impl.cpp @@ -1278,7 +1278,8 @@ void pegasus_client_impl::async_duplicate(dsn::apps::duplicate_rpc rpc, const char *pegasus_client_impl::get_error_string(int error_code) const { auto it = _client_error_to_string.find(error_code); - CHECK(it != _client_error_to_string.end(), "client error {} have no error string", error_code); + PGSCHECK( + it != _client_error_to_string.end(), "client error {} have no error string", error_code); return it->second.c_str(); } diff --git a/src/client_lib/pegasus_scanner_impl.cpp b/src/client_lib/pegasus_scanner_impl.cpp index a6eb731ccc..a75b1cdaab 100644 --- a/src/client_lib/pegasus_scanner_impl.cpp +++ b/src/client_lib/pegasus_scanner_impl.cpp @@ -174,7 +174,7 @@ pegasus_client_impl::pegasus_scanner_impl::get_smart_wrapper() void pegasus_client_impl::pegasus_scanner_impl::_async_next_internal() { // _lock will be locked out of the while block - CHECK(!_queue.empty(), "queue should not be empty when _async_next_internal start"); + PGSCHECK(!_queue.empty(), "queue should not be empty when _async_next_internal start"); std::list temp; while (true) { @@ -264,7 +264,7 @@ void pegasus_client_impl::pegasus_scanner_impl::_next_batch() ::dsn::apps::scan_request req; req.context_id = _context; - CHECK(!_rpc_started, ""); + PGSCHECK(!_rpc_started, ""); _rpc_started = true; _client->scan( req, @@ -300,7 +300,7 @@ void pegasus_client_impl::pegasus_scanner_impl::_start_scan() req.__set_full_scan(_full_scan); req.__set_only_return_count(_options.only_return_count); - CHECK(!_rpc_started, ""); + PGSCHECK(!_rpc_started, ""); _rpc_started = true; _client->get_scanner( req, @@ -315,7 +315,7 @@ void pegasus_client_impl::pegasus_scanner_impl::_on_scan_response(::dsn::error_c dsn::message_ex *req, dsn::message_ex *resp) { - CHECK(_rpc_started, ""); + PGSCHECK(_rpc_started, ""); _rpc_started = false; ::dsn::apps::scan_response response; if (err == ERR_OK) { @@ -380,8 +380,8 @@ pegasus_client_impl::pegasus_scanner_impl::~pegasus_scanner_impl() { dsn::zauto_lock l(_lock); - CHECK(!_rpc_started, "all scan-rpc should be completed here"); - CHECK(_queue.empty(), "queue should be empty"); + PGSCHECK(!_rpc_started, "all scan-rpc should be completed here"); + PGSCHECK(_queue.empty(), "queue should be empty"); if (_client) { if (_context >= SCAN_CONTEXT_ID_VALID_MIN) diff --git a/src/common/common.cpp b/src/common/common.cpp index 4cc6fb7eea..28f8181551 100644 --- a/src/common/common.cpp +++ b/src/common/common.cpp @@ -37,7 +37,7 @@ namespace dsn { /*extern*/ const char *get_current_cluster_name() { - CHECK(!utils::is_empty(FLAGS_cluster_name), "cluster_name is not set"); + PGSCHECK(!utils::is_empty(FLAGS_cluster_name), "cluster_name is not set"); return FLAGS_cluster_name; } diff --git a/src/common/duplication_common.cpp b/src/common/duplication_common.cpp index 4dc5323c65..8f23c08289 100644 --- a/src/common/duplication_common.cpp +++ b/src/common/duplication_common.cpp @@ -65,18 +65,18 @@ const std::string duplication_constants::kDuplicationEnvMasterAppNameKey /*NOLIN /*extern*/ const char *duplication_status_to_string(duplication_status::type status) { auto it = _duplication_status_VALUES_TO_NAMES.find(status); - CHECK(it != _duplication_status_VALUES_TO_NAMES.end(), - "unexpected type of duplication_status: {}", - status); + PGSCHECK(it != _duplication_status_VALUES_TO_NAMES.end(), + "unexpected type of duplication_status: {}", + status); return it->second; } /*extern*/ const char *duplication_fail_mode_to_string(duplication_fail_mode::type fmode) { auto it = _duplication_fail_mode_VALUES_TO_NAMES.find(fmode); - CHECK(it != _duplication_fail_mode_VALUES_TO_NAMES.end(), - "unexpected type of duplication_fail_mode: {}", - fmode); + PGSCHECK(it != _duplication_fail_mode_VALUES_TO_NAMES.end(), + "unexpected type of duplication_fail_mode: {}", + fmode); return it->second; } @@ -112,10 +112,10 @@ class duplication_group_registry : public utils::singleton 0, - "cluster_id({}) for {} should be in [1, 127]", - cluster_id, - cluster); + PGSCHECK(cluster_id < 128 && cluster_id > 0, + "cluster_id({}) for {} should be in [1, 127]", + cluster_id, + cluster); _group.emplace(cluster, static_cast(cluster_id)); } CHECK_EQ_MSG(clusters.size(), diff --git a/src/common/fs_manager.cpp b/src/common/fs_manager.cpp index 1801d2c46b..0ba2b10c13 100644 --- a/src/common/fs_manager.cpp +++ b/src/common/fs_manager.cpp @@ -108,11 +108,11 @@ disk_capacity_metrics::disk_capacity_metrics(const std::string &tag, const std:: const metric_entity_ptr &disk_capacity_metrics::disk_metric_entity() const { - CHECK_NOTNULL(_disk_metric_entity, - "disk metric entity (tag={}, data_dir={}) should has been instantiated: " - "uninitialized entity cannot be used to instantiate metric", - _tag, - _data_dir); + PGSCHECK_NOTNULL(_disk_metric_entity, + "disk metric entity (tag={}, data_dir={}) should has been instantiated: " + "uninitialized entity cannot be used to instantiate metric", + _tag, + _data_dir); return _disk_metric_entity; } @@ -234,7 +234,7 @@ void fs_manager::initialize(const std::vector &data_dirs, if (FLAGS_ignore_broken_disk) { LOG_ERROR("data dir({}) is broken, ignore it, error: {}", dir, err_msg); } else { - CHECK(false, err_msg); + PGSCHECK(false, err_msg); } status = disk_status::IO_ERROR; } @@ -301,7 +301,7 @@ dir_node *fs_manager::find_best_dir_for_new_replica(const gpid &pid) const LOG_INFO("skip the {} state dir_node({})", enum_to_string(dn->status), dn->tag); continue; } - CHECK(!dn->has(pid), "gpid({}) already exists in dir_node({})", pid, dn->tag); + PGSCHECK(!dn->has(pid), "gpid({}) already exists in dir_node({})", pid, dn->tag); uint64_t app_replicas_count = dn->replicas_count(pid.get_app_id()); uint64_t total_replicas_count = dn->replicas_count(); @@ -335,12 +335,12 @@ void fs_manager::specify_dir_for_new_replica_for_test(dir_node *specified_dn, bool dn_found = false; zauto_write_lock l(_lock); for (const auto &dn : _dir_nodes) { - CHECK(!dn->has(pid), "gpid({}) already exists in dir_node({})", pid, dn->tag); + PGSCHECK(!dn->has(pid), "gpid({}) already exists in dir_node({})", pid, dn->tag); if (dn.get() == specified_dn) { dn_found = true; } } - CHECK(dn_found, "dir_node({}) is not exist", specified_dn->tag); + PGSCHECK(dn_found, "dir_node({}) is not exist", specified_dn->tag); CHECK_EQ(disk_status::NORMAL, specified_dn->status); const auto dir = specified_dn->replica_dir(app_type, pid); CHECK_TRUE(dsn::utils::filesystem::create_directory(dir)); @@ -447,7 +447,7 @@ dir_node *fs_manager::find_replica_dir(std::string_view app_type, gpid pid) const auto dir = dn->replica_dir(app_type, pid); if (utils::filesystem::directory_exists(dir)) { // Check if there are duplicate replica instance directories. - CHECK(replica_dir.empty(), "replica dir conflict: {} <--> {}", dir, replica_dir); + PGSCHECK(replica_dir.empty(), "replica dir conflict: {} <--> {}", dir, replica_dir); replica_dir = dir; replica_dn = dn.get(); } @@ -463,7 +463,7 @@ dir_node *fs_manager::create_replica_dir_if_necessary(std::string_view app_type, auto replica_dn = find_replica_dir(app_type, pid); if (replica_dn != nullptr) { // TODO(yingchun): enable this check after unit tests are refactored and fixed. - // CHECK(replica_dn->has(pid), + // PGSCHECK(replica_dn->has(pid), // "replica({})'s directory({}) exists but not in management", // pid, // replica_dn->tag); @@ -471,7 +471,7 @@ dir_node *fs_manager::create_replica_dir_if_necessary(std::string_view app_type, } // TODO(yingchun): enable this check after unit tests are refactored and fixed. - // CHECK(0 == replica_dn->holding_replicas.count(pid.get_app_id()) || + // PGSCHECK(0 == replica_dn->holding_replicas.count(pid.get_app_id()) || // 0 == replica_dn->holding_replicas[pid.get_app_id()].count(pid), ""); // Find a dir_node for the new replica. replica_dn = find_best_dir_for_new_replica(pid); @@ -513,7 +513,7 @@ dir_node *fs_manager::create_child_replica_dir(std::string_view app_type, } } } - CHECK_NOTNULL(child_dn, "can not find parent_dir {} in data_dirs", parent_dir); + PGSCHECK_NOTNULL(child_dn, "can not find parent_dir {} in data_dirs", parent_dir); if (!dsn::utils::filesystem::create_directory(child_dir)) { LOG_ERROR("create child replica directory({}) failed", child_dir); return nullptr; diff --git a/src/common/json_helper.h b/src/common/json_helper.h index feb6a376da..f6e8f4ab59 100644 --- a/src/common/json_helper.h +++ b/src/common/json_helper.h @@ -583,7 +583,7 @@ inline void json_encode(JsonWriter &out, const dsn::ref_ptr &t) { // when a smart ptr is encoded, caller should ensure the ptr is not nullptr // TODO: encoded to null? - CHECK(t.get(), ""); + CHECK(t.get()); json_encode(out, *t); } @@ -599,7 +599,7 @@ inline void json_encode(JsonWriter &out, const std::shared_ptr &t) { // when a smart ptr is encoded, caller should ensure the ptr is not nullptr // TODO: encoded to null? - CHECK(t, ""); + CHECK(t); json_encode(out, *t); } diff --git a/src/common/replication_common.cpp b/src/common/replication_common.cpp index e34bcb5838..fb297e1268 100644 --- a/src/common/replication_common.cpp +++ b/src/common/replication_common.cpp @@ -138,7 +138,7 @@ void replication_options::initialize() std::string error_msg = ""; bool flag = get_data_dir_and_tag( FLAGS_data_dirs, app_dir, app_name, config_data_dirs, config_data_dir_tags, error_msg); - CHECK(flag, error_msg); + PGSCHECK(flag, error_msg); // check if data_dir in black list, data_dirs doesn't contain dir in black list std::vector black_list_dirs; @@ -151,9 +151,10 @@ void replication_options::initialize() data_dir_tags.emplace_back(config_data_dir_tags[i]); } - CHECK(!data_dirs.empty(), "no replica data dir found, maybe not set or excluded by black list"); - CHECK(replica_helper::parse_server_list(FLAGS_server_list, meta_servers), - "invalid meta server config"); + PGSCHECK(!data_dirs.empty(), + "no replica data dir found, maybe not set or excluded by black list"); + PGSCHECK(replica_helper::parse_server_list(FLAGS_server_list, meta_servers), + "invalid meta server config"); } int32_t replication_options::app_mutation_2pc_min_replica_count(int32_t app_max_replica_count) const @@ -297,7 +298,7 @@ replication_options::get_data_dirs_in_black_list(const std::string &fname, LOG_INFO("data_dirs_black_list_file[{}] found, apply it", fname); std::ifstream file(fname); - CHECK(file, "open data_dirs_black_list_file failed: {}", fname); + PGSCHECK(file, "open data_dirs_black_list_file failed: {}", fname); std::string str; int count = 0; diff --git a/src/common/serialization_helper/thrift_helper.h b/src/common/serialization_helper/thrift_helper.h index 54737a30b6..6470490ab2 100644 --- a/src/common/serialization_helper/thrift_helper.h +++ b/src/common/serialization_helper/thrift_helper.h @@ -190,8 +190,8 @@ inline uint32_t rpc_address::read(apache::thrift::protocol::TProtocol *iprot) if (binary_proto != nullptr) { // the protocol is binary protocol auto r = iprot->readI64(reinterpret_cast(_addr.value)); - CHECK(_addr.v4.type == HOST_TYPE_INVALID || _addr.v4.type == HOST_TYPE_IPV4, - "only invalid or ipv4 can be deserialized from binary"); + PGSCHECK(_addr.v4.type == HOST_TYPE_INVALID || _addr.v4.type == HOST_TYPE_IPV4, + "only invalid or ipv4 can be deserialized from binary"); return r; } else { // the protocol is json protocol @@ -249,8 +249,8 @@ inline uint32_t rpc_address::write(apache::thrift::protocol::TProtocol *oprot) c dynamic_cast(oprot); if (binary_proto != nullptr) { // the protocol is binary protocol - CHECK(_addr.v4.type == HOST_TYPE_INVALID || _addr.v4.type == HOST_TYPE_IPV4, - "only invalid or ipv4 can be serialized to binary"); + PGSCHECK(_addr.v4.type == HOST_TYPE_INVALID || _addr.v4.type == HOST_TYPE_IPV4, + "only invalid or ipv4 can be serialized to binary"); return oprot->writeI64((int64_t)_addr.value); } else { // the protocol is json protocol @@ -339,16 +339,16 @@ inline uint32_t host_port::read(apache::thrift::protocol::TProtocol *iprot) _host = host; _port = static_cast(port); _type = static_cast(type_enum_number); - CHECK(_type == HOST_TYPE_INVALID || _type == HOST_TYPE_IPV4, - "only invalid or ipv4 can be deserialized."); + PGSCHECK(_type == HOST_TYPE_INVALID || _type == HOST_TYPE_IPV4, + "only invalid or ipv4 can be deserialized."); return xfer; } inline uint32_t host_port::write(apache::thrift::protocol::TProtocol *oprot) const { - CHECK(_type == HOST_TYPE_INVALID || _type == HOST_TYPE_IPV4, - "only invalid or ipv4 can be serialized."); + PGSCHECK(_type == HOST_TYPE_INVALID || _type == HOST_TYPE_IPV4, + "only invalid or ipv4 can be serialized."); uint32_t xfer = 0; auto binary_proto = dynamic_cast(oprot); if (binary_proto != nullptr) { diff --git a/src/common/storage_serverlet.h b/src/common/storage_serverlet.h index ee1ef3bee2..8a670b1b0e 100644 --- a/src/common/storage_serverlet.h +++ b/src/common/storage_serverlet.h @@ -63,11 +63,11 @@ class storage_serverlet void (*handler)(T *svc, const TReq &req, rpc_replier &resp)) { // Only allowed to register simple.kv rpc handler. - CHECK(dsn::replication::application::RPC_SIMPLE_KV_SIMPLE_KV_READ == rpc_code || - dsn::replication::application::RPC_SIMPLE_KV_SIMPLE_KV_WRITE == rpc_code || - dsn::replication::application::RPC_SIMPLE_KV_SIMPLE_KV_APPEND == rpc_code, - "Not allowed to register with rpc_code {}", - rpc_code); + PGSCHECK(dsn::replication::application::RPC_SIMPLE_KV_SIMPLE_KV_READ == rpc_code || + dsn::replication::application::RPC_SIMPLE_KV_SIMPLE_KV_WRITE == rpc_code || + dsn::replication::application::RPC_SIMPLE_KV_SIMPLE_KV_APPEND == rpc_code, + "Not allowed to register with rpc_code {}", + rpc_code); rpc_handler h = [handler](T *p, dsn::message_ex *r) { TReq req; ::dsn::unmarshall(r, req); @@ -117,16 +117,17 @@ class storage_serverlet static bool register_async_rpc_handler(dsn::task_code rpc_code, const char *name, rpc_handler h) { - CHECK(s_handlers.emplace(rpc_code.to_string(), h).second, - "handler {} has already been registered", - rpc_code); - CHECK(s_handlers.emplace(name, h).second, "handler {} has already been registered", name); + PGSCHECK(s_handlers.emplace(rpc_code.to_string(), h).second, + "handler {} has already been registered", + rpc_code); + PGSCHECK( + s_handlers.emplace(name, h).second, "handler {} has already been registered", name); s_vhandlers.resize(rpc_code + 1); - CHECK(s_vhandlers[rpc_code] == nullptr, - "handler {}({}) has already been registered", - rpc_code, - rpc_code.code()); + PGSCHECK(s_vhandlers[rpc_code] == nullptr, + "handler {}({}) has already been registered", + rpc_code, + rpc_code.code()); s_vhandlers[rpc_code] = h; return true; } diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt index fab0926249..6c6adbc5a5 100644 --- a/src/common/test/CMakeLists.txt +++ b/src/common/test/CMakeLists.txt @@ -34,7 +34,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/failure_detector/failure_detector.cpp b/src/failure_detector/failure_detector.cpp index b3d1378ebd..98b7164be8 100644 --- a/src/failure_detector/failure_detector.cpp +++ b/src/failure_detector/failure_detector.cpp @@ -323,7 +323,7 @@ bool failure_detector::remove_from_allow_list(const ::dsn::host_port &node) void failure_detector::set_allow_list(const std::vector &replica_hps) { - CHECK(!_is_started, "FD is already started, the allow list should really not be modified"); + PGSCHECK(!_is_started, "FD is already started, the allow list should really not be modified"); std::vector nodes; for (const auto &hp : replica_hps) { diff --git a/src/failure_detector/failure_detector_multimaster.h b/src/failure_detector/failure_detector_multimaster.h index 3f352c2b03..61f6cf5b18 100644 --- a/src/failure_detector/failure_detector_multimaster.h +++ b/src/failure_detector/failure_detector_multimaster.h @@ -62,11 +62,11 @@ class slave_failure_detector_with_multimaster : public dsn::fd::failure_detector // server side void on_worker_disconnected(const std::vector<::dsn::host_port> &nodes) override { - CHECK(false, "invalid execution flow"); + PGSCHECK(false, "invalid execution flow"); } void on_worker_connected(const host_port &node) override { - CHECK(false, "invalid execution flow"); + PGSCHECK(false, "invalid execution flow"); } ::dsn::host_port current_server_contact() const; diff --git a/src/failure_detector/test/CMakeLists.txt b/src/failure_detector/test/CMakeLists.txt index 54907d6ee8..0d3bc0abd7 100644 --- a/src/failure_detector/test/CMakeLists.txt +++ b/src/failure_detector/test/CMakeLists.txt @@ -37,7 +37,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES run.sh diff --git a/src/failure_detector/test/failure_detector.cpp b/src/failure_detector/test/failure_detector.cpp index 81e1fdf3cd..53b48b51bd 100644 --- a/src/failure_detector/test/failure_detector.cpp +++ b/src/failure_detector/test/failure_detector.cpp @@ -243,7 +243,7 @@ class test_master : public service_app for (auto &port : ports) { rpc_address addr(network::get_local_ipv4(), std::stoi(port)); const auto hp = ::dsn::host_port::from_address(addr); - CHECK(hp, "'{}' can not be reverse resolved", addr); + PGSCHECK(hp, "'{}' can not be reverse resolved", addr); _master_fd->add_allow_list(hp); } use_allow_list = true; diff --git a/src/geo/bench/CMakeLists.txt b/src/geo/bench/CMakeLists.txt index 559747b59d..5ed35440ab 100644 --- a/src/geo/bench/CMakeLists.txt +++ b/src/geo/bench/CMakeLists.txt @@ -38,7 +38,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy - dsn_utils) + dsn_utils + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/geo/bench/bench.cpp b/src/geo/bench/bench.cpp index 42814687d3..330f158e01 100644 --- a/src/geo/bench/bench.cpp +++ b/src/geo/bench/bench.cpp @@ -97,7 +97,7 @@ int main(int argc, char **argv) std::string value; S2LatLng latlng(S2Testing::SamplePoint(rect)); bool ok = codec.encode_to_value(latlng.lat().degrees(), latlng.lng().degrees(), value); - CHECK(ok, ""); + CHECK(ok); int ret = my_geo.set(std::to_string(i), "", value, 1000); if (ret != pegasus::PERR_OK) { std::cerr << "set data failed. error=" << ret << std::endl; diff --git a/src/geo/lib/geo_client.cpp b/src/geo/lib/geo_client.cpp index 1cbb7b49d6..4aa78177ac 100644 --- a/src/geo/lib/geo_client.cpp +++ b/src/geo/lib/geo_client.cpp @@ -102,13 +102,13 @@ geo_client::geo_client(const char *config_file, const char *geo_app_name) { bool ok = pegasus_client_factory::initialize(config_file); - CHECK(ok, "init pegasus client factory failed"); + PGSCHECK(ok, "init pegasus client factory failed"); _common_data_client = pegasus_client_factory::get_client(cluster_name, common_app_name); - CHECK_NOTNULL(_common_data_client, "init pegasus _common_data_client failed"); + PGSCHECK_NOTNULL(_common_data_client, "init pegasus _common_data_client failed"); _geo_data_client = pegasus_client_factory::get_client(cluster_name, geo_app_name); - CHECK_NOTNULL(_geo_data_client, "init pegasus _geo_data_client failed"); + PGSCHECK_NOTNULL(_geo_data_client, "init pegasus _geo_data_client failed"); dsn::error_s s = _codec.set_latlng_indices(FLAGS_latitude_index, FLAGS_longitude_index); CHECK_OK(s, "set_latlng_indices({}, {}) failed", FLAGS_latitude_index, FLAGS_longitude_index); @@ -667,7 +667,7 @@ void geo_client::async_get_result_from_cells(const S2CellUnion &cids, } } - CHECK(!start_stop_sort_keys.first.empty(), ""); + CHECK(!start_stop_sort_keys.first.empty()); // the last sub slice of current `cid` on FLAGS_max_level in Hilbert curve covered by // `cap` if (start_stop_sort_keys.second.empty()) { diff --git a/src/geo/test/CMakeLists.txt b/src/geo/test/CMakeLists.txt index 73fd8ba108..e17cdd2724 100644 --- a/src/geo/test/CMakeLists.txt +++ b/src/geo/test/CMakeLists.txt @@ -39,7 +39,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy - gtest) + gtest + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/geo/test/geo_test.cpp b/src/geo/test/geo_test.cpp index e66a251d0d..fc9e2c03ee 100644 --- a/src/geo/test/geo_test.cpp +++ b/src/geo/test/geo_test.cpp @@ -62,9 +62,9 @@ class geo_client_test : public ::testing::Test geo_client_test() { std::vector meta_list; - CHECK(dsn::replication::replica_helper::load_servers_from_config( - dsn::PEGASUS_CLUSTER_SECTION_NAME, "onebox", meta_list), - "load_servers_from_config failed"); + PGSCHECK(dsn::replication::replica_helper::load_servers_from_config( + dsn::PEGASUS_CLUSTER_SECTION_NAME, "onebox", meta_list), + "load_servers_from_config failed"); auto ddl_client = new dsn::replication::replication_ddl_client(meta_list); dsn::error_code error = ddl_client->create_app("temp_geo", "pegasus", 4, 3, {}, false); CHECK_EQ(dsn::ERR_OK, error); diff --git a/src/gutil/map_util.h b/src/gutil/map_util.h index 4ce286fc07..56711491fa 100644 --- a/src/gutil/map_util.h +++ b/src/gutil/map_util.h @@ -162,7 +162,7 @@ template > const MapUtilMappedT &FindOrDie(const M &m, const KeyType &key) { auto it = m.find(key); - CHECK(it != m.end(), "Map key not found: {}", key); + CHECK(it != m.end()) << "Map key not found: {}" << key; return gutil::subtle::GetMapped(*it); } @@ -172,7 +172,7 @@ MapUtilMappedT &FindOrDie(M &m, // NOLINT const KeyType &key) { auto it = m.find(key); - CHECK(it != m.end(), "Map key not found: {}", key); + CHECK(it != m.end()) << "Map key not found: {}" << key; return gutil::subtle::GetMapped(*it); } @@ -181,7 +181,7 @@ template > const MapUtilMappedT &FindOrDieNoPrint(const M &m, const KeyType &key) { auto it = m.find(key); - CHECK(it != m.end(), "Map key not found"); + CHECK(it != m.end()) << "Map key not found"; return gutil::subtle::GetMapped(*it); } @@ -191,7 +191,7 @@ MapUtilMappedT &FindOrDieNoPrint(M &m, // NOLINT const KeyType &key) { auto it = m.find(key); - CHECK(it != m.end(), "Map key not found"); + CHECK(it != m.end()) << "Map key not found"; return gutil::subtle::GetMapped(*it); } @@ -391,14 +391,14 @@ bool InsertIfNotPresent(M *m, const MapUtilKeyT &key, const MapUtilMappedT template void InsertOrDie(M *m, const MapUtilInitT &value) { - CHECK(InsertIfNotPresent(m, value), "duplicate value: {}", value); + CHECK(InsertIfNotPresent(m, value)) << "duplicate value: " << value; } // Same as above except doesn't log the value on error. template void InsertOrDieNoPrint(M *m, const MapUtilInitT &value) { - CHECK(InsertIfNotPresent(m, value), "duplicate value."); + CHECK(InsertIfNotPresent(m, value)) << "duplicate value."; } // Inserts the key-value pair into the m. Dies if key was already @@ -406,14 +406,14 @@ void InsertOrDieNoPrint(M *m, const MapUtilInitT &value) template void InsertOrDie(M *m, const MapUtilKeyT &key, const MapUtilMappedT &data) { - CHECK(InsertIfNotPresent(m, key, data), "duplicate key: {}", key); + CHECK(InsertIfNotPresent(m, key, data)) << "duplicate key: " << key; } // Same as above except doesn't log the key on error. template void InsertOrDieNoPrint(M *m, const MapUtilKeyT &key, const MapUtilMappedT &data) { - CHECK(InsertIfNotPresent(m, key, data), "duplicate key."); + CHECK(InsertIfNotPresent(m, key, data)) << "duplicate key."; } // Inserts a new key and default-initialized value. Dies if the key was already @@ -427,7 +427,7 @@ auto InsertKeyOrDie(M *m, const MapUtilKeyT &key) -> typename std::enable_if::value, MapUtilMappedT &>::type { auto res = m->try_emplace(key); - CHECK(res.second, "duplicate key: {}", key); + CHECK(res.second) << "duplicate key: " << key; return gutil::subtle::GetMapped(*res.first); } @@ -437,7 +437,7 @@ auto InsertKeyOrDie(M *m, const MapUtilKeyT &key) -> typename std::enable_if::value, MapUtilMappedT &>::type { auto res = m->insert(MapUtilValueT(key, MapUtilMappedT())); - CHECK(res.second, "duplicate key: {}", key); + CHECK(res.second) << "duplicate key: " << key; return res.first->second; } @@ -545,7 +545,7 @@ InsertOrReturnExisting(M *m, const MapUtilKeyT &key, const MapUtilMappedT template bool ReverseMap(const M &m, ReverseM *reverse) { - CHECK_NOTNULL(reverse, ""); + PGSCHECK_NOTNULL(reverse, ""); bool all_unique = true; for (const auto &kv : m) { if (!InsertOrUpdate(reverse, kv.second, kv.first)) { @@ -601,7 +601,7 @@ MapUtilMappedT EraseKeyReturnValuePtr(M *m, const MapUtilKeyT &key) template void InsertKeysFromMap(const M &m, KeyContainer *key_container) { - CHECK_NOTNULL(key_container, ""); + PGSCHECK_NOTNULL(key_container, ""); for (const auto &kv : m) { key_container->insert(kv.first); } @@ -614,7 +614,7 @@ void InsertKeysFromMap(const M &m, KeyContainer *key_container) template void AppendKeysFromMap(const M &m, KeyContainer *key_container) { - CHECK_NOTNULL(key_container, ""); + PGSCHECK_NOTNULL(key_container, ""); for (const auto &kv : m) { key_container->push_back(kv.first); } @@ -630,7 +630,7 @@ void AppendKeysFromMap(const M &m, KeyContainer *key_container) template void AppendKeysFromMap(const M &m, std::vector *key_container) { - CHECK_NOTNULL(key_container, ""); + PGSCHECK_NOTNULL(key_container, ""); // We now have the opportunity to call reserve(). Calling reserve() every // time is a bad idea for some use cases: libstdc++'s implementation of // std::vector<>::reserve() resizes the vector's backing store to exactly the @@ -655,7 +655,7 @@ void AppendKeysFromMap(const M &m, std::vector *key_container) template void AppendValuesFromMap(const M &m, ValueContainer *value_container) { - CHECK_NOTNULL(value_container, ""); + PGSCHECK_NOTNULL(value_container, ""); for (const auto &kv : m) { value_container->push_back(kv.second); } @@ -671,7 +671,7 @@ void AppendValuesFromMap(const M &m, ValueContainer *value_container) template void AppendValuesFromMap(const M &m, std::vector *value_container) { - CHECK_NOTNULL(value_container, ""); + PGSCHECK_NOTNULL(value_container, ""); // See AppendKeysFromMap for why this is done. if (value_container->empty()) { value_container->reserve(m.size()); @@ -690,7 +690,7 @@ template auto AssociativeEraseIf(M *m, Predicate predicate) -> typename std::enable_iferase(m->begin()))>::value>::type { - CHECK_NOTNULL(m, ""); + PGSCHECK_NOTNULL(m, ""); for (auto it = m->begin(); it != m->end();) { if (predicate(*it)) { m->erase(it++); @@ -704,7 +704,7 @@ template auto AssociativeEraseIf(M *m, Predicate predicate) -> typename std::enable_if< std::is_samebegin()), decltype(m->erase(m->begin()))>::value>::type { - CHECK_NOTNULL(m, ""); + PGSCHECK_NOTNULL(m, ""); for (auto it = m->begin(); it != m->end();) { if (predicate(*it)) { it = m->erase(it); diff --git a/src/gutil/test/CMakeLists.txt b/src/gutil/test/CMakeLists.txt index 75e489cd73..510255bc50 100644 --- a/src/gutil/test/CMakeLists.txt +++ b/src/gutil/test/CMakeLists.txt @@ -29,7 +29,9 @@ set(MY_PROJ_LIBS zstd snappy gmock - gtest) + gtest + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES run.sh) diff --git a/src/gutil/test/no_destructor_test.cpp b/src/gutil/test/no_destructor_test.cpp index a0f5885877..c58f98a9d3 100644 --- a/src/gutil/test/no_destructor_test.cpp +++ b/src/gutil/test/no_destructor_test.cpp @@ -44,7 +44,7 @@ struct Blob // no crash: NoDestructor indeed does not destruct (the moved-out Blob // temporaries do get destroyed though) - ~Blob() { CHECK(moved_out, "~Blob"); } + ~Blob() { PGSCHECK(moved_out, "~Blob"); } int val; bool moved_out = false; diff --git a/src/http/http_client.cpp b/src/http/http_client.cpp index a369fe3e97..3e980f7f03 100644 --- a/src/http/http_client.cpp +++ b/src/http/http_client.cpp @@ -51,7 +51,7 @@ namespace dsn { #define CHECK_IF_CURL_URL_OK(url, expr, ...) \ do { \ - CHECK_NOTNULL(url, "CURLU object has not been allocated"); \ + PGSCHECK_NOTNULL(url, "CURLU object has not been allocated"); \ CHECK_IF_CURL_OK(expr, CURLUE_OK, __VA_ARGS__); \ } while (0) @@ -92,7 +92,7 @@ inline std::string to_error_msg(CURLUcode code) CURLU *new_curlu() { CURLU *url = curl_url(); - CHECK_NOTNULL(url, "fail to allocate a CURLU object due to out of memory"); + PGSCHECK_NOTNULL(url, "fail to allocate a CURLU object due to out of memory"); SET_DEFAULT_HTTP_SCHEME(url); @@ -102,7 +102,7 @@ CURLU *new_curlu() CURLU *dup_curlu(const CURLU *url) { CURLU *new_url = curl_url_dup(url); - CHECK_NOTNULL(new_url, "fail to duplicate a CURLU object due to out of memory"); + PGSCHECK_NOTNULL(new_url, "fail to duplicate a CURLU object due to out of memory"); return new_url; } @@ -198,7 +198,7 @@ DEF_HTTP_URL_SET_FUNC(query, QUERY) dsn::error_s http_url::to_string(std::string &url) const { - CHECK_NOTNULL(_url, "CURLU object has not been allocated"); + PGSCHECK_NOTNULL(_url, "CURLU object has not been allocated"); char *content; RETURN_IF_CURL_URL_GET_NOT_OK(CURLUPART_URL, &content, 0); @@ -257,7 +257,7 @@ inline dsn::error_code to_error_code(CURLcode code) #define RETURN_IF_CURL_EASY_NOT_OK(expr, ...) \ do { \ - CHECK_NOTNULL(_curl, "CURL object has not been allocated"); \ + PGSCHECK_NOTNULL(_curl, "CURL object has not been allocated"); \ RETURN_IF_CURL_NOT_OK(expr, CURLE_OK, __VA_ARGS__); \ } while (0) @@ -277,7 +277,7 @@ inline dsn::error_code to_error_code(CURLcode code) #define CHECK_IF_CURL_EASY_OK(expr, ...) \ do { \ - CHECK_NOTNULL(_curl, "CURL object has not been allocated"); \ + PGSCHECK_NOTNULL(_curl, "CURL object has not been allocated"); \ CHECK_IF_CURL_OK(expr, CURLE_OK, __VA_ARGS__); \ } while (0) diff --git a/src/http/http_message_parser.cpp b/src/http/http_message_parser.cpp index df873eea2e..ce35606960 100644 --- a/src/http/http_message_parser.cpp +++ b/src/http/http_message_parser.cpp @@ -216,7 +216,7 @@ void http_message_parser::prepare_on_send(message_ex *msg) const message_header *header = msg->header; std::vector &buffers = msg->buffers; - CHECK(!header->context.u.is_request, "send response only"); + PGSCHECK(!header->context.u.is_request, "send response only"); unsigned int dsn_size = sizeof(message_header) + header->body_length; int dsn_buf_count = 0; diff --git a/src/http/test/CMakeLists.txt b/src/http/test/CMakeLists.txt index 4400c0183f..f8bd0f1c7d 100644 --- a/src/http/test/CMakeLists.txt +++ b/src/http/test/CMakeLists.txt @@ -29,7 +29,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/meta/app_env_validator.cpp b/src/meta/app_env_validator.cpp index 06288cb611..aa4b2e584e 100644 --- a/src/meta/app_env_validator.cpp +++ b/src/meta/app_env_validator.cpp @@ -351,7 +351,7 @@ const std::unordered_map nlohmann::json app_env_validator::EnvInfo::to_json() const { const auto *type_str = gutil::FindOrNull(ValueType2String, type); - CHECK_NOTNULL(type_str, ""); + CHECK_NOTNULL(type_str); nlohmann::json info; info["type"] = *type_str; info["limitation"] = limit_desc; diff --git a/src/meta/backup_engine.cpp b/src/meta/backup_engine.cpp index 5183415369..cddbd68036 100644 --- a/src/meta/backup_engine.cpp +++ b/src/meta/backup_engine.cpp @@ -133,7 +133,7 @@ error_code backup_engine::write_backup_file(const std::string &file_name, LOG_INFO("create file {} failed", file_name); return err; } - CHECK_NOTNULL( + PGSCHECK_NOTNULL( remote_file, "create file {} succeed, but can't get handle", create_file_req.file_name); remote_file ->write(dist::block_service::write_request{write_buffer}, diff --git a/src/meta/dump_file.h b/src/meta/dump_file.h index 062ffd1fcc..294cd5db1e 100644 --- a/src/meta/dump_file.h +++ b/src/meta/dump_file.h @@ -89,7 +89,7 @@ class dump_file { static __thread char msg_buffer[128]; - CHECK(_is_write, "call append when open file with read mode"); + PGSCHECK(_is_write, "call append when open file with read mode"); block_header hdr = {data_length, 0}; hdr.crc32 = dsn::utils::crc32_calc(data, data_length, _crc); @@ -114,7 +114,7 @@ class dump_file int read_next_buffer(/*out*/ dsn::blob &output) { static __thread char msg_buffer[128]; - CHECK(!_is_write, "call read next buffer when open file with write mode"); + PGSCHECK(!_is_write, "call read next buffer when open file with write mode"); block_header hdr; size_t len = fread(&hdr, sizeof(hdr), 1, _file_handle); diff --git a/src/meta/duplication/meta_duplication_service.cpp b/src/meta/duplication/meta_duplication_service.cpp index 76472a04d8..7dacfb953e 100644 --- a/src/meta/duplication/meta_duplication_service.cpp +++ b/src/meta/duplication/meta_duplication_service.cpp @@ -159,11 +159,11 @@ void meta_duplication_service::do_modify_duplication(std::shared_ptr }); } +// LOG(level, _msg); #define LOG_DUP_HINT_AND_RETURN(resp, level, ...) \ do { \ const std::string _msg(fmt::format(__VA_ARGS__)); \ (resp).__set_hint(_msg); \ - LOG(level, _msg); \ return; \ } while (0) diff --git a/src/meta/duplication/meta_duplication_service.h b/src/meta/duplication/meta_duplication_service.h index 3f06d63265..6a931c0d26 100644 --- a/src/meta/duplication/meta_duplication_service.h +++ b/src/meta/duplication/meta_duplication_service.h @@ -61,8 +61,8 @@ class meta_duplication_service public: meta_duplication_service(server_state *ss, meta_service *ms) : _state(ss), _meta_svc(ms) { - CHECK_NOTNULL(_state, "_state should not be null"); - CHECK_NOTNULL(_meta_svc, "_meta_svc should not be null"); + PGSCHECK_NOTNULL(_state, "_state should not be null"); + PGSCHECK_NOTNULL(_meta_svc, "_meta_svc should not be null"); } /// See replication.thrift for possible errors for each rpc. diff --git a/src/meta/greedy_load_balancer.cpp b/src/meta/greedy_load_balancer.cpp index 81d7482bd9..1751c37d3f 100644 --- a/src/meta/greedy_load_balancer.cpp +++ b/src/meta/greedy_load_balancer.cpp @@ -233,7 +233,7 @@ void greedy_load_balancer::report(const dsn::replication::migration_list &list, __METRIC_INCREMENT(greedy_copy_secondary_operations); break; default: - CHECK(false, ""); + CHECK(false); } } diff --git a/src/meta/load_balance_policy.cpp b/src/meta/load_balance_policy.cpp index 1278b35f98..3e3703d95c 100644 --- a/src/meta/load_balance_policy.cpp +++ b/src/meta/load_balance_policy.cpp @@ -85,7 +85,7 @@ bool calc_disk_load(node_mapper &nodes, { load.clear(); const node_state *ns = get_node_state(nodes, node, false); - CHECK_NOTNULL(ns, "can't find node({}) from node_state", node); + PGSCHECK_NOTNULL(ns, "can't find node({}) from node_state", node); auto add_one_replica_to_disk_load = [&](const gpid &pid) { LOG_DEBUG("add gpid({}) to node({}) disk load", pid, node); @@ -135,7 +135,7 @@ const std::string &get_disk_tag(const app_mapper &apps, const host_port &node, c { const config_context &cc = *get_config_context(apps, pid); auto iter = cc.find_from_serving(node); - CHECK(iter != cc.serving.end(), "can't find disk tag of gpid({}) for {}", pid, node); + PGSCHECK(iter != cc.serving.end(), "can't find disk tag of gpid({}) for {}", pid, node); return iter->disk_tag; } @@ -181,7 +181,7 @@ generate_balancer_request(const app_mapper &apps, new_proposal_action(pc.hp_primary, from, config_type::CT_REMOVE)); break; default: - CHECK(false, ""); + CHECK(false); } LOG_INFO("generate balancer: {} {} from {} of disk_tag({}) to {}", pc.pid, @@ -324,7 +324,7 @@ void load_balance_policy::start_moving_primary(const std::shared_ptr selected, generate_balancer_request( *_global_view->apps, pc, balance_type::MOVE_PRIMARY, from, to)); - CHECK(balancer_result.second, "gpid({}) already inserted as an action", selected); + PGSCHECK(balancer_result.second, "gpid({}) already inserted as an action", selected); --(*prev_load)[get_disk_tag(*_global_view->apps, from, selected)]; ++(*current_load)[get_disk_tag(*_global_view->apps, to, selected)]; @@ -364,7 +364,8 @@ dsn::gpid load_balance_policy::select_moving(std::list &potential_mov } } - CHECK(selected != potential_moving.end(), "can't find gpid to move from({}) to({})", from, to); + PGSCHECK( + selected != potential_moving.end(), "can't find gpid to move from({}) to({})", from, to); auto res = *selected; potential_moving.erase(selected); return res; @@ -493,8 +494,8 @@ void load_balance_policy::number_nodes(const node_mapper &nodes) host_port_id.clear(); host_port_vec.resize(_alive_nodes + 2); for (auto iter = nodes.begin(); iter != nodes.end(); ++iter) { - CHECK(iter->first && iter->second.host_port(), "invalid address"); - CHECK(iter->second.alive(), "dead node"); + PGSCHECK(iter->first && iter->second.host_port(), "invalid address"); + PGSCHECK(iter->second.alive(), "dead node"); host_port_id[iter->first] = current_id; host_port_vec[current_id] = iter->first; @@ -568,7 +569,7 @@ void ford_fulkerson::update_decree(int node_id, const node_state &ns) const auto &pc = _app->pcs[pid.get_partition_index()]; for (const auto &secondary : pc.hp_secondaries) { auto i = _host_port_id.find(secondary); - CHECK(i != _host_port_id.end(), "invalid secondary: {}", secondary); + PGSCHECK(i != _host_port_id.end(), "invalid secondary: {}", secondary); _network[node_id][i->second]++; } return true; @@ -754,9 +755,9 @@ gpid copy_replica_operation::select_partition(migration_list *result) int id_max = *_ordered_host_port_ids.rbegin(); const node_state &ns = _nodes.find(_host_port_vec[id_max])->second; - CHECK(partitions != nullptr && !partitions->empty(), - "max load({}) shouldn't empty", - ns.host_port()); + PGSCHECK(partitions != nullptr && !partitions->empty(), + "max load({}) shouldn't empty", + ns.host_port()); return select_max_load_gpid(partitions, result); } diff --git a/src/meta/meta_backup_service.cpp b/src/meta/meta_backup_service.cpp index 2bfa64ede7..e3054a253b 100644 --- a/src/meta/meta_backup_service.cpp +++ b/src/meta/meta_backup_service.cpp @@ -109,10 +109,10 @@ backup_policy_metrics::backup_policy_metrics(const std::string &policy_name) const metric_entity_ptr &backup_policy_metrics::backup_policy_metric_entity() const { - CHECK_NOTNULL(_backup_policy_metric_entity, - "backup_policy metric entity (policy_name={}) should has been instantiated: " - "uninitialized entity cannot be used to instantiate metric", - _policy_name); + PGSCHECK_NOTNULL(_backup_policy_metric_entity, + "backup_policy metric entity (policy_name={}) should has been instantiated: " + "uninitialized entity cannot be used to instantiate metric", + _policy_name); return _backup_policy_metric_entity; } @@ -149,10 +149,10 @@ void policy_context::start_backup_app_meta_unlocked(int32_t app_id) _backup_sig, app_id); auto iter = _progress.unfinished_partitions_per_app.find(app_id); - CHECK(iter != _progress.unfinished_partitions_per_app.end(), - "{}: can't find app({}) in unfished_map", - _backup_sig, - app_id); + PGSCHECK(iter != _progress.unfinished_partitions_per_app.end(), + "{}: can't find app({}) in unfished_map", + _backup_sig, + app_id); _progress.is_app_skipped[app_id] = true; int total_partitions = iter->second; for (int32_t pidx = 0; pidx < total_partitions; ++pidx) { @@ -195,10 +195,10 @@ void policy_context::start_backup_app_meta_unlocked(int32_t app_id) _backup_service->backup_option().block_retry_delay_ms); return; } - CHECK_NOTNULL(remote_file, - "{}: create file({}) succeed, but can't get handle", - _backup_sig, - create_file_req.file_name); + PGSCHECK_NOTNULL(remote_file, + "{}: create file({}) succeed, but can't get handle", + _backup_sig, + create_file_req.file_name); remote_file->write( dist::block_service::write_request{buffer}, @@ -241,10 +241,10 @@ void policy_context::start_backup_app_meta_unlocked(int32_t app_id) void policy_context::start_backup_app_partitions_unlocked(int32_t app_id) { auto iter = _progress.unfinished_partitions_per_app.find(app_id); - CHECK(iter != _progress.unfinished_partitions_per_app.end(), - "{}: can't find app({}) in unfinished apps", - _backup_sig, - app_id); + PGSCHECK(iter != _progress.unfinished_partitions_per_app.end(), + "{}: can't find app({}) in unfinished apps", + _backup_sig, + app_id); for (int32_t i = 0; i < iter->second; ++i) { start_backup_partition_unlocked(gpid(app_id, i)); } @@ -304,10 +304,10 @@ void policy_context::write_backup_app_finish_flag_unlocked(int32_t app_id, return; } - CHECK_NOTNULL(remote_file, - "{}: create file({}) succeed, but can't get handle", - _backup_sig, - create_file_req.file_name); + PGSCHECK_NOTNULL(remote_file, + "{}: create file({}) succeed, but can't get handle", + _backup_sig, + create_file_req.file_name); if (remote_file->get_size() > 0) { // we only focus whether app_backup_status file is exist, so ignore app_backup_status file's // context @@ -371,10 +371,10 @@ void policy_context::finish_backup_app_unlocked(int32_t app_id) tasking::create_task(LPC_DEFAULT_CALLBACK, &_tracker, [this]() { zauto_lock l(_lock); auto iter = _backup_history.emplace(_cur_backup.backup_id, _cur_backup); - CHECK(iter.second, - "{}: backup_id({}) already in the backup_history", - _policy.policy_name, - _cur_backup.backup_id); + PGSCHECK(iter.second, + "{}: backup_id({}) already in the backup_history", + _policy.policy_name, + _cur_backup.backup_id); _cur_backup.start_time_ms = 0; _cur_backup.end_time_ms = 0; LOG_INFO("{}: finish an old backup, try to start a new one", _backup_sig); @@ -422,10 +422,10 @@ void policy_context::write_backup_info_unlocked(const backup_info &b_info, return; } - CHECK_NOTNULL(remote_file, - "{}: create file({}) succeed, but can't get handle", - _backup_sig, - create_file_req.file_name); + PGSCHECK_NOTNULL(remote_file, + "{}: create file({}) succeed, but can't get handle", + _backup_sig, + create_file_req.file_name); blob buf = dsn::json::json_forwarder::encode(b_info); @@ -728,7 +728,7 @@ void policy_context::sync_backup_to_remote_storage_unlocked(const backup_info &b 0, _backup_service->backup_option().meta_retry_delay_ms); } else { - CHECK(false, "{}: we can't handle this right now, error({})", _backup_sig, err); + PGSCHECK(false, "{}: we can't handle this right now, error({})", _backup_sig, err); } }; @@ -895,7 +895,7 @@ void policy_context::start() continue_current_backup_unlocked(); } - CHECK(!_policy.policy_name.empty(), "policy_name should has been initialized"); + PGSCHECK(!_policy.policy_name.empty(), "policy_name should has been initialized"); _metrics = std::make_unique(_policy.policy_name); issue_gc_backup_info_task_unlocked(); @@ -917,11 +917,11 @@ void policy_context::add_backup_history(const backup_info &info) _policy.policy_name, _cur_backup.backup_id, info.backup_id); - CHECK(_backup_history.empty() || info.backup_id > _backup_history.rbegin()->first, - "{}: backup_id({}) in history larger than current({})", - _policy.policy_name, - _backup_history.rbegin()->first, - info.backup_id); + PGSCHECK(_backup_history.empty() || info.backup_id > _backup_history.rbegin()->first, + "{}: backup_id({}) in history larger than current({})", + _policy.policy_name, + _backup_history.rbegin()->first, + info.backup_id); _cur_backup = info; initialize_backup_progress_unlocked(); _backup_sig = @@ -932,14 +932,14 @@ void policy_context::add_backup_history(const backup_info &info) info.backup_id, info.start_time_ms, info.end_time_ms); - CHECK(_cur_backup.end_time_ms == 0 || info.backup_id < _cur_backup.backup_id, - "{}: backup_id({}) in history larger than current({})", - _policy.policy_name, - info.backup_id, - _cur_backup.backup_id); + PGSCHECK(_cur_backup.end_time_ms == 0 || info.backup_id < _cur_backup.backup_id, + "{}: backup_id({}) in history larger than current({})", + _policy.policy_name, + info.backup_id, + _cur_backup.backup_id); auto result_pair = _backup_history.emplace(info.backup_id, info); - CHECK( + PGSCHECK( result_pair.second, "{}: conflict backup id({})", _policy.policy_name, info.backup_id); } } @@ -982,9 +982,9 @@ void policy_context::set_policy(const policy &p) ->get_block_service_manager() .get_or_create_block_filesystem(_policy.backup_provider_type); } - CHECK(_block_service, - "can't initialize block filesystem by provider ({})", - _policy.backup_provider_type); + PGSCHECK(_block_service, + "can't initialize block filesystem by provider ({})", + _policy.backup_provider_type); } policy policy_context::get_policy() @@ -1097,7 +1097,8 @@ void policy_context::sync_remove_backup_info(const backup_info &info, dsn::task_ 0, _backup_service->backup_option().meta_retry_delay_ms); } else { - CHECK(false, "{}: we can't handle this right now, error({})", _policy.policy_name, err); + PGSCHECK( + false, "{}: we can't handle this right now, error({})", _policy.policy_name, err); } }; @@ -1144,7 +1145,7 @@ void backup_service::start_create_policy_meta_root(dsn::task_ptr callback) 0, _opt.meta_retry_delay_ms); } else { - CHECK(false, "we can't handle this error({}) right now", err); + PGSCHECK(false, "we can't handle this error({}) right now", err); } }); } @@ -1173,9 +1174,9 @@ void backup_service::start_sync_policies() 0, _opt.meta_retry_delay_ms); } else { - CHECK(false, - "sync policies from remote storage encounter error({}), we can't handle " - "this right now"); + PGSCHECK(false, + "sync policies from remote storage encounter error({}), we can't handle " + "this right now"); } } @@ -1199,8 +1200,9 @@ error_code backup_service::sync_policies_from_remote_storage() zauto_lock l(_lock); auto it = _policy_states.find(policy_name); if (it == _policy_states.end()) { - CHECK(false, - "before initializing the backup_info, initialize the policy first"); + PGSCHECK( + false, + "before initializing the backup_info, initialize the policy first"); } ptr = it->second.get(); } @@ -1386,7 +1388,7 @@ void backup_service::add_backup_policy(dsn::message_ex *msg) LOG_INFO("start to add backup polciy {}.", request.policy_name); std::shared_ptr policy_context_ptr = _factory(this); - CHECK_NOTNULL(policy_context_ptr, "invalid policy_context"); + PGSCHECK_NOTNULL(policy_context_ptr, "invalid policy_context"); policy p; p.policy_name = request.policy_name; p.backup_provider_type = request.backup_provider_type; @@ -1434,7 +1436,7 @@ void backup_service::do_add_policy(dsn::message_ex *req, _opt.meta_retry_delay_ms); return; } else { - CHECK(false, "we can't handle this when create backup policy, err({})", err); + PGSCHECK(false, "we can't handle this when create backup policy, err({})", err); } }, value); @@ -1470,7 +1472,7 @@ void backup_service::do_update_policy_to_remote_storage( 0, _opt.meta_retry_delay_ms); } else { - CHECK(false, "we can't handle this when create backup policy, err({})", err); + PGSCHECK(false, "we can't handle this when create backup policy, err({})", err); } }); } diff --git a/src/meta/meta_data.cpp b/src/meta/meta_data.cpp index 44da02f058..3d67672bc2 100644 --- a/src/meta/meta_data.cpp +++ b/src/meta/meta_data.cpp @@ -132,7 +132,7 @@ bool construct_replica(meta_view view, const gpid &pid, int max_replica_count) // we put max_replica_count-1 recent replicas to last_drops, in case of the DDD-state when the // only primary dead // when add node to pc.last_drops, we don't remove it from our cc.drop_list - CHECK(pc.hp_last_drops.empty(), "last_drops of partition({}) must be empty", pid); + PGSCHECK(pc.hp_last_drops.empty(), "last_drops of partition({}) must be empty", pid); for (auto iter = drop_list.rbegin(); iter != drop_list.rend(); ++iter) { if (pc.hp_last_drops.size() + 1 >= max_replica_count) { break; @@ -170,7 +170,7 @@ bool collect_replica(meta_view view, const host_port &node, const replica_info & // adjust the drop list int ans = cc.collect_drop_replica(node, info); - CHECK(cc.check_order(), ""); + CHECK(cc.check_order()); return info.status == partition_status::PS_POTENTIAL_SECONDARY || ans != -1; } @@ -192,7 +192,7 @@ void proposal_actions::track_current_learner(const dsn::host_port &node, const r return; } const auto &act = acts.front(); - CHECK(act.hp_node, ""); + CHECK(act.hp_node); if (act.hp_node != node) { return; } @@ -375,10 +375,10 @@ int config_context::collect_drop_replica(const host_port &node, const replica_in iter = find_from_dropped(node); if (iter == dropped.end()) { - CHECK(!in_dropped, - "adjust position of existing node({}) failed, this is a bug, partition({})", - node, - pc->pid); + PGSCHECK(!in_dropped, + "adjust position of existing node({}) failed, this is a bug, partition({})", + node, + pc->pid); return -1; } return in_dropped ? 1 : 0; diff --git a/src/meta/meta_data.h b/src/meta/meta_data.h index dd2533ecfc..602266b94b 100644 --- a/src/meta/meta_data.h +++ b/src/meta/meta_data.h @@ -554,7 +554,7 @@ void maintain_drops(/*inout*/ std::vector &drops, const T &node, config_type: drops.erase(it); } } else { - CHECK( + PGSCHECK( it == drops.end(), "the node({}) cannot be in drops set before this update", node); drops.push_back(node); if (drops.size() > 3) { diff --git a/src/meta/meta_server_failure_detector.cpp b/src/meta/meta_server_failure_detector.cpp index 9e198582cc..da39d90d70 100644 --- a/src/meta/meta_server_failure_detector.cpp +++ b/src/meta/meta_server_failure_detector.cpp @@ -113,13 +113,13 @@ bool meta_server_failure_detector::get_leader(host_port *leader) // get leader host_port auto addr_part = str.substr(pos + 1, str.length() - pos - 1); *leader = host_port::from_string(addr_part.data()); - CHECK(*leader, "parse {} to rpc_address failed", addr_part); + PGSCHECK(*leader, "parse {} to rpc_address failed", addr_part); // get the return value which implies whether the current node is primary or not bool is_leader = true; auto is_leader_part = str.substr(0, pos); if (!dsn::buf2bool(is_leader_part, is_leader)) { - CHECK(false, "parse {} to bool failed", is_leader_part); + PGSCHECK(false, "parse {} to bool failed", is_leader_part); } return is_leader; }); @@ -226,7 +226,7 @@ void meta_server_failure_detector::reset_stability_stat(const host_port &node) void meta_server_failure_detector::leader_initialize(const std::string &lock_service_owner) { const auto hp = dsn::host_port::from_string(lock_service_owner); - CHECK(hp, "parse {} to host_port failed", lock_service_owner); + PGSCHECK(hp, "parse {} to host_port failed", lock_service_owner); CHECK_EQ_MSG(hp, dsn_primary_host_port(), "acquire leader return success, but owner not match"); _is_leader.store(true); _election_moment.store(dsn_now_ms()); diff --git a/src/meta/meta_server_failure_detector.h b/src/meta/meta_server_failure_detector.h index f656479a1a..fb35ab0ea2 100644 --- a/src/meta/meta_server_failure_detector.h +++ b/src/meta/meta_server_failure_detector.h @@ -96,9 +96,9 @@ class meta_server_failure_detector : public fd::failure_detector // client side virtual void on_master_disconnected(const std::vector &) { - CHECK(false, "unsupported method"); + PGSCHECK(false, "unsupported method"); } - virtual void on_master_connected(const host_port &) { CHECK(false, "unsupported method"); } + virtual void on_master_connected(const host_port &) { PGSCHECK(false, "unsupported method"); } // server side // it is in the protection of failure_detector::_lock diff --git a/src/meta/meta_service.cpp b/src/meta/meta_service.cpp index 98f0339cee..be82bfe884 100644 --- a/src/meta/meta_service.cpp +++ b/src/meta/meta_service.cpp @@ -381,7 +381,7 @@ void meta_service::start_service() // the start function is executed in threadpool default error_code meta_service::start() { - CHECK(!_started, "meta service is already started"); + PGSCHECK(!_started, "meta service is already started"); register_ctrl_commands(); error_code err; @@ -396,7 +396,7 @@ error_code meta_service::start() _failure_detector->set_allow_list(_meta_opts.replica_white_list); _failure_detector->register_ctrl_commands(); - CHECK_GT_MSG(FLAGS_fd_grace_seconds, FLAGS_fd_lease_seconds, ""); + CHECK_GT(FLAGS_fd_grace_seconds, FLAGS_fd_lease_seconds); err = _failure_detector->start(FLAGS_fd_check_interval_seconds, FLAGS_fd_beacon_interval_seconds, FLAGS_fd_lease_seconds, @@ -416,7 +416,7 @@ error_code meta_service::start() dist::cmd::register_remote_command_rpc(); _failure_detector->acquire_leader_lock(); - CHECK(_failure_detector->get_leader(nullptr), "must be primary at this point"); + PGSCHECK(_failure_detector->get_leader(nullptr), "must be primary at this point"); LOG_INFO("{}({}) got the primary lock, start to recover server state from remote storage", dsn_primary_host_port(), dsn_primary_address()); diff --git a/src/meta/meta_split_service.cpp b/src/meta/meta_split_service.cpp index df0c642a2d..8512cbe316 100644 --- a/src/meta/meta_split_service.cpp +++ b/src/meta/meta_split_service.cpp @@ -157,8 +157,8 @@ void meta_split_service::register_child_on_meta(register_child_rpc rpc) zauto_write_lock l(app_lock()); std::shared_ptr app = _state->get_app(app_name); - CHECK(app, "app({}) is not existed", app_name); - CHECK(app->is_stateful, "app({}) is stateless currently", app_name); + PGSCHECK(app, "app({}) is not existed", app_name); + PGSCHECK(app->is_stateful, "app({}) is stateless currently", app_name); const gpid &parent_gpid = request.parent_config.pid; const gpid &child_gpid = request.child_config.pid; @@ -273,8 +273,8 @@ void meta_split_service::on_add_child_on_remote_storage_reply(error_code ec, zauto_write_lock l(app_lock()); std::shared_ptr app = _state->get_app(app_name); - CHECK(app, "app({}) is not existed", app_name); - CHECK(app->is_stateful, "app({}) is stateless currently", app_name); + PGSCHECK(app, "app({}) is not existed", app_name); + PGSCHECK(app->is_stateful, "app({}) is stateless currently", app_name); const gpid &parent_gpid = request.parent_config.pid; const gpid &child_gpid = request.child_config.pid; @@ -497,12 +497,12 @@ void meta_split_service::notify_stop_split(notify_stop_split_rpc rpc) auto &response = rpc.response(); zauto_write_lock l(app_lock()); std::shared_ptr app = _state->get_app(request.app_name); - CHECK(app, "app({}) is not existed", request.app_name); - CHECK(app->is_stateful, "app({}) is stateless currently", request.app_name); - CHECK(request.meta_split_status == split_status::PAUSING || - request.meta_split_status == split_status::CANCELING, - "invalid split_status({})", - dsn::enum_to_string(request.meta_split_status)); + PGSCHECK(app, "app({}) is not existed", request.app_name); + PGSCHECK(app->is_stateful, "app({}) is stateless currently", request.app_name); + PGSCHECK(request.meta_split_status == split_status::PAUSING || + request.meta_split_status == split_status::CANCELING, + "invalid split_status({})", + dsn::enum_to_string(request.meta_split_status)); const std::string &stop_type = rpc.request().meta_split_status == split_status::PAUSING ? "pause" : "cancel"; @@ -583,8 +583,8 @@ void meta_split_service::query_child_state(query_child_state_rpc rpc) zauto_read_lock l(app_lock()); std::shared_ptr app = _state->get_app(app_name); - CHECK(app, "app({}) is not existed", app_name); - CHECK(app->is_stateful, "app({}) is stateless currently", app_name); + PGSCHECK(app, "app({}) is not existed", app_name); + PGSCHECK(app->is_stateful, "app({}) is stateless currently", app_name); if (app->partition_count == request.partition_count) { response.err = ERR_INVALID_STATE; diff --git a/src/meta/meta_state_service_simple.cpp b/src/meta/meta_state_service_simple.cpp index 5eaab761d5..91a547e2ae 100644 --- a/src/meta/meta_state_service_simple.cpp +++ b/src/meta/meta_state_service_simple.cpp @@ -90,7 +90,7 @@ void meta_state_service_simple::write_log(blob &&log_blob, uint64_t log_offset = _offset; _offset += log_blob.length(); auto continuation_task = std::unique_ptr(new operation(false, [=](bool log_succeed) { - CHECK(log_succeed, "we cannot handle logging failure now"); + PGSCHECK(log_succeed, "we cannot handle logging failure now"); __err_cb_bind_and_enqueue(task, internal_operation(), 0); })); auto continuation_task_ptr = continuation_task.get(); @@ -104,8 +104,8 @@ void meta_state_service_simple::write_log(blob &&log_blob, LPC_META_STATE_SERVICE_SIMPLE_INTERNAL, &_tracker, [=](error_code err, size_t bytes) { - CHECK(err == ERR_OK && bytes == log_blob.length(), - "we cannot handle logging failure now"); + PGSCHECK(err == ERR_OK && bytes == log_blob.length(), + "we cannot handle logging failure now"); _log_lock.lock(); continuation_task_ptr->done = true; while (!_task_queue.empty()) { @@ -187,7 +187,7 @@ error_code meta_state_service_simple::delete_node_internal(const std::string &no } auto parent_it = _quick_map.find(parent); - CHECK(parent_it != _quick_map.end(), "unable to find parent node"); + PGSCHECK(parent_it != _quick_map.end(), "unable to find parent node"); // XXX we cannot delete root, right? auto erase_num = parent_it->second->children.erase(name); @@ -212,7 +212,7 @@ error_code meta_state_service_simple::apply_transaction( LOG_DEBUG("internal operation after logged"); simple_transaction_entries *entries = dynamic_cast(t_entries.get()); - CHECK_NOTNULL(entries, "invalid input parameter"); + PGSCHECK_NOTNULL(entries, "invalid input parameter"); error_code ec; for (int i = 0; i != entries->_offset; ++i) { operation_entry &e = entries->_ops[i]; @@ -227,7 +227,7 @@ error_code meta_state_service_simple::apply_transaction( ec = set_data_internal(e._node, e._value); break; default: - CHECK(false, "unsupported operation"); + PGSCHECK(false, "unsupported operation"); } CHECK_EQ_MSG(ERR_OK, ec, "unexpected error when applying"); } @@ -246,7 +246,7 @@ error_code meta_state_service_simple::initialize(const std::vector std::unique_ptr log_file; auto s = dsn::utils::PegasusEnv(dsn::utils::FileDataType::kSensitive) ->NewSequentialFile(log_path, &log_file, rocksdb::EnvOptions()); - CHECK(s.ok(), "open log file '{}' failed, err = {}", log_path, s.ToString()); + PGSCHECK(s.ok(), "open log file '{}' failed, err = {}", log_path, s.ToString()); while (true) { static const int kLogHeaderSize = sizeof(log_header); @@ -256,7 +256,7 @@ error_code meta_state_service_simple::initialize(const std::vector // Read header. char scratch[kLogHeaderSize] = {0}; s = log_file->PositionedRead(_offset, kLogHeaderSize, &result, scratch); - CHECK(s.ok(), "read log file '{}' header failed, err = {}", log_path, s.ToString()); + PGSCHECK(s.ok(), "read log file '{}' header failed, err = {}", log_path, s.ToString()); if (result.empty()) { LOG_INFO("read EOF of log file '{}'", log_path); break; @@ -273,10 +273,10 @@ error_code meta_state_service_simple::initialize(const std::vector // Read body. std::shared_ptr buffer(dsn::utils::make_shared_array(header->size)); s = log_file->PositionedRead(_offset, header->size, &result, buffer.get()); - CHECK(s.ok(), - "read log file '{}' header with bad body, err = {}", - log_path, - s.ToString()); + PGSCHECK(s.ok(), + "read log file '{}' header with bad body, err = {}", + log_path, + s.ToString()); _offset += header->size; binary_reader reader(blob(buffer, header->size)); @@ -308,7 +308,7 @@ error_code meta_state_service_simple::initialize(const std::vector default: // The log is complete but its content is modified by cosmic ray. This is // unacceptable - CHECK(false, "meta state server log corrupted"); + PGSCHECK(false, "meta state server log corrupted"); } } } @@ -402,7 +402,7 @@ task_ptr meta_state_service_simple::submit_transaction( } } break; default: - CHECK(false, "not supported operation"); + PGSCHECK(false, "not supported operation"); break; } diff --git a/src/meta/meta_state_service_utils.cpp b/src/meta/meta_state_service_utils.cpp index b87c566123..7f7c81b501 100644 --- a/src/meta/meta_state_service_utils.cpp +++ b/src/meta/meta_state_service_utils.cpp @@ -35,7 +35,7 @@ namespace mss { meta_storage::meta_storage(dist::meta_state_service *remote_storage, task_tracker *tracker) : _remote(remote_storage), _tracker(tracker) { - CHECK_NOTNULL(tracker, "must set task tracker"); + PGSCHECK_NOTNULL(tracker, "must set task tracker"); } meta_storage::~meta_storage() = default; @@ -44,7 +44,7 @@ void meta_storage::create_node_recursively(std::queue &&nodes, blob &&value, std::function &&cb) { - CHECK(!nodes.empty(), ""); + CHECK(!nodes.empty()); on_create_recursively op; op.initialize(this); diff --git a/src/meta/meta_state_service_utils_impl.h b/src/meta/meta_state_service_utils_impl.h index c13063bdb0..4c5e7aace0 100644 --- a/src/meta/meta_state_service_utils_impl.h +++ b/src/meta/meta_state_service_utils_impl.h @@ -55,9 +55,9 @@ struct op_type "OP_GET_CHILDREN", }; - CHECK(v != OP_NONE && v <= (sizeof(op_type_to_string_map) / sizeof(char *)), - "invalid type: {}", - v); + PGSCHECK(v != OP_NONE && v <= (sizeof(op_type_to_string_map) / sizeof(char *)), + "invalid type: {}", + v); return op_type_to_string_map[v - 1]; } }; @@ -84,11 +84,11 @@ struct operation : pipeline::environment pipeline::repeat(std::move(*this_instance), 1_s); return; } - CHECK(false, - "request({}) on path({}) encountered an unexpected error({})", - op_type::to_string(type), - path, - ec.to_string()); + PGSCHECK(false, + "request({}) on path({}) encountered an unexpected error({})", + op_type::to_string(type), + path, + ec.to_string()); } dist::meta_state_service *remote_storage() const { return _ms->_remote; } diff --git a/src/meta/partition_guardian.cpp b/src/meta/partition_guardian.cpp index 2cbf49122e..ad70f0103e 100644 --- a/src/meta/partition_guardian.cpp +++ b/src/meta/partition_guardian.cpp @@ -82,8 +82,8 @@ pc_status partition_guardian::cure(meta_view view, const partition_configuration &pc = *get_config(*(view.apps), gpid); const proposal_actions &acts = get_config_context(*view.apps, gpid)->lb_actions; - CHECK(app->is_stateful, ""); - CHECK(acts.empty(), ""); + CHECK(app->is_stateful); + CHECK(acts.empty()); pc_status status; if (!pc.hp_primary) { @@ -112,9 +112,9 @@ void partition_guardian::reconfig(meta_view view, const configuration_update_req config_context *cc = get_config_context(*(view.apps), gpid); if (!cc->lb_actions.empty()) { const configuration_proposal_action *current = cc->lb_actions.front(); - CHECK(current != nullptr && current->type != config_type::CT_INVALID, - "invalid proposal for gpid({})", - gpid); + PGSCHECK(current != nullptr && current->type != config_type::CT_INVALID, + "invalid proposal for gpid({})", + gpid); // if the valid proposal is from cure if (!cc->lb_actions.is_from_balancer()) { finish_cure_proposal(view, gpid, *current); @@ -141,7 +141,7 @@ void partition_guardian::reconfig(meta_view view, const configuration_update_req cc->check_size(); } else { cc->remove_from_serving(hp); - CHECK(cc->record_drop_history(hp), "node({}) has been in the dropped", hp); + PGSCHECK(cc->record_drop_history(hp), "node({}) has been in the dropped", hp); } }); } @@ -251,7 +251,7 @@ pc_status partition_guardian::on_missing_primary(meta_view &view, const dsn::gpi RESET_IP_AND_HOST_PORT(action, node); for (const auto &secondary : pc.hp_secondaries) { const auto ns = get_node_state(*(view.nodes), secondary, false); - CHECK_NOTNULL(ns, "invalid secondary: {}", secondary); + PGSCHECK_NOTNULL(ns, "invalid secondary: {}", secondary); if (dsn_unlikely(!ns->alive())) { continue; } @@ -461,7 +461,7 @@ pc_status partition_guardian::on_missing_primary(meta_view &view, const dsn::gpi // Use the action.hp_node after being updated. if (action.hp_node) { - CHECK(action.node, ""); + CHECK(action.node); SET_OBJ_IP_AND_HOST_PORT(action, target, action, node); action.type = config_type::CT_ASSIGN_PRIMARY; @@ -630,7 +630,7 @@ pc_status partition_guardian::on_missing_secondary(meta_view &view, const dsn::g // if not emergency, only try to recover last dropped server const dropped_replica &server = cc.dropped.back(); if (is_node_alive(*view.nodes, server.node)) { - CHECK(server.node, "invalid server address, address = {}", server.node); + PGSCHECK(server.node, "invalid server address, address = {}", server.node); SET_IP_AND_HOST_PORT_BY_DNS(action, node, server.node); } @@ -654,7 +654,7 @@ pc_status partition_guardian::on_missing_secondary(meta_view &view, const dsn::g SET_OBJ_IP_AND_HOST_PORT(action, target, pc, primary); newly_partitions *np = get_newly_partitions(*(view.nodes), action.hp_node); - CHECK_NOTNULL(np, ""); + CHECK_NOTNULL(np); np->newly_add_partition(gpid.get_app_id()); cc.lb_actions.assign_cure_proposal(action); diff --git a/src/meta/server_load_balancer.cpp b/src/meta/server_load_balancer.cpp index 1a57858e38..2bd2e60e09 100644 --- a/src/meta/server_load_balancer.cpp +++ b/src/meta/server_load_balancer.cpp @@ -105,7 +105,7 @@ void newly_partitions::newly_add_partition(int32_t app_id) void newly_partitions::newly_remove_primary(int32_t app_id, bool only_primary) { auto iter = primaries.find(app_id); - CHECK(iter != primaries.end(), "invalid app_id, app_id = {}", app_id); + PGSCHECK(iter != primaries.end(), "invalid app_id, app_id = {}", app_id); CHECK_GT_MSG(iter->second, 0, "invalid primary count"); if (0 == (--iter->second)) { primaries.erase(iter); @@ -122,7 +122,7 @@ void newly_partitions::newly_remove_primary(int32_t app_id, bool only_primary) void newly_partitions::newly_remove_partition(int32_t app_id) { auto iter = partitions.find(app_id); - CHECK(iter != partitions.end(), "invalid app_id, app_id = {}", app_id); + PGSCHECK(iter != partitions.end(), "invalid app_id, app_id = {}", app_id); CHECK_GT_MSG(iter->second, 0, "invalid partition count"); if ((--iter->second) == 0) { partitions.erase(iter); @@ -201,10 +201,10 @@ void server_load_balancer::apply_balancer(meta_view view, const migration_list & // TODO(yingchun): use CHECK_EQ instead if (resp.err != dsn::ERR_OK) { const dsn::gpid &pid = pairs.first; - CHECK(false, - "apply balancer for gpid({}.{}) failed", - pid.get_app_id(), - pid.get_partition_index()); + PGSCHECK(false, + "apply balancer for gpid({}.{}) failed", + pid.get_app_id(), + pid.get_partition_index()); } } } diff --git a/src/meta/server_state.cpp b/src/meta/server_state.cpp index 2c5019cb9a..5fae240df7 100644 --- a/src/meta/server_state.cpp +++ b/src/meta/server_state.cpp @@ -239,10 +239,10 @@ void server_state::transition_staging_state(std::shared_ptr &app) resp.info = *app; send_response(_meta_svc, app->helpers->pending_response, resp); } else { - CHECK(false, - "app({}) not in staging state({})", - app->get_logname(), - enum_to_string(app->status)); + PGSCHECK(false, + "app({}) not in staging state({})", + app->get_logname(), + enum_to_string(app->status)); } LOG_INFO("app({}) transfer from {} to {}", @@ -264,7 +264,7 @@ void server_state::process_one_partition(std::shared_ptr &app) } else if (ans == 0) { transition_staging_state(app); } else { - CHECK(false, "partitions in progress({}) shouldn't be negetive", ans); + PGSCHECK(false, "partitions in progress({}) shouldn't be negetive", ans); } } @@ -280,8 +280,8 @@ error_code server_state::dump_app_states(const char *local_path, file->append_buffer("binary", 6); app_state *app; while ((app = iterator()) != nullptr) { - CHECK(app->status == app_status::AS_AVAILABLE || app->status == app_status::AS_DROPPED, - "invalid app status"); + PGSCHECK(app->status == app_status::AS_AVAILABLE || app->status == app_status::AS_DROPPED, + "invalid app status"); binary_writer writer; dsn::marshall(writer, *app, DSF_THRIFT_BINARY); file->append_buffer(writer.get_buffer()); @@ -452,7 +452,7 @@ error_code server_state::initialize_default_apps() CHECK_GT_MSG( default_app.app_type.length(), 0, "'[{}] app_type' not specified", section); CHECK_GT(default_app.partition_count, 0); - CHECK(parse, "'[{}] envs' is invalid, envs = {}", section, envs_str); + PGSCHECK(parse, "'[{}] envs' is invalid, envs = {}", section, envs_str); std::shared_ptr app = app_state::create(default_app); _all_apps.emplace(app->app_id, app); @@ -474,9 +474,9 @@ error_code server_state::sync_apps_to_remote_storage() _table_metric_entities.clear_entities(); for (auto &kv_pair : _all_apps) { if (kv_pair.second->status == app_status::AS_CREATING) { - CHECK(_exist_apps.find(kv_pair.second->app_name) == _exist_apps.end(), - "invalid app name, name = {}", - kv_pair.second->app_name); + PGSCHECK(_exist_apps.find(kv_pair.second->app_name) == _exist_apps.end(), + "invalid app name, name = {}", + kv_pair.second->app_name); _exist_apps.emplace(kv_pair.second->app_name, kv_pair.second); _table_metric_entities.create_entity(kv_pair.first, kv_pair.second->partition_count); } @@ -507,8 +507,8 @@ error_code server_state::sync_apps_to_remote_storage() std::shared_ptr &app = kv.second; std::string path = get_app_path(*app); - CHECK(app->status == app_status::AS_CREATING || app->status == app_status::AS_DROPPING, - "invalid app status"); + PGSCHECK(app->status == app_status::AS_CREATING || app->status == app_status::AS_DROPPING, + "invalid app status"); blob value = app->to_json(app_status::AS_CREATING == app->status ? app_status::AS_AVAILABLE : app_status::AS_DROPPED); storage->create_node( @@ -580,13 +580,13 @@ dsn::error_code server_state::sync_apps_from_remote_storage() pc.__isset.hp_primary = true; dsn::json::json_forwarder::decode(value, pc); - CHECK(pc.pid.get_app_id() == app->app_id && - pc.pid.get_partition_index() == partition_id, - "invalid partition config"); + PGSCHECK(pc.pid.get_app_id() == app->app_id && + pc.pid.get_partition_index() == partition_id, + "invalid partition config"); { zauto_write_lock l(_lock); app->pcs[partition_id] = pc; - CHECK(pc.__isset.hp_last_drops, ""); + CHECK(pc.__isset.hp_last_drops); for (const auto &last_drop : pc.hp_last_drops) { app->helpers->contexts[partition_id].record_drop_history(last_drop); } @@ -645,8 +645,8 @@ dsn::error_code server_state::sync_apps_from_remote_storage() [this, app_path, &err, &sync_partition](error_code ec, const blob &value) { if (ec == ERR_OK) { app_info info; - CHECK(dsn::json::json_forwarder::decode(value, info), - "invalid json data"); + PGSCHECK(dsn::json::json_forwarder::decode(value, info), + "invalid json data"); std::shared_ptr app = app_state::create(info); { zauto_write_lock l(_lock); @@ -658,10 +658,10 @@ dsn::error_code server_state::sync_apps_from_remote_storage() } else if (app->status == app_status::AS_DROPPED) { app->status = app_status::AS_DROPPING; } else { - CHECK(false, - "invalid status({}) for app({}) in remote storage", - enum_to_string(app->status), - app->get_logname()); + PGSCHECK(false, + "invalid status({}) for app({}) in remote storage", + enum_to_string(app->status), + app->get_logname()); } } app->helpers->split_states.splitting_count = 0; @@ -699,9 +699,9 @@ dsn::error_code server_state::sync_apps_from_remote_storage() if (ERR_OBJECT_NOT_FOUND == err) return err; CHECK_EQ_MSG(ERR_OK, err, "can't handle this error"); - CHECK(transaction_state == std::string(unlock_state) || transaction_state.empty(), - "invalid transaction state({})", - transaction_state); + PGSCHECK(transaction_state == std::string(unlock_state) || transaction_state.empty(), + "invalid transaction state({})", + transaction_state); storage->get_children( _apps_root, @@ -738,7 +738,7 @@ void server_state::initialize_node_state() } for (const auto &secondary : pc.hp_secondaries) { - CHECK(secondary, "invalid secondary: {}", secondary); + PGSCHECK(secondary, "invalid secondary: {}", secondary); node_state *ns = get_node_state(_nodes, secondary, true); ns->put_partition(pc.pid, false); } @@ -767,9 +767,9 @@ error_code server_state::initialize_data_structure() } } else if (err == ERR_OK) { if (FLAGS_recover_from_replica_server) { - CHECK(false, - "find apps from remote storage, but " - "[meta_server].recover_from_replica_server = true"); + PGSCHECK(false, + "find apps from remote storage, but " + "[meta_server].recover_from_replica_server = true"); } else { LOG_INFO( "sync apps from remote storage ok, get {} apps, init the node state accordingly", @@ -821,7 +821,7 @@ void server_state::on_config_sync(configuration_query_by_node_rpc rpc) response.partitions.resize(ns->partition_count()); ns->for_each_partition([&, this](const gpid &pid) { std::shared_ptr app = get_app(pid.get_app_id()); - CHECK(app, "invalid app_id, app_id = {}", pid.get_app_id()); + PGSCHECK(app, "invalid app_id, app_id = {}", pid.get_app_id()); config_context &cc = app->helpers->contexts[pid.get_partition_index()]; // config sync need the newest data to keep the perfect FD, @@ -890,11 +890,11 @@ void server_state::on_config_sync(configuration_query_by_node_rpc rpc) rep.pid); } else { // app is not recognized or partition is not recognized - CHECK(false, - "gpid({}) on node({}) is not exist on meta server, administrator " - "should check consistency of meta data", - rep.pid, - node); + PGSCHECK(false, + "gpid({}) on node({}) is not exist on meta server, administrator " + "should check consistency of meta data", + rep.pid, + node); } } else if (app->status == app_status::AS_DROPPED) { if (app->expire_second == 0) { @@ -1040,11 +1040,11 @@ void server_state::init_app_partition_node(std::shared_ptr &app, 0, std::chrono::milliseconds(1000)); } else { - CHECK(false, - "we can't handle this error in init app partition nodes err({}), gpid({}.{})", - ec, - app->app_id, - pidx); + PGSCHECK(false, + "we can't handle this error in init app partition nodes err({}), gpid({}.{})", + ec, + app->app_id, + pidx); } }; @@ -1070,7 +1070,7 @@ void server_state::do_app_create(std::shared_ptr &app) 0, std::chrono::seconds(1)); } else { - CHECK(false, "we can't handle this right now, err({})", ec); + PGSCHECK(false, "we can't handle this right now, err({})", ec); } }; @@ -1198,7 +1198,7 @@ void server_state::do_app_drop(std::shared_ptr &app) 0, std::chrono::seconds(1)); } else { - CHECK(false, "we can't handle this, error({})", ec); + PGSCHECK(false, "we can't handle this, error({})", ec); } }; @@ -1252,7 +1252,8 @@ void server_state::drop_app(dsn::message_ex *msg) response.err = ERR_BUSY_DROPPING; break; default: - CHECK(false, "invalid app status, status = {}", ::dsn::enum_to_string(app->status)); + PGSCHECK( + false, "invalid app status, status = {}", ::dsn::enum_to_string(app->status)); break; } } @@ -1467,58 +1468,58 @@ void server_state::request_check(const partition_configuration &old_pc, case config_type::CT_ASSIGN_PRIMARY: if (request.__isset.hp_node) { CHECK_NE(old_pc.hp_primary, request.hp_node); - CHECK(!utils::contains(old_pc.hp_secondaries, request.hp_node), ""); + PGSCHECK(!utils::contains(old_pc.hp_secondaries, request.hp_node), ""); } else { CHECK_NE(old_pc.primary, request.node); - CHECK(!utils::contains(old_pc.secondaries, request.node), ""); + PGSCHECK(!utils::contains(old_pc.secondaries, request.node), ""); } break; case config_type::CT_UPGRADE_TO_PRIMARY: if (request.__isset.hp_node) { CHECK_NE(old_pc.hp_primary, request.hp_node); - CHECK(utils::contains(old_pc.hp_secondaries, request.hp_node), ""); + PGSCHECK(utils::contains(old_pc.hp_secondaries, request.hp_node), ""); } else { CHECK_NE(old_pc.primary, request.node); - CHECK(utils::contains(old_pc.secondaries, request.node), ""); + PGSCHECK(utils::contains(old_pc.secondaries, request.node), ""); } break; case config_type::CT_DOWNGRADE_TO_SECONDARY: if (request.__isset.hp_node) { CHECK_EQ(old_pc.hp_primary, request.hp_node); - CHECK(!utils::contains(old_pc.hp_secondaries, request.hp_node), ""); + PGSCHECK(!utils::contains(old_pc.hp_secondaries, request.hp_node), ""); } else { CHECK_EQ(old_pc.primary, request.node); - CHECK(!utils::contains(old_pc.secondaries, request.node), ""); + PGSCHECK(!utils::contains(old_pc.secondaries, request.node), ""); } break; case config_type::CT_DOWNGRADE_TO_INACTIVE: case config_type::CT_REMOVE: if (request.__isset.hp_node) { - CHECK(old_pc.hp_primary == request.hp_node || - utils::contains(old_pc.hp_secondaries, request.hp_node), - ""); + PGSCHECK(old_pc.hp_primary == request.hp_node || + utils::contains(old_pc.hp_secondaries, request.hp_node), + ""); } else { - CHECK(old_pc.primary == request.node || - utils::contains(old_pc.secondaries, request.node), - ""); + PGSCHECK(old_pc.primary == request.node || + utils::contains(old_pc.secondaries, request.node), + ""); } break; case config_type::CT_UPGRADE_TO_SECONDARY: if (request.__isset.hp_node) { CHECK_NE(old_pc.hp_primary, request.hp_node); - CHECK(!utils::contains(old_pc.hp_secondaries, request.hp_node), ""); + PGSCHECK(!utils::contains(old_pc.hp_secondaries, request.hp_node), ""); } else { CHECK_NE(old_pc.primary, request.node); - CHECK(!utils::contains(old_pc.secondaries, request.node), ""); + PGSCHECK(!utils::contains(old_pc.secondaries, request.node), ""); } break; case config_type::CT_PRIMARY_FORCE_UPDATE_BALLOT: { if (request.__isset.hp_node) { CHECK_EQ(old_pc.hp_primary, new_pc.hp_primary); - CHECK(old_pc.hp_secondaries == new_pc.hp_secondaries, ""); + PGSCHECK(old_pc.hp_secondaries == new_pc.hp_secondaries, ""); } else { CHECK_EQ(old_pc.primary, new_pc.primary); - CHECK(old_pc.secondaries == new_pc.secondaries, ""); + PGSCHECK(old_pc.secondaries == new_pc.secondaries, ""); } break; } @@ -1543,15 +1544,15 @@ void server_state::update_configuration_locally( GET_HOST_PORT(*config_request, node, node); if (app.is_stateful) { - CHECK(old_pc.ballot == invalid_ballot || old_pc.ballot + 1 == new_pc.ballot, - "invalid configuration update request, old ballot {}, new ballot {}", - old_pc.ballot, - new_pc.ballot); + PGSCHECK(old_pc.ballot == invalid_ballot || old_pc.ballot + 1 == new_pc.ballot, + "invalid configuration update request, old ballot {}, new ballot {}", + old_pc.ballot, + new_pc.ballot); node_state *ns = nullptr; if (config_request->type != config_type::CT_DROP_PARTITION) { ns = get_node_state(_nodes, node, false); - CHECK_NOTNULL(ns, "invalid node: {}", node); + PGSCHECK_NOTNULL(ns, "invalid node: {}", node); } #ifndef NDEBUG request_check(old_pc, *config_request); @@ -1589,7 +1590,7 @@ void server_state::update_configuration_locally( } case config_type::CT_ADD_SECONDARY: case config_type::CT_ADD_SECONDARY_FOR_LB: - CHECK(false, "invalid execution work flow"); + PGSCHECK(false, "invalid execution work flow"); break; case config_type::CT_REGISTER_CHILD: { ns->put_partition(gpid, true); @@ -1617,14 +1618,14 @@ void server_state::update_configuration_locally( break; } default: - CHECK(false, ""); + PGSCHECK(false, ""); break; } } else { CHECK_EQ(old_pc.ballot, new_pc.ballot); const auto host_node = host_port::from_address(config_request->host_node); // The non-stateful app is just for testing, so just check the host_node is resolvable. - CHECK(host_node, "'{}' can not be reverse resolved", config_request->host_node); + PGSCHECK(host_node, "'{}' can not be reverse resolved", config_request->host_node); new_pc = old_pc; partition_configuration_stateless pcs(new_pc); if (config_request->type == config_type::type::CT_ADD_SECONDARY) { @@ -1639,7 +1640,7 @@ void server_state::update_configuration_locally( } auto it = _nodes.find(host_node); - CHECK(it != _nodes.end(), "invalid node: {}", host_node); + PGSCHECK(it != _nodes.end(), "invalid node: {}", host_node); if (config_type::CT_REMOVE == config_request->type) { it->second.remove_partition(gpid, false); } else { @@ -1725,8 +1726,8 @@ void server_state::on_update_configuration_on_remote_reply( config_context &cc = app->helpers->contexts[gpid.get_partition_index()]; // if multiple threads exist in the thread pool, the check may be failed - CHECK(app->status == app_status::AS_AVAILABLE || app->status == app_status::AS_DROPPING, - "if app removed, this task should be cancelled"); + PGSCHECK(app->status == app_status::AS_AVAILABLE || app->status == app_status::AS_DROPPING, + "if app removed, this task should be cancelled"); if (ec == ERR_TIMEOUT) { cc.pending_sync_task = tasking::enqueue( LPC_META_STATE_HIGH, @@ -1772,7 +1773,7 @@ void server_state::on_update_configuration_on_remote_reply( } } } else { - CHECK(false, "we can't handle this right now, err = {}", ec); + PGSCHECK(false, "we can't handle this right now, err = {}", ec); } } @@ -1790,12 +1791,12 @@ void server_state::recall_partition(std::shared_ptr &app, int pidx) server_state::sStateHash, std::chrono::seconds(1)); } else { - CHECK(false, "unable to handle this({}) right now", error); + PGSCHECK(false, "unable to handle this({}) right now", error); } }; partition_configuration &pc = app->pcs[pidx]; - CHECK((pc.partition_flags & pc_flags::dropped), ""); + PGSCHECK((pc.partition_flags & pc_flags::dropped), ""); pc.partition_flags = 0; blob json_partition = dsn::json::json_forwarder::encode(pc); @@ -1907,7 +1908,7 @@ void server_state::downgrade_secondary_to_inactive(std::shared_ptr &a partition_configuration &pc = app->pcs[pidx]; config_context &cc = app->helpers->contexts[pidx]; - CHECK(pc.hp_primary, "this shouldn't be called if the primary is invalid"); + PGSCHECK(pc.hp_primary, "this shouldn't be called if the primary is invalid"); if (config_status::pending_remote_sync != cc.stage) { configuration_update_request request; request.info = *app; @@ -1948,10 +1949,10 @@ void server_state::downgrade_stateless_nodes(std::shared_ptr &app, } host_port req_node; GET_HOST_PORT(*req, node, req_node); - CHECK(req_node, "invalid node: {}", req_node); + PGSCHECK(req_node, "invalid node: {}", req_node); // remove host_node & node from secondaries/last_drops, as it will be sync to remote // storage - CHECK(pc.__isset.hp_secondaries, "hp_secondaries not set"); + PGSCHECK(pc.__isset.hp_secondaries, "hp_secondaries not set"); for (++i; i < pc.hp_secondaries.size(); ++i) { pc.secondaries[i - 1] = pc.secondaries[i]; pc.last_drops[i - 1] = pc.last_drops[i]; @@ -1989,8 +1990,8 @@ void server_state::on_update_configuration( configuration_update_response response; response.err = ERR_IO_PENDING; - CHECK(app, "get get app for app id({})", gpid.get_app_id()); - CHECK(app->is_stateful, "don't support stateless apps currently, id({})", gpid.get_app_id()); + PGSCHECK(app, "get get app for app id({})", gpid.get_app_id()); + PGSCHECK(app->is_stateful, "don't support stateless apps currently, id({})", gpid.get_app_id()); auto find_name = _config_type_VALUES_TO_NAMES.find(cfg_request->type); if (find_name != _config_type_VALUES_TO_NAMES.end()) { LOG_INFO("recv update config request: type({}), {}", @@ -2036,9 +2037,9 @@ void server_state::on_update_configuration( _meta_svc->reply_data(msg, response); msg->release_ref(); } else { - CHECK(config_status::not_pending == cc.stage, - "invalid config status, cc.stage = {}", - enum_to_string(cc.stage)); + PGSCHECK(config_status::not_pending == cc.stage, + "invalid config status, cc.stage = {}", + enum_to_string(cc.stage)); cc.stage = config_status::pending_remote_sync; cc.pending_sync_request = cfg_request; cc.msg = msg; @@ -2070,7 +2071,7 @@ void server_state::on_partition_node_dead(std::shared_ptr &app, return; } - CHECK(is_secondary(pc, node), ""); + PGSCHECK(is_secondary(pc, node), ""); LOG_INFO("gpid({}): secondary({}) is down, ignored it due to no primary for this partition " "available", pc.pid, @@ -2097,9 +2098,9 @@ void server_state::on_change_node_state(const host_port &node, bool is_alive) ns.set_replicas_collect_flag(false); ns.for_each_partition([&, this](const dsn::gpid &pid) { std::shared_ptr app = get_app(pid.get_app_id()); - CHECK(app != nullptr && app->status != app_status::AS_DROPPED, - "invalid app, app_id = {}", - pid.get_app_id()); + PGSCHECK(app != nullptr && app->status != app_status::AS_DROPPED, + "invalid app, app_id = {}", + pid.get_app_id()); on_partition_node_dead(app, pid.get_partition_index(), node); return true; }); @@ -2160,12 +2161,12 @@ server_state::construct_apps(const std::vector &query_a { // compatible for app.duplicating different between primary and secondaries in // 2.1.x, 2.2.x and 2.3.x release - CHECK(app_info_compatible_equal(info, *old_info), - "conflict app info from ({}) for id({}): new_info({}), old_info({})", - replica_nodes[i], - info.app_id, - boost::lexical_cast(info), - boost::lexical_cast(*old_info)); + PGSCHECK(app_info_compatible_equal(info, *old_info), + "conflict app info from ({}) for id({}): new_info({}), old_info({})", + replica_nodes[i], + info.app_id, + boost::lexical_cast(info), + boost::lexical_cast(*old_info)); } } } @@ -2199,7 +2200,7 @@ server_state::construct_apps(const std::vector &query_a // check conflict table name std::map checked_names; for (int app_id = max_app_id; app_id >= 1; --app_id) { - CHECK(_all_apps.find(app_id) != _all_apps.end(), "invalid app_id, app_id = {}", app_id); + PGSCHECK(_all_apps.find(app_id) != _all_apps.end(), "invalid app_id, app_id = {}", app_id); std::shared_ptr &app = _all_apps[app_id]; std::string old_name = app->app_name; while (checked_names.find(app->app_name) != checked_names.end()) { @@ -2235,7 +2236,7 @@ error_code server_state::construct_partitions( continue; for (replica_info &r : query_resp.replicas) { - CHECK(_all_apps.find(r.pid.get_app_id()) != _all_apps.end(), ""); + PGSCHECK(_all_apps.find(r.pid.get_app_id()) != _all_apps.end(), ""); bool is_accepted = collect_replica({&_all_apps, &_nodes}, replica_nodes[i], r); if (is_accepted) { LOG_INFO("accept replica({}) from node({})", @@ -2253,9 +2254,9 @@ error_code server_state::construct_partitions( int failed_count = 0; for (auto &app_kv : _all_apps) { std::shared_ptr &app = app_kv.second; - CHECK(app->status == app_status::AS_CREATING || app->status == app_status::AS_DROPPING, - "invalid app status, status = {}", - enum_to_string(app->status)); + PGSCHECK(app->status == app_status::AS_CREATING || app->status == app_status::AS_DROPPING, + "invalid app status, status = {}", + enum_to_string(app->status)); if (app->status == app_status::AS_DROPPING) { LOG_INFO("ignore constructing partitions for dropping app({})", app->app_id); } else { @@ -2602,7 +2603,7 @@ bool server_state::check_all_partitions() const auto *pc = get_config(_all_apps, pid); if (!add_secondary_proposed[i] && pc->hp_secondaries.empty()) { const auto &action = add_secondary_actions[i]; - CHECK(action.hp_node, ""); + PGSCHECK(action.hp_node, ""); if (_add_secondary_enable_flow_control && add_secondary_running_nodes[action.hp_node] >= _add_secondary_max_count_for_one_node) { // ignore @@ -2620,7 +2621,7 @@ bool server_state::check_all_partitions() for (int i = 0; i < add_secondary_actions.size(); ++i) { if (!add_secondary_proposed[i]) { const auto &action = add_secondary_actions[i]; - CHECK(action.hp_node, ""); + PGSCHECK(action.hp_node, ""); gpid pid = add_secondary_gpids[i]; const auto *pc = get_config(_all_apps, pid); if (_add_secondary_enable_flow_control && add_secondary_running_nodes[action.hp_node] >= @@ -2717,7 +2718,7 @@ void server_state::get_cluster_balance_score(double &primary_stddev, double &tot void server_state::check_consistency(const dsn::gpid &gpid) { auto iter = _all_apps.find(gpid.get_app_id()); - CHECK(iter != _all_apps.end(), "invalid gpid({})", gpid); + PGSCHECK(iter != _all_apps.end(), "invalid gpid({})", gpid); auto &app = *(iter->second); auto &pc = app.pcs[gpid.get_partition_index()]; @@ -2725,27 +2726,27 @@ void server_state::check_consistency(const dsn::gpid &gpid) if (app.is_stateful) { if (pc.hp_primary) { const auto it = _nodes.find(pc.hp_primary); - CHECK(it != _nodes.end(), "invalid primary: {}", pc.hp_primary); + PGSCHECK(it != _nodes.end(), "invalid primary: {}", pc.hp_primary); CHECK_EQ(it->second.served_as(gpid), partition_status::PS_PRIMARY); - CHECK(!utils::contains(pc.hp_last_drops, pc.hp_primary), - "primary({}) shouldn't appear in last_drops", - pc.hp_primary); + PGSCHECK(!utils::contains(pc.hp_last_drops, pc.hp_primary), + "primary({}) shouldn't appear in last_drops", + pc.hp_primary); } for (const auto &secondary : pc.hp_secondaries) { const auto it = _nodes.find(secondary); - CHECK(it != _nodes.end(), "invalid secondary: {}", secondary); + PGSCHECK(it != _nodes.end(), "invalid secondary: {}", secondary); CHECK_EQ(it->second.served_as(gpid), partition_status::PS_SECONDARY); - CHECK(!utils::contains(pc.hp_last_drops, secondary), - "secondary({}) shouldn't appear in last_drops", - secondary); + PGSCHECK(!utils::contains(pc.hp_last_drops, secondary), + "secondary({}) shouldn't appear in last_drops", + secondary); } } else { partition_configuration_stateless pcs(pc); CHECK_EQ(pcs.hosts().size(), pcs.workers().size()); for (const auto &secondary : pcs.hosts()) { auto it = _nodes.find(secondary); - CHECK(it != _nodes.end(), "invalid secondary: {}", secondary); + PGSCHECK(it != _nodes.end(), "invalid secondary: {}", secondary); CHECK_EQ(it->second.served_as(gpid), partition_status::PS_SECONDARY); } } @@ -2784,7 +2785,7 @@ void server_state::do_update_app_info(const std::string &app_path, 0, std::chrono::seconds(1)); } else { - CHECK(false, "we can't handle this, error({})", ec); + PGSCHECK(false, "we can't handle this, error({})", ec); } }; // TODO(cailiuyang): callback scheduling order may be undefined if multiple requests are @@ -3526,16 +3527,16 @@ void server_state::do_update_max_replica_count(std::shared_ptr &app, continue; } - CHECK(false, - "An error that can't be handled occurs while updating partition-level" - "max_replica_count: error_code={}, app_name={}, app_id={}, " - "partition_index={}, partition_count={}, new_max_replica_count={}", - ec, - app_name, - app->app_id, - i, - app->partition_count, - new_max_replica_count); + PGSCHECK(false, + "An error that can't be handled occurs while updating partition-level" + "max_replica_count: error_code={}, app_name={}, app_id={}, " + "partition_index={}, partition_count={}, new_max_replica_count={}", + ec, + app_name, + app->app_id, + i, + app->partition_count, + new_max_replica_count); } LOG_INFO("all partitions have been changed to the new max_replica_count, ready to update " @@ -3676,14 +3677,14 @@ void server_state::update_partition_max_replica_count(std::shared_ptr return; } - CHECK(context.stage == config_status::not_pending, - "invalid config status while updating max_replica_count: context.stage={}, " - "app_name={}, app_id={}, partition_index={}, new_max_replica_count={}", - enum_to_string(context.stage), - app->app_name, - app->app_id, - partition_index, - new_max_replica_count); + PGSCHECK(context.stage == config_status::not_pending, + "invalid config status while updating max_replica_count: context.stage={}, " + "app_name={}, app_id={}, partition_index={}, new_max_replica_count={}", + enum_to_string(context.stage), + app->app_name, + app->app_id, + partition_index, + new_max_replica_count); context.stage = config_status::pending_remote_sync; context.pending_sync_request.reset(); @@ -3888,14 +3889,14 @@ void server_state::recover_from_max_replica_count_env() int32_t max_replica_count = 0; if (args.size() < 2 || !dsn::buf2int32(args[1], max_replica_count) || max_replica_count <= 0) { - CHECK(false, - "invalid max_replica_count_env: app_name={}, app_id={}, " - "max_replica_count={}, {}={}", - app->app_name, - app->app_id, - app->max_replica_count, - replica_envs::UPDATE_MAX_REPLICA_COUNT, - iter->second); + PGSCHECK(false, + "invalid max_replica_count_env: app_name={}, app_id={}, " + "max_replica_count={}, {}={}", + app->app_name, + app->app_id, + app->max_replica_count, + replica_envs::UPDATE_MAX_REPLICA_COUNT, + iter->second); } tasks.emplace_back(app, max_replica_count); diff --git a/src/meta/server_state_restore.cpp b/src/meta/server_state_restore.cpp index 59dfe2dff5..096473f2d2 100644 --- a/src/meta/server_state_restore.cpp +++ b/src/meta/server_state_restore.cpp @@ -102,7 +102,7 @@ void server_state::sync_app_from_backup_media( callback_tsk->enqueue_with(err, dsn::blob()); return; } - CHECK_NOTNULL(file_handle, "create file from backup media ecounter error"); + PGSCHECK_NOTNULL(file_handle, "create file from backup media ecounter error"); file_handle->read( read_request{0, -1}, TASK_CODE_EXEC_INLINED, [callback_tsk](const read_response &resp) { callback_tsk->enqueue_with(resp.err, resp.buffer); @@ -184,7 +184,7 @@ void server_state::restore_app(dsn::message_ex *msg) if (pair.first != ERR_OK) { ec = pair.first; } else { - CHECK_NOTNULL(pair.second, "app info shouldn't be empty"); + PGSCHECK_NOTNULL(pair.second, "app info shouldn't be empty"); // the same with create_app do_app_create(pair.second); return; @@ -241,7 +241,7 @@ void server_state::on_query_restore_status(configuration_query_restore_rpc rpc) response.err = ERR_OK; std::shared_ptr app = get_app(request.restore_app_id); - CHECK(app, "app must be valid"); + PGSCHECK(app, "app must be valid"); if (app->status == app_status::AS_DROPPED) { response.err = ERR_APP_DROPPED; return; diff --git a/src/meta/table_metrics.cpp b/src/meta/table_metrics.cpp index 2bacf28ac6..f57c681edb 100644 --- a/src/meta/table_metrics.cpp +++ b/src/meta/table_metrics.cpp @@ -143,11 +143,11 @@ partition_metrics::partition_metrics(int32_t table_id, int32_t partition_id) const metric_entity_ptr &partition_metrics::partition_metric_entity() const { - CHECK_NOTNULL(_partition_metric_entity, - "partition metric entity (table_id={}, partition_id={}) should has been " - "instantiated: uninitialized entity cannot be used to instantiate metric", - _table_id, - _partition_id); + PGSCHECK_NOTNULL(_partition_metric_entity, + "partition metric entity (table_id={}, partition_id={}) should has been " + "instantiated: uninitialized entity cannot be used to instantiate metric", + _table_id, + _partition_id); return _partition_metric_entity; } @@ -189,10 +189,10 @@ table_metrics::table_metrics(int32_t table_id, int32_t partition_count) const metric_entity_ptr &table_metrics::table_metric_entity() const { - CHECK_NOTNULL(_table_metric_entity, - "table metric entity (table_id={}) should has been instantiated: " - "uninitialized entity cannot be used to instantiate metric", - _table_id); + PGSCHECK_NOTNULL(_table_metric_entity, + "table metric entity (table_id={}) should has been instantiated: " + "uninitialized entity cannot be used to instantiate metric", + _table_id); return _table_metric_entity; } diff --git a/src/meta/test/CMakeLists.txt b/src/meta/test/CMakeLists.txt index 13a1efe9d1..5f67b23403 100644 --- a/src/meta/test/CMakeLists.txt +++ b/src/meta/test/CMakeLists.txt @@ -44,7 +44,9 @@ set(MY_PROJ_LIBS zookeeper hashtable gtest - hdfs) + hdfs + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES clear.sh diff --git a/src/meta/test/balancer_simulator/CMakeLists.txt b/src/meta/test/balancer_simulator/CMakeLists.txt index 69ddfc4a44..556f009dc9 100644 --- a/src/meta/test/balancer_simulator/CMakeLists.txt +++ b/src/meta/test/balancer_simulator/CMakeLists.txt @@ -30,7 +30,9 @@ set(MY_PROJ_LIBS dsn_meta_server dsn_ranger dsn_replication_common - gtest) + gtest + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES "") dsn_add_test() diff --git a/src/meta/test/balancer_validator.cpp b/src/meta/test/balancer_validator.cpp index 3671a90bd3..131e25fd20 100644 --- a/src/meta/test/balancer_validator.cpp +++ b/src/meta/test/balancer_validator.cpp @@ -68,14 +68,14 @@ static void check_cure(app_mapper &apps, node_mapper &nodes, ::dsn::partition_co break; switch (act.type) { case config_type::CT_ASSIGN_PRIMARY: { - CHECK(!pc.primary, ""); - CHECK(!pc.hp_primary, ""); - CHECK(pc.secondaries.empty(), ""); - CHECK(pc.hp_secondaries.empty(), ""); + PGSCHECK(!pc.primary, ""); + PGSCHECK(!pc.hp_primary, ""); + PGSCHECK(pc.secondaries.empty(), ""); + PGSCHECK(pc.hp_secondaries.empty(), ""); CHECK_EQ(act.node, act.target); CHECK_EQ(act.hp_node, act.hp_target); const auto node = nodes.find(act.hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ns = &node->second; CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_INACTIVE); ns->put_partition(pc.pid, true); @@ -83,12 +83,12 @@ static void check_cure(app_mapper &apps, node_mapper &nodes, ::dsn::partition_co break; } case config_type::CT_ADD_SECONDARY: { - CHECK(!is_member(pc, act.node), ""); - CHECK(!is_member(pc, act.hp_node), ""); + PGSCHECK(!is_member(pc, act.node), ""); + PGSCHECK(!is_member(pc, act.hp_node), ""); CHECK_EQ(pc.primary, act.target); CHECK_EQ(pc.hp_primary, act.hp_target); const auto node = nodes.find(act.hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ADD_IP_AND_HOST_PORT(pc, secondaries, act.node, act.hp_node); ns = &node->second; CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_INACTIVE); @@ -96,7 +96,7 @@ static void check_cure(app_mapper &apps, node_mapper &nodes, ::dsn::partition_co break; } default: - CHECK(false, ""); + PGSCHECK(false, ""); break; } } @@ -108,14 +108,14 @@ static void check_cure(app_mapper &apps, node_mapper &nodes, ::dsn::partition_co ps = guardian.cure({&apps, &nodes}, pc.pid, act); CHECK_EQ(act.type, config_type::CT_UPGRADE_TO_PRIMARY); - CHECK(!pc.primary, ""); - CHECK(!pc.hp_primary, ""); + PGSCHECK(!pc.primary, ""); + PGSCHECK(!pc.hp_primary, ""); CHECK_EQ(act.node, act.target); CHECK_EQ(act.hp_node, act.hp_target); - CHECK(is_secondary(pc, act.node), ""); - CHECK(is_secondary(pc, act.hp_node), ""); + PGSCHECK(is_secondary(pc, act.node), ""); + PGSCHECK(is_secondary(pc, act.hp_node), ""); const auto node = nodes.find(act.hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ns = &node->second; SET_OBJ_IP_AND_HOST_PORT(pc, primary, act, node); std::remove(pc.secondaries.begin(), pc.secondaries.end(), pc.primary); @@ -167,7 +167,7 @@ void meta_service_test_app::balancer_validator() const auto &app = apps[1]; for (const auto &pc : app->pcs) { - CHECK(pc.hp_primary, ""); + PGSCHECK(pc.hp_primary, ""); CHECK_GE(pc.secondaries.size(), pc.max_replica_count - 1); } diff --git a/src/meta/test/meta_app_operation_test.cpp b/src/meta/test/meta_app_operation_test.cpp index 11d458e059..93786733b8 100644 --- a/src/meta/test/meta_app_operation_test.cpp +++ b/src/meta/test/meta_app_operation_test.cpp @@ -152,7 +152,7 @@ class meta_app_operation_test : public meta_test_base int32_t max_replica_count) { auto app = find_app(app_name); - CHECK(app, "app({}) does not exist", app_name); + PGSCHECK(app, "app({}) does not exist", app_name); auto &pc = app->pcs[partition_index]; pc.max_replica_count = max_replica_count; @@ -161,7 +161,7 @@ class meta_app_operation_test : public meta_test_base void set_max_replica_count_env(const std::string &app_name, const std::string &env) { auto app = find_app(app_name); - CHECK(app, "app({}) does not exist", app_name); + PGSCHECK(app, "app({}) does not exist", app_name); if (env.empty()) { app->envs.erase(replica_envs::UPDATE_MAX_REPLICA_COUNT); @@ -215,7 +215,7 @@ class meta_app_operation_test : public meta_test_base int32_t max_replica_count) { auto app = find_app(app_name); - CHECK(app, "app({}) does not exist", app_name); + PGSCHECK(app, "app({}) does not exist", app_name); auto partition_size = static_cast(app->pcs.size()); for (int i = 0; i < partition_size; ++i) { @@ -257,7 +257,7 @@ class meta_app_operation_test : public meta_test_base int32_t expected_max_replica_count) { auto app = find_app(app_name); - CHECK(app, "app({}) does not exist", app_name); + PGSCHECK(app, "app({}) does not exist", app_name); auto partition_size = static_cast(app->pcs.size()); for (int i = 0; i < partition_size; ++i) { @@ -290,7 +290,7 @@ class meta_app_operation_test : public meta_test_base int32_t expected_max_replica_count) { auto app = find_app(app_name); - CHECK(app, "app({}) does not exist", app_name); + PGSCHECK(app, "app({}) does not exist", app_name); // verify local max_replica_count of the app ASSERT_EQ(app->max_replica_count, expected_max_replica_count); diff --git a/src/meta/test/meta_state/CMakeLists.txt b/src/meta/test/meta_state/CMakeLists.txt index dbb7be2ebb..205a336d34 100644 --- a/src/meta/test/meta_state/CMakeLists.txt +++ b/src/meta/test/meta_state/CMakeLists.txt @@ -32,7 +32,9 @@ set(MY_PROJ_LIBS dsn_replication_common dsn_runtime hashtable - gtest) + gtest + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES run.sh diff --git a/src/meta/test/misc/misc.cpp b/src/meta/test/misc/misc.cpp index d4bfa25a0f..b9f2fc1d69 100644 --- a/src/meta/test/misc/misc.cpp +++ b/src/meta/test/misc/misc.cpp @@ -108,7 +108,7 @@ void generate_node_mapper( ns->put_partition(pc.pid, true); } for (const auto &sec : pc.hp_secondaries) { - CHECK(sec, ""); + CHECK(sec); ns = get_node_state(output_nodes, sec, true); ns->put_partition(pc.pid, false); } @@ -134,9 +134,9 @@ void generate_app(/*out*/ std::shared_ptr &app, } } - CHECK(pc.hp_primary, ""); - CHECK(!is_secondary(pc, pc.hp_primary), ""); - CHECK(!is_secondary(pc, pc.primary), ""); + CHECK(pc.hp_primary); + CHECK(!is_secondary(pc, pc.hp_primary)); + CHECK(!is_secondary(pc, pc.primary)); CHECK_EQ(pc.hp_secondaries.size(), 2); CHECK_NE(pc.hp_secondaries[0], pc.hp_secondaries[1]); } @@ -198,7 +198,7 @@ void generate_node_fs_manager(const app_mapper &apps, { nfm.clear(); std::string prefix; - CHECK(dsn::utils::filesystem::get_current_directory(prefix), ""); + CHECK(dsn::utils::filesystem::get_current_directory(prefix)); std::vector data_dirs(total_disks); std::vector tags(total_disks); for (int i = 0; i < data_dirs.size(); ++i) { @@ -234,23 +234,23 @@ void track_disk_info_check_and_apply(const dsn::replication::configuration_propo /*in-out*/ nodes_fs_manager &manager) { config_context *cc = get_config_context(apps, pid); - CHECK_NOTNULL(cc, ""); + PGSCHECK_NOTNULL(cc, ""); dsn::host_port hp_target, hp_node; GET_HOST_PORT(act, target, hp_target); GET_HOST_PORT(act, node, hp_node); fs_manager *target_manager = get_fs_manager(manager, hp_target); - CHECK_NOTNULL(target_manager, ""); + PGSCHECK_NOTNULL(target_manager, ""); fs_manager *node_manager = get_fs_manager(manager, hp_node); - CHECK_NOTNULL(node_manager, ""); + PGSCHECK_NOTNULL(node_manager, ""); std::string dir; replica_info ri; switch (act.type) { case config_type::CT_ASSIGN_PRIMARY: { auto selected = target_manager->find_best_dir_for_new_replica(pid); - CHECK_NOTNULL(selected, ""); + PGSCHECK_NOTNULL(selected, ""); selected->holding_replicas[pid.get_app_id()].emplace(pid); cc->collect_serving_replica(hp_target, ri); break; @@ -258,7 +258,7 @@ void track_disk_info_check_and_apply(const dsn::replication::configuration_propo case config_type::CT_ADD_SECONDARY: case config_type::CT_ADD_SECONDARY_FOR_LB: { auto selected = node_manager->find_best_dir_for_new_replica(pid); - CHECK_NOTNULL(selected, ""); + PGSCHECK_NOTNULL(selected, ""); selected->holding_replicas[pid.get_app_id()].emplace(pid); cc->collect_serving_replica(hp_node, ri); break; @@ -274,7 +274,7 @@ void track_disk_info_check_and_apply(const dsn::replication::configuration_propo break; default: - CHECK(false, ""); + CHECK(false); break; } } @@ -290,8 +290,8 @@ void proposal_action_check_and_apply(const configuration_proposal_action &act, ++pc.ballot; CHECK_NE(act.type, config_type::CT_INVALID); - CHECK(act.target, ""); - CHECK(act.node, ""); + CHECK(act.target); + CHECK(act.node); if (manager) { track_disk_info_check_and_apply(act, pid, apps, nodes, *manager); @@ -305,13 +305,13 @@ void proposal_action_check_and_apply(const configuration_proposal_action &act, case config_type::CT_ASSIGN_PRIMARY: { CHECK_EQ(act.hp_node, act.hp_target); CHECK_EQ(act.node, act.target); - CHECK(!pc.hp_primary, ""); - CHECK(!pc.primary, ""); - CHECK(pc.hp_secondaries.empty(), ""); - CHECK(pc.secondaries.empty(), ""); + PGSCHECK(!pc.hp_primary, ""); + PGSCHECK(!pc.primary, ""); + PGSCHECK(pc.hp_secondaries.empty(), ""); + PGSCHECK(pc.secondaries.empty(), ""); SET_IP_AND_HOST_PORT(pc, primary, act.node, hp_node); const auto node = nodes.find(hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ns = &node->second; CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_INACTIVE); ns->put_partition(pc.pid, true); @@ -321,11 +321,11 @@ void proposal_action_check_and_apply(const configuration_proposal_action &act, CHECK_EQ(hp_target, pc.hp_primary); CHECK_EQ(act.hp_target, pc.hp_primary); CHECK_EQ(act.target, pc.primary); - CHECK(!is_member(pc, hp_node), ""); - CHECK(!is_member(pc, act.node), ""); + PGSCHECK(!is_member(pc, hp_node), ""); + PGSCHECK(!is_member(pc, act.node), ""); ADD_IP_AND_HOST_PORT(pc, secondaries, act.node, hp_node); const auto node = nodes.find(hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ns = &node->second; CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_INACTIVE); ns->put_partition(pc.pid, false); @@ -338,10 +338,10 @@ void proposal_action_check_and_apply(const configuration_proposal_action &act, CHECK_EQ(act.hp_node, pc.hp_primary); CHECK_EQ(act.node, pc.primary); CHECK_EQ(hp_node, pc.hp_primary); - CHECK(!is_secondary(pc, pc.hp_primary), ""); - CHECK(!is_secondary(pc, pc.primary), ""); + PGSCHECK(!is_secondary(pc, pc.hp_primary), ""); + PGSCHECK(!is_secondary(pc, pc.primary), ""); const auto node = nodes.find(hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ns = &node->second; ns->remove_partition(pc.pid, true); ADD_IP_AND_HOST_PORT(pc, secondaries, pc.primary, pc.hp_primary); @@ -349,19 +349,19 @@ void proposal_action_check_and_apply(const configuration_proposal_action &act, break; } case config_type::CT_UPGRADE_TO_PRIMARY: { - CHECK(!pc.hp_primary, ""); - CHECK(!pc.primary, ""); + PGSCHECK(!pc.hp_primary, ""); + PGSCHECK(!pc.primary, ""); CHECK_EQ(hp_node, hp_target); CHECK_EQ(act.hp_node, act.hp_target); CHECK_EQ(act.node, act.target); - CHECK(is_secondary(pc, hp_node), ""); - CHECK(is_secondary(pc, act.node), ""); + PGSCHECK(is_secondary(pc, hp_node), ""); + PGSCHECK(is_secondary(pc, act.node), ""); const auto node = nodes.find(hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ns = &node->second; SET_IP_AND_HOST_PORT(pc, primary, act.node, hp_node); - CHECK(replica_helper::remove_node(hp_node, pc.hp_secondaries), ""); - CHECK(replica_helper::remove_node(act.node, pc.secondaries), ""); + PGSCHECK(replica_helper::remove_node(hp_node, pc.hp_secondaries), ""); + PGSCHECK(replica_helper::remove_node(act.node, pc.secondaries), ""); ns->put_partition(pc.pid, true); break; } @@ -369,13 +369,13 @@ void proposal_action_check_and_apply(const configuration_proposal_action &act, CHECK_EQ(hp_target, pc.hp_primary); CHECK_EQ(act.hp_target, pc.hp_primary); CHECK_EQ(act.target, pc.primary); - CHECK(!is_member(pc, hp_node), ""); - CHECK(!is_member(pc, act.node), ""); - CHECK(act.hp_node, ""); - CHECK(act.node, ""); + PGSCHECK(!is_member(pc, hp_node), ""); + PGSCHECK(!is_member(pc, act.node), ""); + PGSCHECK(act.hp_node, ""); + PGSCHECK(act.node, ""); ADD_IP_AND_HOST_PORT(pc, secondaries, act.node, hp_node); const auto node = nodes.find(hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ns = &node->second; ns->put_partition(pc.pid, false); CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_SECONDARY); @@ -384,24 +384,24 @@ void proposal_action_check_and_apply(const configuration_proposal_action &act, // in balancer, remove primary is not allowed case config_type::CT_REMOVE: case config_type::CT_DOWNGRADE_TO_INACTIVE: { - CHECK(pc.hp_primary, ""); - CHECK(pc.primary, ""); + PGSCHECK(pc.hp_primary, ""); + PGSCHECK(pc.primary, ""); CHECK_EQ(pc.hp_primary, hp_target); CHECK_EQ(pc.hp_primary, act.hp_target); CHECK_EQ(pc.primary, act.target); - CHECK(is_secondary(pc, hp_node), ""); - CHECK(is_secondary(pc, act.node), ""); - CHECK(replica_helper::remove_node(hp_node, pc.hp_secondaries), ""); - CHECK(replica_helper::remove_node(act.node, pc.secondaries), ""); + PGSCHECK(is_secondary(pc, hp_node), ""); + PGSCHECK(is_secondary(pc, act.node), ""); + PGSCHECK(replica_helper::remove_node(hp_node, pc.hp_secondaries), ""); + PGSCHECK(replica_helper::remove_node(act.node, pc.secondaries), ""); const auto node = nodes.find(hp_node); - CHECK(node != nodes.end(), ""); + PGSCHECK(node != nodes.end(), ""); ns = &node->second; CHECK_EQ(ns->served_as(pc.pid), partition_status::PS_SECONDARY); ns->remove_partition(pc.pid, false); break; } default: - CHECK(false, ""); + PGSCHECK(false, ""); break; } } @@ -420,13 +420,13 @@ void migration_check_and_apply(app_mapper &apps, CHECK_LT(proposal->gpid.get_partition_index(), app->partition_count); const auto &pc = app->pcs[proposal->gpid.get_partition_index()]; - CHECK(pc.hp_primary, ""); + PGSCHECK(pc.hp_primary, ""); CHECK_EQ(pc.hp_secondaries.size(), 2); for (const auto &hp : pc.hp_secondaries) { - CHECK(hp, ""); + CHECK(hp); } - CHECK(!is_secondary(pc, pc.hp_primary), ""); - CHECK(!is_secondary(pc, pc.primary), ""); + CHECK(!is_secondary(pc, pc.hp_primary)); + CHECK(!is_secondary(pc, pc.primary)); for (unsigned int j = 0; j < proposal->action_list.size(); ++j) { configuration_proposal_action &act = proposal->action_list[j]; @@ -445,20 +445,20 @@ void app_mapper_compare(const app_mapper &mapper1, const app_mapper &mapper2) CHECK_EQ(mapper1.size(), mapper2.size()); for (auto &kv : mapper1) { const std::shared_ptr &app1 = kv.second; - CHECK(mapper2.find(app1->app_id) != mapper2.end(), ""); + CHECK(mapper2.find(app1->app_id) != mapper2.end()); const std::shared_ptr app2 = mapper2.find(app1->app_id)->second; CHECK_EQ(app1->app_id, app2->app_id); CHECK_EQ(app1->app_name, app2->app_name); CHECK_EQ(app1->app_type, app2->app_type); CHECK_EQ(app1->status, app2->status); - CHECK(app1->status == dsn::app_status::AS_AVAILABLE || - app1->status == dsn::app_status::AS_DROPPED, - ""); + PGSCHECK(app1->status == dsn::app_status::AS_AVAILABLE || + app1->status == dsn::app_status::AS_DROPPED, + ""); if (app1->status == dsn::app_status::AS_AVAILABLE) { CHECK_EQ(app1->partition_count, app2->partition_count); for (unsigned int i = 0; i < app1->partition_count; ++i) { - CHECK(is_partition_config_equal(app1->pcs[i], app2->pcs[i]), ""); + CHECK(is_partition_config_equal(app1->pcs[i], app2->pcs[i])); } } } diff --git a/src/nfs/nfs_client_impl.cpp b/src/nfs/nfs_client_impl.cpp index 5b2bcd3657..0e00c4d946 100644 --- a/src/nfs/nfs_client_impl.cpp +++ b/src/nfs/nfs_client_impl.cpp @@ -467,7 +467,7 @@ void nfs_client_impl::continue_write() std::string file_path = dsn::utils::filesystem::path_combine(fc->user_req->file_size_req.dst_dir, fc->file_name); std::string path = dsn::utils::filesystem::remove_file_name(file_path.c_str()); - CHECK(dsn::utils::filesystem::create_directory(path), "create directory {} failed", path); + PGSCHECK(dsn::utils::filesystem::create_directory(path), "create directory {} failed", path); if (!fc->file_holder->file_handle) { // double check diff --git a/src/nfs/nfs_server_impl.cpp b/src/nfs/nfs_server_impl.cpp index d4f8568b81..5622412797 100644 --- a/src/nfs/nfs_server_impl.cpp +++ b/src/nfs/nfs_server_impl.cpp @@ -113,12 +113,12 @@ void nfs_service_impl::on_copy(const ::dsn::service::copy_request &request, } else { dfile = fh->file_handle; } - DCHECK(fh, ""); + DCHECK(fh); fh->file_access_count++; fh->last_access_time = dsn_now_ms(); } while (false); - CHECK_NOTNULL(dfile, ""); + CHECK_NOTNULL(dfile); LOG_DEBUG("nfs: copy from file {} [{}, {}]", file_path, request.offset, diff --git a/src/nfs/test/CMakeLists.txt b/src/nfs/test/CMakeLists.txt index 4a22ce4867..b138df62db 100644 --- a/src/nfs/test/CMakeLists.txt +++ b/src/nfs/test/CMakeLists.txt @@ -43,7 +43,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy - test_utils) + test_utils + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/perf_counter/perf_counter_atomic.cpp b/src/perf_counter/perf_counter_atomic.cpp index a27b5ee957..db34a67a87 100644 --- a/src/perf_counter/perf_counter_atomic.cpp +++ b/src/perf_counter/perf_counter_atomic.cpp @@ -76,7 +76,7 @@ void perf_counter_number_percentile_atomic::on_timer( timer->async_wait(std::bind( &perf_counter_number_percentile_atomic::on_timer, this, timer, std::placeholders::_1)); } else if (boost::system::errc::operation_canceled != ec) { - CHECK(false, "on_timer error!!!"); + PGSCHECK(false, "on_timer error!!!"); } } diff --git a/src/perf_counter/perf_counter_atomic.h b/src/perf_counter/perf_counter_atomic.h index 40ca5a4444..c2499e4e50 100644 --- a/src/perf_counter/perf_counter_atomic.h +++ b/src/perf_counter/perf_counter_atomic.h @@ -101,7 +101,7 @@ class perf_counter_number_atomic : public perf_counter } virtual double get_percentile(dsn_perf_counter_percentile_type_t type) { - CHECK(false, "invalid execution flow"); + PGSCHECK(false, "invalid execution flow"); return 0.0; } @@ -176,7 +176,7 @@ class perf_counter_rate_atomic : public perf_counter uint64_t task_id = static_cast(utils::get_current_tid()); _val[task_id % DIVIDE_CONTAINER].fetch_add(val, std::memory_order_relaxed); } - virtual void set(int64_t val) { CHECK(false, "invalid execution flow"); } + virtual void set(int64_t val) { PGSCHECK(false, "invalid execution flow"); } virtual double get_value() { uint64_t now = utils::get_current_physical_time_ns(); @@ -196,7 +196,7 @@ class perf_counter_rate_atomic : public perf_counter virtual int64_t get_integer_value() { return (int64_t)get_value(); } virtual double get_percentile(dsn_perf_counter_percentile_type_t type) { - CHECK(false, "invalid execution flow"); + PGSCHECK(false, "invalid execution flow"); return 0.0; } @@ -231,9 +231,9 @@ class perf_counter_number_percentile_atomic : public perf_counter } } - virtual void increment() { CHECK(false, "invalid execution flow"); } - virtual void decrement() { CHECK(false, "invalid execution flow"); } - virtual void add(int64_t val) { CHECK(false, "invalid execution flow"); } + virtual void increment() { PGSCHECK(false, "invalid execution flow"); } + virtual void decrement() { PGSCHECK(false, "invalid execution flow"); } + virtual void add(int64_t val) { PGSCHECK(false, "invalid execution flow"); } virtual void set(int64_t val) { uint64_t idx = _tail.fetch_add(1, std::memory_order_relaxed); @@ -242,7 +242,7 @@ class perf_counter_number_percentile_atomic : public perf_counter virtual double get_value() { - CHECK(false, "invalid execution flow"); + PGSCHECK(false, "invalid execution flow"); return 0.0; } virtual int64_t get_integer_value() { return (int64_t)get_value(); } @@ -250,7 +250,7 @@ class perf_counter_number_percentile_atomic : public perf_counter virtual double get_percentile(dsn_perf_counter_percentile_type_t type) { if ((type < 0) || (type >= COUNTER_PERCENTILE_COUNT)) { - CHECK(false, "send a wrong counter percentile type"); + PGSCHECK(false, "send a wrong counter percentile type"); return 0.0; } return (double)_results[type]; @@ -350,7 +350,7 @@ class perf_counter_number_percentile_atomic : public perf_counter if (ctx->ask[i] == 1) { _results[i] = ctx->tmp[left]; } else - CHECK(false, "select percentail wrong!!!"); + PGSCHECK(false, "select percentail wrong!!!"); return; } diff --git a/src/perf_counter/perf_counters.cpp b/src/perf_counter/perf_counters.cpp index 24e26c699e..f0726487fd 100644 --- a/src/perf_counter/perf_counters.cpp +++ b/src/perf_counter/perf_counters.cpp @@ -180,7 +180,7 @@ perf_counter_ptr perf_counters::get_app_counter(const char *section, bool create_if_not_exist) { auto cnode = task::get_current_node2(); - CHECK_NOTNULL(cnode, "cannot get current service node!"); + PGSCHECK_NOTNULL(cnode, "cannot get current service node!"); return get_global_counter(cnode->full_name(), section, name, flags, dsptr, create_if_not_exist); } @@ -256,7 +256,7 @@ perf_counter *perf_counters::new_counter(const char *app, else if (type == dsn_perf_counter_type_t::COUNTER_TYPE_NUMBER_PERCENTILES) return new perf_counter_number_percentile_atomic(app, section, name, type, dsptr); else { - CHECK(false, "invalid type({})", type); + PGSCHECK(false, "invalid type({})", type); return nullptr; } } diff --git a/src/perf_counter/test/CMakeLists.txt b/src/perf_counter/test/CMakeLists.txt index 1b1a8d2292..0d5947791b 100644 --- a/src/perf_counter/test/CMakeLists.txt +++ b/src/perf_counter/test/CMakeLists.txt @@ -34,7 +34,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy - gtest) + gtest + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES clear.sh diff --git a/src/ranger/ranger_resource_policy.cpp b/src/ranger/ranger_resource_policy.cpp index ae6262be0d..47f0e1af3e 100644 --- a/src/ranger/ranger_resource_policy.cpp +++ b/src/ranger/ranger_resource_policy.cpp @@ -108,7 +108,8 @@ check_ranger_resource_policy_allowed(const std::vector & if (access_control_result::kDenied == check_res) { return access_control_result::kDenied; } - CHECK(access_control_result::kPending == check_res, "the access control result must kPending."); + PGSCHECK(access_control_result::kPending == check_res, + "the access control result must kPending."); // Check if it is allowed by any policy in current resource. check_res = do_check_ranger_resource_policy( @@ -116,7 +117,8 @@ check_ranger_resource_policy_allowed(const std::vector & if (access_control_result::kAllowed == check_res) { return access_control_result::kAllowed; } - CHECK(access_control_result::kPending == check_res, "the access control result must kPending."); + PGSCHECK(access_control_result::kPending == check_res, + "the access control result must kPending."); // The check that does not match any policy in current reosource returns false. return access_control_result::kDenied; @@ -151,9 +153,9 @@ access_control_result do_check_ranger_resource_policy } // In a 'allow_policies' and in a 'allow_policies_exclude' or not match. - CHECK(policy_check_status::kPending == check_status || - policy_check_status::kNotMatched == check_status, - "the policy check status must be kPending or kNotMatched"); + PGSCHECK(policy_check_status::kPending == check_status || + policy_check_status::kNotMatched == check_status, + "the policy check status must be kPending or kNotMatched"); } return access_control_result::kPending; } @@ -187,9 +189,9 @@ access_control_result do_check_ranger_resource_policy( } // In a 'deny_policies' and in a 'deny_policies_exclude' or not match. - CHECK(policy_check_status::kPending == check_status || - policy_check_status::kNotMatched == check_status, - "the policy check status must be kPending or kNotMatched"); + PGSCHECK(policy_check_status::kPending == check_status || + policy_check_status::kNotMatched == check_status, + "the policy check status must be kPending or kNotMatched"); } return access_control_result::kPending; } @@ -205,7 +207,8 @@ access_control_result check_ranger_database_table_policy_allowed( if (access_control_result::kDenied == check_res) { return access_control_result::kDenied; } - CHECK(access_control_result::kPending == check_res, "the access control result must kPending."); + PGSCHECK(access_control_result::kPending == check_res, + "the access control result must kPending."); // Check if it is allowed by any DATABASE_TABLE policy. check_res = do_check_ranger_database_table_policy( @@ -213,7 +216,8 @@ access_control_result check_ranger_database_table_policy_allowed( if (access_control_result::kAllowed == check_res) { return access_control_result::kAllowed; } - CHECK(access_control_result::kPending == check_res, "the access control result must kPending."); + PGSCHECK(access_control_result::kPending == check_res, + "the access control result must kPending."); // The check that does not match any DATABASE_TABLE policy returns false. return access_control_result::kDenied; @@ -235,9 +239,9 @@ access_control_result do_check_ranger_database_table_policycluster_root(), "ranger_policy_meta_root"); tasking::enqueue_timer( @@ -260,7 +260,7 @@ access_control_result ranger_resource_policy_manager::allowed( void ranger_resource_policy_manager::parse_policies_from_json(const rapidjson::Value &data, std::vector &policies) { - CHECK(policies.empty(), "Ranger policy list should not be empty."); + PGSCHECK(policies.empty(), "Ranger policy list should not be empty."); RETURN_VOID_IF_NOT_ARRAY(data); for (const auto &item : data.GetArray()) { CONTINUE_IF_MISSING_MEMBER(item, "accesses"); @@ -604,13 +604,14 @@ dsn::error_code ranger_resource_policy_manager::sync_policies_to_app_envs() {database_name, table_name, policy.policies}); // This table matches the policy whose database is "*". if (policy.database_names.count(database_name) == 0) { - CHECK(policy.database_names.count("*") != 0, - "the list of database_name must contain *"); + PGSCHECK(policy.database_names.count("*") != 0, + "the list of database_name must contain *"); database_table_policy.matched_database_name = "*"; } // This table matches the policy whose database table is "*". if (policy.table_names.count(table_name) == 0) { - CHECK(policy.table_names.count("*") != 0, "the list of table_name must contain *"); + PGSCHECK(policy.table_names.count("*") != 0, + "the list of table_name must contain *"); database_table_policy.matched_table_name = "*"; } matched_database_table_policies.emplace_back(database_table_policy); diff --git a/src/ranger/test/CMakeLists.txt b/src/ranger/test/CMakeLists.txt index 443791ff28..efed990179 100644 --- a/src/ranger/test/CMakeLists.txt +++ b/src/ranger/test/CMakeLists.txt @@ -24,7 +24,9 @@ set(MY_PROJ_LIBS dsn_meta_server dsn_replication_common dsn_utils - gtest) + gtest + glog + gflags) set(MY_BINPLACES run.sh) dsn_add_test() diff --git a/src/redis_protocol/proxy/CMakeLists.txt b/src/redis_protocol/proxy/CMakeLists.txt index a381914c72..5e41c43572 100644 --- a/src/redis_protocol/proxy/CMakeLists.txt +++ b/src/redis_protocol/proxy/CMakeLists.txt @@ -37,7 +37,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BINPLACES "config.ini") diff --git a/src/redis_protocol/proxy_lib/proxy_layer.cpp b/src/redis_protocol/proxy_lib/proxy_layer.cpp index b8eb1666d2..8ba2103416 100644 --- a/src/redis_protocol/proxy_lib/proxy_layer.cpp +++ b/src/redis_protocol/proxy_lib/proxy_layer.cpp @@ -110,7 +110,7 @@ void proxy_stub::remove_session(dsn::rpc_address remote) proxy_session::proxy_session(proxy_stub *op, dsn::message_ex *first_msg) : _stub(op), _is_session_reset(false), _backup_one_request(first_msg) { - CHECK_NOTNULL(first_msg, "null msg when create session"); + PGSCHECK_NOTNULL(first_msg, "null msg when create session"); _backup_one_request->add_ref(); _session_remote = _backup_one_request->header->from_address; diff --git a/src/redis_protocol/proxy_lib/redis_parser.cpp b/src/redis_protocol/proxy_lib/redis_parser.cpp index 99683d902c..52136dc92f 100644 --- a/src/redis_protocol/proxy_lib/redis_parser.cpp +++ b/src/redis_protocol/proxy_lib/redis_parser.cpp @@ -1319,10 +1319,10 @@ void redis_parser::redis_simple_string::marshalling(::dsn::binary_writer &write_ void redis_parser::redis_bulk_string::marshalling(::dsn::binary_writer &write_stream) const { - CHECK((-1 == length && data.length() == 0) || data.length() == length, - "{} VS {}", - data.length(), - length); + PGSCHECK((-1 == length && data.length() == 0) || data.length() == length, + "{} VS {}", + data.length(), + length); write_stream.write_pod('$'); std::string length_str = std::to_string(length); write_stream.write(length_str.c_str(), (int)length_str.length()); @@ -1337,10 +1337,10 @@ void redis_parser::redis_bulk_string::marshalling(::dsn::binary_writer &write_st void redis_parser::redis_array::marshalling(::dsn::binary_writer &write_stream) const { - CHECK((-1 == count && array.size() == 0) || array.size() == count, - "{} VS {}", - array.size(), - count); + PGSCHECK((-1 == count && array.size() == 0) || array.size() == count, + "{} VS {}", + array.size(), + count); write_stream.write_pod('*'); std::string count_str = std::to_string(count); write_stream.write(count_str.c_str(), (int)count_str.length()); diff --git a/src/redis_protocol/proxy_ut/CMakeLists.txt b/src/redis_protocol/proxy_ut/CMakeLists.txt index bddf2c0855..11c87cdddf 100644 --- a/src/redis_protocol/proxy_ut/CMakeLists.txt +++ b/src/redis_protocol/proxy_ut/CMakeLists.txt @@ -41,7 +41,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy - gtest) + gtest + glog + gflags) set(MY_BINPLACES "config.ini" "run.sh") diff --git a/src/replica/backup/cold_backup_context.cpp b/src/replica/backup/cold_backup_context.cpp index 28f3cd791a..a381928ce7 100644 --- a/src/replica/backup/cold_backup_context.cpp +++ b/src/replica/backup/cold_backup_context.cpp @@ -60,7 +60,7 @@ const char *cold_backup_status_to_string(cold_backup_status status) case ColdBackupFailed: return "ColdBackupFailed"; default: - CHECK(false, ""); + PGSCHECK(false, ""); } return "ColdBackupXXX"; } @@ -205,7 +205,7 @@ void cold_backup_context::check_backup_on_remote() ignore_check(); } else if (resp.err == ERR_OK) { const dist::block_service::block_file_ptr &file_handle = resp.file_handle; - CHECK_NOTNULL(file_handle, ""); + PGSCHECK_NOTNULL(file_handle, ""); if (file_handle->get_md5sum().empty() && file_handle->get_size() <= 0) { LOG_INFO("{}: check backup on remote, current_checkpoint file {} is not exist", name, @@ -434,7 +434,7 @@ void cold_backup_context::upload_checkpoint_to_remote() LPC_BACKGROUND_COLD_BACKUP, [this, metadata](const dist::block_service::create_file_response &resp) { if (resp.err == ERR_OK) { - CHECK_NOTNULL(resp.file_handle, ""); + PGSCHECK_NOTNULL(resp.file_handle, ""); if (resp.file_handle->get_md5sum().empty() && resp.file_handle->get_size() <= 0) { _upload_status.store(UploadUncomplete); LOG_INFO("{}: check upload_status complete, cold_backup_metadata isn't exist, " @@ -661,7 +661,7 @@ void cold_backup_context::upload_file(const std::string &local_filename) [this, local_filename](const dist::block_service::create_file_response &resp) { if (resp.err == ERR_OK) { const dist::block_service::block_file_ptr &file_handle = resp.file_handle; - CHECK_NOTNULL(file_handle, ""); + PGSCHECK_NOTNULL(file_handle, ""); int64_t local_file_size = _file_infos.at(local_filename).first; std::string md5 = _file_infos.at(local_filename).second; std::string full_path_local_file = @@ -810,7 +810,7 @@ void cold_backup_context::write_backup_metadata() LPC_BACKGROUND_COLD_BACKUP, [this, metadata](const dist::block_service::create_file_response &resp) { if (resp.err == ERR_OK) { - CHECK_NOTNULL(resp.file_handle, ""); + PGSCHECK_NOTNULL(resp.file_handle, ""); blob buffer = json::json_forwarder::encode(_metadata); // hold itself until callback is executed add_ref(); @@ -894,7 +894,7 @@ void cold_backup_context::write_current_chkpt_file(const std::string &value) LPC_BACKGROUND_COLD_BACKUP, [this, value, current_chkpt_file](const dist::block_service::create_file_response &resp) { if (resp.err == ERR_OK) { - CHECK_NOTNULL(resp.file_handle, ""); + PGSCHECK_NOTNULL(resp.file_handle, ""); auto len = value.length(); std::shared_ptr buf = utils::make_shared_array(len); ::memcpy(buf.get(), value.c_str(), len); @@ -948,7 +948,7 @@ void cold_backup_context::on_write(const dist::block_service::block_file_ptr &fi const blob &value, const std::function &callback) { - CHECK_NOTNULL(file_handle, ""); + PGSCHECK_NOTNULL(file_handle, ""); dist::block_service::write_request req; req.buffer = value; diff --git a/src/replica/backup/cold_backup_context.h b/src/replica/backup/cold_backup_context.h index 0d2f07ffc7..0b9c3be3f3 100644 --- a/src/replica/backup/cold_backup_context.h +++ b/src/replica/backup/cold_backup_context.h @@ -242,9 +242,9 @@ class cold_backup_context : public ref_counter // Progress should be in range of [0, 1000]. void update_progress(int progress) { - CHECK(progress >= 0 && progress <= cold_backup_constant::PROGRESS_FINISHED, - "invalid progress {}", - progress); + PGSCHECK(progress >= 0 && progress <= cold_backup_constant::PROGRESS_FINISHED, + "invalid progress {}", + progress); _progress.store(progress); } diff --git a/src/replica/backup/test/CMakeLists.txt b/src/replica/backup/test/CMakeLists.txt index bacb77adad..0c087b7e37 100644 --- a/src/replica/backup/test/CMakeLists.txt +++ b/src/replica/backup/test/CMakeLists.txt @@ -31,7 +31,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES config-test.ini diff --git a/src/replica/bulk_load/test/CMakeLists.txt b/src/replica/bulk_load/test/CMakeLists.txt index 08abb8f9a7..45cbb7feb6 100644 --- a/src/replica/bulk_load/test/CMakeLists.txt +++ b/src/replica/bulk_load/test/CMakeLists.txt @@ -30,7 +30,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES config-test.ini diff --git a/src/replica/disk_cleaner.cpp b/src/replica/disk_cleaner.cpp index 8a191d67fc..36ba00e599 100644 --- a/src/replica/disk_cleaner.cpp +++ b/src/replica/disk_cleaner.cpp @@ -275,11 +275,11 @@ bool is_data_dir_invalid(const std::string &dir) void move_to_err_path(const std::string &path, const std::string &log_prefix) { const std::string new_path = fmt::format("{}.{}{}", path, dsn_now_us(), kFolderSuffixErr); - CHECK(dsn::utils::filesystem::rename_path(path, new_path), - "{}: failed to move directory from '{}' to '{}'", - log_prefix, - path, - new_path); + PGSCHECK(dsn::utils::filesystem::rename_path(path, new_path), + "{}: failed to move directory from '{}' to '{}'", + log_prefix, + path, + new_path); LOG_WARNING("{}: succeed to move directory from '{}' to '{}'", log_prefix, path, new_path); } diff --git a/src/replica/duplication/replica_follower.cpp b/src/replica/duplication/replica_follower.cpp index 3373d9a86c..2bc5796182 100644 --- a/src/replica/duplication/replica_follower.cpp +++ b/src/replica/duplication/replica_follower.cpp @@ -81,10 +81,10 @@ void replica_follower::init_master_info() std::vector master_metas; dsn::utils::split_args(metas->second.c_str(), master_metas, ','); - CHECK(!master_metas.empty(), "master cluster meta list is invalid!"); + PGSCHECK(!master_metas.empty(), "master cluster meta list is invalid!"); for (const auto &meta : master_metas) { const auto node = host_port::from_string(meta); - CHECK(node, "{} is invalid meta host_port", meta); + PGSCHECK(node, "{} is invalid meta host_port", meta); _master_meta_list.emplace_back(std::move(node)); } } diff --git a/src/replica/duplication/test/CMakeLists.txt b/src/replica/duplication/test/CMakeLists.txt index 57915bbe0e..26a3d5fa18 100644 --- a/src/replica/duplication/test/CMakeLists.txt +++ b/src/replica/duplication/test/CMakeLists.txt @@ -25,6 +25,7 @@ set(MY_PROJ_LIBS dsn.replication.zookeeper_provider dsn_replication_common dsn.failure_detector + dsn_nfs dsn_utils zookeeper hashtable @@ -33,7 +34,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES config-test.ini diff --git a/src/replica/log_block.h b/src/replica/log_block.h index 4e63360141..98561eac7e 100644 --- a/src/replica/log_block.h +++ b/src/replica/log_block.h @@ -69,7 +69,7 @@ class log_block // ``` blob &front() { - CHECK(!_data.empty(), "trying to get first blob out of an empty log block"); + PGSCHECK(!_data.empty(), "trying to get first blob out of an empty log block"); return _data.front(); } diff --git a/src/replica/log_file.cpp b/src/replica/log_file.cpp index ab88a3e2e6..b25b2ae615 100644 --- a/src/replica/log_file.cpp +++ b/src/replica/log_file.cpp @@ -68,7 +68,7 @@ log_file::~log_file() { close(); } } auto pos = name.find_first_of('.'); - CHECK(pos != std::string::npos, "invalid log_file, name = {}", name); + PGSCHECK(pos != std::string::npos, "invalid log_file, name = {}", name); auto pos2 = name.find_first_of('.', pos + 1); if (pos2 == std::string::npos) { err = ERR_INVALID_PARAMETERS; @@ -179,9 +179,9 @@ log_file::log_file( if (is_read) { int64_t sz; - CHECK(dsn::utils::filesystem::file_size(_path, dsn::utils::FileDataType::kSensitive, sz), - "fail to get file size of {}.", - _path); + PGSCHECK(dsn::utils::filesystem::file_size(_path, dsn::utils::FileDataType::kSensitive, sz), + "fail to get file size of {}.", + _path); _end_offset += sz; } } @@ -203,7 +203,7 @@ void log_file::close() void log_file::flush() const { - CHECK(!_is_read, "log file must be of write mode"); + PGSCHECK(!_is_read, "log file must be of write mode"); zauto_lock lock(_write_lock); if (_handle) { @@ -214,7 +214,7 @@ void log_file::flush() const error_code log_file::read_next_log_block(/*out*/ ::dsn::blob &bb) { - CHECK(_is_read, "log file must be of read mode"); + PGSCHECK(_is_read, "log file must be of read mode"); auto err = _stream->read_next(sizeof(log_block_header), bb); if (err != ERR_OK || bb.length() != sizeof(log_block_header)) { if (err == ERR_OK || err == ERR_HANDLE_EOF) { @@ -277,7 +277,7 @@ aio_task_ptr log_file::commit_log_blocks(log_appender &pending, aio_handler &&callback, int hash) { - CHECK(!_is_read, "log file must be of write mode"); + PGSCHECK(!_is_read, "log file must be of write mode"); CHECK_GT(pending.size(), 0); zauto_lock lock(_write_lock); diff --git a/src/replica/mutation.cpp b/src/replica/mutation.cpp index de754cb9cf..d73284227f 100644 --- a/src/replica/mutation.cpp +++ b/src/replica/mutation.cpp @@ -165,7 +165,7 @@ void mutation::add_client_request(task_code code, dsn::message_ex *request) void *ptr; size_t size; - CHECK(request->read_next(&ptr, &size), "payload is not present"); + PGSCHECK(request->read_next(&ptr, &size), "payload is not present"); request->read_commit(0); // so we can re-read the request buffer in replicated app update.data.assign((char *)ptr, 0, (int)size); @@ -317,7 +317,7 @@ void mutation::write_to(binary_writer &writer, dsn::message_ex * /*to*/) const reader.read_pod(isset); header.timestamp = 0; } else { - CHECK(false, "invalid mutation log version: {:#018x}", version); + PGSCHECK(false, "invalid mutation log version: {:#018x}", version); } } @@ -396,7 +396,7 @@ mutation_ptr mutation_queue::add_work(task_code code, dsn::message_ex *request, if (_current_op_count >= _max_concurrent_op) return nullptr; else if (_hdr.is_empty()) { - CHECK_NOTNULL(_pending_mutation, "pending mutation cannot be null"); + PGSCHECK_NOTNULL(_pending_mutation, "pending mutation cannot be null"); auto ret = _pending_mutation; _pending_mutation = nullptr; diff --git a/src/replica/mutation.h b/src/replica/mutation.h index cd99d957c4..6419fa3a80 100644 --- a/src/replica/mutation.h +++ b/src/replica/mutation.h @@ -108,7 +108,7 @@ class mutation : public ref_counter void copy_from(mutation_ptr &old); void set_logged() { - CHECK(!is_logged(), ""); + PGSCHECK(!is_logged(), ""); _not_logged = 0; } unsigned int decrease_left_secondary_ack_count() { return --_left_secondary_ack_count; } @@ -212,10 +212,10 @@ class mutation_queue ~mutation_queue() { clear(); - CHECK(_hdr.is_empty(), - "work queue is deleted when there are still {} running ops or pending work items " - "in queue", - _current_op_count); + PGSCHECK(_hdr.is_empty(), + "work queue is deleted when there are still {} running ops or pending work items " + "in queue", + _current_op_count); } mutation_ptr add_work(task_code code, dsn::message_ex *request, replica *r); diff --git a/src/replica/mutation_log.cpp b/src/replica/mutation_log.cpp index df3ca2e6b2..f511ff483e 100644 --- a/src/replica/mutation_log.cpp +++ b/src/replica/mutation_log.cpp @@ -229,9 +229,9 @@ void mutation_log_private::init_states() void mutation_log_private::write_pending_mutations(bool release_lock_required) { - CHECK(release_lock_required, "lock must be hold at this point"); - CHECK(!_is_writing.load(std::memory_order_relaxed), ""); - CHECK_NOTNULL(_pending_write, ""); + PGSCHECK(release_lock_required, "lock must be hold at this point"); + PGSCHECK(!_is_writing.load(std::memory_order_relaxed), ""); + PGSCHECK_NOTNULL(_pending_write, ""); CHECK_GT(_pending_write->size(), 0); auto pr = mark_new_offset(_pending_write->size(), false); CHECK_EQ_PREFIX(pr.second, _pending_write->start_offset()); @@ -270,7 +270,7 @@ void mutation_log_private::commit_pending_mutations(log_file_ptr &lf, LPC_WRITE_REPLICATION_LOG_PRIVATE, &_tracker, [this, lf, pending, max_decree, max_commit](error_code err, size_t sz) mutable { - CHECK(_is_writing.load(std::memory_order_relaxed), ""); + PGSCHECK(_is_writing.load(std::memory_order_relaxed), ""); for (auto &block : pending->all_blocks()) { auto hdr = (log_block_header *)block.front().data(); @@ -374,7 +374,7 @@ error_code mutation_log::open(replay_callback read_callback, io_failure_callback write_error_callback, const std::map &replay_condition) { - CHECK(!_is_opened, "cannot open an opened mutation_log"); + PGSCHECK(!_is_opened, "cannot open an opened mutation_log"); CHECK_NULL(_current_log_file, ""); // create dir if necessary @@ -396,7 +396,7 @@ error_code mutation_log::open(replay_callback read_callback, } if (nullptr == read_callback) { - CHECK(file_list.empty(), ""); + PGSCHECK(file_list.empty(), ""); } std::sort(file_list.begin(), file_list.end()); @@ -429,9 +429,9 @@ error_code mutation_log::open(replay_callback read_callback, log->end_offset() - log->start_offset()); } - CHECK(_log_files.find(log->index()) == _log_files.end(), - "invalid log_index, index = {}", - log->index()); + PGSCHECK(_log_files.find(log->index()) == _log_files.end(), + "invalid log_index, index = {}", + log->index()); _log_files[log->index()] = log; } @@ -443,7 +443,7 @@ error_code mutation_log::open(replay_callback read_callback, if (!replay_condition.empty()) { if (_is_private) { auto find = replay_condition.find(_private_gpid); - CHECK(find != replay_condition.end(), "invalid gpid({})", _private_gpid); + PGSCHECK(find != replay_condition.end(), "invalid gpid({})", _private_gpid); for (auto it = _log_files.begin(); it != _log_files.end(); ++it) { if (it->second->previous_log_max_decree(_private_gpid) <= find->second) { // previous logs can be ignored @@ -496,13 +496,13 @@ error_code mutation_log::open(replay_callback read_callback, if (mark_it != _log_files.rend()) { // set replay_begin to the next position of mark_it. replay_begin = _log_files.find(mark_it->first); - CHECK(replay_begin != _log_files.end(), - "invalid log_index, index = {}", - mark_it->first); + PGSCHECK(replay_begin != _log_files.end(), + "invalid log_index, index = {}", + mark_it->first); replay_begin++; - CHECK(replay_begin != _log_files.end(), - "invalid log_index, index = {}", - mark_it->first); + PGSCHECK(replay_begin != _log_files.end(), + "invalid log_index, index = {}", + mark_it->first); } } @@ -600,9 +600,9 @@ error_code mutation_log::create_new_log_file() // update states _last_file_index++; - CHECK(_log_files.find(_last_file_index) == _log_files.end(), - "invalid log_offset, offset = {}", - _last_file_index); + PGSCHECK(_log_files.find(_last_file_index) == _log_files.end(), + "invalid log_offset, offset = {}", + _last_file_index); _log_files[_last_file_index] = logf; // switch the current log file @@ -634,7 +634,7 @@ error_code mutation_log::create_new_log_file() LOG_ERROR("write mutation log file header failed, file = {}, err = {}", logf->path(), err); - CHECK(_io_error_callback, ""); + PGSCHECK(_io_error_callback, ""); _io_error_callback(err); } }, @@ -691,7 +691,7 @@ std::pair mutation_log::mark_new_offset(size_t size, _switch_file_demand = false; } } else { - CHECK_NOTNULL(_current_log_file, ""); + PGSCHECK_NOTNULL(_current_log_file, ""); } int64_t write_start_offset = _global_end_offset; @@ -711,14 +711,14 @@ decree mutation_log::max_decree(gpid gpid) const decree mutation_log::max_decree_on_disk() const { zauto_lock l(_lock); - CHECK(_is_private, "this method is only valid for private logs"); + PGSCHECK(_is_private, "this method is only valid for private logs"); return _plog_max_decree_on_disk; } decree mutation_log::max_commit_on_disk() const { zauto_lock l(_lock); - CHECK(_is_private, "this method is only valid for private logs"); + PGSCHECK(_is_private, "this method is only valid for private logs"); return _plog_max_commit_on_disk; } @@ -730,7 +730,7 @@ decree mutation_log::max_gced_decree(gpid gpid) const decree mutation_log::max_gced_decree_no_lock(gpid gpid) const { - CHECK(_is_private, ""); + PGSCHECK(_is_private, ""); decree result = invalid_decree; for (auto &log : _log_files) { @@ -800,10 +800,10 @@ error_code mutation_log::reset_from(const std::string &dir, } } else { // Once rollback failed, dir should be recovered manually in case data is lost. - CHECK(utils::filesystem::rename_path(temp_dir, _dir), - "rename temp dir {} back to current dir {} failed", - temp_dir, - _dir); + PGSCHECK(utils::filesystem::rename_path(temp_dir, _dir), + "rename temp dir {} back to current dir {} failed", + temp_dir, + _dir); } }); @@ -816,10 +816,10 @@ error_code mutation_log::reset_from(const std::string &dir, auto dir_resolve = dsn::defer([this, dir, &err]() { if (err != ERR_OK) { - CHECK(utils::filesystem::rename_path(_dir, dir), - "rename current dir {} back to source dir {} failed", - _dir, - dir); + PGSCHECK(utils::filesystem::rename_path(_dir, dir), + "rename current dir {} back to source dir {} failed", + _dir, + dir); } }); @@ -884,7 +884,7 @@ void mutation_log::update_max_decree_on_disk(decree max_decree, decree max_commi void mutation_log::update_max_decree_on_disk_no_lock(decree d) { - CHECK(_is_private, "this method is only valid for private logs"); + PGSCHECK(_is_private, "this method is only valid for private logs"); if (d > _plog_max_decree_on_disk) { _plog_max_decree_on_disk = d; } @@ -892,7 +892,7 @@ void mutation_log::update_max_decree_on_disk_no_lock(decree d) void mutation_log::update_max_commit_on_disk_no_lock(decree d) { - CHECK(_is_private, "this method is only valid for private logs"); + PGSCHECK(_is_private, "this method is only valid for private logs"); if (d > _plog_max_commit_on_disk) { _plog_max_commit_on_disk = d; } @@ -900,7 +900,7 @@ void mutation_log::update_max_commit_on_disk_no_lock(decree d) bool mutation_log::get_learn_state(gpid gpid, decree start, /*out*/ learn_state &state) const { - CHECK(_is_private, "this method is only valid for private logs"); + PGSCHECK(_is_private, "this method is only valid for private logs"); CHECK_EQ(_private_gpid, gpid); binary_writer temp_writer; @@ -1002,7 +1002,7 @@ void mutation_log::get_parent_mutations_and_logs(gpid pid, std::vector &files, uint64_t &total_file_size) const { - CHECK(_is_private, "this method is only valid for private logs"); + PGSCHECK(_is_private, "this method is only valid for private logs"); CHECK_EQ(_private_gpid, pid); mutation_list.clear(); @@ -1098,7 +1098,7 @@ int mutation_log::garbage_collection(gpid gpid, int64_t reserve_max_size, int64_t reserve_max_time) { - CHECK(_is_private, "this method is only valid for private log"); + PGSCHECK(_is_private, "this method is only valid for private log"); log_file_map_by_index files; decree max_decree = invalid_decree; @@ -1119,9 +1119,9 @@ int mutation_log::garbage_collection(gpid gpid, } // the last one should be the current log file - CHECK(current_file_index == -1 || files.rbegin()->first == current_file_index, - "invalid current_file_index, index = {}", - current_file_index); + PGSCHECK(current_file_index == -1 || files.rbegin()->first == current_file_index, + "invalid current_file_index, index = {}", + current_file_index); // find the largest file which can be deleted. // after iterate, the 'mark_it' will point to the largest file which can be deleted. @@ -1170,7 +1170,7 @@ int mutation_log::garbage_collection(gpid gpid, // update max decree for the next log file auto &max_decrees = log->previous_log_max_decrees(); auto it3 = max_decrees.find(gpid); - CHECK(it3 != max_decrees.end(), "impossible for private logs"); + PGSCHECK(it3 != max_decrees.end(), "impossible for private logs"); max_decree = it3->second.max_decree; already_reserved_size += log->end_offset() - log->start_offset(); } diff --git a/src/replica/mutation_log_replay.cpp b/src/replica/mutation_log_replay.cpp index 0e7956c8d7..de309a434d 100644 --- a/src/replica/mutation_log_replay.cpp +++ b/src/replica/mutation_log_replay.cpp @@ -124,7 +124,7 @@ dsn::error_s read_block(dsn::replication::log_file_ptr &log, while (!reader->is_eof()) { auto old_size = reader->get_remaining_size(); mutation_ptr mu = mutation::read_from(*reader, nullptr); - CHECK_NOTNULL(mu, ""); + PGSCHECK_NOTNULL(mu, ""); mu->set_logged(); if (mu->data.header.log_offset != end_offset) { @@ -162,7 +162,8 @@ dsn::error_s read_block(dsn::replication::log_file_ptr &log, } } - CHECK(logs.find(log->index()) == logs.end(), "invalid log index, index = {}", log->index()); + PGSCHECK( + logs.find(log->index()) == logs.end(), "invalid log index, index = {}", log->index()); logs[log->index()] = log; } diff --git a/src/replica/prepare_list.cpp b/src/replica/prepare_list.cpp index d2fdff2334..7d9e18b492 100644 --- a/src/replica/prepare_list.cpp +++ b/src/replica/prepare_list.cpp @@ -139,7 +139,7 @@ error_code prepare_list::prepare(mutation_ptr &mu, return ERR_OK; default: - CHECK(false, "invalid partition_status, status = {}", enum_to_string(status)); + PGSCHECK(false, "invalid partition_status, status = {}", enum_to_string(status)); return ERR_OK; } } @@ -200,7 +200,7 @@ void prepare_list::commit(decree d, commit_type ct) return; } default: - CHECK(false, "invalid commit type {}", ct); + PGSCHECK(false, "invalid commit type {}", ct); } return; diff --git a/src/replica/replica.cpp b/src/replica/replica.cpp index f6d772169d..4482532d80 100644 --- a/src/replica/replica.cpp +++ b/src/replica/replica.cpp @@ -323,10 +323,10 @@ replica::replica(replica_stub *stub, { init_plog_gc_enabled(); - CHECK(!_app_info.app_type.empty(), ""); - CHECK_NOTNULL(stub, ""); + PGSCHECK(!_app_info.app_type.empty(), ""); + PGSCHECK_NOTNULL(stub, ""); _stub = stub; - CHECK_NOTNULL(dn, ""); + PGSCHECK_NOTNULL(dn, ""); _dir_node = dn; _dir = dn->replica_dir(_app_info.app_type, gpid); _options = &stub->options(); @@ -438,7 +438,7 @@ void replica::on_client_read(dsn::message_ex *request, bool ignore_throttling) METRIC_VAR_INCREMENT(backup_requests); } - CHECK(_app, ""); + PGSCHECK(_app, ""); auto storage_error = _app->on_request(request); // kNotFound is normal, it indicates that the key is not found (including expired) // in the storage engine, so just ignore it. @@ -516,7 +516,7 @@ void replica::execute_mutation(mutation_ptr &mu) // make sure private log saves the state // catch-up will be done later after checkpoint task is fininished - CHECK_NOTNULL(_private_log, ""); + PGSCHECK_NOTNULL(_private_log, ""); } break; case partition_status::PS_POTENTIAL_SECONDARY: @@ -534,7 +534,7 @@ void replica::execute_mutation(mutation_ptr &mu) // prepare also happens with learner_status::LearningWithPrepare, in this case // make sure private log saves the state, // catch-up will be done later after the checkpoint task is finished - CHECK_NOTNULL(_private_log, ""); + PGSCHECK_NOTNULL(_private_log, ""); } break; case partition_status::PS_PARTITION_SPLIT: @@ -546,7 +546,7 @@ void replica::execute_mutation(mutation_ptr &mu) case partition_status::PS_ERROR: break; default: - CHECK(false, "invalid partition_status, status = {}", enum_to_string(status())); + PGSCHECK(false, "invalid partition_status, status = {}", enum_to_string(status())); } LOG_DEBUG_PREFIX("TwoPhaseCommit, mutation {} committed, err = {}", mu->name(), err); @@ -622,13 +622,13 @@ void replica::close() _tracker.cancel_outstanding_tasks(); cleanup_preparing_mutations(true); - CHECK(_primary_states.is_cleaned(), "primary context is not cleared"); + PGSCHECK(_primary_states.is_cleaned(), "primary context is not cleared"); if (partition_status::PS_INACTIVE == status()) { - CHECK(_secondary_states.is_cleaned(), "secondary context is not cleared"); - CHECK(_potential_secondary_states.is_cleaned(), - "potential secondary context is not cleared"); - CHECK(_split_states.is_cleaned(), "partition split context is not cleared"); + PGSCHECK(_secondary_states.is_cleaned(), "secondary context is not cleared"); + PGSCHECK(_potential_secondary_states.is_cleaned(), + "potential secondary context is not cleared"); + PGSCHECK(_split_states.is_cleaned(), "partition split context is not cleared"); } // for partition_status::PS_ERROR, context cleanup is done here as they may block diff --git a/src/replica/replica_2pc.cpp b/src/replica/replica_2pc.cpp index 8f48438d1a..d350a150da 100644 --- a/src/replica/replica_2pc.cpp +++ b/src/replica/replica_2pc.cpp @@ -238,20 +238,21 @@ void replica::init_prepare(mutation_ptr &mu, bool reconciliation, bool pop_all_c const auto request_count = mu->client_requests.size(); mu->data.header.last_committed_decree = last_committed_decree(); - log_level_t level = LOG_LEVEL_DEBUG; + // log_level_t level = LOG_LEVEL_DEBUG; if (mu->data.header.decree == invalid_decree) { mu->set_id(get_ballot(), _prepare_list->max_decree() + 1); // print a debug log if necessary if (FLAGS_prepare_decree_gap_for_debug_logging > 0 && mu->get_decree() % FLAGS_prepare_decree_gap_for_debug_logging == 0) - level = LOG_LEVEL_INFO; - mu->set_timestamp(_uniq_timestamp_us.next()); + // level = LOG_LEVEL_INFO; + mu->set_timestamp(_uniq_timestamp_us.next()); } else { mu->set_id(get_ballot(), mu->data.header.decree); } mu->_tracer->set_name(fmt::format("mutation[{}]", mu->name())); - LOG(level, "{}: mutation {} init_prepare, mutation_tid={}", name(), mu->name(), mu->tid()); + // LOG(level, "{}: mutation {} init_prepare, mutation_tid={}", name(), mu->name(), + // mu->tid()); // child should prepare mutation synchronously mu->set_is_sync_to_child(_primary_states.sync_send_write_request); @@ -332,7 +333,7 @@ void replica::init_prepare(mutation_ptr &mu, bool reconciliation, bool pop_all_c do_possible_commit_on_primary(mu); } else { CHECK_EQ(mu->data.header.log_offset, invalid_offset); - CHECK(mu->log_task() == nullptr, ""); + PGSCHECK(mu->log_task() == nullptr, ""); int64_t pending_size; mu->log_task() = _private_log->append(mu, LPC_WRITE_REPLICATION_LOG, @@ -344,7 +345,7 @@ void replica::init_prepare(mutation_ptr &mu, bool reconciliation, bool pop_all_c std::placeholders::_2), get_gpid().thread_hash(), &pending_size); - CHECK_NOTNULL(mu->log_task(), ""); + PGSCHECK_NOTNULL(mu->log_task(), ""); } _primary_states.last_prepare_ts_ms = mu->prepare_ts_ms(); @@ -539,7 +540,7 @@ void replica::on_prepare(dsn::message_ex *request) _split_mgr->copy_mutation(mu); } - CHECK(mu->log_task() == nullptr, ""); + PGSCHECK(mu->log_task() == nullptr, ""); mu->log_task() = _private_log->append(mu, LPC_WRITE_REPLICATION_LOG, &_tracker, @@ -549,7 +550,7 @@ void replica::on_prepare(dsn::message_ex *request) std::placeholders::_1, std::placeholders::_2), get_gpid().thread_hash()); - CHECK_NOTNULL(mu->log_task(), ""); + PGSCHECK_NOTNULL(mu->log_task(), ""); } void replica::on_append_log_completed(mutation_ptr &mu, error_code err, size_t size) @@ -596,7 +597,7 @@ void replica::on_append_log_completed(mutation_ptr &mu, error_code err, size_t s case partition_status::PS_ERROR: break; default: - CHECK(false, "invalid partition_status, status = {}", enum_to_string(status())); + PGSCHECK(false, "invalid partition_status, status = {}", enum_to_string(status())); break; } } @@ -666,9 +667,9 @@ void replica::on_prepare_reply(std::pair p switch (target_status) { case partition_status::PS_SECONDARY: - CHECK(_primary_states.check_exist(node, partition_status::PS_SECONDARY), - "invalid secondary node address, address = {}", - node); + PGSCHECK(_primary_states.check_exist(node, partition_status::PS_SECONDARY), + "invalid secondary node address, address = {}", + node); CHECK_GT(mu->left_secondary_ack_count(), 0); if (0 == mu->decrease_left_secondary_ack_count()) { do_possible_commit_on_primary(mu); @@ -771,7 +772,7 @@ void replica::ack_prepare_message(error_code err, mutation_ptr &mu) resp.last_committed_decree_in_prepare_list = last_committed_decree(); const std::vector &prepare_requests = mu->prepare_requests(); - CHECK(!prepare_requests.empty(), "mutation = {}", mu->name()); + PGSCHECK(!prepare_requests.empty(), "mutation = {}", mu->name()); if (err == ERR_OK) { if (mu->is_child_acked()) { diff --git a/src/replica/replica_backup.cpp b/src/replica/replica_backup.cpp index 79ec2cd0a0..997cc58aec 100644 --- a/src/replica/replica_backup.cpp +++ b/src/replica/replica_backup.cpp @@ -108,7 +108,7 @@ void replica::on_cold_backup(const backup_request &request, /*out*/ backup_respo return; } auto r = _cold_backup_contexts.insert(std::make_pair(policy_name, new_context)); - CHECK(r.second, ""); + PGSCHECK(r.second, ""); backup_context = r.first->second; backup_context->block_service = block_service; backup_context->backup_root = request.__isset.backup_path @@ -361,11 +361,11 @@ static bool filter_checkpoint(const std::string &dir, if (ret == 1) { related_chkpt_dirs.emplace_back(std::move(dirname)); } else if (ret == 2) { - CHECK(valid_chkpt_dir.empty(), - "{}: there are two valid backup checkpoint dir, {} VS {}", - backup_context->name, - valid_chkpt_dir, - dirname); + PGSCHECK(valid_chkpt_dir.empty(), + "{}: there are two valid backup checkpoint dir, {} VS {}", + backup_context->name, + valid_chkpt_dir, + dirname); valid_chkpt_dir = dirname; } } @@ -465,11 +465,11 @@ void replica::generate_backup_checkpoint(cold_backup_context_ptr backup_context) // parse checkpoint dirname std::string policy_name; int64_t backup_id = 0, decree = 0, timestamp = 0; - CHECK(backup_parse_dir_name( - valid_backup_chkpt_dirname.c_str(), policy_name, backup_id, decree, timestamp), - "{}: valid chekpoint dirname {}", - backup_context->name, - valid_backup_chkpt_dirname); + PGSCHECK(backup_parse_dir_name( + valid_backup_chkpt_dirname.c_str(), policy_name, backup_id, decree, timestamp), + "{}: valid chekpoint dirname {}", + backup_context->name, + valid_backup_chkpt_dirname); if (statistic_file_infos_under_dir(valid_chkpt_full_path, file_infos, total_size)) { backup_context->checkpoint_decree = decree; diff --git a/src/replica/replica_base.h b/src/replica/replica_base.h index 79583c13f1..34ac0facc3 100644 --- a/src/replica/replica_base.h +++ b/src/replica/replica_base.h @@ -56,11 +56,11 @@ struct replica_base const metric_entity_ptr &replica_metric_entity() const { - CHECK_NOTNULL(_replica_metric_entity, - "replica metric entity (table_id={}, partition_id={}) should has been " - "instantiated: uninitialized entity cannot be used to instantiate metric", - _gpid.get_app_id(), - _gpid.get_partition_index()); + PGSCHECK_NOTNULL(_replica_metric_entity, + "replica metric entity (table_id={}, partition_id={}) should has been " + "instantiated: uninitialized entity cannot be used to instantiate metric", + _gpid.get_app_id(), + _gpid.get_partition_index()); return _replica_metric_entity; } diff --git a/src/replica/replica_check.cpp b/src/replica/replica_check.cpp index 32cf5f70fa..c32830903f 100644 --- a/src/replica/replica_check.cpp +++ b/src/replica/replica_check.cpp @@ -91,7 +91,7 @@ void replica::init_group_check() if (partition_status::PS_PRIMARY != status() || FLAGS_group_check_disabled) return; - CHECK(nullptr == _primary_states.group_check_task, ""); + PGSCHECK(nullptr == _primary_states.group_check_task, ""); _primary_states.group_check_task = tasking::enqueue_timer( LPC_GROUP_CHECK, &_tracker, @@ -104,7 +104,7 @@ void replica::broadcast_group_check() { FAIL_POINT_INJECT_F("replica_broadcast_group_check", [](std::string_view) {}); - CHECK_NOTNULL(_primary_states.group_check_task, ""); + PGSCHECK_NOTNULL(_primary_states.group_check_task, ""); LOG_INFO_PREFIX("start to broadcast group check"); @@ -146,7 +146,7 @@ void replica::broadcast_group_check() if (request->config.status == partition_status::PS_POTENTIAL_SECONDARY) { auto it = _primary_states.learners.find(hp); - CHECK(it != _primary_states.learners.end(), "learner {} is missing", hp); + PGSCHECK(it != _primary_states.learners.end(), "learner {} is missing", hp); request->config.learner_signature = it->second.signature; } @@ -222,7 +222,7 @@ void replica::on_group_check(const group_check_request &request, case partition_status::PS_ERROR: break; default: - CHECK(false, "invalid partition_status, status = {}", enum_to_string(status())); + PGSCHECK(false, "invalid partition_status, status = {}", enum_to_string(status())); } response.pid = get_gpid(); diff --git a/src/replica/replica_chkpt.cpp b/src/replica/replica_chkpt.cpp index 368d1a4ab0..fecfd1af7f 100644 --- a/src/replica/replica_chkpt.cpp +++ b/src/replica/replica_chkpt.cpp @@ -495,7 +495,7 @@ void replica::on_checkpoint_completed(error_code err) if (_app->last_committed_decree() > _prepare_list->min_decree()) { for (auto d = _app->last_committed_decree() + 1; d <= c; d++) { auto mu = _prepare_list->get_mutation_by_decree(d); - CHECK_NOTNULL(mu, "invalid mutation, decree = {}", d); + PGSCHECK_NOTNULL(mu, "invalid mutation, decree = {}", d); err = _app->apply_mutation(mu); if (ERR_OK != err) { _secondary_states.checkpoint_is_running = false; diff --git a/src/replica/replica_config.cpp b/src/replica/replica_config.cpp index 3bcd5faaff..31d41afdc1 100644 --- a/src/replica/replica_config.cpp +++ b/src/replica/replica_config.cpp @@ -145,7 +145,7 @@ void replica::on_config_proposal(configuration_update_request &proposal) remove(proposal); break; default: - CHECK(false, "invalid config_type, type = {}", enum_to_string(proposal.type)); + PGSCHECK(false, "invalid config_type, type = {}", enum_to_string(proposal.type)); } } @@ -192,12 +192,12 @@ void replica::add_potential_secondary(const configuration_update_request &propos CHECK_EQ(proposal.config.ballot, get_ballot()); CHECK_EQ(proposal.config.pid, _primary_states.pc.pid); CHECK_EQ(proposal.config.hp_primary, _primary_states.pc.hp_primary); - CHECK(proposal.config.hp_secondaries == _primary_states.pc.hp_secondaries, ""); + PGSCHECK(proposal.config.hp_secondaries == _primary_states.pc.hp_secondaries, ""); host_port node; GET_HOST_PORT(proposal, node, node); - CHECK(!_primary_states.check_exist(node, partition_status::PS_PRIMARY), "node = {}", node); - CHECK(!_primary_states.check_exist(node, partition_status::PS_SECONDARY), "node = {}", node); + PGSCHECK(!_primary_states.check_exist(node, partition_status::PS_PRIMARY), "node = {}", node); + PGSCHECK(!_primary_states.check_exist(node, partition_status::PS_SECONDARY), "node = {}", node); int potential_secondaries_count = _primary_states.pc.hp_secondaries.size() + _primary_states.learners.size(); @@ -218,7 +218,7 @@ void replica::add_potential_secondary(const configuration_update_request &propos LOG_INFO_PREFIX("add a new secondary({}) for future load balancer", node); } } else { - CHECK(false, "invalid config_type, type = {}", enum_to_string(proposal.type)); + PGSCHECK(false, "invalid config_type, type = {}", enum_to_string(proposal.type)); } } @@ -272,7 +272,7 @@ void replica::downgrade_to_secondary_on_primary(configuration_update_request &pr CHECK_EQ(proposal.config.pid, _primary_states.pc.pid); CHECK_EQ(proposal.config.hp_primary, _primary_states.pc.hp_primary); - CHECK(proposal.config.hp_secondaries == _primary_states.pc.hp_secondaries, ""); + PGSCHECK(proposal.config.hp_secondaries == _primary_states.pc.hp_secondaries, ""); CHECK_EQ(proposal.hp_node, proposal.config.hp_primary); CHECK_EQ(proposal.node, proposal.config.primary); @@ -289,7 +289,7 @@ void replica::downgrade_to_inactive_on_primary(configuration_update_request &pro CHECK_EQ(proposal.config.pid, _primary_states.pc.pid); CHECK_EQ(proposal.config.hp_primary, _primary_states.pc.hp_primary); - CHECK(proposal.config.hp_secondaries == _primary_states.pc.hp_secondaries, ""); + PGSCHECK(proposal.config.hp_secondaries == _primary_states.pc.hp_secondaries, ""); host_port node; GET_HOST_PORT(proposal, node, node); @@ -298,12 +298,12 @@ void replica::downgrade_to_inactive_on_primary(configuration_update_request &pro RESET_IP_AND_HOST_PORT(proposal.config, primary); } else { CHECK_NE(proposal.node, proposal.config.primary); - CHECK(replica_helper::remove_node(proposal.node, proposal.config.secondaries), - "remove node failed, node = {}", - proposal.node); - CHECK(replica_helper::remove_node(node, proposal.config.hp_secondaries), - "remove node failed, node = {}", - node); + PGSCHECK(replica_helper::remove_node(proposal.node, proposal.config.secondaries), + "remove node failed, node = {}", + proposal.node); + PGSCHECK(replica_helper::remove_node(node, proposal.config.hp_secondaries), + "remove node failed, node = {}", + node); } update_configuration_on_meta_server( @@ -317,7 +317,7 @@ void replica::remove(configuration_update_request &proposal) CHECK_EQ(proposal.config.pid, _primary_states.pc.pid); CHECK_EQ(proposal.config.hp_primary, _primary_states.pc.hp_primary); - CHECK(proposal.config.hp_secondaries == _primary_states.pc.hp_secondaries, ""); + PGSCHECK(proposal.config.hp_secondaries == _primary_states.pc.hp_secondaries, ""); host_port node; GET_HOST_PORT(proposal, node, node); @@ -330,12 +330,12 @@ void replica::remove(configuration_update_request &proposal) RESET_IP_AND_HOST_PORT(proposal.config, primary); break; case partition_status::PS_SECONDARY: { - CHECK(replica_helper::remove_node(proposal.node, proposal.config.secondaries), - "remove node failed, node = {}", - proposal.node); - CHECK(replica_helper::remove_node(node, proposal.config.hp_secondaries), - "remove_node failed, node = {}", - node); + PGSCHECK(replica_helper::remove_node(proposal.node, proposal.config.secondaries), + "remove node failed, node = {}", + proposal.node); + PGSCHECK(replica_helper::remove_node(node, proposal.config.hp_secondaries), + "remove_node failed, node = {}", + node); } break; case partition_status::PS_POTENTIAL_SECONDARY: break; @@ -386,9 +386,9 @@ void replica::update_configuration_on_meta_server(config_type::type type, new_pc.last_committed_decree = last_committed_decree(); if (type == config_type::CT_PRIMARY_FORCE_UPDATE_BALLOT) { - CHECK(status() == partition_status::PS_INACTIVE && _inactive_is_transient && - _is_initializing, - ""); + PGSCHECK(status() == partition_status::PS_INACTIVE && _inactive_is_transient && + _is_initializing, + ""); CHECK_EQ(new_pc.hp_primary, node); } else if (type != config_type::CT_ASSIGN_PRIMARY && type != config_type::CT_UPGRADE_TO_PRIMARY) { @@ -504,7 +504,7 @@ void replica::on_update_configuration_on_meta_server_reply( if (resp.err == ERR_OK) { CHECK_EQ(req->config.pid, resp.config.pid); CHECK_EQ(req->config.hp_primary, resp.config.hp_primary); - CHECK(req->config.hp_secondaries == resp.config.hp_secondaries, ""); + PGSCHECK(req->config.hp_secondaries == resp.config.hp_secondaries, ""); switch (req->type) { case config_type::CT_UPGRADE_TO_PRIMARY: @@ -532,11 +532,11 @@ void replica::on_update_configuration_on_meta_server_reply( break; } case config_type::CT_PRIMARY_FORCE_UPDATE_BALLOT: - CHECK(_is_initializing, ""); + PGSCHECK(_is_initializing, ""); _is_initializing = false; break; default: - CHECK(false, "invalid config_type, type = {}", enum_to_string(req->type)); + PGSCHECK(false, "invalid config_type, type = {}", enum_to_string(req->type)); } } @@ -702,10 +702,10 @@ bool replica::update_local_configuration(const replica_configuration &config, return true; }); - CHECK(config.ballot > get_ballot() || (same_ballot && config.ballot == get_ballot()), - "invalid ballot, {} VS {}", - config.ballot, - get_ballot()); + PGSCHECK(config.ballot > get_ballot() || (same_ballot && config.ballot == get_ballot()), + "invalid ballot, {} VS {}", + config.ballot, + get_ballot()); CHECK_EQ(config.pid, get_gpid()); partition_status::type old_status = status(); @@ -856,10 +856,10 @@ bool replica::update_local_configuration(const replica_configuration &config, clear_cold_backup_state(); break; case partition_status::PS_POTENTIAL_SECONDARY: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); break; default: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); } break; case partition_status::PS_SECONDARY: @@ -892,13 +892,13 @@ bool replica::update_local_configuration(const replica_configuration &config, // _secondary_states.cleanup(true); => do it in close as it may block break; default: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); } break; case partition_status::PS_POTENTIAL_SECONDARY: switch (config.status) { case partition_status::PS_PRIMARY: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); break; case partition_status::PS_SECONDARY: _prepare_list->truncate(_app->last_committed_decree()); @@ -921,7 +921,7 @@ bool replica::update_local_configuration(const replica_configuration &config, // "potential secondary context cleanup failed"); break; default: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); } break; case partition_status::PS_PARTITION_SPLIT: @@ -935,7 +935,7 @@ bool replica::update_local_configuration(const replica_configuration &config, _split_states.cleanup(true); break; case partition_status::PS_POTENTIAL_SECONDARY: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); break; case partition_status::PS_INACTIVE: break; @@ -943,7 +943,7 @@ bool replica::update_local_configuration(const replica_configuration &config, _split_states.cleanup(false); break; default: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); } break; case partition_status::PS_INACTIVE: @@ -954,13 +954,13 @@ bool replica::update_local_configuration(const replica_configuration &config, } switch (config.status) { case partition_status::PS_PRIMARY: - CHECK(_inactive_is_transient, "must be in transient state for being primary next"); + PGSCHECK(_inactive_is_transient, "must be in transient state for being primary next"); _inactive_is_transient = false; init_group_check(); replay_prepare_list(); break; case partition_status::PS_SECONDARY: - CHECK(_inactive_is_transient, "must be in transient state for being secondary next"); + PGSCHECK(_inactive_is_transient, "must be in transient state for being secondary next"); _inactive_is_transient = false; break; case partition_status::PS_POTENTIAL_SECONDARY: @@ -982,31 +982,31 @@ bool replica::update_local_configuration(const replica_configuration &config, _inactive_is_transient = false; break; default: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); } break; case partition_status::PS_ERROR: switch (config.status) { case partition_status::PS_PRIMARY: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); break; case partition_status::PS_SECONDARY: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); break; case partition_status::PS_POTENTIAL_SECONDARY: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); break; case partition_status::PS_INACTIVE: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); break; case partition_status::PS_ERROR: break; default: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); } break; default: - CHECK(false, "invalid execution path"); + PGSCHECK(false, "invalid execution path"); } LOG_INFO_PREFIX( @@ -1045,7 +1045,7 @@ bool replica::update_local_configuration(const replica_configuration &config, init_prepare(next, false); } - CHECK(_primary_states.pc.__isset.hp_secondaries, ""); + PGSCHECK(_primary_states.pc.__isset.hp_secondaries, ""); if (_primary_states.pc.hp_secondaries.size() + 1 < _options->app_mutation_2pc_min_replica_count(_app_info.max_replica_count)) { std::vector queued; diff --git a/src/replica/replica_context.cpp b/src/replica/replica_context.cpp index 1d483d7015..6c8ea22295 100644 --- a/src/replica/replica_context.cpp +++ b/src/replica/replica_context.cpp @@ -141,7 +141,7 @@ bool primary_context::check_exist(const ::dsn::host_port &node, partition_status case partition_status::PS_POTENTIAL_SECONDARY: return learners.find(node) != learners.end(); default: - CHECK(false, "invalid partition_status, status = {}", enum_to_string(st)); + PGSCHECK(false, "invalid partition_status, status = {}", enum_to_string(st)); return false; } } diff --git a/src/replica/replica_context.h b/src/replica/replica_context.h index 8fba146646..7806c88c9e 100644 --- a/src/replica/replica_context.h +++ b/src/replica/replica_context.h @@ -79,8 +79,8 @@ typedef std::unordered_map<::dsn::host_port, remote_learner_state> learner_map; if (t != nullptr) { \ bool finished; \ t->cancel(false, &finished); \ - CHECK(finished || dsn_task_is_running_inside(task_.get()), \ - "task must be finished at this point"); \ + PGSCHECK(finished || dsn_task_is_running_inside(task_.get()), \ + "task must be finished at this point"); \ task_ = nullptr; \ } \ } diff --git a/src/replica/replica_failover.cpp b/src/replica/replica_failover.cpp index e563336f46..d7e2e1fe5c 100644 --- a/src/replica/replica_failover.cpp +++ b/src/replica/replica_failover.cpp @@ -80,10 +80,10 @@ void replica::handle_remote_failure(partition_status::type st, switch (st) { case partition_status::PS_SECONDARY: - CHECK(_primary_states.check_exist(node, partition_status::PS_SECONDARY), - "invalid node address, address = {}, status = {}", - node, - enum_to_string(st)); + PGSCHECK(_primary_states.check_exist(node, partition_status::PS_SECONDARY), + "invalid node address, address = {}, status = {}", + node, + enum_to_string(st)); { configuration_update_request request; SET_IP_AND_HOST_PORT_BY_DNS(request, node, node); @@ -103,7 +103,7 @@ void replica::handle_remote_failure(partition_status::type st, case partition_status::PS_ERROR: break; default: - CHECK(false, "invalid partition_status, status = {}", enum_to_string(st)); + PGSCHECK(false, "invalid partition_status, status = {}", enum_to_string(st)); break; } } diff --git a/src/replica/replica_http_service.h b/src/replica/replica_http_service.h index 84f652d815..92d73ce40a 100644 --- a/src/replica/replica_http_service.h +++ b/src/replica/replica_http_service.h @@ -80,7 +80,7 @@ class replica_http_service : public http_server_base case manual_compaction_status::FINISHED: return "finished"; default: - CHECK(false, "invalid status({})", status); + PGSCHECK(false, "invalid status({})", status); __builtin_unreachable(); } } diff --git a/src/replica/replica_init.cpp b/src/replica/replica_init.cpp index 664587f636..4139920c69 100644 --- a/src/replica/replica_init.cpp +++ b/src/replica/replica_init.cpp @@ -114,12 +114,12 @@ decree replica::get_replay_start_decree() error_code replica::init_app_and_prepare_list(bool create_new) { - CHECK(nullptr == _app, ""); + PGSCHECK(nullptr == _app, ""); error_code err; std::string log_dir = utils::filesystem::path_combine(dir(), "plog"); _app.reset(replication_app_base::new_storage_instance(_app_info.app_type, this)); - CHECK(nullptr == _private_log, ""); + PGSCHECK(nullptr == _private_log, ""); if (create_new) { err = _app->open_new_internal(this, /* private_log_start */ 0); @@ -216,12 +216,12 @@ error_code replica::init_app_and_prepare_list(bool create_new) if (nullptr == _private_log) { LOG_INFO_PREFIX("clear private log, dir = {}", log_dir); - CHECK(dsn::utils::filesystem::remove_path(log_dir), - "Fail to delete directory {}", - log_dir); - CHECK(dsn::utils::filesystem::create_directory(log_dir), - "Fail to create directory {}", - log_dir); + PGSCHECK(dsn::utils::filesystem::remove_path(log_dir), + "Fail to delete directory {}", + log_dir); + PGSCHECK(dsn::utils::filesystem::create_directory(log_dir), + "Fail to create directory {}", + log_dir); _private_log = new mutation_log_private(log_dir, FLAGS_log_private_file_size_mb, get_gpid(), this); @@ -264,7 +264,7 @@ bool replica::replay_mutation(mutation_ptr &mu, bool is_private) // for example, the recovery need it to select a proper primary if (mu->data.header.ballot > get_ballot()) { _config.ballot = mu->data.header.ballot; - CHECK(update_local_configuration(_config, true), ""); + PGSCHECK(update_local_configuration(_config, true), ""); } if (is_private && offset < _app->init_info().init_offset_in_private_log) { diff --git a/src/replica/replica_learn.cpp b/src/replica/replica_learn.cpp index b1c30692e5..b98a0b048f 100644 --- a/src/replica/replica_learn.cpp +++ b/src/replica/replica_learn.cpp @@ -160,7 +160,7 @@ void replica::init_learn(uint64_t signature) if (_prepare_list->count() > 0 && ac + 1 >= _prepare_list->min_decree()) { for (auto d = ac + 1; d <= pc; d++) { auto mu = _prepare_list->get_mutation_by_decree(d); - CHECK_NOTNULL(mu, "mutation must not be nullptr, decree = {}", d); + PGSCHECK_NOTNULL(mu, "mutation must not be nullptr, decree = {}", d); auto err = _app->apply_mutation(mu); if (ERR_OK != err) { handle_learning_error(err, true); @@ -206,9 +206,9 @@ void replica::init_learn(uint64_t signature) case learner_status::LearningWithoutPrepare: break; default: - CHECK(false, - "invalid learner_status, status = {}", - enum_to_string(_potential_secondary_states.learning_status)); + PGSCHECK(false, + "invalid learner_status, status = {}", + enum_to_string(_potential_secondary_states.learning_status)); } } @@ -628,7 +628,7 @@ void replica::on_learn_reply(error_code err, learn_request &&req, learn_response "ballot have changed", req.signature, FMT_HOST_PORT_AND_IP(resp.config, primary)); - CHECK(update_local_configuration(resp.config), ""); + PGSCHECK(update_local_configuration(resp.config), ""); } if (status() != partition_status::PS_POTENTIAL_SECONDARY) { @@ -668,11 +668,11 @@ void replica::on_learn_reply(error_code err, learn_request &&req, learn_response if (dsn::utils::filesystem::directory_exists(old_dir)) { char rename_dir[1024]; sprintf(rename_dir, "%s.%" PRIu64 ".discarded", old_dir.c_str(), dsn_now_us()); - CHECK(dsn::utils::filesystem::rename_path(old_dir, rename_dir), - "{}: failed to move directory from '{}' to '{}'", - name(), - old_dir, - rename_dir); + PGSCHECK(dsn::utils::filesystem::rename_path(old_dir, rename_dir), + "{}: failed to move directory from '{}' to '{}'", + name(), + old_dir, + rename_dir); LOG_WARNING_PREFIX("replica_dir_op succeed to move directory from '{}' to '{}'", old_dir, rename_dir); @@ -755,7 +755,7 @@ void replica::on_learn_reply(error_code err, learn_request &&req, learn_response if (resp.prepare_start_decree != invalid_decree) { CHECK_EQ(resp.type, learn_type::LT_CACHE); - CHECK(resp.state.files.empty(), ""); + PGSCHECK(resp.state.files.empty(), ""); CHECK_EQ(_potential_secondary_states.learning_status, learner_status::LearningWithoutPrepare); _potential_secondary_states.learning_status = learner_status::LearningWithPrepareTransient; @@ -841,7 +841,7 @@ void replica::on_learn_reply(error_code err, learn_request &&req, learn_response // thinks they should _prepare_list->commit(resp.prepare_start_decree - 1, COMMIT_TO_DECREE_HARD); CHECK_EQ(_prepare_list->last_committed_decree(), _app->last_committed_decree()); - CHECK(resp.state.files.empty(), ""); + PGSCHECK(resp.state.files.empty(), ""); // all state is complete CHECK_GE_MSG(_app->last_committed_decree() + 1, @@ -978,7 +978,7 @@ bool replica::prepare_cached_learn_state(const learn_request &request, int count = 0; for (decree d = learn_start_decree; d < response.prepare_start_decree; d++) { auto mu = _prepare_list->get_mutation_by_decree(d); - CHECK_NOTNULL(mu, "mutation must not be nullptr, decree = {}", d); + PGSCHECK_NOTNULL(mu, "mutation must not be nullptr, decree = {}", d); mu->write_to(writer, nullptr); count++; } @@ -1049,9 +1049,9 @@ void replica::on_copy_remote_state_completed(error_code err, } else if (_potential_secondary_states.learning_status == learner_status::LearningWithPrepare) { CHECK_EQ(resp.type, learn_type::LT_CACHE); } else { - CHECK(resp.type == learn_type::LT_APP || resp.type == learn_type::LT_LOG, - "invalid learn_type, type = {}", - enum_to_string(resp.type)); + PGSCHECK(resp.type == learn_type::LT_APP || resp.type == learn_type::LT_LOG, + "invalid learn_type, type = {}", + enum_to_string(resp.type)); learn_state lstate; lstate.from_decree_excluded = resp.state.from_decree_excluded; diff --git a/src/replica/replica_stub.cpp b/src/replica/replica_stub.cpp index ebab553809..bc07bd79fa 100644 --- a/src/replica/replica_stub.cpp +++ b/src/replica/replica_stub.cpp @@ -428,11 +428,11 @@ void replica_stub::initialize(const replication_options &opts, bool clear /* = f // clear dirs if need if (clear) { - CHECK(dsn::utils::filesystem::remove_path(_options.slog_dir), - "Fail to remove {}.", - _options.slog_dir); + PGSCHECK(dsn::utils::filesystem::remove_path(_options.slog_dir), + "Fail to remove {}.", + _options.slog_dir); for (auto &dir : _options.data_dirs) { - CHECK(dsn::utils::filesystem::remove_path(dir), "Fail to remove {}.", dir); + PGSCHECK(dsn::utils::filesystem::remove_path(dir), "Fail to remove {}.", dir); } } @@ -486,11 +486,11 @@ void replica_stub::initialize(const replication_options &opts, bool clear /* = f auto full_slog_path = fmt::format("{}/replica/slog/", _options.slog_dir); if (utils::filesystem::directory_exists(full_slog_path)) { std::vector slog_files; - CHECK(utils::filesystem::get_subfiles(full_slog_path, slog_files, false), - "check slog files failed"); - CHECK(slog_files.empty(), - "slog({}) files are not empty. Make sure you are upgrading from 2.5.0", - full_slog_path); + PGSCHECK(utils::filesystem::get_subfiles(full_slog_path, slog_files, false), + "check slog files failed"); + PGSCHECK(slog_files.empty(), + "slog({}) files are not empty. Make sure you are upgrading from 2.5.0", + full_slog_path); } // Start to load replicas in available data directories. @@ -502,9 +502,9 @@ void replica_stub::initialize(const replication_options &opts, bool clear /* = f continue; } std::vector sub_directories; - CHECK(dsn::utils::filesystem::get_subdirectories(dn->full_dir, sub_directories, false), - "fail to get sub_directories in {}", - dn->full_dir); + PGSCHECK(dsn::utils::filesystem::get_subdirectories(dn->full_dir, sub_directories, false), + "fail to get sub_directories in {}", + dn->full_dir); dirs_by_dn.emplace(dn.get(), sub_directories); } @@ -540,10 +540,10 @@ void replica_stub::initialize(const replication_options &opts, bool clear /* = f r->last_prepared_decree()); utils::auto_lock l(rps_lock); - CHECK(rps.find(r->get_gpid()) == rps.end(), - "conflict replica dir: {} <--> {}", - r->dir(), - rps[r->get_gpid()]->dir()); + PGSCHECK(rps.find(r->get_gpid()) == rps.end(), + "conflict replica dir: {} <--> {}", + r->dir(), + rps[r->get_gpid()]->dir()); rps[r->get_gpid()] = r; }, @@ -1580,7 +1580,7 @@ void replica_stub::on_gc_replica(replica_stub_ptr this_, gpid id) } const auto replica_path = dn->replica_dir(closed_info.first.app_type, id); - CHECK( + PGSCHECK( dsn::utils::filesystem::directory_exists(replica_path), "dir({}) not exist", replica_path); LOG_INFO("start to move replica({}) as garbage, path: {}", id, replica_path); const auto rename_path = fmt::format("{}.{}{}", replica_path, dsn_now_us(), kFolderSuffixGar); @@ -1774,7 +1774,7 @@ void replica_stub::open_replica( auto dn = _fs_manager.find_replica_dir(app.app_type, id); if (dn != nullptr) { dir = dn->replica_dir(app.app_type, id); - CHECK(dsn::utils::filesystem::directory_exists(dir), "dir({}) not exist", dir); + PGSCHECK(dsn::utils::filesystem::directory_exists(dir), "dir({}) not exist", dir); // NOTICE: if partition is DDD, and meta select one replica as primary, it will execute the // load-process because of a.b.pegasus is exist, so it will never execute the restore // process below @@ -1793,9 +1793,9 @@ void replica_stub::open_replica( const auto origin_dn = _fs_manager.find_replica_dir(origin_dir_type, id); if (origin_dn != nullptr) { const auto origin_tmp_dir = origin_dn->replica_dir(origin_dir_type, id); - CHECK(dsn::utils::filesystem::directory_exists(origin_tmp_dir), - "dir({}) not exist", - origin_tmp_dir); + PGSCHECK(dsn::utils::filesystem::directory_exists(origin_tmp_dir), + "dir({}) not exist", + origin_tmp_dir); LOG_INFO("mark the dir {} as garbage, start revert and load disk migration origin " "replica data({})", dir, @@ -1819,16 +1819,16 @@ void replica_stub::open_replica( // NOTICE: if dir a.b.pegasus does not exist, or .app-info does not exist, but the ballot > // 0, or the last_committed_decree > 0, start replica will fail if ((configuration_update != nullptr) && (configuration_update->info.is_stateful)) { - CHECK(configuration_update->config.ballot == 0 && - configuration_update->config.last_committed_decree == 0, - "{}@{}: cannot load replica({}.{}), ballot = {}, " - "last_committed_decree = {}, but it does not existed!", - id, - _primary_host_port_cache, - id, - app.app_type.c_str(), - configuration_update->config.ballot, - configuration_update->config.last_committed_decree); + PGSCHECK(configuration_update->config.ballot == 0 && + configuration_update->config.last_committed_decree == 0, + "{}@{}: cannot load replica({}.{}), ballot = {}, " + "last_committed_decree = {}, but it does not existed!", + id, + _primary_host_port_cache, + id, + app.app_type.c_str(), + configuration_update->config.ballot, + configuration_update->config.last_committed_decree); } // NOTICE: only new_replica_group's assign_primary will execute this; if server restart when @@ -1854,9 +1854,9 @@ void replica_stub::open_replica( // replica(if contain valid data, it will execute load-process) if (!restore_if_necessary && ::dsn::utils::filesystem::directory_exists(dir)) { - CHECK(::dsn::utils::filesystem::remove_path(dir), - "remove useless directory({}) failed", - dir); + PGSCHECK(::dsn::utils::filesystem::remove_path(dir), + "remove useless directory({}) failed", + dir); } rep = new_replica(id, app, restore_if_necessary, is_duplication_follower); } @@ -1876,7 +1876,7 @@ void replica_stub::open_replica( CHECK_GT_MSG(_opening_replicas.erase(id), 0, "replica {} is not in _opening_replicas", id); METRIC_VAR_DECREMENT(opening_replicas); - CHECK(_replicas.find(id) == _replicas.end(), "replica {} is already in _replicas", id); + PGSCHECK(_replicas.find(id) == _replicas.end(), "replica {} is already in _replicas", id); _replicas.insert(replicas::value_type(rep->get_gpid(), rep)); METRIC_VAR_INCREMENT(total_replicas); @@ -1913,7 +1913,7 @@ replica *replica_stub::new_replica(gpid gpid, return nullptr; } const auto &dir = dn->replica_dir(app.app_type, gpid); - CHECK(dsn::utils::filesystem::directory_exists(dir), "dir({}) not exist", dir); + PGSCHECK(dsn::utils::filesystem::directory_exists(dir), "dir({}) not exist", dir); auto *rep = new replica(this, gpid, app, dn, restore_if_necessary, is_duplication_follower); error_code err; if (restore_if_necessary && (err = rep->restore_checkpoint()) != dsn::ERR_OK) { @@ -2049,14 +2049,14 @@ void replica_stub::clear_on_failure(replica *rep) task_ptr replica_stub::begin_close_replica(replica_ptr r) { - CHECK(r->status() == partition_status::PS_ERROR || - r->status() == partition_status::PS_INACTIVE || - r->disk_migrator()->status() >= disk_migration_status::MOVED, - "invalid state(partition_status={}, migration_status={}) when calling " - "replica({}) close", - enum_to_string(r->status()), - enum_to_string(r->disk_migrator()->status()), - r->name()); + PGSCHECK(r->status() == partition_status::PS_ERROR || + r->status() == partition_status::PS_INACTIVE || + r->disk_migrator()->status() >= disk_migration_status::MOVED, + "invalid state(partition_status={}, migration_status={}) when calling " + "replica({}) close", + enum_to_string(r->status()), + enum_to_string(r->disk_migrator()->status()), + r->name()); gpid id = r->get_gpid(); @@ -2101,7 +2101,7 @@ void replica_stub::close_replica(replica_ptr r) { zauto_write_lock l(_replicas_lock); auto find = _closing_replicas.find(id); - CHECK(find != _closing_replicas.end(), "replica {} is not in _closing_replicas", name); + PGSCHECK(find != _closing_replicas.end(), "replica {} is not in _closing_replicas", name); _closed_replicas.emplace( id, std::make_pair(std::get<2>(find->second), std::get<3>(find->second))); _closing_replicas.erase(find); @@ -2139,7 +2139,7 @@ void replica_stub::trigger_checkpoint(replica_ptr r, bool is_emergency) void replica_stub::handle_log_failure(error_code err) { LOG_ERROR("handle log failure: {}", err); - CHECK(s_not_exit_on_log_failure, ""); + PGSCHECK(s_not_exit_on_log_failure, ""); } void replica_stub::open_service() @@ -2674,7 +2674,7 @@ replica_ptr replica_stub::create_child_replica_if_not_found(gpid child_pid, "replica_stub_create_child_replica_if_not_found", [=](std::string_view) -> replica_ptr { const auto dn = _fs_manager.create_child_replica_dir(app->app_type, child_pid, parent_dir); - CHECK_NOTNULL(dn, ""); + PGSCHECK_NOTNULL(dn, ""); auto *rep = new replica(this, child_pid, *app, dn, false); rep->_config.status = partition_status::PS_INACTIVE; _replicas.insert(replicas::value_type(child_pid, rep)); @@ -2697,7 +2697,7 @@ replica_ptr replica_stub::create_child_replica_if_not_found(gpid child_pid, replica *rep = new_replica(child_pid, *app, false, false, parent_dir); if (rep != nullptr) { auto pr = _replicas.insert(replicas::value_type(child_pid, rep)); - CHECK(pr.second, "child replica {} has been existed", rep->name()); + PGSCHECK(pr.second, "child replica {} has been existed", rep->name()); METRIC_VAR_INCREMENT(total_replicas); _closed_replicas.erase(child_pid); } diff --git a/src/replica/replication_app_base.cpp b/src/replica/replication_app_base.cpp index e15df7829d..937f058c29 100644 --- a/src/replica/replication_app_base.cpp +++ b/src/replica/replication_app_base.cpp @@ -196,8 +196,9 @@ error_code replication_app_base::open_internal(replica *r) error_code replication_app_base::open_new_internal(replica *r, int64_t private_log_start) { - CHECK(utils::filesystem::remove_path(_dir_data), "remove data dir {} failed", _dir_data); - CHECK(utils::filesystem::create_directory(_dir_data), "create data dir {} failed", _dir_data); + PGSCHECK(utils::filesystem::remove_path(_dir_data), "remove data dir {} failed", _dir_data); + PGSCHECK( + utils::filesystem::create_directory(_dir_data), "create data dir {} failed", _dir_data); LOG_AND_RETURN_NOT_TRUE(ERROR_PREFIX, utils::filesystem::directory_exists(_dir_data), ERR_FILE_OPERATION_FAILED, @@ -222,7 +223,7 @@ error_code replication_app_base::open() std::unique_ptr argvs = std::make_unique(argc); char **argv = argvs.get(); - CHECK_NOTNULL(argv, ""); + PGSCHECK_NOTNULL(argv, ""); int idx = 0; argv[idx++] = (char *)(info->app_name.c_str()); if (argc > 1) { diff --git a/src/replica/split/replica_split_manager.cpp b/src/replica/split/replica_split_manager.cpp index 371d92f092..962f50d1d9 100644 --- a/src/replica/split/replica_split_manager.cpp +++ b/src/replica/split/replica_split_manager.cpp @@ -574,7 +574,7 @@ void replica_split_manager::child_catch_up_states() // on child partition _replica->_prepare_list->min_decree()); for (decree d = local_decree + 1; d <= goal_decree; ++d) { auto mu = _replica->_prepare_list->get_mutation_by_decree(d); - CHECK_NOTNULL(mu, ""); + PGSCHECK_NOTNULL(mu, ""); error_code ec = _replica->_app->apply_mutation(mu); if (ec != ERR_OK) { child_handle_split_error("child_catchup failed because apply mutation failed"); @@ -822,7 +822,7 @@ void replica_split_manager::parent_send_update_partition_count_request( 0_ms, 0, get_gpid().thread_hash()); - DCHECK(request->hp_target, ""); + DCHECK(request->hp_target); DCHECK_EQ(request->target, dsn::dns_resolver::instance().resolve_address(request->hp_target)); rpc.call(request->target, tracker(), [this, rpc, not_replied_addresses](error_code ec) mutable { on_update_child_group_partition_count_reply( @@ -919,7 +919,7 @@ void replica_split_manager::on_update_child_group_partition_count_reply( "failed to update child node({}) partition_count, error = {}, wait and retry", FMT_HOST_PORT_AND_IP(request, target), error); - DCHECK(request.hp_target, ""); + DCHECK(request.hp_target); DCHECK_EQ(request.target, dsn::dns_resolver::instance().resolve_address(request.hp_target)); tasking::enqueue( LPC_PARTITION_SPLIT, diff --git a/src/replica/split/test/CMakeLists.txt b/src/replica/split/test/CMakeLists.txt index 6bacdf05c5..cc5b5806fa 100644 --- a/src/replica/split/test/CMakeLists.txt +++ b/src/replica/split/test/CMakeLists.txt @@ -25,7 +25,9 @@ set(MY_PROJ_LIBS dsn_replication_common dsn_runtime hashtable - gtest) + gtest + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES config-test.ini diff --git a/src/replica/storage/simple_kv/CMakeLists.txt b/src/replica/storage/simple_kv/CMakeLists.txt index f8595297e2..6da0757c91 100644 --- a/src/replica/storage/simple_kv/CMakeLists.txt +++ b/src/replica/storage/simple_kv/CMakeLists.txt @@ -40,7 +40,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) file(GLOB RES_FILES *.ini diff --git a/src/replica/storage/simple_kv/simple_kv.server.impl.cpp b/src/replica/storage/simple_kv/simple_kv.server.impl.cpp index 473d322818..54c6124c08 100644 --- a/src/replica/storage/simple_kv/simple_kv.server.impl.cpp +++ b/src/replica/storage/simple_kv/simple_kv.server.impl.cpp @@ -129,9 +129,9 @@ ::dsn::error_code simple_kv_service_impl::stop(bool clear_state) { zauto_lock l(_lock); if (clear_state) { - CHECK(dsn::utils::filesystem::remove_path(_dir_data), - "Fail to delete directory {}", - _dir_data); + PGSCHECK(dsn::utils::filesystem::remove_path(_dir_data), + "Fail to delete directory {}", + _dir_data); reset_state(); } } @@ -151,9 +151,9 @@ void simple_kv_service_impl::recover() std::vector sub_list; std::string path = _dir_data; - CHECK(dsn::utils::filesystem::get_subfiles(path, sub_list, false), - "Fail to get subfiles in {}", - path); + PGSCHECK(dsn::utils::filesystem::get_subfiles(path, sub_list, false), + "Fail to get subfiles in {}", + path); for (auto &fpath : sub_list) { auto &&s = dsn::utils::filesystem::get_file_name(fpath); if (s.substr(0, strlen("checkpoint.")) != std::string("checkpoint.")) @@ -180,7 +180,7 @@ void simple_kv_service_impl::recover(const std::string &name, int64_t version) std::unique_ptr rfile; auto s = dsn::utils::PegasusEnv(dsn::utils::FileDataType::kSensitive) ->NewSequentialFile(name, &rfile, rocksdb::EnvOptions()); - CHECK(s.ok(), "open log file '{}' failed, err = {}", name, s.ToString()); + PGSCHECK(s.ok(), "open log file '{}' failed, err = {}", name, s.ToString()); _store.clear(); @@ -191,8 +191,8 @@ void simple_kv_service_impl::recover(const std::string &name, int64_t version) static const uint64_t kHeaderSize = sizeof(count) + sizeof(magic); char buff[kHeaderSize] = {0}; s = rfile->Read(kHeaderSize, &result, buff); - CHECK(s.ok(), "read header failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read header failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); binary_reader reader(blob(buff, 0, kHeaderSize)); CHECK_EQ(sizeof(count), reader.read(count)); @@ -204,24 +204,24 @@ void simple_kv_service_impl::recover(const std::string &name, int64_t version) // Read key. uint32_t sz = 0; s = rfile->Read(sizeof(sz), &result, (char *)&sz); - CHECK(s.ok(), "read key size failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read key size failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); std::shared_ptr key_buffer(dsn::utils::make_shared_array(sz)); s = rfile->Read(sz, &result, key_buffer.get()); - CHECK(s.ok(), "read key failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read key failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); std::string key = result.ToString(); // Read value. s = rfile->Read(sizeof(sz), &result, (char *)&sz); - CHECK(s.ok(), "read value size failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read value size failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); std::shared_ptr value_buffer(dsn::utils::make_shared_array(sz)); s = rfile->Read(sz, &result, value_buffer.get()); - CHECK(s.ok(), "read value failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read value failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); std::string value = result.ToString(); // Store the kv pair. @@ -236,12 +236,12 @@ ::dsn::error_code simple_kv_service_impl::sync_checkpoint() zauto_lock l(_lock); if (last_commit == last_durable_decree()) { - CHECK(utils::filesystem::file_exists(fname), "checkpoint file {} is missing!", fname); + PGSCHECK(utils::filesystem::file_exists(fname), "checkpoint file {} is missing!", fname); return ERR_OK; } auto wfile = file::open(fname, file::FileOpenType::kWriteOnly); - CHECK_NOTNULL(wfile, ""); + PGSCHECK_NOTNULL(wfile, ""); #define WRITE_DATA_SIZE(data, size) \ do { \ diff --git a/src/replica/storage/simple_kv/test/CMakeLists.txt b/src/replica/storage/simple_kv/test/CMakeLists.txt index 1aa7dbaa15..636df7f29f 100644 --- a/src/replica/storage/simple_kv/test/CMakeLists.txt +++ b/src/replica/storage/simple_kv/test/CMakeLists.txt @@ -40,7 +40,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) FILE(GLOB CASE_FILES "case-*") set(MY_BINPLACES diff --git a/src/replica/storage/simple_kv/test/case.cpp b/src/replica/storage/simple_kv/test/case.cpp index d94eafaa56..480930aeda 100644 --- a/src/replica/storage/simple_kv/test/case.cpp +++ b/src/replica/storage/simple_kv/test/case.cpp @@ -325,7 +325,7 @@ struct event_type_helper const char *get(event_type type) { auto it = type_to_name.find(type); - CHECK(it != type_to_name.end(), ""); + PGSCHECK(it != type_to_name.end(), ""); return it->second.c_str(); } bool get(const std::string &name, event_type &type) @@ -417,7 +417,7 @@ event *event::parse(int line_no, const std::string ¶ms) e = new event_on_rpc_response_enqueue(); break; default: - CHECK(false, ""); + PGSCHECK(false, ""); } if (!e->internal_parse(kv_map)) { std::cerr << "bad line: line_no=" << line_no @@ -535,7 +535,7 @@ void event_on_rpc::init(message_ex *msg, task *tsk) _trace_id = fmt::sprintf("%016llx", msg->header->trace_id); _rpc_name = msg->header->rpc_name; const auto hp = host_port::from_address(msg->header->from_address); - CHECK(hp, "'{}' can not be reverse resolved", msg->header->from_address); + PGSCHECK(hp, "'{}' can not be reverse resolved", msg->header->from_address); _from = address_to_node(hp); _to = address_to_node(msg->to_host_port); } @@ -711,9 +711,9 @@ bool modify_case_line::parse(const std::string ¶ms) if (!event_case_line::parse(params)) return false; size_t pos = params.find(':'); - CHECK(pos != std::string::npos, ""); + PGSCHECK(pos != std::string::npos, ""); std::map kv_map; - CHECK(parse_kv_map(line_no(), params.substr(pos + 1), kv_map), ""); + PGSCHECK(parse_kv_map(line_no(), params.substr(pos + 1), kv_map), ""); std::map::const_iterator it; if ((it = kv_map.find("modify_delay")) != kv_map.end()) _modify_delay = it->second; @@ -724,8 +724,8 @@ void modify_case_line::modify(const event *ev) { if (!_modify_delay.empty()) { const event_on_task *e = dynamic_cast(ev); - CHECK_NOTNULL(e, ""); - CHECK_NOTNULL(e->_task, ""); + PGSCHECK_NOTNULL(e, ""); + PGSCHECK_NOTNULL(e->_task, ""); e->_task->set_delay(boost::lexical_cast(_modify_delay)); } } @@ -758,7 +758,7 @@ std::string client_case_line::to_string() const break; } default: - CHECK(false, ""); + PGSCHECK(false, ""); } return oss.str(); } @@ -822,7 +822,7 @@ bool client_case_line::parse(const std::string ¶ms) break; } default: - CHECK(false, ""); + PGSCHECK(false, ""); } if (!parse_ok) { std::cerr << "bad line: line_no=" << line_no() << ": unknown error: " << kv_map["err"] @@ -846,7 +846,7 @@ std::string client_case_line::type_name() const case replica_config: return "replica_config"; default: - CHECK(false, ""); + PGSCHECK(false, ""); } return ""; } @@ -1094,14 +1094,14 @@ void test_case::output(const std::string &line) void test_case::print(case_line *cl, const std::string &other, bool is_skip) { if (is_skip) { - CHECK(cl == nullptr, ""); - CHECK(!other.empty(), ""); + PGSCHECK(cl == nullptr, ""); + PGSCHECK(!other.empty(), ""); std::cout << " s " << other << std::endl; return; } if (cl == nullptr) { - CHECK(!other.empty(), ""); + PGSCHECK(!other.empty(), ""); std::cout << " + " << other << std::endl; } else // cl != nullptr { @@ -1392,7 +1392,7 @@ void test_case::on_state_change(const state_snapshot &last, const state_snapshot void test_case::internal_register_creator(const std::string &name, case_line_creator creator) { - CHECK(_creators.find(name) == _creators.end(), ""); + PGSCHECK(_creators.find(name) == _creators.end(), ""); _creators[name] = creator; } } // namespace test diff --git a/src/replica/storage/simple_kv/test/checker.cpp b/src/replica/storage/simple_kv/test/checker.cpp index de6e52c552..8d6119c404 100644 --- a/src/replica/storage/simple_kv/test/checker.cpp +++ b/src/replica/storage/simple_kv/test/checker.cpp @@ -287,7 +287,7 @@ void test_checker::on_replica_state_change(const host_port &from, void test_checker::on_config_change(const app_mapper &new_config) { const partition_configuration *pc = get_config(new_config, g_default_gpid); - CHECK_NOTNULL(pc, "drop table is not allowed in test"); + PGSCHECK_NOTNULL(pc, "drop table is not allowed in test"); parti_config cur_config; cur_config.convert_from(*pc); diff --git a/src/replica/storage/simple_kv/test/common.cpp b/src/replica/storage/simple_kv/test/common.cpp index 61dd9a5131..48b11aa855 100644 --- a/src/replica/storage/simple_kv/test/common.cpp +++ b/src/replica/storage/simple_kv/test/common.cpp @@ -63,7 +63,7 @@ const char *partition_status_to_short_string(partition_status::type s) case partition_status::PS_INVALID: return "inv"; default: - CHECK(false, "invalid partition_status, status = {}", ::dsn::enum_to_string(s)); + PGSCHECK(false, "invalid partition_status, status = {}", ::dsn::enum_to_string(s)); return ""; } } @@ -82,7 +82,7 @@ partition_status::type partition_status_from_short_string(const std::string &str return partition_status::PS_POTENTIAL_SECONDARY; if (str == "inv") return partition_status::PS_INVALID; - CHECK(false, ""); + PGSCHECK(false, ""); return partition_status::PS_INVALID; } @@ -91,7 +91,7 @@ std::string address_to_node(host_port addr) if (!addr) { return "-"; } - CHECK(test_checker::s_inited, ""); + PGSCHECK(test_checker::s_inited, ""); return test_checker::instance().address_to_node_name(addr); } @@ -99,7 +99,7 @@ host_port node_to_address(const std::string &name) { if (name == "-") return host_port(); - CHECK(test_checker::s_inited, ""); + PGSCHECK(test_checker::s_inited, ""); return test_checker::instance().node_name_to_address(name); } diff --git a/src/replica/storage/simple_kv/test/simple_kv.server.impl.cpp b/src/replica/storage/simple_kv/test/simple_kv.server.impl.cpp index 56fc195bf9..6c4734fe8b 100644 --- a/src/replica/storage/simple_kv/test/simple_kv.server.impl.cpp +++ b/src/replica/storage/simple_kv/test/simple_kv.server.impl.cpp @@ -138,9 +138,9 @@ ::dsn::error_code simple_kv_service_impl::stop(bool clear_state) dsn::zauto_lock l(_lock); if (clear_state) { - CHECK(dsn::utils::filesystem::remove_path(data_dir()), - "Fail to delete directory {}", - data_dir()); + PGSCHECK(dsn::utils::filesystem::remove_path(data_dir()), + "Fail to delete directory {}", + data_dir()); _store.clear(); reset_state(); } @@ -160,9 +160,9 @@ void simple_kv_service_impl::recover() std::vector sub_list; std::string path = data_dir(); - CHECK(dsn::utils::filesystem::get_subfiles(path, sub_list, false), - "Fail to get subfiles in {}", - path); + PGSCHECK(dsn::utils::filesystem::get_subfiles(path, sub_list, false), + "Fail to get subfiles in {}", + path); for (auto &fpath : sub_list) { auto &&s = dsn::utils::filesystem::get_file_name(fpath); if (s.substr(0, strlen("checkpoint.")) != std::string("checkpoint.")) @@ -190,7 +190,7 @@ void simple_kv_service_impl::recover(const std::string &name, int64_t version) std::unique_ptr rfile; auto s = dsn::utils::PegasusEnv(dsn::utils::FileDataType::kSensitive) ->NewSequentialFile(name, &rfile, rocksdb::EnvOptions()); - CHECK(s.ok(), "open log file '{}' failed, err = {}", name, s.ToString()); + PGSCHECK(s.ok(), "open log file '{}' failed, err = {}", name, s.ToString()); _store.clear(); @@ -201,8 +201,8 @@ void simple_kv_service_impl::recover(const std::string &name, int64_t version) static const uint64_t kHeaderSize = sizeof(count) + sizeof(magic); char buff[kHeaderSize] = {0}; s = rfile->Read(kHeaderSize, &result, buff); - CHECK(s.ok(), "read header failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read header failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); binary_reader reader(blob(buff, 0, kHeaderSize)); CHECK_EQ(sizeof(count), reader.read(count)); @@ -214,24 +214,24 @@ void simple_kv_service_impl::recover(const std::string &name, int64_t version) // Read key. uint32_t sz = 0; s = rfile->Read(sizeof(sz), &result, (char *)&sz); - CHECK(s.ok(), "read key size failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read key size failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); std::shared_ptr key_buffer(dsn::utils::make_shared_array(sz)); s = rfile->Read(sz, &result, key_buffer.get()); - CHECK(s.ok(), "read key failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read key failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); std::string key = result.ToString(); // Read value. s = rfile->Read(sizeof(sz), &result, (char *)&sz); - CHECK(s.ok(), "read value size failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read value size failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); std::shared_ptr value_buffer(dsn::utils::make_shared_array(sz)); s = rfile->Read(sz, &result, value_buffer.get()); - CHECK(s.ok(), "read value failed, err = {}", s.ToString()); - CHECK(!result.empty(), "read EOF of file '{}'", name); + PGSCHECK(s.ok(), "read value failed, err = {}", s.ToString()); + PGSCHECK(!result.empty(), "read EOF of file '{}'", name); std::string value = result.ToString(); // Store the kv pair. @@ -253,7 +253,7 @@ ::dsn::error_code simple_kv_service_impl::sync_checkpoint() std::string fname = fmt::format("{}/checkpoint.{}", data_dir(), last_commit); auto wfile = file::open(fname, file::FileOpenType::kWriteOnly); - CHECK_NOTNULL(wfile, ""); + PGSCHECK_NOTNULL(wfile, ""); #define WRITE_DATA_SIZE(data, size) \ do { \ diff --git a/src/replica/test/CMakeLists.txt b/src/replica/test/CMakeLists.txt index ef30c7d031..a0536de09b 100644 --- a/src/replica/test/CMakeLists.txt +++ b/src/replica/test/CMakeLists.txt @@ -44,7 +44,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES clear.sh diff --git a/src/replica/test/mock_utils.h b/src/replica/test/mock_utils.h index e89e6c7f98..05ea36fce8 100644 --- a/src/replica/test/mock_utils.h +++ b/src/replica/test/mock_utils.h @@ -250,7 +250,7 @@ create_mock_replica(replica_stub *stub, int app_id = 1, int partition_index = 1) app_info.app_name = "temp"; auto *dn = stub->get_fs_manager()->create_replica_dir_if_necessary(app_info.app_type, pid); - CHECK_NOTNULL(dn, ""); + PGSCHECK_NOTNULL(dn, ""); return std::make_unique(stub, pid, app_info, dn); } @@ -310,7 +310,7 @@ class mock_replica_stub : public replica_stub if (dn == nullptr) { dn = _fs_manager.create_replica_dir_if_necessary(info.app_type, pid); } - CHECK_NOTNULL(dn, ""); + PGSCHECK_NOTNULL(dn, ""); mock_replica_ptr rep = new mock_replica(this, pid, info, dn, need_restore, is_duplication_follower); rep->set_replica_config(config); @@ -332,7 +332,7 @@ class mock_replica_stub : public replica_stub config.status = status; auto dn = _fs_manager.create_replica_dir_if_necessary(info.app_type, pid); - CHECK_NOTNULL(dn, ""); + PGSCHECK_NOTNULL(dn, ""); auto *rep = new mock_replica(this, pid, info, dn, need_restore, is_duplication_follower); rep->set_replica_config(config); return rep; diff --git a/src/replica/test/replica_learn_test.cpp b/src/replica/test/replica_learn_test.cpp index b7ff94bc5c..6f709cb16c 100644 --- a/src/replica/test/replica_learn_test.cpp +++ b/src/replica/test/replica_learn_test.cpp @@ -50,7 +50,7 @@ class replica_learn_test : public duplication_test_base ai.duplicating = true; dir_node *dn = stub->get_fs_manager()->find_best_dir_for_new_replica(pid); - CHECK_NOTNULL(dn, ""); + PGSCHECK_NOTNULL(dn, ""); auto r = std::make_unique(stub.get(), pid, ai, dn); r->as_primary(); return r; diff --git a/src/runtime/fault_injector.cpp b/src/runtime/fault_injector.cpp index c7d54e192f..08fcf6077c 100644 --- a/src/runtime/fault_injector.cpp +++ b/src/runtime/fault_injector.cpp @@ -325,7 +325,7 @@ void fault_injector::install(service_spec &spec) std::string section_name = fmt::format("task.{}", dsn::task_code(i)); task_spec *spec = task_spec::get(i); - CHECK_NOTNULL(spec, ""); + PGSCHECK_NOTNULL(spec, ""); fj_opt &lopt = s_fj_opts[i]; read_config(section_name.c_str(), lopt, &default_opt); diff --git a/src/runtime/pipeline.h b/src/runtime/pipeline.h index c538bf2efa..93faaa4cbf 100644 --- a/src/runtime/pipeline.h +++ b/src/runtime/pipeline.h @@ -108,7 +108,7 @@ struct result // void step_down_next_stage(Args &&...args) { - CHECK_NOTNULL(__func, "no next stage is linked"); + PGSCHECK_NOTNULL(__func, "no next stage is linked"); __func(std::make_tuple(std::forward(args)...)); } @@ -263,7 +263,7 @@ struct when : environment inline void base::run_pipeline() { - CHECK_NOTNULL(__conf.tracker, "must configure task tracker"); + PGSCHECK_NOTNULL(__conf.tracker, "must configure task tracker"); _paused.store(false, std::memory_order_release); diff --git a/src/runtime/profiler.cpp b/src/runtime/profiler.cpp index 2228cc35b3..d617ed7ad0 100644 --- a/src/runtime/profiler.cpp +++ b/src/runtime/profiler.cpp @@ -169,11 +169,12 @@ static void profiler_on_task_create(task *caller, task *callee) static void profiler_on_task_enqueue(task *caller, task *callee) { auto callee_code = callee->spec().code; - CHECK(callee_code >= 0 && callee_code <= s_task_code_max, "code = {}", callee_code.code()); + PGSCHECK(callee_code >= 0 && callee_code <= s_task_code_max, "code = {}", callee_code.code()); if (caller != nullptr) { auto caller_code = caller->spec().code; - CHECK(caller_code >= 0 && caller_code <= s_task_code_max, "code = {}", caller_code.code()); + PGSCHECK( + caller_code >= 0 && caller_code <= s_task_code_max, "code = {}", caller_code.code()); auto &prof = s_spec_profilers[caller_code]; if (prof.collect_call_count) { @@ -191,7 +192,7 @@ static void profiler_on_task_begin(task *this_) { auto code = this_->spec().code; // TODO(yingchun): duplicate checks, should refactor later - CHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); + PGSCHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); uint64_t &qts = task_ext_for_profiler::get(this_); uint64_t now = dsn_now_ns(); @@ -204,7 +205,7 @@ static void profiler_on_task_begin(task *this_) static void profiler_on_task_end(task *this_) { auto code = this_->spec().code; - CHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); + PGSCHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); uint64_t qts = task_ext_for_profiler::get(this_); uint64_t now = dsn_now_ns(); @@ -216,7 +217,7 @@ static void profiler_on_task_end(task *this_) static void profiler_on_task_cancelled(task *this_) { auto code = this_->spec().code; - CHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); + PGSCHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); METRIC_INCREMENT(s_spec_profilers[code], profiler_cancelled_tasks); } @@ -232,14 +233,15 @@ static void profiler_on_aio_call(task *caller, aio_task *callee) { if (nullptr != caller) { auto caller_code = caller->spec().code; - CHECK(caller_code >= 0 && caller_code <= s_task_code_max, "code = {}", caller_code.code()); + PGSCHECK( + caller_code >= 0 && caller_code <= s_task_code_max, "code = {}", caller_code.code()); auto &prof = s_spec_profilers[caller_code]; if (prof.collect_call_count) { auto callee_code = callee->spec().code; - CHECK(callee_code >= 0 && callee_code <= s_task_code_max, - "code = {}", - callee_code.code()); + PGSCHECK(callee_code >= 0 && callee_code <= s_task_code_max, + "code = {}", + callee_code.code()); prof.call_counts[callee_code]++; } } @@ -251,7 +253,7 @@ static void profiler_on_aio_call(task *caller, aio_task *callee) static void profiler_on_aio_enqueue(aio_task *this_) { auto code = this_->spec().code; - CHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); + PGSCHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); uint64_t &ats = task_ext_for_profiler::get(this_); uint64_t now = dsn_now_ns(); @@ -267,13 +269,14 @@ static void profiler_on_rpc_call(task *caller, message_ex *req, rpc_response_tas { if (nullptr != caller) { auto caller_code = caller->spec().code; - CHECK(caller_code >= 0 && caller_code <= s_task_code_max, "code = {}", caller_code.code()); + PGSCHECK( + caller_code >= 0 && caller_code <= s_task_code_max, "code = {}", caller_code.code()); auto &prof = s_spec_profilers[caller_code]; if (prof.collect_call_count) { - CHECK(req->local_rpc_code >= 0 && req->local_rpc_code <= s_task_code_max, - "code = {}", - req->local_rpc_code.code()); + PGSCHECK(req->local_rpc_code >= 0 && req->local_rpc_code <= s_task_code_max, + "code = {}", + req->local_rpc_code.code()); prof.call_counts[req->local_rpc_code]++; } } @@ -287,7 +290,7 @@ static void profiler_on_rpc_call(task *caller, message_ex *req, rpc_response_tas static void profiler_on_rpc_request_enqueue(rpc_request_task *callee) { auto callee_code = callee->spec().code; - CHECK(callee_code >= 0 && callee_code <= s_task_code_max, "code = {}", callee_code.code()); + PGSCHECK(callee_code >= 0 && callee_code <= s_task_code_max, "code = {}", callee_code.code()); uint64_t now = dsn_now_ns(); task_ext_for_profiler::get(callee) = now; @@ -315,22 +318,22 @@ static void profiler_on_rpc_create_response(message_ex *req, message_ex *resp) static void profiler_on_rpc_reply(task *caller, message_ex *msg) { auto caller_code = caller->spec().code; - CHECK(caller_code >= 0 && caller_code <= s_task_code_max, "code = {}", caller_code.code()); + PGSCHECK(caller_code >= 0 && caller_code <= s_task_code_max, "code = {}", caller_code.code()); auto &prof = s_spec_profilers[caller_code]; if (prof.collect_call_count) { - CHECK(msg->local_rpc_code >= 0 && msg->local_rpc_code <= s_task_code_max, - "code = {}", - msg->local_rpc_code.code()); + PGSCHECK(msg->local_rpc_code >= 0 && msg->local_rpc_code <= s_task_code_max, + "code = {}", + msg->local_rpc_code.code()); prof.call_counts[msg->local_rpc_code]++; } uint64_t qts = message_ext_for_profiler::get(msg); uint64_t now = dsn_now_ns(); task_spec *spec = task_spec::get(msg->local_rpc_code); - CHECK_NOTNULL(spec, "task_spec cannot be null, code = {}", msg->local_rpc_code.code()); + PGSCHECK_NOTNULL(spec, "task_spec cannot be null, code = {}", msg->local_rpc_code.code()); auto code = spec->rpc_paired_code; - CHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); + PGSCHECK(code >= 0 && code <= s_task_code_max, "code = {}", code.code()); METRIC_SET(s_spec_profilers[code], profiler_server_rpc_latency_ns, now - qts); @@ -341,7 +344,7 @@ static void profiler_on_rpc_reply(task *caller, message_ex *msg) static void profiler_on_rpc_response_enqueue(rpc_response_task *resp) { auto resp_code = resp->spec().code; - CHECK(resp_code >= 0 && resp_code <= s_task_code_max, "code = {}", resp_code.code()); + PGSCHECK(resp_code >= 0 && resp_code <= s_task_code_max, "code = {}", resp_code.code()); uint64_t &cts = task_ext_for_profiler::get(resp); uint64_t now = dsn_now_ns(); @@ -376,7 +379,7 @@ task_spec_profiler::task_spec_profiler(int code) { const auto §ion_name = fmt::format("task.{}", _task_name); auto spec = task_spec::get(code); - CHECK_NOTNULL(spec, "spec should be non-null: task_code={}, task_name={}", code, _task_name); + PGSCHECK_NOTNULL(spec, "spec should be non-null: task_code={}, task_name={}", code, _task_name); collect_call_count = dsn_config_get_value_bool( section_name.c_str(), "collect_call_count", FLAGS_collect_call_count, ""); @@ -501,10 +504,10 @@ task_spec_profiler::task_spec_profiler(int code) const metric_entity_ptr &task_spec_profiler::profiler_metric_entity() const { - CHECK_NOTNULL(_profiler_metric_entity, - "profiler metric entity (task_name={}) should has been instantiated: " - "uninitialized entity cannot be used to instantiate metric", - _task_name); + PGSCHECK_NOTNULL(_profiler_metric_entity, + "profiler metric entity (task_name={}) should has been instantiated: " + "uninitialized entity cannot be used to instantiate metric", + _task_name); return _profiler_metric_entity; } diff --git a/src/runtime/rpc/asio_net_provider.cpp b/src/runtime/rpc/asio_net_provider.cpp index 8c9457cbb3..4b5aaa2c6b 100644 --- a/src/runtime/rpc/asio_net_provider.cpp +++ b/src/runtime/rpc/asio_net_provider.cpp @@ -135,15 +135,15 @@ error_code asio_network_provider::start(rpc_channel channel, int port, bool clie boost::asio::io_service::work work(*_io_services[i]); boost::system::error_code ec; _io_services[i]->run(ec); - CHECK(!ec, "boost::asio::io_service run failed: err({})", ec.message()); + PGSCHECK(!ec, "boost::asio::io_service run failed: err({})", ec.message()); })); } _acceptor = nullptr; - CHECK(channel == RPC_CHANNEL_TCP || channel == RPC_CHANNEL_UDP, - "invalid given channel {}", - channel); + PGSCHECK(channel == RPC_CHANNEL_TCP || channel == RPC_CHANNEL_UDP, + "invalid given channel {}", + channel); _address = rpc_address(get_local_ipv4(), port); _hp = ::dsn::host_port::from_address(_address); @@ -471,7 +471,7 @@ error_code asio_udp_provider::start(rpc_channel channel, int port, bool client_o boost::asio::io_service::work work(_io_service); boost::system::error_code ec; _io_service.run(ec); - CHECK(!ec, "boost::asio::io_service run failed: err({})", ec.message()); + PGSCHECK(!ec, "boost::asio::io_service run failed: err({})", ec.message()); })); } diff --git a/src/runtime/rpc/dns_resolver.cpp b/src/runtime/rpc/dns_resolver.cpp index bfd7f5206d..9b60a2306f 100644 --- a/src/runtime/rpc/dns_resolver.cpp +++ b/src/runtime/rpc/dns_resolver.cpp @@ -76,7 +76,7 @@ bool dns_resolver::get_cached_addresses(const host_port &hp, std::vector &addresses) { - CHECK(addresses.empty(), "invalid addresses, not empty"); + PGSCHECK(addresses.empty(), "invalid addresses, not empty"); if (get_cached_addresses(hp, addresses)) { return error_s::ok(); } @@ -128,7 +128,7 @@ rpc_address dns_resolver::resolve_address(const host_port &hp) case HOST_TYPE_IPV4: { std::vector addresses; CHECK_OK(resolve_addresses(hp, addresses), "host_port '{}' can not be resolved", hp); - CHECK(!addresses.empty(), "host_port '{}' can not be resolved to any address", hp); + PGSCHECK(!addresses.empty(), "host_port '{}' can not be resolved to any address", hp); if (addresses.size() > 1) { LOG_WARNING("host_port '{}' resolves to {} different addresses, using the first one {}", diff --git a/src/runtime/rpc/group_host_port.h b/src/runtime/rpc/group_host_port.h index ae1181358e..b4222c8624 100644 --- a/src/runtime/rpc/group_host_port.h +++ b/src/runtime/rpc/group_host_port.h @@ -128,13 +128,13 @@ inline rpc_group_host_port::rpc_group_host_port(const rpc_group_address *g_addr) _name = g_addr->name(); for (const auto &addr : g_addr->members()) { const auto hp = host_port::from_address(addr); - CHECK(hp, "'{}' can not be reverse resolved", addr); + PGSCHECK(hp, "'{}' can not be reverse resolved", addr); CHECK_TRUE(add(hp)); } _update_leader_automatically = g_addr->is_update_leader_automatically(); if (g_addr->leader()) { const auto hp = host_port::from_address(g_addr->leader()); - CHECK(hp, "'{}' can not be reverse resolved", g_addr->leader()); + PGSCHECK(hp, "'{}' can not be reverse resolved", g_addr->leader()); set_leader(hp); } } @@ -194,7 +194,7 @@ inline void rpc_group_host_port::set_leader(const host_port &hp) inline uint32_t rpc_group_host_port::random_index_unlocked() const { - CHECK(!_members.empty(), "invaild group member size"); + PGSCHECK(!_members.empty(), "invaild group member size"); return rand::next_u32(0, static_cast(_members.size() - 1)); } diff --git a/src/runtime/rpc/network.cpp b/src/runtime/rpc/network.cpp index c572b19a8d..c0780c0494 100644 --- a/src/runtime/rpc/network.cpp +++ b/src/runtime/rpc/network.cpp @@ -99,7 +99,7 @@ rpc_session::~rpc_session() bool rpc_session::set_connecting() { - CHECK(is_client(), "must be client session"); + PGSCHECK(is_client(), "must be client session"); utils::auto_lock l(_lock); if (_connect_state == SS_DISCONNECTED) { @@ -112,7 +112,7 @@ bool rpc_session::set_connecting() void rpc_session::set_connected() { - CHECK(is_client(), "must be client session"); + PGSCHECK(is_client(), "must be client session"); { utils::auto_lock l(_lock); @@ -298,7 +298,7 @@ void rpc_session::send_message(message_ex *msg) return; } - CHECK_NOTNULL(_parser, "parser should not be null when send"); + PGSCHECK_NOTNULL(_parser, "parser should not be null when send"); _parser->prepare_on_send(msg); uint64_t sig; @@ -345,7 +345,8 @@ void rpc_session::on_send_completed(uint64_t signature) { utils::auto_lock l(_lock); if (signature != 0) { - CHECK(_is_sending_next && signature == _message_sent + 1, "sent msg must be sending"); + PGSCHECK(_is_sending_next && signature == _message_sent + 1, + "sent msg must be sending"); _is_sending_next = false; // the _sending_msgs may have been cleared when reading of the rpc_session is failed. @@ -471,7 +472,7 @@ bool rpc_session::on_recv_message(message_ex *msg, int delay_ms) return false; } - DCHECK(!is_client(), "only rpc server session can recv rpc requests"); + DCHECK(!is_client()) << "only rpc server session can recv rpc requests"; _net.on_recv_request(msg, delay_ms); } @@ -579,7 +580,7 @@ void network::on_recv_reply(uint64_t id, message_ex *msg, int delay_ms) message_parser *network::new_message_parser(network_header_format hdr_format) { message_parser *parser = message_parser_manager::instance().create_parser(hdr_format); - CHECK_NOTNULL(parser, "message parser '{}' not registerd or invalid!", hdr_format); + PGSCHECK_NOTNULL(parser, "message parser '{}' not registerd or invalid!", hdr_format); return parser; } @@ -622,7 +623,7 @@ void connection_oriented_network::inject_drop_message(message_ex *msg, bool is_s // - but if is_send == true, there may be is_session != nullptr, when it is a // normal (not forwarding) reply message from server to client, in which case // the io_session has also been set. - CHECK(is_send, "received message should always has io_session set"); + PGSCHECK(is_send, "received message should always has io_session set"); utils::auto_read_lock l(_clients_lock); auto it = _clients.find(msg->to_address); if (it != _clients.end()) { diff --git a/src/runtime/rpc/network.sim.cpp b/src/runtime/rpc/network.sim.cpp index ecde4fb171..efd8903c5d 100644 --- a/src/runtime/rpc/network.sim.cpp +++ b/src/runtime/rpc/network.sim.cpp @@ -115,12 +115,12 @@ void sim_client_session::send(uint64_t sig) { node_scoper ns(rnet->node()); - CHECK(server_session->on_recv_message(recv_msg, - recv_msg->to_address == - recv_msg->header->from_address - ? 0 - : rnet->net_delay_milliseconds()), - ""); + PGSCHECK(server_session->on_recv_message(recv_msg, + recv_msg->to_address == + recv_msg->header->from_address + ? 0 + : rnet->net_delay_milliseconds()), + ""); } } } @@ -145,12 +145,13 @@ void sim_server_session::send(uint64_t sig) { node_scoper ns(_client->net().node()); - CHECK(_client->on_recv_message( - recv_msg, - recv_msg->to_address == recv_msg->header->from_address - ? 0 - : (static_cast(&_net))->net_delay_milliseconds()), - ""); + PGSCHECK( + _client->on_recv_message( + recv_msg, + recv_msg->to_address == recv_msg->header->from_address + ? 0 + : (static_cast(&_net))->net_delay_milliseconds()), + ""); } } @@ -167,9 +168,9 @@ sim_network_provider::sim_network_provider(rpc_engine *rpc, network *inner_provi error_code sim_network_provider::start(rpc_channel channel, int port, bool client_only) { - CHECK(channel == RPC_CHANNEL_TCP || channel == RPC_CHANNEL_UDP, - "invalid given channel {}", - channel); + PGSCHECK(channel == RPC_CHANNEL_TCP || channel == RPC_CHANNEL_UDP, + "invalid given channel {}", + channel); _address = dsn::rpc_address::from_host_port("localhost", port); _hp = ::dsn::host_port::from_address(_address); diff --git a/src/runtime/rpc/rpc_engine.cpp b/src/runtime/rpc/rpc_engine.cpp index 24eb71be54..6f55331dff 100644 --- a/src/runtime/rpc/rpc_engine.cpp +++ b/src/runtime/rpc/rpc_engine.cpp @@ -104,8 +104,8 @@ bool rpc_client_matcher::on_recv_reply(network *net, uint64_t key, message_ex *r } } - DCHECK_NOTNULL(call, "rpc response task cannot be nullptr"); - DCHECK_NOTNULL(timeout_task, "rpc timeout task cannot be nullptr"); + DPGSCHECK_NOTNULL(call, "rpc response task cannot be nullptr"); + DPGSCHECK_NOTNULL(timeout_task, "rpc timeout task cannot be nullptr"); if (timeout_task != task::get_current_task()) { timeout_task->cancel(false); // no need to wait @@ -151,7 +151,7 @@ bool rpc_client_matcher::on_recv_reply(network *net, uint64_t key, message_ex *r if (req->server_address.group_address()->is_update_leader_automatically()) { req->server_address.group_address()->set_leader(addr); const auto hp = host_port::from_address(addr); - CHECK(hp, "'{}' can not be reverse resolved", addr); + PGSCHECK(hp, "'{}' can not be reverse resolved", addr); req->server_host_port.group_host_port()->set_leader(hp); } break; @@ -160,7 +160,7 @@ bool rpc_client_matcher::on_recv_reply(network *net, uint64_t key, message_ex *r } break; default: - CHECK(false, "not implemented"); + PGSCHECK(false, "not implemented"); break; } @@ -182,7 +182,8 @@ bool rpc_client_matcher::on_recv_reply(network *net, uint64_t key, message_ex *r req->server_address.group_address()->set_leader( reply->header->from_address); const auto hp = host_port::from_address(reply->header->from_address); - CHECK(hp, "'{}' can not be reverse resolved", reply->header->from_address); + PGSCHECK( + hp, "'{}' can not be reverse resolved", reply->header->from_address); req->server_host_port.group_host_port()->set_leader(hp); } break; @@ -191,7 +192,7 @@ bool rpc_client_matcher::on_recv_reply(network *net, uint64_t key, message_ex *r } break; default: - CHECK(false, "not implemented"); + PGSCHECK(false, "not implemented"); break; } } @@ -240,7 +241,7 @@ void rpc_client_matcher::on_rpc_timeout(uint64_t key) } } - DCHECK_NOTNULL(call, "rpc response task is missing for rpc request {}", key); + DPGSCHECK_NOTNULL(call, "rpc response task is missing for rpc request {}", key); // if timeout if (!resend) { @@ -313,14 +314,14 @@ void rpc_client_matcher::on_call(message_ex *request, const rpc_response_task_pt timeout_ms = sp->rpc_request_resend_timeout_milliseconds; } - DCHECK_NOTNULL(call, "rpc response task cannot be nullptr"); + DPGSCHECK_NOTNULL(call, "rpc response task cannot be nullptr"); task *timeout_task(new rpc_timeout_task(this, hdr.id, call->node())); { utils::auto_lock<::dsn::utils::ex_lock_nr_spin> l(_requests_lock[bucket_index]); auto pr = _requests[bucket_index].emplace(hdr.id, match_entry{call, timeout_task, timeout_ts_ms}); - CHECK(pr.second, "the message is already on the fly!!!"); + PGSCHECK(pr.second, "the message is already on the fly!!!"); } timeout_task->set_delay(timeout_ms); @@ -357,10 +358,10 @@ bool rpc_server_dispatcher::register_rpc_handler(dsn::task_code code, utils::auto_write_lock l(_handlers_lock); auto it = _handlers.find(code.to_string()); auto it2 = _handlers.find(extra_name); - CHECK(it == _handlers.end() && it2 == _handlers.end(), - "rpc registration confliction for '{}' '{}'", - code, - extra_name); + PGSCHECK(it == _handlers.end() && it2 == _handlers.end(), + "rpc registration confliction for '{}' '{}'", + code, + extra_name); _handlers[code.to_string()] = ctx.get(); _handlers[ctx->extra_name] = ctx.get(); @@ -423,7 +424,7 @@ rpc_request_task *rpc_server_dispatcher::on_request(message_ex *msg, service_nod //---------------------------------------------------------------------------------------------- rpc_engine::rpc_engine(service_node *node) : _node(node), _rpc_matcher(this) { - CHECK_NOTNULL(_node, ""); + CHECK_NOTNULL(_node); _is_running = false; _is_serving = false; } @@ -525,7 +526,7 @@ error_code rpc_engine::start(const service_app_spec &aspec) _local_primary_address = _client_nets[NET_HDR_DSN][0]->address(); _local_primary_address.set_port(aspec.ports.size() > 0 ? *aspec.ports.begin() : aspec.id); _local_primary_host_port = host_port::from_address(_local_primary_address); - CHECK(_local_primary_host_port, "'{}' can not be reverse resolved", _local_primary_address); + PGSCHECK(_local_primary_host_port, "'{}' can not be reverse resolved", _local_primary_address); LOG_INFO("=== service_node=[{}], primary_address=[{}({})] ===", _node->full_name(), @@ -649,10 +650,10 @@ void rpc_engine::call_group(rpc_address addr, call_ip(request->server_address.group_address()->random_member(), request, call); break; case GRPC_TO_ALL: - CHECK(false, "to be implemented"); + PGSCHECK(false, "to be implemented"); break; default: - CHECK(false, "invalid group rpc mode {}", sp->grpc_mode); + PGSCHECK(false, "invalid group rpc mode {}", sp->grpc_mode); } } @@ -664,7 +665,7 @@ void rpc_engine::call_ip(rpc_address addr, { DCHECK_EQ_MSG(addr.type(), HOST_TYPE_IPV4, "only IPV4 is now supported"); DCHECK_GT_MSG(addr.port(), MAX_CLIENT_PORT, "only server address can be called"); - CHECK(request->header->from_address, "from address must be set before call call_ip"); + PGSCHECK(request->header->from_address, "from address must be set before call call_ip"); while (!request->dl.is_alone()) { LOG_WARNING("msg request {} (trace_id = {:#018x}) is in sending queue, try to pick out ...", @@ -683,11 +684,11 @@ void rpc_engine::call_ip(rpc_address addr, auto &hdr = *request->header; network *net = _client_nets[request->hdr_format][sp->rpc_call_channel].get(); - CHECK_NOTNULL(net, - "network not present for rpc channel '{}' with format '{}' used by rpc {}", - sp->rpc_call_channel, - sp->rpc_call_header_format, - hdr.rpc_name); + PGSCHECK_NOTNULL(net, + "network not present for rpc channel '{}' with format '{}' used by rpc {}", + sp->rpc_call_channel, + sp->rpc_call_header_format, + hdr.rpc_name); LOG_DEBUG("rpc_name = {}, remote_addr = {}, header_format = {}, channel = {}, seq_id = {}, " "trace_id = {:#018x}", @@ -790,7 +791,7 @@ void rpc_engine::reply(message_ex *response, error_code err) // use the header format recorded in the message auto rpc_channel = sp ? sp->rpc_call_channel : RPC_CHANNEL_TCP; network *net = _client_nets[response->hdr_format][rpc_channel].get(); - CHECK_NOTNULL( + PGSCHECK_NOTNULL( net, "client network not present for rpc channel '{}' with format '{}' used by rpc {}", RPC_CHANNEL_TCP, @@ -814,11 +815,12 @@ void rpc_engine::reply(message_ex *response, error_code err) auto rpc_channel = sp ? sp->rpc_call_channel : RPC_CHANNEL_TCP; network *net = _server_nets[response->header->from_address.port()][rpc_channel].get(); - CHECK_NOTNULL(net, - "server network not present for rpc channel '{}' on port {} used by rpc {}", - RPC_CHANNEL_UDP, - response->header->from_address.port(), - response->header->rpc_name); + PGSCHECK_NOTNULL( + net, + "server network not present for rpc channel '{}' on port {} used by rpc {}", + RPC_CHANNEL_UDP, + response->header->from_address.port(), + response->header->rpc_name); if (no_fail) { net->send_message(response); @@ -837,11 +839,11 @@ void rpc_engine::reply(message_ex *response, error_code err) void rpc_engine::forward(message_ex *request, rpc_address address) { - CHECK(request->header->context.u.is_request, "only rpc request can be forwarded"); - CHECK(request->header->context.u.is_forward_supported, - "rpc msg {} (trace_id = {:#018x}) does not support being forwared", - task_spec::get(request->local_rpc_code)->name, - request->header->trace_id); + PGSCHECK(request->header->context.u.is_request, "only rpc request can be forwarded"); + PGSCHECK(request->header->context.u.is_forward_supported, + "rpc msg {} (trace_id = {:#018x}) does not support being forwared", + task_spec::get(request->local_rpc_code)->name, + request->header->trace_id); CHECK_NE_MSG(address, _local_primary_address, "cannot forward msg {} (trace_id = {:#018x}) to the local node", diff --git a/src/runtime/rpc/rpc_engine.h b/src/runtime/rpc/rpc_engine.h index 47980afbde..f012fbefe5 100644 --- a/src/runtime/rpc/rpc_engine.h +++ b/src/runtime/rpc/rpc_engine.h @@ -224,7 +224,7 @@ rpc_engine::call_address(rpc_address addr, message_ex *request, const rpc_respon call_group(addr, request, call); break; default: - CHECK(false, "invalid target address type {}", request->server_address.type()); + PGSCHECK(false, "invalid target address type {}", request->server_address.type()); break; } } diff --git a/src/runtime/rpc/rpc_holder.h b/src/runtime/rpc/rpc_holder.h index b1e4af7b84..d2163c7299 100644 --- a/src/runtime/rpc/rpc_holder.h +++ b/src/runtime/rpc/rpc_holder.h @@ -113,31 +113,31 @@ class rpc_holder const TRequest &request() const { - CHECK(_i, "rpc_holder is uninitialized"); + PGSCHECK(_i, "rpc_holder is uninitialized"); return *(_i->thrift_request); } TRequest *mutable_request() const { - CHECK(_i, "rpc_holder is uninitialized"); + PGSCHECK(_i, "rpc_holder is uninitialized"); return _i->thrift_request.get(); } TResponse &response() const { - CHECK(_i, "rpc_holder is uninitialized"); + PGSCHECK(_i, "rpc_holder is uninitialized"); return _i->thrift_response; } dsn::error_code &error() const { - CHECK(_i, "rpc_holder is uninitialized"); + PGSCHECK(_i, "rpc_holder is uninitialized"); return _i->rpc_error; } message_ex *dsn_request() const { - CHECK(_i, "rpc_holder is uninitialized"); + PGSCHECK(_i, "rpc_holder is uninitialized"); return _i->dsn_request; } @@ -242,8 +242,8 @@ class rpc_holder using mail_box_u_ptr = std::unique_ptr; static void enable_mocking() { - CHECK(_mail_box == nullptr && _forward_mail_box == nullptr, - "remember to call clear_mocking_env after testing"); + PGSCHECK(_mail_box == nullptr && _forward_mail_box == nullptr, + "remember to call clear_mocking_env after testing"); _mail_box = std::make_unique(); _forward_mail_box = std::make_unique(); } @@ -259,13 +259,13 @@ class rpc_holder static mail_box_t &mail_box() { - CHECK(_mail_box, "call this function only when you are in mock mode"); + PGSCHECK(_mail_box, "call this function only when you are in mock mode"); return *_mail_box.get(); } static mail_box_t &forward_mail_box() { - CHECK(_forward_mail_box, "call this function only when you are in mock mode"); + PGSCHECK(_forward_mail_box, "call this function only when you are in mock mode"); return *_forward_mail_box.get(); } @@ -292,7 +292,7 @@ class rpc_holder int thread_hash) : thrift_request(std::move(req)), auto_reply(false) { - CHECK(thrift_request, "req should not be null"); + PGSCHECK(thrift_request, "req should not be null"); dsn_request = message_ex::create_request( code, static_cast(timeout.count()), thread_hash, partition_hash); diff --git a/src/runtime/rpc/rpc_host_port.cpp b/src/runtime/rpc/rpc_host_port.cpp index 42ed764010..b12bc3875d 100644 --- a/src/runtime/rpc/rpc_host_port.cpp +++ b/src/runtime/rpc/rpc_host_port.cpp @@ -162,7 +162,7 @@ void host_port::assign_group(const char *name) error_s host_port::resolve_addresses(std::vector &addresses) const { - CHECK(addresses.empty(), ""); + CHECK(addresses.empty()); switch (type()) { case HOST_TYPE_INVALID: @@ -172,7 +172,7 @@ error_s host_port::resolve_addresses(std::vector &addresses) const case HOST_TYPE_IPV4: break; default: - CHECK(false, ""); + CHECK(false); __builtin_unreachable(); } diff --git a/src/runtime/rpc/rpc_host_port.h b/src/runtime/rpc/rpc_host_port.h index 2a643bb4e0..60578bd264 100644 --- a/src/runtime/rpc/rpc_host_port.h +++ b/src/runtime/rpc/rpc_host_port.h @@ -51,7 +51,7 @@ class TProtocol; const auto &_obj = (obj); \ auto &_target = (target); \ if (_obj.__isset.hp_##field) { \ - DCHECK(_obj.field, "invalid address: {}", _obj.field); \ + DPGSCHECK(_obj.field, "invalid address: {}", _obj.field); \ DCHECK_EQ(_obj.field, dsn::dns_resolver::instance().resolve_address(_obj.hp_##field)); \ _target = _obj.hp_##field; \ } else { \ @@ -66,7 +66,7 @@ class TProtocol; do { \ const auto &_obj = (obj); \ auto &_target = (target); \ - CHECK(_target.empty(), ""); \ + CHECK(_target.empty()); \ if (_obj.__isset.hp_##field) { \ DCHECK_EQ(_obj.field.size(), _obj.hp_##field.size()); \ _target = _obj.hp_##field; \ @@ -292,7 +292,7 @@ class host_port std::shared_ptr group_host_port() const { - CHECK_NOTNULL(_group_host_port, "group_host_port cannot be null!"); + PGSCHECK_NOTNULL(_group_host_port, "group_host_port cannot be null!"); return _group_host_port; } void assign_group(const char *name); diff --git a/src/runtime/rpc/rpc_message.cpp b/src/runtime/rpc/rpc_message.cpp index 00412db721..f441053450 100644 --- a/src/runtime/rpc/rpc_message.cpp +++ b/src/runtime/rpc/rpc_message.cpp @@ -92,7 +92,7 @@ message_ex::~message_ex() // release_header_buffer(); if (!_is_read) { - CHECK(_rw_committed, "message write is not committed"); + PGSCHECK(_rw_committed, "message write is not committed"); } } @@ -207,7 +207,7 @@ message_ex *message_ex::copy_message_no_reply(const message_ex &old_msg) message_ex *message_ex::copy(bool clone_content, bool copy_for_receive) { - CHECK(this->_rw_committed, "should not copy the message when read/write is not committed"); + PGSCHECK(this->_rw_committed, "should not copy the message when read/write is not committed"); // ATTENTION: // - if this message is a written message, set copied message's write pointer to the end, @@ -280,8 +280,8 @@ message_ex *message_ex::copy_and_prepare_send(bool clone_content) if (_is_read) { // the message_header is hidden ahead of the buffer, expose it to buffer CHECK_EQ_MSG(buffers.size(), 1, "there must be only one buffer for read msg"); - CHECK((char *)header + sizeof(message_header) == (char *)buffers[0].data(), - "header and content must be contigous"); + PGSCHECK((char *)header + sizeof(message_header) == (char *)buffers[0].data(), + "header and content must be contigous"); copy->buffers[0] = copy->buffers[0].range(-(int)sizeof(message_header)); @@ -409,9 +409,9 @@ void message_ex::release_buffer_header() void message_ex::write_next(void **ptr, size_t *size, size_t min_size) { // printf("%p %s\n", this, __FUNCTION__); - CHECK(!this->_is_read && this->_rw_committed, - "there are pending msg write not committed" - ", please invoke dsn_msg_write_next and dsn_msg_write_commit in pairs"); + PGSCHECK(!this->_is_read && this->_rw_committed, + "there are pending msg write not committed" + ", please invoke dsn_msg_write_next and dsn_msg_write_commit in pairs"); auto ptr_data(utils::make_shared_array(min_size)); *size = min_size; *ptr = ptr_data.get(); @@ -428,9 +428,9 @@ void message_ex::write_next(void **ptr, size_t *size, size_t min_size) void message_ex::write_commit(size_t size) { // printf("%p %s\n", this, __FUNCTION__); - CHECK(!this->_rw_committed, - "there are no pending msg write to be committed" - ", please invoke dsn_msg_write_next and dsn_msg_write_commit in pairs"); + PGSCHECK(!this->_rw_committed, + "there are no pending msg write to be committed" + ", please invoke dsn_msg_write_next and dsn_msg_write_commit in pairs"); this->_rw_offset += (int)size; *this->buffers.rbegin() = this->buffers.rbegin()->range(0, (int)this->_rw_offset); @@ -441,9 +441,9 @@ void message_ex::write_commit(size_t size) bool message_ex::read_next(void **ptr, size_t *size) { // printf("%p %s %d\n", this, __FUNCTION__, utils::get_current_tid()); - CHECK(this->_is_read && this->_rw_committed, - "there are pending msg read not committed" - ", please invoke dsn_msg_read_next and dsn_msg_read_commit in pairs"); + PGSCHECK(this->_is_read && this->_rw_committed, + "there are pending msg read not committed" + ", please invoke dsn_msg_read_next and dsn_msg_read_commit in pairs"); int idx = this->_rw_index; if (-1 == idx || this->_rw_offset == static_cast(this->buffers[idx].length())) { @@ -466,9 +466,9 @@ bool message_ex::read_next(void **ptr, size_t *size) bool message_ex::read_next(blob &data) { // printf("%p %s %d\n", this, __FUNCTION__, utils::get_current_tid()); - CHECK(this->_is_read && this->_rw_committed, - "there are pending msg read not committed" - ", please invoke dsn_msg_read_next and dsn_msg_read_commit in pairs"); + PGSCHECK(this->_is_read && this->_rw_committed, + "there are pending msg read not committed" + ", please invoke dsn_msg_read_next and dsn_msg_read_commit in pairs"); int idx = this->_rw_index; if (-1 == idx || this->_rw_offset == static_cast(this->buffers[idx].length())) { @@ -489,9 +489,9 @@ bool message_ex::read_next(blob &data) void message_ex::read_commit(size_t size) { // printf("%p %s\n", this, __FUNCTION__); - CHECK(!this->_rw_committed, - "there are no pending msg read to be committed" - ", please invoke dsn_msg_read_next and dsn_msg_read_commit in pairs"); + PGSCHECK(!this->_rw_committed, + "there are no pending msg read to be committed" + ", please invoke dsn_msg_read_next and dsn_msg_read_commit in pairs"); CHECK_NE_MSG(-1, this->_rw_index, "no buffer in curent msg is under read"); this->_rw_offset += (int)size; diff --git a/src/runtime/rpc/rpc_stream.h b/src/runtime/rpc/rpc_stream.h index 62dfc82284..18b2a71868 100644 --- a/src/runtime/rpc/rpc_stream.h +++ b/src/runtime/rpc/rpc_stream.h @@ -56,8 +56,8 @@ class rpc_read_stream : public binary_reader _msg = msg; if (nullptr != _msg) { ::dsn::blob bb; - CHECK(((::dsn::message_ex *)_msg)->read_next(bb), - "read msg must have one segment of buffer ready"); + PGSCHECK(((::dsn::message_ex *)_msg)->read_next(bb), + "read msg must have one segment of buffer ready"); init(std::move(bb)); } } diff --git a/src/runtime/rpc/serialization.h b/src/runtime/rpc/serialization.h index 7aa5738a11..6a4ede62ca 100644 --- a/src/runtime/rpc/serialization.h +++ b/src/runtime/rpc/serialization.h @@ -64,7 +64,7 @@ inline void marshall(binary_writer &writer, const ThriftType &value, dsn_msg_ser marshall_thrift_json(writer, value); break; default: - CHECK(false, serialization::no_registered_function_error_notice(value, fmt)); + PGSCHECK(false, serialization::no_registered_function_error_notice(value, fmt)); } } @@ -79,7 +79,7 @@ inline void unmarshall(binary_reader &reader, ThriftType &value, dsn_msg_seriali unmarshall_thrift_json(reader, value); break; default: - CHECK(false, serialization::no_registered_function_error_notice(value, fmt)); + PGSCHECK(false, serialization::no_registered_function_error_notice(value, fmt)); } } diff --git a/src/runtime/rpc/thrift_message_parser.cpp b/src/runtime/rpc/thrift_message_parser.cpp index d547075025..507bcbb7e7 100644 --- a/src/runtime/rpc/thrift_message_parser.cpp +++ b/src/runtime/rpc/thrift_message_parser.cpp @@ -305,7 +305,7 @@ message_ex *thrift_message_parser::get_message_on_receive(message_reader *reader case 1: return parse_request_body_v1(reader, read_next); default: - CHECK(false, "invalid header version: {}", _header_version); + PGSCHECK(false, "invalid header version: {}", _header_version); } return nullptr; @@ -327,9 +327,9 @@ void thrift_message_parser::prepare_on_send(message_ex *msg) auto &header = msg->header; auto &buffers = msg->buffers; - CHECK(!header->context.u.is_request, "only support send response"); - CHECK(header->server.error_name[0], "error name should be set"); - CHECK(!buffers.empty(), "buffers can not be empty"); + PGSCHECK(!header->context.u.is_request, "only support send response"); + PGSCHECK(header->server.error_name[0], "error name should be set"); + PGSCHECK(!buffers.empty(), "buffers can not be empty"); // write thrift response header and thrift message begin binary_writer header_writer; diff --git a/src/runtime/scheduler.cpp b/src/runtime/scheduler.cpp index 440e105907..7fc3b2d801 100644 --- a/src/runtime/scheduler.cpp +++ b/src/runtime/scheduler.cpp @@ -282,7 +282,7 @@ void scheduler::schedule() t->release_ref(); // added by previous t->enqueue from app } else { - CHECK(e.system_task, "app and system tasks cannot be both empty"); + PGSCHECK(e.system_task, "app and system tasks cannot be both empty"); e.system_task(); } } diff --git a/src/runtime/service_api_c.cpp b/src/runtime/service_api_c.cpp index f4ed022344..64cb58870f 100644 --- a/src/runtime/service_api_c.cpp +++ b/src/runtime/service_api_c.cpp @@ -240,7 +240,7 @@ bool dsn_run_config(const char *config, bool is_server) bool dsn_mimic_app(const char *app_role, int index) { auto worker = ::dsn::task::get_current_worker2(); - CHECK(worker == nullptr, "cannot call dsn_mimic_app in rDSN threads"); + PGSCHECK(worker == nullptr, "cannot call dsn_mimic_app in rDSN threads"); auto cnode = ::dsn::task::get_current_node2(); if (cnode != nullptr) { @@ -418,14 +418,14 @@ bool run(const char *config_file, // setup data dir auto &data_dir = spec.data_dir; - CHECK(!dsn::utils::filesystem::file_exists(data_dir), "{} should not be a file.", data_dir); + PGSCHECK(!dsn::utils::filesystem::file_exists(data_dir), "{} should not be a file.", data_dir); if (!dsn::utils::filesystem::directory_exists(data_dir)) { - CHECK(dsn::utils::filesystem::create_directory(data_dir), "Fail to create {}", data_dir); + PGSCHECK(dsn::utils::filesystem::create_directory(data_dir), "Fail to create {}", data_dir); } std::string cdir; - CHECK(dsn::utils::filesystem::get_absolute_path(data_dir, cdir), - "Fail to get absolute path from {}", - data_dir); + PGSCHECK(dsn::utils::filesystem::get_absolute_path(data_dir, cdir), + "Fail to get absolute path from {}", + data_dir); spec.data_dir = cdir; ::dsn::utils::coredump::init(); @@ -490,7 +490,7 @@ bool run(const char *config_file, for (const auto &toollet_name : spec.toollets) { auto tlet = dsn::tools::internal_use_only::get_toollet(toollet_name.c_str(), ::dsn::PROVIDER_TYPE_MAIN); - CHECK_NOTNULL(tlet, "toolet not found"); + PGSCHECK_NOTNULL(tlet, "toolet not found"); tlet->install(spec); } @@ -534,18 +534,18 @@ bool run(const char *config_file, for (const auto &app_name_and_index : app_names_and_indexes) { std::vector name_and_index; ::dsn::utils::split_args(app_name_and_index.c_str(), name_and_index, '@'); - CHECK(!name_and_index.empty(), - "app_name should be specified in '{}'", - app_name_and_index); + PGSCHECK(!name_and_index.empty(), + "app_name should be specified in '{}'", + app_name_and_index); if (std::string("apps.") + name_and_index.front() == sp.config_section) { if (name_and_index.size() < 2) { create_it = true; } else { int32_t index = 0; const auto index_str = name_and_index.back(); - CHECK(dsn::buf2int32(index_str, index), - "'{}' is not a valid index", - index_str); + PGSCHECK(dsn::buf2int32(index_str, index), + "'{}' is not a valid index", + index_str); create_it = (index == sp.index); } break; diff --git a/src/runtime/service_app.h b/src/runtime/service_app.h index 71e23fc6d7..3a7b67aca9 100644 --- a/src/runtime/service_app.h +++ b/src/runtime/service_app.h @@ -84,7 +84,7 @@ class service_app virtual error_code stop(bool cleanup = false) { return ERR_OK; } virtual void on_intercepted_request(gpid pid, bool is_write, dsn::message_ex *msg) { - CHECK(false, "not supported"); + PGSCHECK(false, "not supported"); } bool is_started() const { return _started; } diff --git a/src/runtime/service_engine.cpp b/src/runtime/service_engine.cpp index dee8a53342..d364ce204c 100644 --- a/src/runtime/service_engine.cpp +++ b/src/runtime/service_engine.cpp @@ -78,7 +78,7 @@ error_code service_node::init_rpc_engine() dsn::error_code service_node::start_app() { - CHECK(_entity, "entity hasn't initialized"); + PGSCHECK(_entity, "entity hasn't initialized"); _entity->set_host_port(rpc()->primary_host_port()); std::vector args; @@ -93,7 +93,7 @@ dsn::error_code service_node::start_app() dsn::error_code service_node::stop_app(bool cleanup) { - CHECK(_entity, "entity hasn't initialized"); + PGSCHECK(_entity, "entity hasn't initialized"); dsn::error_code res = _entity->stop(cleanup); if (res == dsn::ERR_OK) { _entity->set_started(false); @@ -124,7 +124,7 @@ error_code service_node::start() // init task engine _computation = std::make_unique(this); _computation->create(_app_spec.pools); - CHECK(!_computation->is_started(), "task engine must not be started at this point"); + PGSCHECK(!_computation->is_started(), "task engine must not be started at this point"); // init rpc err = init_rpc_engine(); @@ -133,7 +133,7 @@ error_code service_node::start() // start task engine _computation->start(); - CHECK(_computation->is_started(), "task engine must be started at this point"); + PGSCHECK(_computation->is_started(), "task engine must be started at this point"); // create service_app { @@ -225,12 +225,12 @@ void service_engine::start_node(service_app_spec &app_spec) // union to existing node if any port is shared auto it = app_name_by_port.find(p); if (it != app_name_by_port.end()) { - CHECK(false, - "network port {} usage confliction for {} vs {}, " - "please reconfig", - p, - it->second, - app_spec.full_name); + PGSCHECK(false, + "network port {} usage confliction for {} vs {}, " + "please reconfig", + p, + it->second, + app_spec.full_name); } app_name_by_port.emplace(p, app_spec.full_name); } diff --git a/src/runtime/task/simple_task_queue.cpp b/src/runtime/task/simple_task_queue.cpp index 879a9700c6..d8a063e123 100644 --- a/src/runtime/task/simple_task_queue.cpp +++ b/src/runtime/task/simple_task_queue.cpp @@ -76,7 +76,7 @@ void simple_timer_service::start() boost::asio::io_service::work work(_ios); boost::system::error_code ec; _ios.run(ec); - CHECK(!ec, "io_service in simple_timer_service run failed: {}", ec.message()); + PGSCHECK(!ec, "io_service in simple_timer_service run failed: {}", ec.message()); }); _is_running = true; } @@ -122,7 +122,7 @@ task *simple_task_queue::dequeue(/*inout*/ int &batch_size) { long c = 0; auto t = _samples.dequeue(c); - CHECK_NOTNULL(t, "dequeue does not return empty tasks"); + PGSCHECK_NOTNULL(t, "dequeue does not return empty tasks"); batch_size = 1; return t; } diff --git a/src/runtime/task/task.cpp b/src/runtime/task/task.cpp index 7d83948f3b..00e03bf001 100644 --- a/src/runtime/task/task.cpp +++ b/src/runtime/task/task.cpp @@ -61,10 +61,10 @@ __thread uint16_t tls_dsn_lower32_task_id_mask = 0; tls_dsn.node_id = node->id(); if (worker != nullptr) { - CHECK(worker->pool()->node() == node, - "worker not belonging to the given node: {} vs {}", - worker->pool()->node()->full_name(), - node->full_name()); + PGSCHECK(worker->pool()->node() == node, + "worker not belonging to the given node: {} vs {}", + worker->pool()->node()->full_name(), + node->full_name()); } tls_dsn.node = node; @@ -91,17 +91,17 @@ __thread uint16_t tls_dsn_lower32_task_id_mask = 0; /*static*/ void task::on_tls_dsn_not_set() { - CHECK(service_engine::instance().spec().enable_default_app_mimic, - "rDSN context is not initialized properly, to be fixed as follows:\n" - "(1). the current thread does NOT belongs to any rDSN service node, please invoke " - "dsn_mimic_app first,\n" - " or, you can enable [core] enable_default_app_mimic = true in your config " - "file so mimic_app can be omitted\n" - "(2). the current thread belongs to a rDSN service node, and you are writing " - "providers for rDSN, please use\n" - " task::set_tls_dsn_context(...) at the beginning of your new thread in your " - "providers;\n" - "(3). this should not happen, please help fire an issue so we we can investigate"); + PGSCHECK(service_engine::instance().spec().enable_default_app_mimic, + "rDSN context is not initialized properly, to be fixed as follows:\n" + "(1). the current thread does NOT belongs to any rDSN service node, please invoke " + "dsn_mimic_app first,\n" + " or, you can enable [core] enable_default_app_mimic = true in your config " + "file so mimic_app can be omitted\n" + "(2). the current thread belongs to a rDSN service node, and you are writing " + "providers for rDSN, please use\n" + " task::set_tls_dsn_context(...) at the beginning of your new thread in your " + "providers;\n" + "(3). this should not happen, please help fire an issue so we we can investigate"); dsn_mimic_app("mimic", 1); } @@ -119,9 +119,9 @@ task::task(dsn::task_code code, int hash, service_node *node) _node = node; } else { auto p = get_current_node(); - CHECK_NOTNULL(p, - "tasks without explicit service node can only be created " - "inside threads which is attached to specific node"); + PGSCHECK_NOTNULL(p, + "tasks without explicit service node can only be created " + "inside threads which is attached to specific node"); _node = p; } @@ -271,7 +271,7 @@ bool task::wait_on_cancel() bool task::wait(int timeout_milliseconds) { - CHECK(this != task::get_current_task(), "task cannot wait itself"); + PGSCHECK(this != task::get_current_task(), "task cannot wait itself"); auto cs = state(); @@ -326,7 +326,7 @@ bool task::cancel(bool wait_until_finished, /*out*/ bool *finished /*= nullptr*/ finish = true; } else if (wait_until_finished) { _wait_for_cancel = true; - CHECK( + PGSCHECK( wait_on_cancel(), "wait failed, it is only possible when task runs for more than 0x0fffffff ms"); @@ -372,7 +372,7 @@ const char *task::get_current_node_name() void task::enqueue() { - CHECK_NOTNULL(_node, "service node unknown for this task"); + PGSCHECK_NOTNULL(_node, "service node unknown for this task"); CHECK_NE_MSG(_spec->type, TASK_TYPE_RPC_RESPONSE, "tasks with TASK_TYPE_RPC_RESPONSE type use task::enqueue(caller_pool()) instead"); @@ -386,14 +386,14 @@ void task::enqueue(task_worker_pool *pool) { this->add_ref(); // released in exec_internal (even when cancelled) - CHECK_NOTNULL(pool, - "pool {} not ready, and there are usually two cases: " - "(1). thread pool not designatd in '[{}] pools'; " - "(2). the caller is executed in io threads " - "which is forbidden unless you explicitly set [task.{}].allow_inline = true", - _spec->pool_code, - _node->spec().config_section, - _spec->name); + PGSCHECK_NOTNULL(pool, + "pool {} not ready, and there are usually two cases: " + "(1). thread pool not designatd in '[{}] pools'; " + "(2). the caller is executed in io threads " + "which is forbidden unless you explicitly set [task.{}].allow_inline = true", + _spec->pool_code, + _node->spec().config_section, + _spec->name); if (spec().type == TASK_TYPE_COMPUTE) { spec().on_task_enqueue.execute(get_current_task(), this); @@ -407,7 +407,7 @@ void task::enqueue(task_worker_pool *pool) // fast execution if (_is_null) { - CHECK(_node == task::get_current_node(), ""); + PGSCHECK(_node == task::get_current_node(), ""); exec_internal(); return; } @@ -478,9 +478,9 @@ void timer_task::exec() } // valid interval, we reset task state to READY if (dsn_likely(_interval_ms > 0)) { - CHECK(set_retry(true), - "timer task set retry failed, with state = {}", - enum_to_string(state())); + PGSCHECK(set_retry(true), + "timer task set retry failed, with state = {}", + enum_to_string(state())); set_delay(_interval_ms); } } diff --git a/src/runtime/task/task.h b/src/runtime/task/task.h index 68b41bf625..dafab826f5 100644 --- a/src/runtime/task/task.h +++ b/src/runtime/task/task.h @@ -506,9 +506,9 @@ class rpc_response_task : public task void replace_callback(rpc_response_handler &&cb) { task_state cur_state = state(); - CHECK(cur_state == TASK_STATE_READY || cur_state == TASK_STATE_RUNNING, - "invalid task_state: {}", - enum_to_string(cur_state)); + PGSCHECK(cur_state == TASK_STATE_READY || cur_state == TASK_STATE_RUNNING, + "invalid task_state: {}", + enum_to_string(cur_state)); _cb = std::move(cb); } void replace_callback(const rpc_response_handler &cb) diff --git a/src/runtime/task/task_engine.cpp b/src/runtime/task/task_engine.cpp index 138afedac7..7bb952b0fa 100644 --- a/src/runtime/task/task_engine.cpp +++ b/src/runtime/task/task_engine.cpp @@ -148,15 +148,15 @@ void task_worker_pool::add_timer(task *t) void task_worker_pool::enqueue(task *t) { - CHECK(t->spec().pool_code == spec().pool_code || t->spec().type == TASK_TYPE_RPC_RESPONSE, - "Invalid thread pool used"); + PGSCHECK(t->spec().pool_code == spec().pool_code || t->spec().type == TASK_TYPE_RPC_RESPONSE, + "Invalid thread pool used"); CHECK_EQ_MSG( t->delay_milliseconds(), 0, "task delayed should be dispatched to timer service first"); - CHECK(_is_running, - "worker pool {} must be started before enqueue task {}", - spec().name, - t->spec().name); + PGSCHECK(_is_running, + "worker pool {} must be started before enqueue task {}", + spec().name, + t->spec().name); unsigned int idx = (_spec.partitioned ? static_cast(t->hash()) % static_cast(_queues.size()) : 0); diff --git a/src/runtime/task/task_engine.sim.cpp b/src/runtime/task/task_engine.sim.cpp index 1703001817..768a8abd81 100644 --- a/src/runtime/task/task_engine.sim.cpp +++ b/src/runtime/task/task_engine.sim.cpp @@ -147,7 +147,7 @@ void sim_lock_provider::lock() _sema.wait(TIME_MS_MAX); - CHECK(-1 == _current_holder && _lock_depth == 0, "must be unlocked state"); + PGSCHECK(-1 == _current_holder && _lock_depth == 0, "must be unlocked state"); _current_holder = ctid; ++_lock_depth; } @@ -166,7 +166,7 @@ bool sim_lock_provider::try_lock() bool r = _sema.wait(0); if (r) { - CHECK(-1 == _current_holder && _lock_depth == 0, "must be unlocked state"); + PGSCHECK(-1 == _current_holder && _lock_depth == 0, "must be unlocked state"); _current_holder = ctid; ++_lock_depth; } @@ -210,7 +210,7 @@ void sim_lock_nr_provider::lock() _sema.wait(TIME_MS_MAX); - CHECK(-1 == _current_holder && _lock_depth == 0, "must be unlocked state"); + PGSCHECK(-1 == _current_holder && _lock_depth == 0, "must be unlocked state"); _current_holder = ctid; ++_lock_depth; } @@ -226,7 +226,7 @@ bool sim_lock_nr_provider::try_lock() bool r = _sema.wait(0); if (r) { - CHECK(-1 == _current_holder && _lock_depth == 0, "must be unlocked state"); + PGSCHECK(-1 == _current_holder && _lock_depth == 0, "must be unlocked state"); _current_holder = ctid; ++_lock_depth; } diff --git a/src/runtime/task/task_queue.cpp b/src/runtime/task/task_queue.cpp index b22e01bdb8..8482afbdcb 100644 --- a/src/runtime/task/task_queue.cpp +++ b/src/runtime/task/task_queue.cpp @@ -131,10 +131,10 @@ void task_queue::enqueue_internal(task *task) const metric_entity_ptr &task_queue::queue_metric_entity() const { - CHECK_NOTNULL(_queue_metric_entity, - "queue metric entity (queue_name={}) should has been instantiated: " - "uninitialized entity cannot be used to instantiate metric", - _name); + PGSCHECK_NOTNULL(_queue_metric_entity, + "queue metric entity (queue_name={}) should has been instantiated: " + "uninitialized entity cannot be used to instantiate metric", + _name); return _queue_metric_entity; } diff --git a/src/runtime/task/task_spec.cpp b/src/runtime/task/task_spec.cpp index 096b0bd1b0..51f652d175 100644 --- a/src/runtime/task/task_spec.cpp +++ b/src/runtime/task/task_spec.cpp @@ -206,7 +206,7 @@ bool task_spec::init() std::string section_name = std::string("task.") + std::string(dsn::task_code(code).to_string()); task_spec *spec = task_spec::get(code); - CHECK_NOTNULL(spec, ""); + PGSCHECK_NOTNULL(spec, ""); if (!read_config(section_name.c_str(), *spec, &default_spec)) return false; @@ -215,9 +215,9 @@ bool task_spec::init() spec->allow_inline = true; } - CHECK(spec->rpc_request_delays_milliseconds.size() == 0 || - spec->rpc_request_delays_milliseconds.size() == 6, - "invalid length of rpc_request_delays_milliseconds, must be of length 6"); + PGSCHECK(spec->rpc_request_delays_milliseconds.size() == 0 || + spec->rpc_request_delays_milliseconds.size() == 6, + "invalid length of rpc_request_delays_milliseconds, must be of length 6"); if (spec->rpc_request_delays_milliseconds.size() > 0) { spec->rpc_request_delayer.initialize(spec->rpc_request_delays_milliseconds); } diff --git a/src/runtime/task/task_tracker.h b/src/runtime/task/task_tracker.h index dd510f7ffc..d5cd70fc24 100644 --- a/src/runtime/task/task_tracker.h +++ b/src/runtime/task/task_tracker.h @@ -176,7 +176,7 @@ class task_tracker // ------- inlined implementation ---------- inline void trackable_task::set_tracker(task_tracker *owner, task *tsk) { - CHECK(_owner == nullptr, "task tracker is already set"); + PGSCHECK(_owner == nullptr, "task tracker is already set"); _owner = owner; _task = tsk; _deleting_owner.store(OWNER_DELETE_NOT_LOCKED, std::memory_order_release); diff --git a/src/runtime/test/CMakeLists.txt b/src/runtime/test/CMakeLists.txt index 83e355c449..cf97b10f46 100644 --- a/src/runtime/test/CMakeLists.txt +++ b/src/runtime/test/CMakeLists.txt @@ -33,7 +33,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy - gtest) + gtest + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) set(MY_BINPLACES config-test-corrupt-message.ini diff --git a/src/runtime/test/rpc.cpp b/src/runtime/test/rpc.cpp index 3682ca5789..a96eb8a6c7 100644 --- a/src/runtime/test/rpc.cpp +++ b/src/runtime/test/rpc.cpp @@ -54,7 +54,7 @@ static dsn::rpc_address build_group() server_group.assign_group("server_group.test"); dsn::rpc_group_address *g = server_group.group_address(); for (uint16_t p = TEST_PORT_BEGIN; p <= TEST_PORT_END; ++p) { - CHECK(g->add(dsn::rpc_address::from_host_port("localhost", p)), ""); + CHECK(g->add(dsn::rpc_address::from_host_port("localhost", p))); } g->set_leader(dsn::rpc_address::from_host_port("localhost", TEST_PORT_BEGIN)); diff --git a/src/runtime/tracer.cpp b/src/runtime/tracer.cpp index e85d88ed5f..8e7392271b 100644 --- a/src/runtime/tracer.cpp +++ b/src/runtime/tracer.cpp @@ -303,7 +303,7 @@ void tracer::install(service_spec &spec) std::string section_name = fmt::format("task.{}", dsn::task_code(i)); task_spec *spec = task_spec::get(i); - CHECK_NOTNULL(spec, ""); + PGSCHECK_NOTNULL(spec, ""); if (!dsn_config_get_value_bool(section_name.c_str(), "is_trace", diff --git a/src/sample/CMakeLists.txt b/src/sample/CMakeLists.txt index 294a671115..81c8670a46 100644 --- a/src/sample/CMakeLists.txt +++ b/src/sample/CMakeLists.txt @@ -24,7 +24,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::filesystem Boost::system) diff --git a/src/security/access_controller.cpp b/src/security/access_controller.cpp index 2d74e8f4a5..fb1fa691dc 100644 --- a/src/security/access_controller.cpp +++ b/src/security/access_controller.cpp @@ -45,8 +45,8 @@ access_controller::access_controller() { // when FLAGS_enable_ranger_acl is true, FLAGS_enable_acl must be true. // TODO(wanghao): check with DSN_DEFINE_group_validator(). - CHECK(!FLAGS_enable_ranger_acl || FLAGS_enable_acl, - "when FLAGS_enable_ranger_acl is true, FLAGS_enable_acl must be true too"); + PGSCHECK(!FLAGS_enable_ranger_acl || FLAGS_enable_acl, + "when FLAGS_enable_ranger_acl is true, FLAGS_enable_acl must be true too"); utils::split_args(FLAGS_super_users, _super_users, ','); } diff --git a/src/security/kinit_context.cpp b/src/security/kinit_context.cpp index 2347e7abb5..2ab8e7a4ed 100644 --- a/src/security/kinit_context.cpp +++ b/src/security/kinit_context.cpp @@ -66,9 +66,9 @@ class kinit_context; // will not pass. error_s check_configuration() { - CHECK(FLAGS_enable_auth || FLAGS_enable_zookeeper_kerberos, - "There is no need to check configuration if FLAGS_enable_auth" - " and FLAGS_enable_zookeeper_kerberos both are not true"); + PGSCHECK(FLAGS_enable_auth || FLAGS_enable_zookeeper_kerberos, + "There is no need to check configuration if FLAGS_enable_auth" + " and FLAGS_enable_zookeeper_kerberos both are not true"); if (utils::is_empty(FLAGS_krb5_keytab) || !utils::filesystem::file_exists(FLAGS_krb5_keytab)) { return error_s::make(ERR_INVALID_PARAMETERS, @@ -304,7 +304,7 @@ void kinit_context::schedule_renew_credentials() } else if (err == boost::system::errc::operation_canceled) { LOG_WARNING("the renew credentials timer is cancelled"); } else { - CHECK(false, "unhandled error({})", err.message()); + PGSCHECK(false, "unhandled error({})", err.message()); } }); } diff --git a/src/security/negotiation_manager.cpp b/src/security/negotiation_manager.cpp index 22a4098f52..e42145a2d5 100644 --- a/src/security/negotiation_manager.cpp +++ b/src/security/negotiation_manager.cpp @@ -67,8 +67,8 @@ void negotiation_manager::open_service() void negotiation_manager::on_negotiation_request(negotiation_rpc rpc) { - CHECK(!rpc.dsn_request()->io_session->is_client(), - "only server session receives negotiation request"); + PGSCHECK(!rpc.dsn_request()->io_session->is_client(), + "only server session receives negotiation request"); // reply SASL_AUTH_DISABLE if auth is not enable if (!FLAGS_enable_auth) { @@ -85,8 +85,8 @@ void negotiation_manager::on_negotiation_request(negotiation_rpc rpc) void negotiation_manager::on_negotiation_response(error_code err, negotiation_rpc rpc) { - CHECK(rpc.dsn_request()->io_session->is_client(), - "only client session receives negotiation response"); + PGSCHECK(rpc.dsn_request()->io_session->is_client(), + "only client session receives negotiation response"); std::shared_ptr nego = get_negotiation(rpc); if (nullptr != nego) { diff --git a/src/security/sasl_init.cpp b/src/security/sasl_init.cpp index 1f9712c34c..33004225a3 100644 --- a/src/security/sasl_init.cpp +++ b/src/security/sasl_init.cpp @@ -17,6 +17,7 @@ #include "sasl_init.h" +#include #include #include #include @@ -33,18 +34,18 @@ DSN_DEFINE_string(security, sasl_plugin_path, "/usr/lib/sasl2", "path to search namespace dsn { namespace security { -log_level_t get_log_level(int level) +google::LogSeverity get_log_level(int level) { switch (level) { case SASL_LOG_ERR: - return LOG_LEVEL_ERROR; + return google::ERROR; case SASL_LOG_FAIL: case SASL_LOG_WARN: - return LOG_LEVEL_WARNING; + return google::WARNING; case SASL_LOG_NOTE: - return LOG_LEVEL_INFO; + return google::INFO; default: - return LOG_LEVEL_DEBUG; + return google::INFO; } } @@ -54,7 +55,7 @@ int sasl_simple_logger(void *context, int level, const char *msg) return SASL_OK; } - LOG(get_log_level(level), "sasl log info: {}", msg); + // LOG(get_log_level(level)) << "sasl log info: " << msg; return SASL_OK; } @@ -82,7 +83,7 @@ int sasl_get_username(void *context, int id, const char **result, unsigned *len) } return SASL_OK; default: - CHECK(false, "unexpected SASL callback type: {}", id); + PGSCHECK(false, "unexpected SASL callback type: {}", id); return SASL_BADPARAM; } } diff --git a/src/security/test/CMakeLists.txt b/src/security/test/CMakeLists.txt index a7c4e6a5a9..a8a9972285 100644 --- a/src/security/test/CMakeLists.txt +++ b/src/security/test/CMakeLists.txt @@ -28,7 +28,9 @@ set(MY_PROJ_LIBS dsn_runtime dsn_utils gtest - rocksdb) + rocksdb + glog + gflags) set(MY_BINPLACES config.ini run.sh) diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index fbb990e4ac..77cc239683 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -42,7 +42,10 @@ set(REPLICA_SERVER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/rocksdb_wrapper.cpp) set(SERVER_COMMON_LIBS - dsn_utils) + dsn_dist_cmd + dsn_utils + glog + gflags) set(COLLECTOR_LIBS ${SERVER_COMMON_LIBS} dsn_meta_server diff --git a/src/server/available_detector.cpp b/src/server/available_detector.cpp index 1052b0ff7a..7a5c92af7c 100644 --- a/src/server/available_detector.cpp +++ b/src/server/available_detector.cpp @@ -100,16 +100,16 @@ available_detector::available_detector() _cluster_name = dsn::get_current_cluster_name(); _meta_list.clear(); dsn::replication::replica_helper::parse_server_list(FLAGS_server_list, _meta_list); - CHECK(!_meta_list.empty(), ""); + PGSCHECK(!_meta_list.empty(), ""); // initialize the _client. if (!pegasus_client_factory::initialize(nullptr)) { - CHECK(false, "Initialize the pegasus client failed"); + PGSCHECK(false, "Initialize the pegasus client failed"); } _client = pegasus_client_factory::get_client(_cluster_name.c_str(), FLAGS_available_detect_app); - CHECK_NOTNULL(_client, "Initialize the _client failed"); + PGSCHECK_NOTNULL(_client, "Initialize the _client failed"); _result_writer = std::make_unique(_client); _ddl_client.reset(new replication_ddl_client(_meta_list)); - CHECK_NOTNULL(_ddl_client, "Initialize the _ddl_client failed"); + PGSCHECK_NOTNULL(_ddl_client, "Initialize the _ddl_client failed"); if (!dsn::utils::is_empty(FLAGS_available_detect_alert_email_address)) { _send_alert_email_cmd = std::string("cd ") + FLAGS_available_detect_alert_script_dir + "; bash sendmail.sh alert " + diff --git a/src/server/capacity_unit_calculator.cpp b/src/server/capacity_unit_calculator.cpp index 8a4745f4ba..75a3bd07c7 100644 --- a/src/server/capacity_unit_calculator.cpp +++ b/src/server/capacity_unit_calculator.cpp @@ -127,9 +127,9 @@ capacity_unit_calculator::capacity_unit_calculator( _write_hotkey_collector(write_hotkey_collector), _read_size_throttling_controller(read_size_throttling_controller) { - CHECK(_read_hotkey_collector, "read hotkey collector is a nullptr"); - CHECK(_write_hotkey_collector, "write hotkey collector is a nullptr"); - CHECK(_read_size_throttling_controller, "_read_size_throttling_controller is a nullptr"); + PGSCHECK(_read_hotkey_collector, "read hotkey collector is a nullptr"); + PGSCHECK(_write_hotkey_collector, "write hotkey collector is a nullptr"); + PGSCHECK(_read_size_throttling_controller, "_read_size_throttling_controller is a nullptr"); _log_read_cu_size = log(FLAGS_perf_counter_read_capacity_unit_size) / log(2); _log_write_cu_size = log(FLAGS_perf_counter_write_capacity_unit_size) / log(2); diff --git a/src/server/hotkey_collector.cpp b/src/server/hotkey_collector.cpp index ca67a74d03..7f14439f08 100644 --- a/src/server/hotkey_collector.cpp +++ b/src/server/hotkey_collector.cpp @@ -290,7 +290,7 @@ void hotkey_collector::on_start_detect(dsn::replication::detect_hotkey_response resp.err = dsn::ERR_INVALID_STATE; resp.__set_err_hint(hint); LOG_ERROR_PREFIX(hint); - CHECK(false, "invalid collector state"); + PGSCHECK(false, "invalid collector state"); } resp.__set_err_hint(hint); LOG_WARNING_PREFIX(hint); diff --git a/src/server/info_collector.cpp b/src/server/info_collector.cpp index c2b1fe0943..6f7d6277cf 100644 --- a/src/server/info_collector.cpp +++ b/src/server/info_collector.cpp @@ -78,7 +78,7 @@ info_collector::info_collector() _meta_servers.assign_group("meta-servers"); for (auto &ms : meta_servers) { - CHECK(_meta_servers.group_host_port()->add(ms), ""); + PGSCHECK(_meta_servers.group_host_port()->add(ms), ""); } _cluster_name = dsn::get_current_cluster_name(); @@ -89,9 +89,9 @@ info_collector::info_collector() _shell_context->ddl_client.reset(new replication_ddl_client(meta_servers)); // initialize the _client. - CHECK(pegasus_client_factory::initialize(nullptr), "Initialize the pegasus client failed"); + PGSCHECK(pegasus_client_factory::initialize(nullptr), "Initialize the pegasus client failed"); _client = pegasus_client_factory::get_client(_cluster_name.c_str(), FLAGS_usage_stat_app); - CHECK_NOTNULL(_client, "Initialize the client failed"); + PGSCHECK_NOTNULL(_client, "Initialize the client failed"); _result_writer = std::make_unique(_client); // _capacity_unit_retry_wait_seconds is in range of [1, 10] diff --git a/src/server/pegasus_server_impl.cpp b/src/server/pegasus_server_impl.cpp index ffb4b8c1c9..6e1efa18df 100644 --- a/src/server/pegasus_server_impl.cpp +++ b/src/server/pegasus_server_impl.cpp @@ -217,7 +217,7 @@ void pegasus_server_impl::parse_checkpoints() pegasus_server_impl::~pegasus_server_impl() { if (_is_open) { - CHECK_NOTNULL(_db, ""); + CHECK_NOTNULL(_db); release_db(); } } @@ -355,8 +355,8 @@ int pegasus_server_impl::on_batched_write_requests(int64_t decree, dsn::message_ex **requests, int count) { - CHECK(_is_open, ""); - CHECK_NOTNULL(requests, ""); + CHECK(_is_open); + CHECK_NOTNULL(requests); return _server_write->on_batched_write_requests(requests, count, decree, timestamp); } @@ -1084,7 +1084,7 @@ void pegasus_server_impl::on_sortkey_count(sortkey_count_rpc rpc) void pegasus_server_impl::on_ttl(ttl_rpc rpc) { - CHECK(_is_open, ""); + CHECK(_is_open); const auto &key = rpc.request(); auto &resp = rpc.response(); @@ -1209,9 +1209,9 @@ void pegasus_server_impl::on_get_scanner(get_scanner_rpc rpc) // hashkey, we should not seek this prefix by prefix bloom filter. However, it only // happen when do full scan (scanners got by get_unordered_scanners), in which case the // following flags has been updated. - CHECK(!_data_cf_opts.prefix_extractor || rd_opts.total_order_seek, "Invalid option"); - CHECK(!_data_cf_opts.prefix_extractor || !rd_opts.prefix_same_as_start, - "Invalid option"); + PGSCHECK(!_data_cf_opts.prefix_extractor || rd_opts.total_order_seek, "Invalid option"); + PGSCHECK(!_data_cf_opts.prefix_extractor || !rd_opts.prefix_same_as_start, + "Invalid option"); } } @@ -1855,7 +1855,7 @@ dsn::error_code pegasus_server_impl::start(int argc, char **argv) void pegasus_server_impl::cancel_background_work(bool wait) { if (_is_open) { - CHECK_NOTNULL(_db, ""); + CHECK_NOTNULL(_db); rocksdb::CancelAllBackgroundWork(_db, wait); } } @@ -1863,8 +1863,8 @@ void pegasus_server_impl::cancel_background_work(bool wait) ::dsn::error_code pegasus_server_impl::stop(bool clear_state) { if (!_is_open) { - CHECK(_db == nullptr, ""); - CHECK(!clear_state, "should not be here if do clear"); + CHECK_EQ(_db, nullptr); + PGSCHECK(!clear_state, "should not be here if do clear"); return ::dsn::ERR_OK; } @@ -2226,7 +2226,7 @@ ::dsn::error_code pegasus_server_impl::get_checkpoint(int64_t learn_start, const dsn::blob &learn_request, dsn::replication::learn_state &state) { - CHECK(_is_open, ""); + CHECK(_is_open); int64_t ci = last_durable_decree(); if (ci == 0) { @@ -2320,7 +2320,7 @@ pegasus_server_impl::storage_apply_checkpoint(chkpt_apply_mode mode, return err; } - CHECK(_is_open, ""); + CHECK(_is_open); CHECK_EQ(ci, last_durable_decree()); LOG_INFO_PREFIX("apply checkpoint succeed, last_durable_decree = {}", last_durable_decree()); @@ -2365,7 +2365,7 @@ bool pegasus_server_impl::validate_filter(::dsn::apps::filter_type::type filter_ } } default: - CHECK(false, "unsupported filter type: {}", filter_type); + PGSCHECK(false, "unsupported filter type: {}", filter_type); } return false; } diff --git a/src/server/pegasus_server_impl_init.cpp b/src/server/pegasus_server_impl_init.cpp index d679d6ce3d..ed2d37ecd6 100644 --- a/src/server/pegasus_server_impl_init.cpp +++ b/src/server/pegasus_server_impl_init.cpp @@ -688,16 +688,16 @@ pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r) _data_cf_opts.level0_slowdown_writes_trigger = FLAGS_rocksdb_level0_slowdown_writes_trigger; _data_cf_opts.level0_stop_writes_trigger = FLAGS_rocksdb_level0_stop_writes_trigger; - CHECK(parse_compression_types(FLAGS_rocksdb_compression_type, - _data_cf_opts.compression_per_level), - "parse rocksdb_compression_type failed."); + PGSCHECK(parse_compression_types(FLAGS_rocksdb_compression_type, + _data_cf_opts.compression_per_level), + "parse rocksdb_compression_type failed."); _meta_cf_opts = _data_cf_opts; // Set level0_file_num_compaction_trigger of meta CF as 10 to reduce frequent compaction. _meta_cf_opts.level0_file_num_compaction_trigger = 10; // Data in meta CF is very little, disable compression to save CPU load. - CHECK(parse_compression_types("none", _meta_cf_opts.compression_per_level), - "parse rocksdb_compression_type failed."); + PGSCHECK(parse_compression_types("none", _meta_cf_opts.compression_per_level), + "parse rocksdb_compression_type failed."); _tbl_opts.read_amp_bytes_per_bit = FLAGS_read_amp_bytes_per_bit; @@ -770,9 +770,9 @@ pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r) LOG_INFO_PREFIX("rocksdb_keep_log_file_num = {}", _db_opts.keep_log_file_num); auto index_type_item = INDEX_TYPE_STRING_MAP.find(FLAGS_rocksdb_index_type); - CHECK(index_type_item != INDEX_TYPE_STRING_MAP.end(), - "[pegasus.server]rocksdb_index_type should be one among binary_search, " - "hash_search, two_level_index_search or binary_search_with_first_key."); + PGSCHECK(index_type_item != INDEX_TYPE_STRING_MAP.end(), + "[pegasus.server]rocksdb_index_type should be one among binary_search, " + "hash_search, two_level_index_search or binary_search_with_first_key."); _tbl_opts.index_type = index_type_item->second; LOG_INFO_PREFIX("rocksdb_index_type = {}", FLAGS_rocksdb_index_type); diff --git a/src/server/pegasus_server_write.cpp b/src/server/pegasus_server_write.cpp index 33437ca692..07a76daddd 100644 --- a/src/server/pegasus_server_write.cpp +++ b/src/server/pegasus_server_write.cpp @@ -101,7 +101,7 @@ int pegasus_server_write::on_batched_writes(dsn::message_ex **requests, int coun _write_svc->batch_prepare(_decree); for (int i = 0; i < count; ++i) { - CHECK_NOTNULL(requests[i], "request[{}] is null", i); + PGSCHECK_NOTNULL(requests[i], "request[{}] is null", i); // Make sure all writes are batched even if they are failed, // since we need to record the total qps and rpc latencies, diff --git a/src/server/pegasus_write_service.cpp b/src/server/pegasus_write_service.cpp index 2fb5733265..c0267744e8 100644 --- a/src/server/pegasus_write_service.cpp +++ b/src/server/pegasus_write_service.cpp @@ -316,7 +316,7 @@ int pegasus_write_service::batch_commit(int64_t decree) void pegasus_write_service::batch_abort(int64_t decree, int err) { CHECK_GT_MSG(_batch_start_time, 0, "batch_abort must be called after batch_prepare"); - CHECK(err, "must abort on non-zero err"); + PGSCHECK(err, "must abort on non-zero err"); _impl->batch_abort(decree, err); clear_up_batch_states(); diff --git a/src/server/pegasus_write_service_impl.h b/src/server/pegasus_write_service_impl.h index 35a9c6399d..ce7133fff1 100644 --- a/src/server/pegasus_write_service_impl.h +++ b/src/server/pegasus_write_service_impl.h @@ -673,7 +673,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base } } default: - CHECK(false, "unsupported check type: {}", check_type); + PGSCHECK(false, "unsupported check type: {}", check_type); } return false; } diff --git a/src/server/test/CMakeLists.txt b/src/server/test/CMakeLists.txt index 082a98c1e4..a1b5994814 100644 --- a/src/server/test/CMakeLists.txt +++ b/src/server/test/CMakeLists.txt @@ -52,7 +52,9 @@ set(MY_PROJ_LIBS pegasus_base gtest gmock - hashtable) + hashtable + glog + gflags) add_definitions(-DPEGASUS_UNIT_TEST) add_definitions(-DENABLE_FAIL) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/server/test/pegasus_server_test_base.h b/src/server/test/pegasus_server_test_base.h index 00a46cf753..2fde10e639 100644 --- a/src/server/test/pegasus_server_test_base.h +++ b/src/server/test/pegasus_server_test_base.h @@ -65,13 +65,13 @@ class pegasus_server_test_base : public pegasus::encrypt_data_test_base app_info.app_type = "pegasus"; auto *dn = _replica_stub->get_fs_manager()->find_best_dir_for_new_replica(_gpid); - CHECK_NOTNULL(dn, ""); + PGSCHECK_NOTNULL(dn, ""); _replica = new dsn::replication::replica(_replica_stub, _gpid, app_info, dn, false, false); const auto dir_data = dsn::utils::filesystem::path_combine( _replica->dir(), dsn::replication::replication_app_base::kDataDir); - CHECK(dsn::utils::filesystem::create_directory(dir_data), - "create data dir {} failed", - dir_data); + PGSCHECK(dsn::utils::filesystem::create_directory(dir_data), + "create data dir {} failed", + dir_data); _server = std::make_unique(_replica); } diff --git a/src/server/test/rocksdb_wrapper_test.cpp b/src/server/test/rocksdb_wrapper_test.cpp index 7831afc713..089a1a6f7e 100644 --- a/src/server/test/rocksdb_wrapper_test.cpp +++ b/src/server/test/rocksdb_wrapper_test.cpp @@ -86,7 +86,7 @@ class rocksdb_wrapper_test : public pegasus_server_test_base app_info.duplicating = true; auto *dn = _replica_stub->get_fs_manager()->find_best_dir_for_new_replica(_gpid); - CHECK_NOTNULL(dn, ""); + PGSCHECK_NOTNULL(dn, ""); _replica = new dsn::replication::replica(_replica_stub, _gpid, app_info, dn, false, false); _server = std::make_unique(_replica); diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index 830515c676..882d7f482e 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -35,6 +35,7 @@ set(MY_PROJ_LIBS dsn.block_service.hdfs dsn.block_service dsn.failure_detector + dsn_dist_cmd pegasus_client_static pegasus_geo_lib rocksdb @@ -45,7 +46,9 @@ set(MY_PROJ_LIBS absl::strings s2 hdfs - curl) + curl + glog + gflags) set(MY_BINPLACES ${CMAKE_CURRENT_SOURCE_DIR}/config.ini) diff --git a/src/shell/command_helper.h b/src/shell/command_helper.h index 3e3b11ca45..50f788b287 100644 --- a/src/shell/command_helper.h +++ b/src/shell/command_helper.h @@ -1647,9 +1647,9 @@ inline std::unique_ptr create_table_aggregate_stats_calcs } const auto &iter = pcs_by_appid.find(row.app_id); - CHECK(iter != pcs_by_appid.end(), - "table could not be found in pcs_by_appid: table_id={}", - row.app_id); + PGSCHECK(iter != pcs_by_appid.end(), + "table could not be found in pcs_by_appid: table_id={}", + row.app_id); for (const auto &pc : iter->second) { if (pc.hp_primary != node) { @@ -2121,7 +2121,7 @@ inline bool get_capacity_unit_stat(shell_context *sc, int32_t app_id, pidx; std::string counter_name; bool r = parse_app_pegasus_perf_counter_name(m.name, app_id, pidx, counter_name); - CHECK(r, "name = {}", m.name); + PGSCHECK(r, "name = {}", m.name); if (counter_name == "recent.read.cu") { nodes_stat[i].cu_value_by_app[app_id].first += (int64_t)m.value; } else if (counter_name == "recent.write.cu") { @@ -2185,7 +2185,7 @@ inline bool get_storage_size_stat(shell_context *sc, app_storage_size_stat &st_s std::string counter_name; bool parse_ret = parse_app_pegasus_perf_counter_name( m.name, app_id_x, partition_index_x, counter_name); - CHECK(parse_ret, "name = {}", m.name); + PGSCHECK(parse_ret, "name = {}", m.name); if (counter_name != "disk.storage.sst(MB)") continue; auto find = pcs_by_appid.find(app_id_x); diff --git a/src/shell/commands/data_operations.cpp b/src/shell/commands/data_operations.cpp index 2c36739c27..ce2982eaa4 100644 --- a/src/shell/commands/data_operations.cpp +++ b/src/shell/commands/data_operations.cpp @@ -115,7 +115,7 @@ bool data_operations(command_executor *e, shell_context *sc, arguments args) } auto iter = data_operations_map.find(args.argv[0]); - CHECK(iter != data_operations_map.end(), "filter should done earlier"); + PGSCHECK(iter != data_operations_map.end(), "filter should done earlier"); executor func = iter->second; if (sc->current_app_name.empty()) { @@ -2444,7 +2444,7 @@ bool count_data(command_executor *e, shell_context *sc, arguments args) std::vector rows; const std::string table_name(sc->pg_client->get_app_name()); - CHECK(!table_name.empty(), "table_name must be non-empty, see data_operations()"); + PGSCHECK(!table_name.empty(), "table_name must be non-empty, see data_operations()"); if (!get_rdb_estimated_keys_stats(sc, table_name, rows)) { fprintf(stderr, "ERROR: get rdb_estimated_keys stats failed"); diff --git a/src/shell/commands/debugger.cpp b/src/shell/commands/debugger.cpp index 100c6ef75d..88a751698b 100644 --- a/src/shell/commands/debugger.cpp +++ b/src/shell/commands/debugger.cpp @@ -149,7 +149,7 @@ bool mlog_dump(command_executor *e, shell_context *sc, arguments args) int count) mutable { for (int i = 0; i < count; ++i) { dsn::message_ex *request = requests[i]; - CHECK_NOTNULL(request, ""); + PGSCHECK_NOTNULL(request, ""); ::dsn::message_ex *msg = (::dsn::message_ex *)request; if (msg->local_rpc_code == RPC_REPLICATION_WRITE_EMPTY) { os << INDENT << "[EMPTY]" << std::endl; diff --git a/src/shell/commands/local_partition_split.cpp b/src/shell/commands/local_partition_split.cpp index f880f42464..b90e8a424b 100644 --- a/src/shell/commands/local_partition_split.cpp +++ b/src/shell/commands/local_partition_split.cpp @@ -304,8 +304,8 @@ bool open_rocksdb(const rocksdb::DBOptions &db_opts, std::vector *cf_hdls, rocksdb::DB **db) { - CHECK_NOTNULL(cf_hdls, ""); - CHECK_NOTNULL(db, ""); + PGSCHECK_NOTNULL(cf_hdls, ""); + PGSCHECK_NOTNULL(db, ""); if (read_only) { RETURN_FALSE_IF_NON_RDB_OK( rocksdb::DB::OpenForReadOnly(db_opts, rdb_dir, cf_dscs, cf_hdls, db), @@ -325,8 +325,8 @@ bool open_rocksdb(const rocksdb::DBOptions &db_opts, void release_db(std::vector *cf_hdls, rocksdb::DB **db) { - CHECK_NOTNULL(cf_hdls, ""); - CHECK_NOTNULL(db, ""); + PGSCHECK_NOTNULL(cf_hdls, ""); + PGSCHECK_NOTNULL(db, ""); for (auto cf_hdl : *cf_hdls) { delete cf_hdl; } diff --git a/src/shell/main.cpp b/src/shell/main.cpp index 41dd95d144..f5f7f29538 100644 --- a/src/shell/main.cpp +++ b/src/shell/main.cpp @@ -702,7 +702,7 @@ void register_all_commands() { for (int i = 0; commands[i].name != nullptr; ++i) { auto pr = s_commands_map.emplace(commands[i].name, &commands[i]); - CHECK(pr.second, "the command '{}' is already registered!!!", commands[i].name); + PGSCHECK(pr.second, "the command '{}' is already registered!!!", commands[i].name); s_max_name_length = std::max(s_max_name_length, strlen(commands[i].name)); } } diff --git a/src/test/bench_test/CMakeLists.txt b/src/test/bench_test/CMakeLists.txt index 5a52808d8d..926692d95c 100644 --- a/src/test/bench_test/CMakeLists.txt +++ b/src/test/bench_test/CMakeLists.txt @@ -36,7 +36,9 @@ set(MY_PROJ_LIBS snappy sasl2 gssapi_krb5 - krb5) + krb5 + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/bench_test/benchmark.cpp b/src/test/bench_test/benchmark.cpp index 321c56f86a..f960ce195b 100644 --- a/src/test/bench_test/benchmark.cpp +++ b/src/test/bench_test/benchmark.cpp @@ -99,7 +99,7 @@ benchmark::benchmark() { _client = pegasus_client_factory::get_client(FLAGS_pegasus_cluster_name, FLAGS_pegasus_app_name); - CHECK_NOTNULL(_client, ""); + PGSCHECK_NOTNULL(_client, ""); // init operation method map _operation_method = {{kUnknown, nullptr}, @@ -128,7 +128,7 @@ void benchmark::run_benchmark(int thread_count, operation_type op_type) { // get method by operation type bench_method method = _operation_method[op_type]; - CHECK_NOTNULL(method, ""); + PGSCHECK_NOTNULL(method, ""); // create histogram statistic std::shared_ptr hist_stats = rocksdb::CreateDBStatistics(); diff --git a/src/test/function_test/backup_restore/CMakeLists.txt b/src/test/function_test/backup_restore/CMakeLists.txt index c35974f279..487141ee39 100644 --- a/src/test/function_test/backup_restore/CMakeLists.txt +++ b/src/test/function_test/backup_restore/CMakeLists.txt @@ -34,7 +34,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/base_api/CMakeLists.txt b/src/test/function_test/base_api/CMakeLists.txt index 149abaa592..adede6bbc5 100644 --- a/src/test/function_test/base_api/CMakeLists.txt +++ b/src/test/function_test/base_api/CMakeLists.txt @@ -41,7 +41,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/bulk_load/CMakeLists.txt b/src/test/function_test/bulk_load/CMakeLists.txt index 03f55fac24..d4ce26e033 100644 --- a/src/test/function_test/bulk_load/CMakeLists.txt +++ b/src/test/function_test/bulk_load/CMakeLists.txt @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -set(MY_PROJ_NAME "bulk_load_test") +set(MY_PROJ_NAME bulk_load_test) project(${MY_PROJ_NAME} C CXX) # Source files under CURRENT project directory will be automatically included. @@ -43,7 +43,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/detect_hotspot/CMakeLists.txt b/src/test/function_test/detect_hotspot/CMakeLists.txt index e78150224b..f146f6b524 100644 --- a/src/test/function_test/detect_hotspot/CMakeLists.txt +++ b/src/test/function_test/detect_hotspot/CMakeLists.txt @@ -41,7 +41,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/partition_split/CMakeLists.txt b/src/test/function_test/partition_split/CMakeLists.txt index ba4f0ca40b..49efc2e177 100644 --- a/src/test/function_test/partition_split/CMakeLists.txt +++ b/src/test/function_test/partition_split/CMakeLists.txt @@ -41,7 +41,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/recovery/CMakeLists.txt b/src/test/function_test/recovery/CMakeLists.txt index 491bd68b52..af57167cc3 100644 --- a/src/test/function_test/recovery/CMakeLists.txt +++ b/src/test/function_test/recovery/CMakeLists.txt @@ -41,7 +41,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/restore/CMakeLists.txt b/src/test/function_test/restore/CMakeLists.txt index 3a96d13ac3..d34dd2b2ff 100644 --- a/src/test/function_test/restore/CMakeLists.txt +++ b/src/test/function_test/restore/CMakeLists.txt @@ -41,7 +41,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/security/CMakeLists.txt b/src/test/function_test/security/CMakeLists.txt index dbe32de945..1aec6fc43a 100644 --- a/src/test/function_test/security/CMakeLists.txt +++ b/src/test/function_test/security/CMakeLists.txt @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -set(MY_PROJ_NAME "security_test") +set(MY_PROJ_NAME security_test) set(MY_PROJ_SRC "") set(MY_SRC_SEARCH_MODE "GLOB") @@ -35,7 +35,9 @@ set(MY_PROJ_LIBS gtest function_test_utils rocksdb - test_utils) + test_utils + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/throttle/CMakeLists.txt b/src/test/function_test/throttle/CMakeLists.txt index 5b7884f780..73556ee99f 100644 --- a/src/test/function_test/throttle/CMakeLists.txt +++ b/src/test/function_test/throttle/CMakeLists.txt @@ -41,7 +41,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/function_test/utils/global_env.cpp b/src/test/function_test/utils/global_env.cpp index a703fefd2f..f87f4fd041 100644 --- a/src/test/function_test/utils/global_env.cpp +++ b/src/test/function_test/utils/global_env.cpp @@ -51,7 +51,7 @@ void global_env::get_dirs() std::cout << "Pegasus project root: " << _pegasus_root << std::endl; char task_target[512] = {0}; - CHECK(getcwd(task_target, sizeof(task_target)), ""); + PGSCHECK(getcwd(task_target, sizeof(task_target)), ""); _working_dir = task_target; std::cout << "working dir: " << _working_dir << std::endl; } diff --git a/src/test/kill_test/CMakeLists.txt b/src/test/kill_test/CMakeLists.txt index 23b8590791..4ba85fc7b0 100644 --- a/src/test/kill_test/CMakeLists.txt +++ b/src/test/kill_test/CMakeLists.txt @@ -41,7 +41,9 @@ set(MY_PROJ_LIBS snappy sasl2 gssapi_krb5 - krb5) + krb5 + glog + gflags) set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config.ini") set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/test/kill_test/process_kill_testor.cpp b/src/test/kill_test/process_kill_testor.cpp index 9e52c1c4d1..a9d660ee5e 100644 --- a/src/test/kill_test/process_kill_testor.cpp +++ b/src/test/kill_test/process_kill_testor.cpp @@ -81,7 +81,7 @@ process_kill_testor::process_kill_testor(const char *config_file) : kill_testor( kill_round = 0; _killer_handler.reset(killer_handler::new_handler(FLAGS_killer_handler)); - CHECK(_killer_handler, "invalid FLAGS_killer_handler({})", FLAGS_killer_handler); + PGSCHECK(_killer_handler, "invalid FLAGS_killer_handler({})", FLAGS_killer_handler); _job_types = {META, REPLICA, ZOOKEEPER}; _job_index_to_kill.resize(JOB_LENGTH); @@ -230,7 +230,7 @@ void process_kill_testor::stop_verifier_and_exit(const char *msg) std::stringstream ss; int ret = dsn::utils::pipe_execute( "ps aux | grep pegasus | grep verifier | awk '{print $2}' | xargs kill -9", ss); - CHECK(ret == 0 || ret == 256, ""); + PGSCHECK(ret == 0 || ret == 256, ""); LOG_FATAL(msg); } diff --git a/src/test/pressure_test/CMakeLists.txt b/src/test/pressure_test/CMakeLists.txt index 8b63bc2c4e..30ee309d12 100644 --- a/src/test/pressure_test/CMakeLists.txt +++ b/src/test/pressure_test/CMakeLists.txt @@ -37,7 +37,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy - dsn_utils) + dsn_utils + glog + gflags) set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-pressure.ini") diff --git a/src/test/pressure_test/main.cpp b/src/test/pressure_test/main.cpp index 876df3789d..5b020f0805 100644 --- a/src/test/pressure_test/main.cpp +++ b/src/test/pressure_test/main.cpp @@ -169,12 +169,12 @@ void test_get(int32_t qps) sortkey, [hashkey, sortkey](int ec, string &&val, pegasus_client::internal_info &&info) { if (ec == PERR_OK) { - CHECK(verify(hashkey, sortkey, val), - "hashkey({}) - sortkey({}) - value({}), but value({})", - hashkey, - sortkey, - get_value(hashkey, sortkey, FLAGS_value_len), - val); + PGSCHECK(verify(hashkey, sortkey, val), + "hashkey({}) - sortkey({}) - value({}), but value({})", + hashkey, + sortkey, + get_value(hashkey, sortkey, FLAGS_value_len), + val); } else if (ec == PERR_NOT_FOUND) { // don't output info } else if (ec == PERR_TIMEOUT) { @@ -207,11 +207,11 @@ void test_del(int32_t qps) hashkey, sortkey, [hashkey, sortkey](int ec, pegasus_client::internal_info &&info) { - CHECK(ec == PERR_OK || ec == PERR_NOT_FOUND || ec == PERR_TIMEOUT, - "del hashkey({}) - sortkey({}) failed with err({})", - hashkey, - sortkey, - pg_client->get_error_string(ec)); + PGSCHECK(ec == PERR_OK || ec == PERR_NOT_FOUND || ec == PERR_TIMEOUT, + "del hashkey({}) - sortkey({}) failed with err({})", + hashkey, + sortkey, + pg_client->get_error_string(ec)); }); cnt -= 1; } @@ -220,7 +220,7 @@ void test_del(int32_t qps) quota_task->cancel(false); } -void test_scan(int32_t qps) { CHECK(false, "not implemented"); } +void test_scan(int32_t qps) { PGSCHECK(false, "not implemented"); } static std::map> _all_funcs; @@ -249,14 +249,14 @@ int main(int argc, const char **argv) LOG_INFO("pressureclient {} qps = {}", FLAGS_operation_name, FLAGS_qps); pg_client = pegasus_client_factory::get_client(FLAGS_test_cluster_name, FLAGS_app_name); - CHECK_NOTNULL(pg_client, "initialize pg_client failed"); + PGSCHECK_NOTNULL(pg_client, "initialize pg_client failed"); auto it = _all_funcs.find(FLAGS_operation_name); if (it != _all_funcs.end()) { LOG_INFO("start pressureclient with {} qps({})", FLAGS_operation_name, FLAGS_qps); it->second(FLAGS_qps); } else { - CHECK(false, "Unknown operation name({})", FLAGS_operation_name); + PGSCHECK(false, "Unknown operation name({})", FLAGS_operation_name); } return 0; } diff --git a/src/utils/blob.h b/src/utils/blob.h index 62bc0a8a51..fc4c1a2522 100644 --- a/src/utils/blob.h +++ b/src/utils/blob.h @@ -109,7 +109,7 @@ class blob /// NOTE: this operation is not efficient since it involves a memory copy. [[nodiscard]] static blob create_from_bytes(const char *s, size_t len) { - CHECK_NOTNULL(s, "null source pointer would lead to undefined behaviour"); + PGSCHECK_NOTNULL(s, "null source pointer would lead to undefined behaviour"); std::shared_ptr s_arr(new char[len], std::default_delete()); memcpy(s_arr.get(), s, len); @@ -193,7 +193,7 @@ class blob // access this in their own `operator==`. bool operator==(const blob &) const { - CHECK(false, "not implemented"); + PGSCHECK(false, "not implemented"); return false; } diff --git a/src/utils/builtin_metrics.cpp b/src/utils/builtin_metrics.cpp index 6c8b8ee5a8..4e3cac4f62 100644 --- a/src/utils/builtin_metrics.cpp +++ b/src/utils/builtin_metrics.cpp @@ -50,14 +50,14 @@ builtin_metrics::builtin_metrics() builtin_metrics::~builtin_metrics() { - CHECK(!_timer, "timer should have been destroyed by stop()"); + PGSCHECK(!_timer, "timer should have been destroyed by stop()"); } void builtin_metrics::on_close() {} void builtin_metrics::start() { - CHECK(!_timer, "timer should not have been initialized before start()"); + PGSCHECK(!_timer, "timer should not have been initialized before start()"); _timer.reset(new metric_timer(FLAGS_builtin_metrics_update_interval_ms, std::bind(&builtin_metrics::update, this), @@ -66,7 +66,7 @@ void builtin_metrics::start() void builtin_metrics::stop() { - CHECK(_timer, "timer should have been initialized before stop()"); + PGSCHECK(_timer, "timer should have been initialized before stop()"); // Close the timer synchronously. _timer->close(); diff --git a/src/utils/casts.h b/src/utils/casts.h index ce20a7770d..67fd84cf30 100644 --- a/src/utils/casts.h +++ b/src/utils/casts.h @@ -39,7 +39,7 @@ inline To down_cast(From *from) // Use RTTI to do double-check, though in practice the unit tests are seldom built in debug // mode. For example, the unit tests of github CI for both rDSN and Pegasus are built in // release mode. - CHECK(from == NULL || dynamic_cast(from) != NULL, ""); + PGSCHECK(from == NULL || dynamic_cast(from) != NULL, ""); return static_cast(from); } diff --git a/src/utils/command_manager.cpp b/src/utils/command_manager.cpp index b5d56e2afb..2cb4a08670 100644 --- a/src/utils/command_manager.cpp +++ b/src/utils/command_manager.cpp @@ -56,7 +56,7 @@ command_manager::register_command(const std::vector &commands, utils::auto_write_lock l(_lock); for (const auto &cmd : commands) { - CHECK(!cmd.empty(), "should not register empty command"); + PGSCHECK(!cmd.empty(), "should not register empty command"); gutil::InsertOrDie(&_handler_by_cmd, cmd, ch); } @@ -101,7 +101,7 @@ command_manager::register_multiple_commands(const std::vector &comm void command_manager::deregister_command(uintptr_t cmd_id) { const auto ch = reinterpret_cast(cmd_id); - CHECK_NOTNULL(ch, "cannot deregister a null command id"); + PGSCHECK_NOTNULL(ch, "cannot deregister a null command id"); utils::auto_write_lock l(_lock); for (const auto &cmd : ch->commands) { _handler_by_cmd.erase(cmd); @@ -247,10 +247,11 @@ command_manager::command_manager() command_manager::~command_manager() { _cmds.clear(); - CHECK(_handler_by_cmd.empty(), - "All commands must be deregistered before command_manager is destroyed, however '{}' is " - "still registered", - _handler_by_cmd.begin()->first); + PGSCHECK( + _handler_by_cmd.empty(), + "All commands must be deregistered before command_manager is destroyed, however '{}' is " + "still registered", + _handler_by_cmd.begin()->first); } } // namespace dsn diff --git a/src/utils/env.cpp b/src/utils/env.cpp index f20d59ea34..5cfea18be1 100644 --- a/src/utils/env.cpp +++ b/src/utils/env.cpp @@ -66,7 +66,7 @@ rocksdb::Env *NewEncryptedEnv() "id=AES;hex_instance_key={};method={}", FLAGS_server_key, FLAGS_encryption_method); const auto &s = rocksdb::EncryptionProvider::CreateFromString( rocksdb::ConfigOptions(), provider_id, &provider); - CHECK(s.ok(), "Failed to create encryption provider: {}", s.ToString()); + PGSCHECK(s.ok(), "Failed to create encryption provider: {}", s.ToString()); // Create an encrypted env. return NewEncryptedEnv(rocksdb::Env::Default(), provider); @@ -134,11 +134,11 @@ rocksdb::Status do_copy_file(const std::string &src_fname, src_file->Read(bytes_per_copy, &result, buffer.get()), "failed to read file {}", src_fname); - CHECK(!result.empty(), - "read file {} at offset {} with size {} failed", - src_fname, - offset, - bytes_per_copy); + PGSCHECK(!result.empty(), + "read file {} at offset {} with size {} failed", + src_fname, + offset, + bytes_per_copy); LOG_AND_RETURN_NOT_RDB_OK( WARNING, dst_file->Append(result), "failed to write file {}", dst_fname); diff --git a/src/utils/errors.h b/src/utils/errors.h index 734ee9375b..7ec739679d 100644 --- a/src/utils/errors.h +++ b/src/utils/errors.h @@ -198,13 +198,13 @@ class error_with const T &get_value() const { - CHECK(_err.is_ok(), get_error().description()); + CHECK(_err.is_ok()) << get_error().description(); return *_value; } T &get_value() { - CHECK(_err.is_ok(), get_error().description()); + CHECK(_err.is_ok()) << get_error().description(); return *_value; } @@ -263,7 +263,7 @@ USER_DEFINED_STRUCTURE_FORMATTER(::dsn::error_s); #define CHECK_OK(s, ...) \ do { \ const ::dsn::error_s &_s = (s); \ - CHECK(_s.is_ok(), fmt::format(__VA_ARGS__)); \ + PGSCHECK(_s.is_ok(), fmt::format(__VA_ARGS__)); \ } while (false) #define RETURN_ERRS_NOT_TRUE(exp, code, ...) \ diff --git a/src/utils/flags.cpp b/src/utils/flags.cpp index 0eaf13806a..10d8f4b07a 100644 --- a/src/utils/flags.cpp +++ b/src/utils/flags.cpp @@ -68,7 +68,7 @@ class flag_data case type_enum: \ value() = dsn_config_get_value_##suffix(_section, _name, value(), _desc); \ if (_validator) { \ - CHECK(_validator(), "validation failed: {}", _name); \ + PGSCHECK(_validator(), "validation failed: {}", _name); \ } \ break @@ -274,7 +274,7 @@ class flag_registry : public utils::singleton void add_validator(const char *name, validator_fn &validator) { auto it = _flags.find(name); - CHECK(it != _flags.end(), "flag '{}' does not exist", name); + PGSCHECK(it != _flags.end(), "flag '{}' does not exist", name); flag_data &flag = it->second; if (!flag.validator()) { flag.set_validator(validator); @@ -283,9 +283,9 @@ class flag_registry : public utils::singleton void add_group_validator(const char *name, group_validator_fn &validator) { - CHECK(_group_flag_validators.find(name) == _group_flag_validators.end(), - "duplicate group flag validator '{}'", - name); + PGSCHECK(_group_flag_validators.find(name) == _group_flag_validators.end(), + "duplicate group flag validator '{}'", + name); _group_flag_validators[name] = validator; } @@ -298,14 +298,14 @@ class flag_registry : public utils::singleton std::string total_message; if (!run_group_validators(&total_message)) { - CHECK(false, "{}", total_message); + PGSCHECK(false, "{}", total_message); } } void add_tag(const char *name, const flag_tag &tag) { auto it = _flags.find(name); - CHECK(it != _flags.end(), "flag '{}' does not exist", name); + PGSCHECK(it != _flags.end(), "flag '{}' does not exist", name); it->second.add_tag(tag); } diff --git a/src/utils/fmt_logging.h b/src/utils/fmt_logging.h index 97e751a48c..6958f18218 100644 --- a/src/utils/fmt_logging.h +++ b/src/utils/fmt_logging.h @@ -20,27 +20,35 @@ #pragma once #include +#include #include #include "utils/api_utilities.h" -// The macros below no longer use the default snprintf method for log message formatting, -// instead we use fmt::format. -// TODO(wutao1): prevent construction of std::string for each log. +#define LOG_DEBUG(...) \ + do { \ + VLOG(1) << fmt::format(__VA_ARGS__); \ + } while (false) + +#define LOG_INFO(...) \ + do { \ + LOG(INFO) << fmt::format(__VA_ARGS__); \ + } while (false) + +#define LOG_WARNING(...) \ + do { \ + LOG(WARNING) << fmt::format(__VA_ARGS__); \ + } while (false) -// __FILENAME__ macro comes from the cmake, in which we calculate a filename without path. -#define LOG(level, ...) \ +#define LOG_ERROR(...) \ do { \ - if (level >= log_start_level) \ - global_log( \ - __FILENAME__, __FUNCTION__, __LINE__, level, fmt::format(__VA_ARGS__).c_str()); \ + LOG(ERROR) << fmt::format(__VA_ARGS__); \ } while (false) -#define LOG_DEBUG(...) LOG(LOG_LEVEL_DEBUG, __VA_ARGS__) -#define LOG_INFO(...) LOG(LOG_LEVEL_INFO, __VA_ARGS__) -#define LOG_WARNING(...) LOG(LOG_LEVEL_WARNING, __VA_ARGS__) -#define LOG_ERROR(...) LOG(LOG_LEVEL_ERROR, __VA_ARGS__) -#define LOG_FATAL(...) LOG(LOG_LEVEL_FATAL, __VA_ARGS__) +#define LOG_FATAL(...) \ + do { \ + LOG(FATAL) << fmt::format(__VA_ARGS__); \ + } while (false) #define LOG_WARNING_IF(x, ...) \ do { \ @@ -70,9 +78,9 @@ } \ } while (false) -#define CHECK(x, ...) CHECK_EXPRESSION(x, x, __VA_ARGS__) -#define CHECK_NOTNULL(p, ...) CHECK((p) != nullptr, __VA_ARGS__) -#define CHECK_NULL(p, ...) CHECK((p) == nullptr, __VA_ARGS__) +#define PGSCHECK(x, ...) CHECK_EXPRESSION(x, x, __VA_ARGS__) +#define PGSCHECK_NOTNULL(p, ...) PGSCHECK((p) != nullptr, __VA_ARGS__) +#define CHECK_NULL(p, ...) PGSCHECK((p) == nullptr, __VA_ARGS__) // Macros for writing log message prefixed by log_prefix(). #define LOG_DEBUG_PREFIX(...) LOG_DEBUG("[{}] {}", log_prefix(), fmt::format(__VA_ARGS__)) @@ -186,16 +194,6 @@ inline const char *null_str_printer(const char *s) { return s == nullptr ? "(nul var1 < var2, _v1 < _v2, "{} vs {} {}", _v1, _v2, fmt::format(__VA_ARGS__)); \ } while (false) -#define CHECK_STREQ(var1, var2) CHECK_STREQ_MSG(var1, var2, "") -#define CHECK_STRNE(var1, var2) CHECK_STRNE_MSG(var1, var2, "") - -#define CHECK_NE(var1, var2) CHECK_NE_MSG(var1, var2, "") -#define CHECK_EQ(var1, var2) CHECK_EQ_MSG(var1, var2, "") -#define CHECK_GE(var1, var2) CHECK_GE_MSG(var1, var2, "") -#define CHECK_LE(var1, var2) CHECK_LE_MSG(var1, var2, "") -#define CHECK_GT(var1, var2) CHECK_GT_MSG(var1, var2, "") -#define CHECK_LT(var1, var2) CHECK_LT_MSG(var1, var2, "") - #define CHECK_TRUE(var) CHECK_EQ(var, true) #define CHECK_FALSE(var) CHECK_EQ(var, false) @@ -325,8 +323,8 @@ inline const char *null_str_printer(const char *s) { return s == nullptr ? "(nul } while (0) #ifndef NDEBUG -#define DCHECK CHECK -#define DCHECK_NOTNULL CHECK_NOTNULL +#define DPGSCHECK PGSCHECK +#define DPGSCHECK_NOTNULL PGSCHECK_NOTNULL #define DCHECK_NE_MSG CHECK_NE_MSG #define DCHECK_EQ_MSG CHECK_EQ_MSG @@ -335,13 +333,6 @@ inline const char *null_str_printer(const char *s) { return s == nullptr ? "(nul #define DCHECK_GT_MSG CHECK_GT_MSG #define DCHECK_LT_MSG CHECK_LT_MSG -#define DCHECK_NE CHECK_NE -#define DCHECK_EQ CHECK_EQ -#define DCHECK_GE CHECK_GE -#define DCHECK_LE CHECK_LE -#define DCHECK_GT CHECK_GT -#define DCHECK_LT CHECK_LT - #define DCHECK_NE_PREFIX CHECK_NE_PREFIX #define DCHECK_EQ_PREFIX CHECK_EQ_PREFIX #define DCHECK_GE_PREFIX CHECK_GE_PREFIX @@ -349,8 +340,8 @@ inline const char *null_str_printer(const char *s) { return s == nullptr ? "(nul #define DCHECK_GT_PREFIX CHECK_GT_PREFIX #define DCHECK_LT_PREFIX CHECK_LT_PREFIX #else -#define DCHECK(x, ...) -#define DCHECK_NOTNULL(p, ...) +#define DPGSCHECK(x, ...) +#define DPGSCHECK_NOTNULL(p, ...) #define DCHECK_NE_MSG(var1, var2, ...) #define DCHECK_EQ_MSG(var1, var2, ...) @@ -359,13 +350,6 @@ inline const char *null_str_printer(const char *s) { return s == nullptr ? "(nul #define DCHECK_GT_MSG(var1, var2, ...) #define DCHECK_LT_MSG(var1, var2, ...) -#define DCHECK_NE(var1, var2) -#define DCHECK_EQ(var1, var2) -#define DCHECK_GE(var1, var2) -#define DCHECK_LE(var1, var2) -#define DCHECK_GT(var1, var2) -#define DCHECK_LT(var1, var2) - #define DCHECK_NE_PREFIX(var1, var2) #define DCHECK_EQ_PREFIX(var1, var2) #define DCHECK_GE_PREFIX(var1, var2) diff --git a/src/utils/latency_tracer.cpp b/src/utils/latency_tracer.cpp index f5c97f511b..7573eb7e4d 100644 --- a/src/utils/latency_tracer.cpp +++ b/src/utils/latency_tracer.cpp @@ -107,13 +107,14 @@ latency_tracer_metrics::latency_tracer_metrics(const std::string &description, const dsn::metric_entity_ptr &latency_tracer_metrics::latency_tracer_metric_entity() const { - CHECK_NOTNULL(_latency_tracer_metric_entity, - "latency_tracer metric entity (description={}, starting_point={}, end_point={}) " - "should has been instantiated: uninitialized entity cannot be used to " - "instantiate metric", - _description, - _starting_point, - _end_point); + PGSCHECK_NOTNULL( + _latency_tracer_metric_entity, + "latency_tracer metric entity (description={}, starting_point={}, end_point={}) " + "should has been instantiated: uninitialized entity cannot be used to " + "instantiate metric", + _description, + _starting_point, + _end_point); return _latency_tracer_metric_entity; } diff --git a/src/utils/logging.cpp b/src/utils/logging.cpp index 66aeeb8aef..d1e564d9c1 100644 --- a/src/utils/logging.cpp +++ b/src/utils/logging.cpp @@ -40,6 +40,12 @@ #include "utils/logging_provider.h" #include "utils/sys_exit_hook.h" +// glog: minloglevel (int, default=0, which is INFO) +// Log messages at or above this level. Again, the numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. +// glog: v (int, default=0) +// Show all VLOG(m) messages for m less or equal the value of this flag. Overridable by --vmodule. Refer to verbose logging for more detail. +// glog: vmodule (string, default="") +// Per-module verbose level. The argument has to contain a comma-separated list of =. is a glob pattern (e.g., gfs* for all modules whose name starts with "gfs"), matched against the filename base (that is, name ignoring .cc/.h./-inl.h). overrides any value given by --v. See also verbose logging for more details. DSN_DEFINE_string(core, logging_start_level, "LOG_LEVEL_INFO", diff --git a/src/utils/long_adder_bench/CMakeLists.txt b/src/utils/long_adder_bench/CMakeLists.txt index 71568c61ae..62b1afb98a 100644 --- a/src/utils/long_adder_bench/CMakeLists.txt +++ b/src/utils/long_adder_bench/CMakeLists.txt @@ -33,7 +33,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/utils/metrics.cpp b/src/utils/metrics.cpp index 89e3ff1f7f..f248e57f13 100644 --- a/src/utils/metrics.cpp +++ b/src/utils/metrics.cpp @@ -151,8 +151,8 @@ void encode_metrics(dsn::metric_json_writer &writer, const dsn::metric_filters &filters) { // We shouldn't reach here if no metric is chosen, thus just mark an assertion. - CHECK(!metrics.empty(), - "this entity should not be encoded into the response since no metric is chosen"); + PGSCHECK(!metrics.empty(), + "this entity should not be encoded into the response since no metric is chosen"); writer.Key(dsn::kMetricEntityMetricsField.c_str()); @@ -749,9 +749,9 @@ void metric_timer::on_timer(const boost::system::error_code &ec) // Cancel can only be launched by close(). auto expected_state = state::kClosing; - CHECK(_state.compare_exchange_strong(expected_state, state::kClosed), - "wrong state for metric_timer: {}, while expecting closing state", - static_cast(expected_state)); + PGSCHECK(_state.compare_exchange_strong(expected_state, state::kClosed), + "wrong state for metric_timer: {}, while expecting closing state", + static_cast(expected_state)); on_close(); return; diff --git a/src/utils/metrics.h b/src/utils/metrics.h index b399d9313a..cdc1e0f3f7 100644 --- a/src/utils/metrics.h +++ b/src/utils/metrics.h @@ -1417,9 +1417,9 @@ class percentile : public closeable_metric _nth_element_finder(), _timer() { - CHECK(_sample_size > 0 && (_sample_size & (_sample_size - 1)) == 0, - "sample_sizes should be > 0 and power of 2"); - CHECK(_samples, ""); + PGSCHECK(_sample_size > 0 && (_sample_size & (_sample_size - 1)) == 0, + "sample_sizes should be > 0 and power of 2"); + CHECK(_samples); for (const auto &kth : kth_percentiles) { _kth_percentile_bitset.set(static_cast(kth)); diff --git a/src/utils/nth_element.h b/src/utils/nth_element.h index c048a9c170..5277ea71b1 100644 --- a/src/utils/nth_element.h +++ b/src/utils/nth_element.h @@ -66,9 +66,9 @@ class stl_nth_element_finder void set_nths(const nth_container_type &nths) { _nths = nths; - CHECK(std::is_sorted(_nths.begin(), _nths.end()), - "nth indexes({}) is not sorted", - fmt::join(_nths, " ")); + PGSCHECK(std::is_sorted(_nths.begin(), _nths.end()), + "nth indexes({}) is not sorted", + fmt::join(_nths, " ")); _elements.assign(_nths.size(), value_type{}); } @@ -85,7 +85,7 @@ class stl_nth_element_finder { for (size_type i = 0; i < _nths.size();) { auto nth_iter = begin + _nths[i]; - CHECK(nth_iter >= first && nth_iter < last, "Invalid iterators for nth_element()"); + PGSCHECK(nth_iter >= first && nth_iter < last, "Invalid iterators for nth_element()"); std::nth_element(first, nth_iter, last, _comp); _elements[i] = *nth_iter; diff --git a/src/utils/output_utils.cpp b/src/utils/output_utils.cpp index dfaa799633..ae778355c1 100644 --- a/src/utils/output_utils.cpp +++ b/src/utils/output_utils.cpp @@ -54,7 +54,7 @@ void json_encode(Writer &writer, const table_printer &tp) dsn::json::json_encode(writer, tp._matrix_data[row][1]); // row data } } else { - CHECK(false, "Unknown mode"); + PGSCHECK(false, "Unknown mode"); } if (!tp._name.empty()) { writer.EndObject(); @@ -64,7 +64,8 @@ void json_encode(Writer &writer, const table_printer &tp) void table_printer::add_title(const std::string &title, alignment align) { check_mode(data_mode::kMultiColumns); - CHECK(_matrix_data.empty() && _max_col_width.empty(), "'add_title' must be called only once"); + PGSCHECK(_matrix_data.empty() && _max_col_width.empty(), + "'add_title' must be called only once"); _max_col_width.push_back(title.length()); _align_left.push_back(align == alignment::kLeft); add_row(title); @@ -108,7 +109,7 @@ void table_printer::output(std::ostream &out, output_format format) const output_in_json(out); break; default: - CHECK(false, "Unknown format"); + PGSCHECK(false, "Unknown format"); } } @@ -122,7 +123,7 @@ void table_printer::output_in_tabular(std::ostream &out) const if (_mode == data_mode::kSingleColumn) { separator = ": "; } else { - CHECK(_mode == data_mode::kMultiColumns, "Unknown mode"); + PGSCHECK(_mode == data_mode::kMultiColumns, "Unknown mode"); } if (!_name.empty()) { @@ -158,7 +159,7 @@ void table_printer::check_mode(data_mode mode) _mode = mode; return; } - CHECK(_mode == mode, ""); + PGSCHECK(_mode == mode, ""); } void multi_table_printer::add(table_printer &&tp) { _tps.emplace_back(std::move(tp)); } @@ -177,7 +178,7 @@ void multi_table_printer::output(std::ostream &out, output_in_json(out); break; default: - CHECK(false, "Unknown format"); + PGSCHECK(false, "Unknown format"); } } diff --git a/src/utils/simple_logger.cpp b/src/utils/simple_logger.cpp index 881b97ecd8..355cc0bdd6 100644 --- a/src/utils/simple_logger.cpp +++ b/src/utils/simple_logger.cpp @@ -56,6 +56,9 @@ #include "utils/strings.h" #include "utils/time_utils.h" +// GLOG_DEFINE_uint32(max_log_size, 1800, +// "approx. maximum log file size (in MB). A value of 0 will " +// "be silently overridden to 1."); DSN_DEFINE_uint64(tools.simple_logger, max_log_file_bytes, 64 * 1024 * 1024, @@ -88,6 +91,8 @@ DSN_DEFINE_validator(stderr_start_level_on_stdout, [](const char *value) -> bool return LOG_LEVEL_DEBUG <= level && level <= LOG_LEVEL_FATAL; }); +// glog: stderrthreshold (int, default=2, which is ERROR) +// Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. DSN_DEFINE_string( tools.simple_logger, stderr_start_level, @@ -107,26 +112,23 @@ namespace tools { namespace { int print_header(FILE *fp, log_level_t stderr_start_level, log_level_t log_level) { - // The leading character of each log line, corresponding to the log level - // D: Debug - // I: Info - // W: Warning - // E: Error - // F: Fatal - static char s_level_char[] = "DIWEF"; - - uint64_t ts = dsn_now_ns(); - std::string time_str; - dsn::utils::time_ms_to_string(ts / 1000000, time_str); - - int tid = dsn::utils::get_current_tid(); const auto header = fmt::format( - "{}{} ({} {}) {}", s_level_char[log_level], time_str, ts, tid, log_prefixed_message_func()); - const int written_size = fmt::fprintf(fp, "%s", header.c_str()); - if (log_level >= stderr_start_level) { - fmt::fprintf(stderr, "%s", header.c_str()); + "{}", log_prefixed_message_func()); + + void LogPrefixFormatter(std::ostream& s, const google::LogMessage& m, void* /*data*/) { + s << google::GetLogSeverityName(m.severity())[0] // 'I', 'W', 'E' or 'F'. + << setw(4) << 1900 + m.time().year() << '-' + << setw(2) << 1 + m.time().month() << '-' + << setw(2) << m.time().day() << ' ' + << setw(2) << m.time().hour() << ':' + << setw(2) << m.time().min() << ':' + << setw(2) << m.time().sec() << '.' + << setw(3) << m.time().usec() << ' ' + << setfill(' ') << setw(5) << m.thread_id() << setfill('0') << ' ' + << m.basename() << ':' << m.line() << ']'; } - return written_size; + + return 0; } int print_long_header(FILE *fp, @@ -166,9 +168,9 @@ inline void process_fatal_log(log_level_t log_level) bool coredump = true; FAIL_POINT_INJECT_NOT_RETURN_F("coredump_for_fatal_log", [&coredump](std::string_view str) { - CHECK(buf2bool(str, coredump), - "invalid coredump toggle for fatal log, should be true or false: {}", - str); + PGSCHECK(buf2bool(str, coredump), + "invalid coredump toggle for fatal log, should be true or false: {}", + str); }); if (dsn_likely(coredump)) { @@ -226,6 +228,11 @@ simple_logger::simple_logger(const char *log_dir, const char *role_name) _log(nullptr), _file_bytes(0) { +// glog: log_dir (string, default="") +// If specified, logfiles are written into this directory instead of the default logging directory. +// GLOG_DEFINE_bool(timestamp_in_logfile_name, +// BoolFromEnv("GOOGLE_TIMESTAMP_IN_LOGFILE_NAME", true), +// "put a timestamp at the end of the log file name"); // Use 'role_name' if it is specified, otherwise use 'base_name'. const std::string symlink_name( fmt::format("{}.log", utils::is_empty(role_name) ? FLAGS_base_name : role_name)); @@ -287,7 +294,7 @@ void simple_logger::create_log_file() const std::string file_name(fmt::format("{}{}", _file_name_prefix, time_str)); const std::string path(utils::filesystem::path_combine(_log_dir, file_name)); _log = ::fopen(path.c_str(), "w+"); - CHECK_NOTNULL(_log, "Failed to fopen {}: {}", path, dsn::utils::safe_strerror(errno)); + PGSCHECK_NOTNULL(_log, "Failed to fopen {}: {}", path, dsn::utils::safe_strerror(errno)); // Unlink the latest log file. if (::unlink(_symlink_path.c_str()) != 0) { @@ -408,7 +415,7 @@ void simple_logger::log( { utils::auto_lock<::dsn::utils::ex_lock> l(_lock); - CHECK_NOTNULL(_log, "Log file hasn't been initialized yet"); + PGSCHECK_NOTNULL(_log, "Log file hasn't been initialized yet"); print_header(log_level); print_long_header(file, function, line, log_level); print_body(str, log_level); diff --git a/src/utils/strings.cpp b/src/utils/strings.cpp index aa73ff520c..fdb841fec5 100644 --- a/src/utils/strings.cpp +++ b/src/utils/strings.cpp @@ -159,7 +159,7 @@ inline bool is_trailing_space(char ch) // Skip trailing spaces and find the end of token. const char *find_token_end(const char *token_begin, const char *end) { - CHECK(token_begin < end, ""); + PGSCHECK(token_begin < end, ""); for (; end > token_begin && is_trailing_space(*(end - 1)); --end) { } @@ -205,7 +205,7 @@ void split(const char *input, const Inserter &inserter, Container &output) { - CHECK_NOTNULL(input, ""); + PGSCHECK_NOTNULL(input, ""); output.clear(); @@ -224,7 +224,7 @@ void split(const char *input, break; case split_args_state::kSplitToken: { auto token_end = find_token_end(token_begin, p); - CHECK(token_begin <= token_end, ""); + PGSCHECK(token_begin <= token_end, ""); if (token_begin == token_end && !keep_place_holder) { // Current token is empty, and place holder is not needed. break; diff --git a/src/utils/test/CMakeLists.txt b/src/utils/test/CMakeLists.txt index 8502cabb76..c4148db25e 100644 --- a/src/utils/test/CMakeLists.txt +++ b/src/utils/test/CMakeLists.txt @@ -38,7 +38,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/utils/test/fmt_logging_test.cpp b/src/utils/test/fmt_logging_test.cpp index c19126c7c5..d233b84eee 100644 --- a/src/utils/test/fmt_logging_test.cpp +++ b/src/utils/test/fmt_logging_test.cpp @@ -48,7 +48,7 @@ TEST(fmt_logging, basic) ASSERT_EQ(fmt::format("{}", LPC_REPLICATION_LOW), "LPC_REPLICATION_LOW"); ASSERT_EQ(std::string_view("yes"), "yes"); ASSERT_EQ(fmt::format("{}", std::string_view("yes\0yes")), "yes\0yes"); - ASSERT_DEATH(CHECK(false, "CHECK false in test"), "CHECK false in test"); + ASSERT_DEATH(PGSCHECK(false, "PGSCHECK false in test"), "PGSCHECK false in test"); } } // namespace replication diff --git a/src/utils/test/logging.cpp b/src/utils/test/logging.cpp index 64eccf29e2..863be2d31d 100644 --- a/src/utils/test/logging.cpp +++ b/src/utils/test/logging.cpp @@ -64,7 +64,7 @@ TEST(LoggingTest, LogMacro) for (auto test : tests) { // Test logging_provider::log. - LOG(test.level, "LOG: sortkey = {}", test.str); + // LOG(test.level, "LOG: sortkey = {}", test.str); } dsn::fail::teardown(); diff --git a/src/utils/test/metrics_test.cpp b/src/utils/test/metrics_test.cpp index fcd9cf227c..8dd4de0384 100644 --- a/src/utils/test/metrics_test.cpp +++ b/src/utils/test/metrics_test.cpp @@ -747,11 +747,11 @@ void run_percentile(const metric_entity_ptr &my_entity, Checker checker) { CHECK_GT(num_threads, 0); - CHECK(data.size() <= sample_size && data.size() % num_threads == 0, - "Invalid arguments, data_size={}, sample_size={}, num_threads={}", - data.size(), - sample_size, - num_threads); + PGSCHECK(data.size() <= sample_size && data.size() % num_threads == 0, + "Invalid arguments, data_size={}, sample_size={}, num_threads={}", + data.size(), + sample_size, + num_threads); auto my_metric = prototype.instantiate(my_entity, interval_ms, kth_percentiles, sample_size); diff --git a/src/utils/test/nth_element_bench/CMakeLists.txt b/src/utils/test/nth_element_bench/CMakeLists.txt index 3aae31e4a6..144478dda4 100644 --- a/src/utils/test/nth_element_bench/CMakeLists.txt +++ b/src/utils/test/nth_element_bench/CMakeLists.txt @@ -33,7 +33,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/utils/test/nth_element_utils.h b/src/utils/test/nth_element_utils.h index 85e618a318..ac49bf473f 100644 --- a/src/utils/test/nth_element_utils.h +++ b/src/utils/test/nth_element_utils.h @@ -60,12 +60,13 @@ class nth_element_case_generator _nths(nths), _rand(Rand()) { - CHECK(std::is_sorted(_nths.begin(), _nths.end()), - "nth indexes({}) is not sorted", - fmt::join(_nths, " ")); + PGSCHECK(std::is_sorted(_nths.begin(), _nths.end()), + "nth indexes({}) is not sorted", + fmt::join(_nths, " ")); for (const auto &nth : _nths) { - CHECK(nth >= 0 && nth < _array_size, "nth should be in the range [0, {})", _array_size); + PGSCHECK( + nth >= 0 && nth < _array_size, "nth should be in the range [0, {})", _array_size); } } diff --git a/src/zookeeper/lock_struct.cpp b/src/zookeeper/lock_struct.cpp index d88837fe2d..3ccc34d972 100644 --- a/src/zookeeper/lock_struct.cpp +++ b/src/zookeeper/lock_struct.cpp @@ -210,7 +210,7 @@ void lock_struct::owner_change(lock_struct_ptr _this, int zoo_event) } else if (ZOO_NOTWATCHING_EVENT == zoo_event) _this->get_lock_owner(false); else - CHECK(false, "unexpected event"); + PGSCHECK(false, "unexpected event"); } /*static*/ void lock_struct::after_remove_duplicated_locknode(lock_struct_ptr _this, diff --git a/src/zookeeper/test/CMakeLists.txt b/src/zookeeper/test/CMakeLists.txt index 7dabd1faf5..6a0e845f12 100644 --- a/src/zookeeper/test/CMakeLists.txt +++ b/src/zookeeper/test/CMakeLists.txt @@ -42,7 +42,9 @@ set(MY_PROJ_LIBS rocksdb lz4 zstd - snappy) + snappy + glog + gflags) set(MY_BOOST_LIBS Boost::system Boost::filesystem) diff --git a/src/zookeeper/test/distributed_lock_zookeeper.cpp b/src/zookeeper/test/distributed_lock_zookeeper.cpp index 75747a4da9..11b373de64 100644 --- a/src/zookeeper/test/distributed_lock_zookeeper.cpp +++ b/src/zookeeper/test/distributed_lock_zookeeper.cpp @@ -85,7 +85,7 @@ class simple_adder_server : public dsn::service_app LOG_INFO("lock: error_code: {}, name: {}, lock version: {}", ec, name, version); }, DLOCK_CALLBACK, - [](error_code, const std::string &, int) { CHECK(false, "session expired"); }, + [](error_code, const std::string &, int) { PGSCHECK(false, "session expired"); }, opt); task_pair.first->wait(); for (int i = 0; i < 1000; ++i) { diff --git a/src/zookeeper/zookeeper_session.cpp b/src/zookeeper/zookeeper_session.cpp index 380eafa0b0..975efd62b0 100644 --- a/src/zookeeper/zookeeper_session.cpp +++ b/src/zookeeper/zookeeper_session.cpp @@ -217,16 +217,16 @@ int zookeeper_session::attach(void *callback_owner, const state_callback &cb) sasl_errstring(err, nullptr, nullptr)); if (!utils::is_empty(FLAGS_sasl_password_file)) { - CHECK(utils::filesystem::file_exists(FLAGS_sasl_password_file), - "sasl_password_file {} not exist!", - FLAGS_sasl_password_file); + PGSCHECK(utils::filesystem::file_exists(FLAGS_sasl_password_file), + "sasl_password_file {} not exist!", + FLAGS_sasl_password_file); } auto param_host = ""; if (!utils::is_empty(FLAGS_sasl_service_fqdn)) { - CHECK(dsn::rpc_address::from_host_port(FLAGS_sasl_service_fqdn), - "sasl_service_fqdn '{}' is invalid", - FLAGS_sasl_service_fqdn); + PGSCHECK(dsn::rpc_address::from_host_port(FLAGS_sasl_service_fqdn), + "sasl_service_fqdn '{}' is invalid", + FLAGS_sasl_service_fqdn); param_host = FLAGS_sasl_service_fqdn; } // DIGEST-MD5 requires '--server-fqdn zk-sasl-md5' for historical reasons on zk c client @@ -251,7 +251,7 @@ int zookeeper_session::attach(void *callback_owner, const state_callback &cb) &sasl_params); } while (false); - CHECK_NOTNULL(_handle, "zookeeper session init failed"); + PGSCHECK_NOTNULL(_handle, "zookeeper session init failed"); _watchers.push_back(watcher_object()); _watchers.back().watcher_path = ""; @@ -398,7 +398,7 @@ void zookeeper_session::global_watcher( if (type != ZOO_SESSION_EVENT && path != nullptr) LOG_INFO("watcher path: {}", path); - CHECK(zoo_session->_handle == handle, ""); + PGSCHECK(zoo_session->_handle == handle, ""); zoo_session->dispatch_event(type, state, type == ZOO_SESSION_EVENT ? "" : path); } diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index d197e26b50..db468b3d05 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -324,6 +324,8 @@ ExternalProject_Add(s2geometry -DBUILD_SHARED_LIBS=OFF -DGTEST_ROOT=${googletest_SRC}/googletest -DWITH_PYTHON=OFF + -DWITH_GFLAGS=OFF + -DWITH_GLOG=OFF -DBUILD_EXAMPLES=OFF DEPENDS googletest abseil DOWNLOAD_EXTRACT_TIMESTAMP true @@ -489,3 +491,36 @@ ExternalProject_Add(spdlog DOWNLOAD_EXTRACT_TIMESTAMP true DOWNLOAD_NO_PROGRESS true ) + +ExternalProject_Add(gflags + URL https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz + URL_MD5 1a865b93bacfa963201af3f75b7bd64c + PATCH_COMMAND "" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${TP_OUTPUT} + -DBUILD_SHARED_LIBS=OFF + -DBUILD_STATIC_LIBS=ON + -DBUILD_TESTING=OFF + -DINSTALL_HEADERS=ON + -DINSTALL_SHARED_LIBS=OFF + -DINSTALL_STATIC_LIBS=ON + BUILD_COMMAND make -j${PARALLEL} + INSTALL_COMMAND make install + DOWNLOAD_EXTRACT_TIMESTAMP true + DOWNLOAD_NO_PROGRESS true +) + +ExternalProject_Add(glog + URL https://github.com/google/glog/archive/refs/tags/v0.7.1.tar.gz + URL_MD5 128e2995cc33d794ff24f785a3060346 + PATCH_COMMAND "" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${TP_OUTPUT} + -DBUILD_SHARED_LIBS=ON + -DBUILD_EXAMPLES=OFF + -DWITH_GFLAGS=ON + -DWITH_GTEST=OFF + BUILD_COMMAND make -j${PARALLEL} + INSTALL_COMMAND make install + DEPENDS gflags + DOWNLOAD_EXTRACT_TIMESTAMP true + DOWNLOAD_NO_PROGRESS true +)