Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(macro): use DCHECK* to replace dbg_dassert and self defined ASSERT_* #41

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ src/base/rrdb_types.cpp
src/include/rrdb/rrdb_types.h
src/common/serialization_helper/dsn.layer2_types.h
src/runtime/dsn.layer2_types.cpp
src/runtime
src/*builder

onebox/
Expand Down
2 changes: 1 addition & 1 deletion java-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<guava.version>28.1-jre</guava.version>
<mockito.version>2.24.5</mockito.version>
<dropwizard.version>3.1.2</dropwizard.version>
<apache.commons.configuration2.version>2.7</apache.commons.configuration2.version>
<apache.commons.configuration2.version>2.8.0</apache.commons.configuration2.version>
<slf4j.version>1.7.2</slf4j.version>
<apache.commons.lang3.version>3.1</apache.commons.lang3.version>
<zkclient.version>0.2</zkclient.version>
Expand Down
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
5 changes: 3 additions & 2 deletions src/common/gpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include <cstdint>
#include <ostream>
#include <thrift/protocol/TProtocol.h>

namespace dsn {
Expand Down Expand Up @@ -71,9 +72,9 @@ class gpid

int thread_hash() const { return _value.u.app_id * 7919 + _value.u.partition_index; }

friend std::ostream &operator<<(std::ostream &os, gpid id)
friend std::ostream &operator<<(std::ostream &os, const gpid &id)
{
return os << std::string(id.to_string());
return os << id.to_string();
}

private:
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
25 changes: 6 additions & 19 deletions src/meta/test/balancer_simulator/balancer_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,17 @@
*/

#include <algorithm>

#include <gtest/gtest.h>

#include "meta/greedy_load_balancer.h"
#include "meta/meta_data.h"
#include "meta/server_load_balancer.h"
#include "meta/greedy_load_balancer.h"
#include "meta/test/misc/misc.h"
#include "utils/fmt_logging.h"

using namespace dsn::replication;

#ifdef ASSERT_EQ
#undef ASSERT_EQ
#endif
#define ASSERT_EQ(left, right) CHECK((left) == (right), "")

#ifdef ASSERT_TRUE
#undef ASSERT_TRUE
#endif
#define ASSERT_TRUE(exp) CHECK((exp), "")

#ifdef ASSERT_FALSE
#undef ASSERT_FALSE
#endif
#define ASSERT_FALSE(exp) CHECK(!(exp), "")

class simple_priority_queue
{
public:
Expand Down Expand Up @@ -143,8 +130,8 @@ void generate_balanced_apps(/*out*/ app_mapper &apps,

apps.emplace(the_app->app_id, the_app);

ASSERT_TRUE(pri_max - pri_min <= 1);
ASSERT_TRUE(part_max - part_min <= 1);
CHECK_LE(pri_max - pri_min, 1);
CHECK_LE(part_max - part_min, 1);
}

void random_move_primary(app_mapper &apps, node_mapper &nodes, int primary_move_ratio)
Expand Down Expand Up @@ -184,7 +171,7 @@ void greedy_balancer_perfect_move_primary()
for (const auto &kv : ml) {
const std::shared_ptr<configuration_balancer_request> &req = kv.second;
for (const configuration_proposal_action &act : req->action_list) {
ASSERT_TRUE(act.type != config_type::CT_ADD_SECONDARY_FOR_LB);
CHECK_NE(act.type, config_type::CT_ADD_SECONDARY_FOR_LB);
}
}
glb.check({&apps, &nodes}, ml);
Expand Down
Loading