Skip to content

Commit

Permalink
refactor(macro): use CHECK_* to replace dassert_* (part 3) (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 authored Nov 7, 2022
1 parent c7638fc commit e2a0088
Show file tree
Hide file tree
Showing 86 changed files with 476 additions and 547 deletions.
23 changes: 11 additions & 12 deletions src/block_service/block_service_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ namespace block_service {

block_service_registry::block_service_registry()
{
bool ans;
ans = utils::factory_store<block_filesystem>::register_factory(
"fds_service", block_filesystem::create<fds_service>, PROVIDER_TYPE_MAIN);
dassert(ans, "register fds_service failed");

ans = utils::factory_store<block_filesystem>::register_factory(
"hdfs_service", block_filesystem::create<hdfs_service>, PROVIDER_TYPE_MAIN);
dassert(ans, "register hdfs_service failed");

ans = utils::factory_store<block_filesystem>::register_factory(
"local_service", block_filesystem::create<local_service>, PROVIDER_TYPE_MAIN);
dassert(ans, "register local_service failed");
CHECK(utils::factory_store<block_filesystem>::register_factory(
"fds_service", block_filesystem::create<fds_service>, PROVIDER_TYPE_MAIN),
"register fds_service failed");

CHECK(utils::factory_store<block_filesystem>::register_factory(
"hdfs_service", block_filesystem::create<hdfs_service>, PROVIDER_TYPE_MAIN),
"register hdfs_service failed");

CHECK(utils::factory_store<block_filesystem>::register_factory(
"local_service", block_filesystem::create<local_service>, PROVIDER_TYPE_MAIN),
"register local_service failed");
}

block_service_manager::block_service_manager()
Expand Down
16 changes: 8 additions & 8 deletions src/block_service/fds/fds_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,19 @@ error_code fds_file_object::get_file_meta()

// get file length
auto iter = meta.find(fds_service::FILE_LENGTH_CUSTOM_KEY);
dassert_f(iter != meta.end(),
"can't find {} in object({})'s metadata",
fds_service::FILE_LENGTH_CUSTOM_KEY.c_str(),
_fds_path.c_str());
CHECK(iter != meta.end(),
"can't find {} in object({})'s metadata",
fds_service::FILE_LENGTH_CUSTOM_KEY,
_fds_path);
bool valid = dsn::buf2uint64(iter->second, _size);
CHECK(valid, "error to get file size");

// get md5 key
iter = meta.find(fds_service::FILE_MD5_KEY);
dassert_f(iter != meta.end(),
"can't find {} in object({})'s metadata",
fds_service::FILE_MD5_KEY,
_fds_path);
CHECK(iter != meta.end(),
"can't find {} in object({})'s metadata",
fds_service::FILE_MD5_KEY,
_fds_path);
_md5sum = iter->second;

_has_meta_synced = true;
Expand Down
7 changes: 3 additions & 4 deletions src/block_service/local/local_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ error_code local_service::initialize(const std::vector<std::string> &args)
LOG_WARNING("old local block service root dir has already exist, path(%s)",
_root.c_str());
} else {
if (!::dsn::utils::filesystem::create_directory(_root)) {
dassert(false, "local block service create directory(%s) fail", _root.c_str());
return ERR_FS_INTERNAL;
}
CHECK(::dsn::utils::filesystem::create_directory(_root),
"local block service create directory({}) fail",
_root);
}
LOG_INFO("local block service initialize succeed with root(%s)", _root.c_str());
}
Expand Down
8 changes: 4 additions & 4 deletions src/client/partition_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ void partition_resolver::call_task(const rpc_response_task_ptr &t)
dynamic_cast<rpc_response_task *>(task::get_current_task());
partition_resolver_ptr r(this);

dassert(ctask != nullptr, "current task must be rpc_response_task");
CHECK_NOTNULL(ctask, "current task must be rpc_response_task");
ctask->replace_callback(std::move(oc));
dassert(ctask->set_retry(false),
"rpc_response_task set retry failed, state = %s",
enum_to_string(ctask->state()));
CHECK(ctask->set_retry(false),
"rpc_response_task set retry failed, state = {}",
enum_to_string(ctask->state()));

// sleep gap milliseconds before retry
tasking::enqueue(LPC_RPC_DELAY_CALL,
Expand Down
2 changes: 1 addition & 1 deletion src/client/replication_ddl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ ::dsn::error_code replication_ddl_client::clear_app_envs(const std::string &app_
if (clear_all) {
req->__set_clear_prefix("");
} else {
dassert(!prefix.empty(), "prefix can not be empty");
CHECK(!prefix.empty(), "prefix can not be empty");
req->__set_clear_prefix(prefix);
}

Expand Down
3 changes: 1 addition & 2 deletions src/client_lib/pegasus_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,7 @@ 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);
dassert(
it != _client_error_to_string.end(), "client error %d have no error string", error_code);
CHECK(it != _client_error_to_string.end(), "client error {} have no error string", error_code);
return it->second.c_str();
}

Expand Down
6 changes: 4 additions & 2 deletions src/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
// specific language governing permissions and limitations
// under the License.

#include "common/common.h"
#include "common.h"

#include "utils/flags.h"
#include "utils/fmt_logging.h"

namespace dsn {
DSN_DEFINE_string("replication", cluster_name, "", "name of this cluster");

/*extern*/ const char *get_current_cluster_name()
{
dassert(strlen(FLAGS_cluster_name) != 0, "cluster_name is not set");
CHECK_GT_MSG(strlen(FLAGS_cluster_name), 0, "cluster_name is not set");
return FLAGS_cluster_name;
}
} // namespace dsn
12 changes: 6 additions & 6 deletions src/common/duplication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ const std::string duplication_constants::kDuplicationEnvMasterMetasKey /*NOLINT*
/*extern*/ const char *duplication_status_to_string(duplication_status::type status)
{
auto it = _duplication_status_VALUES_TO_NAMES.find(status);
dassert(it != _duplication_status_VALUES_TO_NAMES.end(),
"unexpected type of duplication_status: %d",
status);
CHECK(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);
dassert(it != _duplication_fail_mode_VALUES_TO_NAMES.end(),
"unexpected type of duplication_fail_mode: %d",
fmode);
CHECK(it != _duplication_fail_mode_VALUES_TO_NAMES.end(),
"unexpected type of duplication_fail_mode: {}",
fmode);
return it->second;
}

Expand Down
6 changes: 1 addition & 5 deletions src/common/fs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ void fs_manager::allocate_dir(const gpid &pid, const std::string &type, /*out*/
unsigned least_total_replicas_count = 0;

for (auto &n : _dir_nodes) {
dassert(!n->has(pid),
"gpid(%d.%d) already in dir_node(%s)",
pid.get_app_id(),
pid.get_partition_index(),
n->tag.c_str());
CHECK(!n->has(pid), "gpid({}) already in dir_node({})", pid, n->tag);
unsigned app_replicas = n->replicas_count(pid.get_app_id());
unsigned total_replicas = n->replicas_count();

Expand Down
2 changes: 1 addition & 1 deletion src/common/json_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ inline void json_encode(JsonWriter &out, const std::shared_ptr<T> &t)
{
// when a smart ptr is encoded, caller should ensure the ptr is not nullptr
// TODO: encoded to null?
dassert(t.get(), "");
CHECK(t, "");
json_encode(out, *t);
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/storage_serverlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class storage_serverlet

static bool register_async_rpc_handler(dsn::task_code rpc_code, const char *name, rpc_handler h)
{
dassert(s_handlers.emplace(rpc_code.to_string(), h).second,
"handler %s has already been registered",
rpc_code.to_string());
dassert(s_handlers.emplace(name, h).second, "handler %s has already been registered", name);
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);

s_vhandlers.resize(rpc_code + 1);
CHECK(s_vhandlers[rpc_code] == nullptr,
Expand Down
2 changes: 1 addition & 1 deletion src/meta/duplication/duplication_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ extern void json_encode(dsn::json::JsonWriter &out, const duplication_fail_mode:

extern bool json_decode(const dsn::json::JsonObject &in, duplication_fail_mode::type &s);

// TODO(yingchun): remember to update it when refactor dassert_f
// TODO(yingchun): remember to cleanup dassert_dup
#define dassert_dup(_pred_, _dup_, ...) \
CHECK(_pred_, "[a{}d{}] {}", _dup_->app_id, _dup_->id, fmt::format(__VA_ARGS__));

Expand Down
15 changes: 3 additions & 12 deletions src/meta/load_balance_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ const std::string &get_disk_tag(const app_mapper &apps, const rpc_address &node,
{
const config_context &cc = *get_config_context(apps, pid);
auto iter = cc.find_from_serving(node);
dassert(iter != cc.serving.end(),
"can't find disk tag of gpid(%d.%d) for %s",
pid.get_app_id(),
pid.get_partition_index(),
node.to_string());
CHECK(iter != cc.serving.end(), "can't find disk tag of gpid({}) for {}", pid, node);
return iter->disk_tag;
}

Expand Down Expand Up @@ -335,10 +331,7 @@ dsn::gpid load_balance_policy::select_moving(std::list<dsn::gpid> &potential_mov
}
}

dassert_f(selected != potential_moving.end(),
"can't find gpid to move from({}) to({})",
from.to_string(),
to.to_string());
CHECK(selected != potential_moving.end(), "can't find gpid to move from({}) to({})", from, to);
auto res = *selected;
potential_moving.erase(selected);
return res;
Expand Down Expand Up @@ -556,9 +549,7 @@ void ford_fulkerson::update_decree(int node_id, const node_state &ns)
const partition_configuration &pc = _app->partitions[pid.get_partition_index()];
for (const auto &secondary : pc.secondaries) {
auto i = _address_id.find(secondary);
dassert_f(i != _address_id.end(),
"invalid secondary address, address = {}",
secondary.to_string());
CHECK(i != _address_id.end(), "invalid secondary address, address = {}", secondary);
_network[node_id][i->second]++;
}
return true;
Expand Down
7 changes: 4 additions & 3 deletions src/meta/meta_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ bool construct_replica(meta_view view, const gpid &pid, int max_replica_count)

// treat last server in drop_list as the primary
const dropped_replica &server = drop_list.back();
dassert(server.ballot != invalid_ballot,
"the ballot of server must not be invalid_ballot, node = %s",
server.node.to_string());
CHECK_NE_MSG(server.ballot,
invalid_ballot,
"the ballot of server must not be invalid_ballot, node = {}",
server.node);
pc.primary = server.node;
pc.ballot = server.ballot;
pc.partition_flags = 0;
Expand Down
7 changes: 4 additions & 3 deletions src/meta/meta_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ void meta_options::initialize()
break;
}
}
dassert(meta_function_level_on_start != meta_function_level::fl_invalid,
"invalid function level: %s",
level_str);
CHECK_NE_MSG(meta_function_level_on_start,
meta_function_level::fl_invalid,
"invalid function level: {}",
level_str);

recover_from_replica_server = dsn_config_get_value_bool(
"meta_server",
Expand Down
21 changes: 10 additions & 11 deletions src/replica/backup/cold_backup_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const char *cold_backup_status_to_string(cold_backup_status status)
case ColdBackupFailed:
return "ColdBackupFailed";
default:
dassert(false, "");
CHECK(false, "");
}
return "ColdBackupXXX";
}
Expand Down Expand Up @@ -195,7 +195,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;
dassert(file_handle != nullptr, "");
CHECK_NOTNULL(file_handle, "");
if (file_handle->get_md5sum().empty() && file_handle->get_size() <= 0) {
LOG_INFO("%s: check backup on remote, current_checkpoint file %s is not exist",
name,
Expand Down Expand Up @@ -421,7 +421,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) {
dassert(resp.file_handle != nullptr, "");
CHECK_NOTNULL(resp.file_handle, "");
if (resp.file_handle->get_md5sum().empty() && resp.file_handle->get_size() <= 0) {
_upload_status.store(UploadUncomplete);
LOG_INFO("%s: check upload_status complete, cold_backup_metadata isn't exist, "
Expand Down Expand Up @@ -650,7 +650,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;
dassert(file_handle != nullptr, "");
CHECK_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 =
Expand Down Expand Up @@ -735,9 +735,8 @@ void cold_backup_context::on_upload(const dist::block_service::block_file_ptr &f
if (resp.err == ERR_OK) {
std::string local_filename =
::dsn::utils::filesystem::get_file_name(full_path_local_file);
dassert(_file_infos.at(local_filename).first ==
static_cast<int64_t>(resp.uploaded_size),
"");
CHECK_EQ(_file_infos.at(local_filename).first,
static_cast<int64_t>(resp.uploaded_size));
LOG_INFO("%s: upload checkpoint file complete, file = %s",
name,
full_path_local_file.c_str());
Expand Down Expand Up @@ -803,7 +802,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) {
dassert(resp.file_handle != nullptr, "");
CHECK_NOTNULL(resp.file_handle, "");
blob buffer = json::json_forwarder<cold_backup_metadata>::encode(_metadata);
// hold itself until callback is executed
add_ref();
Expand Down Expand Up @@ -887,7 +886,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) {
dassert(resp.file_handle != nullptr, "");
CHECK_NOTNULL(resp.file_handle, "");
auto len = value.length();
std::shared_ptr<char> buf = utils::make_shared_array<char>(len);
::memcpy(buf.get(), value.c_str(), len);
Expand Down Expand Up @@ -940,7 +939,7 @@ void cold_backup_context::on_write(const dist::block_service::block_file_ptr &fi
const blob &value,
const std::function<void(bool)> &callback)
{
dassert(file_handle != nullptr, "");
CHECK_NOTNULL(file_handle, "");
dist::block_service::write_request req;
req.buffer = value;

Expand Down Expand Up @@ -1021,7 +1020,7 @@ void cold_backup_context::on_upload_file_complete(const std::string &local_filen
}
return;
} else {
dassert(total != 0.0, "total = %" PRId64 "", total);
CHECK_GT(total, 0.0);
update_progress(static_cast<int>(complete_size / total * 1000));
LOG_INFO("%s: the progress of upload checkpoint is %d", name, _progress.load());
}
Expand Down
2 changes: 1 addition & 1 deletion src/replica/duplication/mutation_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void mutation_buffer::commit(decree d, commit_type ct)
// | |
// n+m(m>1) n+k(k>=m)
//
// just LOG_ERROR but not dassert if mutation loss or other problem, it's different from
// just LOG_ERROR but not CHECK if mutation loss or other problem, it's different from
// base class implement. And from the error and perf-counter, we can choose restart
// duplication
// or ignore the loss.
Expand Down
2 changes: 1 addition & 1 deletion src/replica/log_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class log_block
// ```
blob &front()
{
dassert(!_data.empty(), "trying to get first blob out of an empty log block");
CHECK(!_data.empty(), "trying to get first blob out of an empty log block");
return _data.front();
}

Expand Down
Loading

0 comments on commit e2a0088

Please sign in to comment.