Skip to content

Commit

Permalink
add CHECK_NOTNULL
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Oct 27, 2022
1 parent 6d4fe80 commit 8317629
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 29 deletions.
4 changes: 1 addition & 3 deletions src/base/value_schema_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/common/replication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/geo/lib/geo_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/meta/backup_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/redis_protocol/proxy_lib/proxy_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/replica/replication_app_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/server/available_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<result_writer>(_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 + " ";
Expand Down
2 changes: 1 addition & 1 deletion src/server/info_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<result_writer>(_client);

_capacity_unit_fetch_interval_seconds =
Expand Down
8 changes: 4 additions & 4 deletions src/server/pegasus_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1761,15 +1761,15 @@ 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);
}
}

::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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/pegasus_server_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/server/pegasus_write_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shell/commands/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench_test/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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<rocksdb::Statistics> hist_stats = rocksdb::CreateDBStatistics();
Expand Down
2 changes: 1 addition & 1 deletion src/test/kill_test/process_kill_testor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/test/pressure_test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/fmt_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down

0 comments on commit 8317629

Please sign in to comment.