diff --git a/src/base/value_schema_manager.cpp b/src/base/value_schema_manager.cpp index 238b39dd4a..e532527fc9 100644 --- a/src/base/value_schema_manager.cpp +++ b/src/base/value_schema_manager.cpp @@ -56,9 +56,7 @@ 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); - if (nullptr == schema) { - CHECK(false, "data version({}) in meta cf is not supported", meta_cf_data_version); - } + CHECK_NOTNULL(schema, "data version({}) in meta cf is not supported", meta_cf_data_version); return schema; } } diff --git a/src/common/replication_common.cpp b/src/common/replication_common.cpp index 9ea8ceb241..0eb3211543 100644 --- a/src/common/replication_common.cpp +++ b/src/common/replication_common.cpp @@ -159,9 +159,7 @@ void replication_options::initialize() data_dir_tags.emplace_back(config_data_dir_tags[i]); } - if (data_dirs.empty()) { - CHECK(false, "no replica data dir found, maybe not set or excluded by black list"); - } + CHECK(!data_dirs.empty(), "no replica data dir found, maybe not set or excluded by black list"); deny_client_on_start = dsn_config_get_value_bool("replication", "deny_client_on_start", @@ -580,9 +578,7 @@ replication_options::get_data_dirs_in_black_list(const std::string &fname, LOG_INFO_F("data_dirs_black_list_file[{}] found, apply it", fname); std::ifstream file(fname); - if (!file) { - CHECK(false, "open data_dirs_black_list_file failed: {}", fname); - } + CHECK(file, "open data_dirs_black_list_file failed: {}", fname); std::string str; int count = 0; diff --git a/src/geo/lib/geo_client.cpp b/src/geo/lib/geo_client.cpp index a8ac068165..8497f4c948 100644 --- a/src/geo/lib/geo_client.cpp +++ b/src/geo/lib/geo_client.cpp @@ -70,10 +70,10 @@ geo_client::geo_client(const char *config_file, CHECK(ok, "init pegasus client factory failed"); _common_data_client = pegasus_client_factory::get_client(cluster_name, common_app_name); - CHECK(_common_data_client, "init pegasus _common_data_client failed"); + CHECK_NOTNULL(_common_data_client, "init pegasus _common_data_client failed"); _geo_data_client = pegasus_client_factory::get_client(cluster_name, geo_app_name); - CHECK(_geo_data_client, "init pegasus _geo_data_client failed"); + CHECK_NOTNULL(_geo_data_client, "init pegasus _geo_data_client failed"); _min_level = (int32_t)dsn_config_get_value_uint64( "geo_client.lib", "min_level", 12, "min cell level for scan"); diff --git a/src/meta/backup_engine.cpp b/src/meta/backup_engine.cpp index 64d611d54e..a205ba622c 100644 --- a/src/meta/backup_engine.cpp +++ b/src/meta/backup_engine.cpp @@ -103,7 +103,8 @@ error_code backup_engine::write_backup_file(const std::string &file_name, LOG_INFO_F("create file {} failed", file_name); return err; } - CHECK(remote_file, "create file {} succeed, but can't get handle", create_file_req.file_name); + CHECK_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}, TASK_CODE_EXEC_INLINED, diff --git a/src/redis_protocol/proxy_lib/proxy_layer.cpp b/src/redis_protocol/proxy_lib/proxy_layer.cpp index 2aec20a095..3172eff3fe 100644 --- a/src/redis_protocol/proxy_lib/proxy_layer.cpp +++ b/src/redis_protocol/proxy_lib/proxy_layer.cpp @@ -106,7 +106,7 @@ void proxy_stub::remove_session(dsn::rpc_address remote_address) proxy_session::proxy_session(proxy_stub *op, dsn::message_ex *first_msg) : _stub(op), _is_session_reset(false), _backup_one_request(first_msg) { - CHECK(first_msg, "null msg when create session"); + CHECK_NOTNULL(first_msg, "null msg when create session"); _backup_one_request->add_ref(); _remote_address = _backup_one_request->header->from_address; diff --git a/src/replica/replication_app_base.cpp b/src/replica/replication_app_base.cpp index 61a473cbf3..f77dc248c7 100644 --- a/src/replica/replication_app_base.cpp +++ b/src/replica/replication_app_base.cpp @@ -75,7 +75,7 @@ error_code write_blob_to_file(const std::string &file, const blob &data) sz = s; }, 0); - CHECK(tsk, "create file::write task failed"); + CHECK_NOTNULL(tsk, "create file::write task failed"); tracker.wait_outstanding_tasks(); file::flush(hfile); file::close(hfile); diff --git a/src/server/available_detector.cpp b/src/server/available_detector.cpp index b7e95a63b6..6ee734edbf 100644 --- a/src/server/available_detector.cpp +++ b/src/server/available_detector.cpp @@ -82,10 +82,10 @@ available_detector::available_detector() CHECK(false, "Initialize the pegasus client failed"); } _client = pegasus_client_factory::get_client(_cluster_name.c_str(), _app_name.c_str()); - CHECK(_client, "Initialize the _client failed"); + CHECK_NOTNULL(_client, "Initialize the _client failed"); _result_writer = dsn::make_unique(_client); _ddl_client.reset(new replication_ddl_client(_meta_list)); - CHECK(_ddl_client, "Initialize the _ddl_client failed"); + CHECK_NOTNULL(_ddl_client, "Initialize the _ddl_client failed"); if (!_alert_email_address.empty()) { _send_alert_email_cmd = "cd " + _alert_script_dir + "; bash sendmail.sh alert " + _alert_email_address + " " + _cluster_name + " " + _app_name + " "; diff --git a/src/server/info_collector.cpp b/src/server/info_collector.cpp index b82b3a12a6..2f9b0b7eb3 100644 --- a/src/server/info_collector.cpp +++ b/src/server/info_collector.cpp @@ -75,7 +75,7 @@ info_collector::info_collector() CHECK(false, "Initialize the pegasus client failed"); } _client = pegasus_client_factory::get_client(_cluster_name.c_str(), _usage_stat_app.c_str()); - CHECK(_client, "Initialize the client failed"); + CHECK_NOTNULL(_client, "Initialize the client failed"); _result_writer = dsn::make_unique(_client); _capacity_unit_fetch_interval_seconds = diff --git a/src/server/pegasus_server_impl.cpp b/src/server/pegasus_server_impl.cpp index 32ed4a236f..899bcb2aad 100644 --- a/src/server/pegasus_server_impl.cpp +++ b/src/server/pegasus_server_impl.cpp @@ -114,7 +114,7 @@ void pegasus_server_impl::parse_checkpoints() pegasus_server_impl::~pegasus_server_impl() { if (_is_open) { - CHECK(_db, ""); + CHECK_NOTNULL(_db, ""); release_db(); } } @@ -259,7 +259,7 @@ int pegasus_server_impl::on_batched_write_requests(int64_t decree, int count) { CHECK(_is_open, ""); - CHECK(requests, ""); + CHECK_NOTNULL(requests, ""); return _server_write->on_batched_write_requests(requests, count, decree, timestamp); } @@ -1761,7 +1761,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(_db, ""); + CHECK_NOTNULL(_db, ""); rocksdb::CancelAllBackgroundWork(_db, wait); } } @@ -1769,7 +1769,7 @@ void pegasus_server_impl::cancel_background_work(bool wait) ::dsn::error_code pegasus_server_impl::stop(bool clear_state) { if (!_is_open) { - dassert(!_db, ""); + dassert(_db == nullptr, ""); dassert(!clear_state, "should not be here if do clear"); return ::dsn::ERR_OK; } diff --git a/src/server/pegasus_server_write.cpp b/src/server/pegasus_server_write.cpp index 116b6080d6..f3d8b21eb0 100644 --- a/src/server/pegasus_server_write.cpp +++ b/src/server/pegasus_server_write.cpp @@ -84,7 +84,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(requests[i], "request[{}] is null", i); + CHECK_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_impl.h b/src/server/pegasus_write_service_impl.h index 5beab4089b..70b90cc299 100644 --- a/src/server/pegasus_write_service_impl.h +++ b/src/server/pegasus_write_service_impl.h @@ -674,7 +674,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base } } default: - CHECK(false, "unsupported check type: %d", check_type); + CHECK(false, "unsupported check type: {}", check_type); } return false; } diff --git a/src/shell/commands/debugger.cpp b/src/shell/commands/debugger.cpp index 3878ae4412..571ed0afea 100644 --- a/src/shell/commands/debugger.cpp +++ b/src/shell/commands/debugger.cpp @@ -90,7 +90,7 @@ bool mlog_dump(command_executor *e, shell_context *sc, arguments args) int64_t decree, int64_t timestamp, dsn::message_ex **requests, int count) mutable { for (int i = 0; i < count; ++i) { dsn::message_ex *request = requests[i]; - CHECK(request, ""); + CHECK_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/test/bench_test/benchmark.cpp b/src/test/bench_test/benchmark.cpp index 515c093291..0d45bf2329 100644 --- a/src/test/bench_test/benchmark.cpp +++ b/src/test/bench_test/benchmark.cpp @@ -33,7 +33,7 @@ benchmark::benchmark() { _client = pegasus_client_factory::get_client(config::instance().pegasus_cluster_name.c_str(), config::instance().pegasus_app_name.c_str()); - CHECK(_client, ""); + CHECK_NOTNULL(_client, ""); // init operation method map _operation_method = {{kUnknown, nullptr}, @@ -60,7 +60,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(method, ""); + CHECK_NOTNULL(method, ""); // create histogram statistic std::shared_ptr hist_stats = rocksdb::CreateDBStatistics(); diff --git a/src/test/kill_test/process_kill_testor.cpp b/src/test/kill_test/process_kill_testor.cpp index b4f7fecb35..c9a67101f0 100644 --- a/src/test/kill_test/process_kill_testor.cpp +++ b/src/test/kill_test/process_kill_testor.cpp @@ -53,7 +53,7 @@ process_kill_testor::process_kill_testor(const char *config_file) : kill_testor( dsn_config_get_value_string(section, "killer_handler", "", "killer handler"); dassert(killer_name.size() > 0, ""); _killer_handler.reset(killer_handler::new_handler(killer_name.c_str())); - CHECK(_killer_handler.get(), "invalid killer_name({})", killer_name); + CHECK(_killer_handler, "invalid killer_name({})", killer_name); _job_types = {META, REPLICA, ZOOKEEPER}; _job_index_to_kill.resize(JOB_LENGTH); diff --git a/src/test/pressure_test/main.cpp b/src/test/pressure_test/main.cpp index db812b2369..32f1fce3e0 100644 --- a/src/test/pressure_test/main.cpp +++ b/src/test/pressure_test/main.cpp @@ -259,8 +259,7 @@ int main(int argc, const char **argv) LOG_INFO("pressureclient %s qps = %d", op_name.c_str(), qps); pg_client = pegasus_client_factory::get_client(cluster_name.c_str(), app_name.c_str()); - - CHECK(pg_client, "initialize pg_client failed"); + CHECK_NOTNULL(pg_client, "initialize pg_client failed"); auto it = _all_funcs.find(op_name); if (it != _all_funcs.end()) { diff --git a/src/utils/fmt_logging.h b/src/utils/fmt_logging.h index a3f18474eb..33d843bd6b 100644 --- a/src/utils/fmt_logging.h +++ b/src/utils/fmt_logging.h @@ -47,6 +47,7 @@ } while (false) #define CHECK dassert_f +#define CHECK_NOTNULL(p, ...) CHECK(p != nullptr, __VA_ARGS__) // Macros for writing log message prefixed by log_prefix(). #define LOG_DEBUG_PREFIX(...) LOG_DEBUG_F("[{}] {}", log_prefix(), fmt::format(__VA_ARGS__))