Skip to content

Commit

Permalink
refactor(macro): use CHECK_* to replace dassert_* (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Oct 29, 2022
1 parent 68a1a01 commit 10f7328
Show file tree
Hide file tree
Showing 118 changed files with 1,054 additions and 1,346 deletions.
7 changes: 4 additions & 3 deletions src/aio/aio_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ aio_task::aio_task(dsn::task_code code, aio_handler &&cb, int hash, service_node
{
_is_null = (_cb == nullptr);

dassert_f(TASK_TYPE_AIO == spec().type,
"{} is not of AIO type, please use DEFINE_TASK_CODE_AIO to define the task code",
spec().name);
CHECK_EQ_MSG(TASK_TYPE_AIO,
spec().type,
"{} is not of AIO type, please use DEFINE_TASK_CODE_AIO to define the task code",
spec().name);
set_error_code(ERR_IO_PENDING);

_aio_ctx = file::prepare_aio_context(this);
Expand Down
4 changes: 2 additions & 2 deletions src/aio/disk_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ aio_task *disk_file::write(aio_task *tsk, void *ctx)

aio_task *disk_file::on_read_completed(aio_task *wk, error_code err, size_t size)
{
dassert(wk->next == nullptr, "");
CHECK(wk->next == nullptr, "");
auto ret = _read_queue.on_work_completed(wk, nullptr);
wk->enqueue(err, size);
wk->release_ref(); // added in above read
Expand Down Expand Up @@ -138,7 +138,7 @@ aio_task *disk_file::on_write_completed(aio_task *wk, void *ctx, error_code err,
}

if (err == ERR_OK) {
dassert(size == 0, "written buffer size does not equal to input buffer's size");
CHECK_EQ_MSG(size, 0, "written buffer size does not equal to input buffer's size");
}

return ret;
Expand Down
19 changes: 8 additions & 11 deletions src/base/pegasus_key_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace pegasus {
template <typename T>
void pegasus_generate_key(::dsn::blob &key, const T &hash_key, const T &sort_key)
{
dassert(hash_key.length() < UINT16_MAX, "hash key length must be less than UINT16_MAX");
CHECK_LT(hash_key.length(), UINT16_MAX);

int len = 2 + hash_key.length() + sort_key.length();
std::shared_ptr<char> buf(::dsn::utils::make_shared_array<char>(len));
Expand All @@ -64,7 +64,7 @@ void pegasus_generate_key(::dsn::blob &key, const T &hash_key, const T &sort_key
template <typename T>
void pegasus_generate_next_blob(::dsn::blob &next, const T &hash_key)
{
dassert(hash_key.length() < UINT16_MAX, "hash key length must be less than UINT16_MAX");
CHECK_LT(hash_key.length(), UINT16_MAX);

int hash_key_len = hash_key.length();
std::shared_ptr<char> buf(::dsn::utils::make_shared_array<char>(hash_key_len + 2));
Expand Down Expand Up @@ -102,14 +102,13 @@ void pegasus_generate_next_blob(::dsn::blob &next, const T &hash_key, const T &s
inline void
pegasus_restore_key(const ::dsn::blob &key, ::dsn::blob &hash_key, ::dsn::blob &sort_key)
{
dassert(key.length() >= 2, "key length must be no less than 2");
CHECK_GE(key.length(), 2);

// hash_key_len is in big endian
uint16_t hash_key_len = ::dsn::endian::ntoh(*(uint16_t *)(key.data()));

if (hash_key_len > 0) {
dassert(key.length() >= 2 + hash_key_len,
"key length must be no less than (2 + hash_key_len)");
CHECK_GE(key.length(), 2 + hash_key_len);
hash_key = key.range(2, hash_key_len);
} else {
hash_key = ::dsn::blob();
Expand All @@ -127,14 +126,13 @@ pegasus_restore_key(const ::dsn::blob &key, ::dsn::blob &hash_key, ::dsn::blob &
inline void
pegasus_restore_key(const ::dsn::blob &key, std::string &hash_key, std::string &sort_key)
{
dassert(key.length() >= 2, "key length must be no less than 2");
CHECK_GE(key.length(), 2);

// hash_key_len is in big endian
uint16_t hash_key_len = ::dsn::endian::ntoh(*(uint16_t *)(key.data()));

if (hash_key_len > 0) {
dassert(key.length() >= 2 + hash_key_len,
"key length must be no less than (2 + hash_key_len)");
CHECK_GE(key.length(), 2 + hash_key_len);
hash_key.assign(key.data() + 2, hash_key_len);
} else {
hash_key.clear();
Expand All @@ -151,15 +149,14 @@ pegasus_restore_key(const ::dsn::blob &key, std::string &hash_key, std::string &
template <typename T>
inline uint64_t pegasus_key_hash(const T &key)
{
dassert(key.size() >= 2, "key length must be no less than 2");
CHECK_GE(key.size(), 2);

// hash_key_len is in big endian
uint16_t hash_key_len = ::dsn::endian::ntoh(*(uint16_t *)(key.data()));

if (hash_key_len > 0) {
// hash_key_len > 0, compute hash from hash_key
dassert(key.size() >= 2 + hash_key_len,
"key length must be no less than (2 + hash_key_len)");
CHECK_GE(key.size(), 2 + hash_key_len);
return dsn::utils::crc64_calc(key.data() + 2, hash_key_len, 0);
} else {
// hash_key_len == 0, compute hash from sort_key
Expand Down
13 changes: 3 additions & 10 deletions src/base/pegasus_value_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ inline uint64_t extract_timestamp_from_timetag(uint64_t timetag)
/// \return expire_ts in host endian
inline uint32_t pegasus_extract_expire_ts(uint32_t version, dsn::string_view value)
{
dassert_f(version <= PEGASUS_DATA_VERSION_MAX,
"data version({}) must be <= {}",
version,
PEGASUS_DATA_VERSION_MAX);

CHECK_LE(version, PEGASUS_DATA_VERSION_MAX);
return dsn::data_input(value).read_u32();
}

Expand All @@ -76,10 +72,7 @@ inline uint32_t pegasus_extract_expire_ts(uint32_t version, dsn::string_view val
inline void
pegasus_extract_user_data(uint32_t version, std::string &&raw_value, ::dsn::blob &user_data)
{
dassert_f(version <= PEGASUS_DATA_VERSION_MAX,
"data version({}) must be <= {}",
version,
PEGASUS_DATA_VERSION_MAX);
CHECK_LE(version, PEGASUS_DATA_VERSION_MAX);

auto *s = new std::string(std::move(raw_value));
dsn::data_input input(*s);
Expand Down Expand Up @@ -110,7 +103,7 @@ inline uint64_t pegasus_extract_timetag(int version, dsn::string_view value)
inline void pegasus_update_expire_ts(uint32_t version, std::string &value, uint32_t new_expire_ts)
{
if (version == 0 || version == 1) {
dassert_f(value.length() >= sizeof(uint32_t), "value must include 'expire_ts' header");
CHECK_GE_MSG(value.length(), sizeof(uint32_t), "value must include 'expire_ts' header");

new_expire_ts = dsn::endian::hton(new_expire_ts);
memcpy(const_cast<char *>(value.data()), &new_expire_ts, sizeof(uint32_t));
Expand Down
2 changes: 1 addition & 1 deletion src/base/value_schema_v0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ std::unique_ptr<value_field> value_schema_v0::extract_timestamp(dsn::string_view

void value_schema_v0::update_expire_ts(std::string &value, std::unique_ptr<value_field> field)
{
dassert_f(value.length() >= sizeof(uint32_t), "value must include 'expire_ts' header");
CHECK_GE_MSG(value.length(), sizeof(uint32_t), "value must include 'expire_ts' header");
auto expire_field = static_cast<expire_timestamp_field *>(field.get());

auto new_expire_ts = dsn::endian::hton(expire_field->expire_ts);
Expand Down
2 changes: 1 addition & 1 deletion src/base/value_schema_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ std::unique_ptr<value_field> value_schema_v1::extract_time_tag(dsn::string_view

void value_schema_v1::update_expire_ts(std::string &value, std::unique_ptr<value_field> field)
{
dassert_f(value.length() >= sizeof(uint32_t), "value must include 'expire_ts' header");
CHECK_GE_MSG(value.length(), sizeof(uint32_t), "value must include 'expire_ts' header");
auto expire_field = static_cast<expire_timestamp_field *>(field.get());

auto new_expire_ts = dsn::endian::hton(expire_field->expire_ts);
Expand Down
5 changes: 3 additions & 2 deletions src/base/value_schema_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ std::unique_ptr<value_field> value_schema_v2::extract_time_tag(dsn::string_view

void value_schema_v2::update_expire_ts(std::string &value, std::unique_ptr<value_field> field)
{
dassert_f(value.length() >= sizeof(uint32_t) + sizeof(uint8_t),
"value must include 'expire_ts' header");
CHECK_GE_MSG(value.length(),
sizeof(uint32_t) + sizeof(uint8_t),
"value must include 'expire_ts' header");
auto expire_field = static_cast<expire_timestamp_field *>(field.get());

auto new_expire_ts = dsn::endian::hton(expire_field->expire_ts);
Expand Down
6 changes: 3 additions & 3 deletions src/block_service/directio_writable_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ direct_io_writable_file::~direct_io_writable_file()
return;
}
// Here is an ensurance, users shuold call finalize manually
dassert(_offset == 0, "finalize() should be called before destructor");
CHECK_EQ_MSG(_offset, 0, "finalize() should be called before destructor");

free(_buffer);
close(_fd);
Expand Down Expand Up @@ -92,7 +92,7 @@ bool direct_io_writable_file::initialize()

bool direct_io_writable_file::finalize()
{
dassert(_buffer && _fd >= 0, "Initialize the instance first");
CHECK(_buffer && _fd >= 0, "Initialize the instance first");

if (_offset > 0) {
if (::write(_fd, _buffer, _buffer_size) != _buffer_size) {
Expand All @@ -108,7 +108,7 @@ bool direct_io_writable_file::finalize()

bool direct_io_writable_file::write(const char *s, size_t n)
{
dassert(_buffer && _fd >= 0, "Initialize the instance first");
CHECK(_buffer && _fd >= 0, "Initialize the instance first");

uint32_t remaining = n;
while (remaining > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/client_lib/pegasus_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pegasus_client_impl::pegasus_client_impl(const char *cluster_name, const char *a
std::vector<dsn::rpc_address> meta_servers;
dsn::replication::replica_helper::load_meta_servers(
meta_servers, PEGASUS_CLUSTER_SECTION_NAME.c_str(), cluster_name);
dassert(meta_servers.size() > 0, "");
CHECK_GT(meta_servers.size(), 0);
_meta_server.assign_group("meta-servers");
_meta_server.group_address()->add_list(meta_servers);

Expand Down
18 changes: 10 additions & 8 deletions src/common/duplication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,22 @@ class duplication_group_registry : public utils::singleton<duplication_group_reg
for (std::string &cluster : clusters) {
int64_t cluster_id =
dsn_config_get_value_int64("duplication-group", cluster.data(), 0, "");
dassert(cluster_id < 128 && cluster_id > 0,
"cluster_id(%zd) for %s should be in [1, 127]",
cluster_id,
cluster.data());
CHECK(cluster_id < 128 && cluster_id > 0,
"cluster_id({}) for {} should be in [1, 127]",
cluster_id,
cluster.data());
_group.emplace(cluster, static_cast<uint8_t>(cluster_id));
}
dassert_f(clusters.size() == _group.size(),
"there might be duplicate cluster_name in configuration");
CHECK_EQ_MSG(clusters.size(),
_group.size(),
"there might be duplicate cluster_name in configuration");

for (const auto &kv : _group) {
_distinct_cids.insert(kv.second);
}
dassert_f(_distinct_cids.size() == _group.size(),
"there might be duplicate cluster_id in configuration");
CHECK_EQ_MSG(_distinct_cids.size(),
_group.size(),
"there might be duplicate cluster_id in configuration");
}
~duplication_group_registry() = default;

Expand Down
10 changes: 5 additions & 5 deletions src/common/fs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ void fs_manager::remove_replica(const gpid &pid)
unsigned remove_count = 0;
for (auto &n : _dir_nodes) {
unsigned r = n->remove(pid);
dassert(remove_count + r <= 1,
"gpid(%d.%d) found in dir(%s), which was removed before",
pid.get_app_id(),
pid.get_partition_index(),
n->tag.c_str());
CHECK_LE_MSG(remove_count + r,
1,
"gpid({}) found in dir({}), which was removed before",
pid,
n->tag);
if (r != 0) {
LOG_INFO("%s: remove gpid(%d.%d) from dir(%s)",
dsn_primary_address().to_string(),
Expand Down
16 changes: 7 additions & 9 deletions src/common/replication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,7 @@ void replication_options::initialize()

void replication_options::sanity_check()
{
dassert(max_mutation_count_in_prepare_list >= staleness_for_commit,
"%d VS %d",
max_mutation_count_in_prepare_list,
staleness_for_commit);
CHECK_GE(max_mutation_count_in_prepare_list, staleness_for_commit);
}

int32_t replication_options::app_mutation_2pc_min_replica_count(int32_t app_max_replica_count) const
Expand Down Expand Up @@ -478,11 +475,12 @@ bool replica_helper::load_meta_servers(/*out*/ std::vector<dsn::rpc_address> &se
std::vector<std::string> hostname_port;
uint32_t ip = 0;
utils::split_args(s.c_str(), hostname_port, ':');
dassert_f(2 == hostname_port.size(),
"invalid address '{}' specified in config [{}].{}",
s.c_str(),
section,
key);
CHECK_EQ_MSG(2,
hostname_port.size(),
"invalid address '{}' specified in config [{}].{}",
s,
section,
key);
uint32_t port_num = 0;
CHECK(dsn::internal::buf2unsigned(hostname_port[1], port_num) && port_num < UINT16_MAX,
"invalid address '{}' specified in config [{}].{}",
Expand Down
8 changes: 4 additions & 4 deletions src/common/serialization_helper/thrift_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,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<int64_t &>(_addr.value));
dassert(_addr.v4.type == HOST_TYPE_INVALID || _addr.v4.type == HOST_TYPE_IPV4,
"only invalid or ipv4 can be deserialized from binary");
CHECK(_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
Expand Down Expand Up @@ -247,8 +247,8 @@ inline uint32_t rpc_address::write(apache::thrift::protocol::TProtocol *oprot) c
dynamic_cast<apache::thrift::protocol::TBinaryProtocol *>(oprot);
if (binary_proto != nullptr) {
// the protocol is binary protocol
dassert(_addr.v4.type == HOST_TYPE_INVALID || _addr.v4.type == HOST_TYPE_IPV4,
"only invalid or ipv4 can be serialized to binary");
CHECK(_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
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 @@ -105,10 +105,10 @@ class storage_serverlet
dassert(s_handlers.emplace(name, h).second, "handler %s has already been registered", name);

s_vhandlers.resize(rpc_code + 1);
dassert(s_vhandlers[rpc_code] == nullptr,
"handler %s(%d) has already been registered",
rpc_code.to_string(),
rpc_code.code());
CHECK(s_vhandlers[rpc_code] == nullptr,
"handler {}({}) has already been registered",
rpc_code.to_string(),
rpc_code.code());
s_vhandlers[rpc_code] = h;
return true;
}
Expand Down
5 changes: 1 addition & 4 deletions src/failure_detector/failure_detector_multimaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ void slave_failure_detector_with_multimaster::end_ping(::dsn::error_code err,
if (!failure_detector::end_ping_internal(err, ack))
return;

dassert(ack.this_node == _meta_servers.group_address()->leader(),
"ack.this_node[%s] vs meta_servers.leader[%s]",
ack.this_node.to_string(),
_meta_servers.group_address()->leader().to_string());
CHECK_EQ(ack.this_node, _meta_servers.group_address()->leader());

if (ERR_OK != err) {
rpc_address next = _meta_servers.group_address()->next(ack.this_node);
Expand Down
5 changes: 1 addition & 4 deletions src/geo/lib/geo_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ geo_client::geo_client(const char *config_file,
_max_level = (int32_t)dsn_config_get_value_uint64(
"geo_client.lib", "max_level", 16, "max cell level for scan");

dassert_f(_min_level < _max_level,
"_min_level({}) must be less than _max_level({})",
_min_level,
_max_level);
CHECK_LT(_min_level, _max_level);

uint32_t latitude_index = (uint32_t)dsn_config_get_value_uint64(
"geo_client.lib", "latitude_index", 5, "latitude index in value");
Expand Down
2 changes: 1 addition & 1 deletion src/http/http_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void http_message_parser::prepare_on_send(message_ex *msg)
int dsn_buf_count = 0;
while (dsn_size > 0 && dsn_buf_count < buffers.size()) {
blob &buf = buffers[dsn_buf_count];
dassert(dsn_size >= buf.length(), "%u VS %u", dsn_size, buf.length());
CHECK_GE(dsn_size, buf.length());
dsn_size -= buf.length();
++dsn_buf_count;
}
Expand Down
4 changes: 2 additions & 2 deletions src/meta/greedy_load_balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ bool greedy_load_balancer::all_replica_infos_collected(const node_state &ns)

void greedy_load_balancer::greedy_balancer(const bool balance_checker)
{
dassert(t_alive_nodes >= FLAGS_min_live_node_count_for_unfreeze,
"too few nodes will be freezed");
CHECK_GE_MSG(
t_alive_nodes, FLAGS_min_live_node_count_for_unfreeze, "too few nodes will be freezed");

for (auto &kv : *(t_global_view->nodes)) {
node_state &ns = kv.second;
Expand Down
18 changes: 10 additions & 8 deletions src/meta/load_balance_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ void load_balance_policy::init(const meta_view *global_view, migration_list *lis
bool load_balance_policy::primary_balance(const std::shared_ptr<app_state> &app,
bool only_move_primary)
{
dassert(_alive_nodes >= FLAGS_min_live_node_count_for_unfreeze,
"too few alive nodes will lead to freeze");
CHECK_GE_MSG(_alive_nodes,
FLAGS_min_live_node_count_for_unfreeze,
"too few alive nodes will lead to freeze");
LOG_INFO_F("primary balancer for app({}:{})", app->app_name, app->app_id);

auto graph = ford_fulkerson::builder(app, *_global_view->nodes, address_id).build();
Expand Down Expand Up @@ -278,12 +279,13 @@ void load_balance_policy::start_moving_primary(const std::shared_ptr<app_state>
{
std::list<dsn::gpid> potential_moving = calc_potential_moving(app, from, to);
auto potential_moving_size = potential_moving.size();
dassert_f(plan_moving <= potential_moving_size,
"from({}) to({}) plan({}), can_move({})",
from.to_string(),
to.to_string(),
plan_moving,
potential_moving_size);
CHECK_LE_MSG(plan_moving,
potential_moving_size,
"from({}) to({}) plan({}), can_move({})",
from.to_string(),
to.to_string(),
plan_moving,
potential_moving_size);

while (plan_moving-- > 0) {
dsn::gpid selected = select_moving(potential_moving, prev_load, current_load, from, to);
Expand Down
Loading

0 comments on commit 10f7328

Please sign in to comment.