Skip to content

Commit

Permalink
refactor(log): adjust log level and rename for d*_replica/dup/rocksdb…
Browse files Browse the repository at this point in the history
… macros (apache#1202)
  • Loading branch information
acelyc111 authored Oct 26, 2022
1 parent 88fa55c commit db1761e
Show file tree
Hide file tree
Showing 38 changed files with 1,023 additions and 1,014 deletions.
11 changes: 5 additions & 6 deletions src/meta/duplication/duplication_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,13 @@ void duplication_info::persist_status()
zauto_write_lock l(_lock);

if (!_is_altering) {
derror_dup(this, "callers never write a duplication that is not altering to meta store");
LOG_ERROR_PREFIX("callers never write a duplication that is not altering to meta store");
return;
}
ddebug_dup(this,
"change duplication status from {} to {} successfully [app_id: {}]",
duplication_status_to_string(_status),
duplication_status_to_string(_next_status),
app_id);
LOG_INFO_PREFIX("change duplication status from {} to {} successfully [app_id: {}]",
duplication_status_to_string(_status),
duplication_status_to_string(_next_status),
app_id);

_is_altering = false;
_status = _next_status;
Expand Down
16 changes: 6 additions & 10 deletions src/meta/duplication/duplication_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class duplication_info
follower_cluster_name(std::move(follower_cluster_name)),
follower_cluster_metas(std::move(follower_cluster_metas)),
store_path(std::move(meta_store_path)),
create_timestamp_ms(create_now_ms)
create_timestamp_ms(create_now_ms),
prefix_for_log(fmt::format("a{}d{}", app_id, id))
{
for (int i = 0; i < partition_count; i++) {
_progress[i] = {};
Expand Down Expand Up @@ -185,6 +186,8 @@ class duplication_info
// To json encoded string.
std::string to_string() const;

const char *log_prefix() const { return prefix_for_log.c_str(); }

private:
friend class duplication_info_test;
friend class meta_duplication_service_test;
Expand Down Expand Up @@ -237,6 +240,7 @@ class duplication_info
const std::vector<rpc_address> follower_cluster_metas;
const std::string store_path; // store path on meta service = get_duplication_path(app, dupid)
const uint64_t create_timestamp_ms{0}; // the time when this dup is created.
const std::string prefix_for_log;
};

extern void json_encode(dsn::json::JsonWriter &out, const duplication_status::type &s);
Expand All @@ -247,15 +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);

// Macros for writing log message prefixed by appid and dupid.
#define ddebug_dup(_dup_, ...) \
LOG_INFO_F("[a{}d{}] {}", _dup_->app_id, _dup_->id, fmt::format(__VA_ARGS__));
#define dwarn_dup(_dup_, ...) \
LOG_WARNING_F("[a{}d{}] {}", _dup_->app_id, _dup_->id, fmt::format(__VA_ARGS__));
#define derror_dup(_dup_, ...) \
LOG_ERROR_F("[a{}d{}] {}", _dup_->app_id, _dup_->id, fmt::format(__VA_ARGS__));
#define dfatal_dup(_dup_, ...) \
LOG_FATAL_F("[a{}d{}] {}", _dup_->app_id, _dup_->id, fmt::format(__VA_ARGS__));
// TODO(yingchun): remember to update it when refactor dassert_f
#define dassert_dup(_pred_, _dup_, ...) \
dassert_f(_pred_, "[a{}d{}] {}", _dup_->app_id, _dup_->id, fmt::format(__VA_ARGS__));

Expand Down
21 changes: 11 additions & 10 deletions src/meta/duplication/meta_duplication_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ void meta_duplication_service::do_add_duplication(std::shared_ptr<app_state> &ap
std::queue<std::string> nodes({get_duplication_path(*app), std::to_string(dup->id)});
_meta_svc->get_meta_storage()->create_node_recursively(
std::move(nodes), std::move(value), [app, this, dup, rpc]() mutable {
ddebug_dup(dup,
"add duplication successfully [app_name: {}, follower: {}]",
LOG_INFO_F("[{}] add duplication successfully [app_name: {}, follower: {}]",
dup->log_prefix(),
app->app_name,
dup->follower_cluster_name);

Expand Down Expand Up @@ -590,19 +590,20 @@ void meta_duplication_service::do_restore_duplication_progress(

int64_t confirmed_decree = invalid_decree;
if (!buf2int64(value, confirmed_decree)) {
derror_dup(dup,
"invalid confirmed_decree {} on partition_idx {}",
value.to_string(),
partition_idx);
LOG_ERROR_F("[{}] invalid confirmed_decree {} on partition_idx {}",
dup->log_prefix(),
value.to_string(),
partition_idx);
return; // fail fast
}

dup->init_progress(partition_idx, confirmed_decree);

ddebug_dup(dup,
"initialize progress from metastore [partition_idx: {}, confirmed: {}]",
partition_idx,
confirmed_decree);
LOG_INFO_F(
"[{}] initialize progress from metastore [partition_idx: {}, confirmed: {}]",
dup->log_prefix(),
partition_idx,
confirmed_decree);
});
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/replica/backup/replica_backup_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void replica_backup_manager::on_clear_cold_backup(const backup_clear_request &re
if (find != _replica->_cold_backup_contexts.end()) {
cold_backup_context_ptr backup_context = find->second;
if (backup_context->is_checkpointing()) {
ddebug_replica(
LOG_INFO_PREFIX(
"{}: delay clearing obsoleted cold backup context, cause backup_status == "
"ColdBackupCheckpointing",
backup_context->name);
Expand Down Expand Up @@ -143,9 +143,9 @@ void replica_backup_manager::collect_backup_info()

void replica_backup_manager::background_clear_backup_checkpoint(const std::string &policy_name)
{
ddebug_replica("schedule to clear all checkpoint dirs of policy({}) after {} minutes",
policy_name,
_replica->options()->cold_backup_checkpoint_reserve_minutes);
LOG_INFO_PREFIX("schedule to clear all checkpoint dirs of policy({}) after {} minutes",
policy_name,
_replica->options()->cold_backup_checkpoint_reserve_minutes);
tasking::enqueue(
LPC_BACKGROUND_COLD_BACKUP,
&_replica->_tracker,
Expand All @@ -157,7 +157,7 @@ void replica_backup_manager::background_clear_backup_checkpoint(const std::strin
// clear all checkpoint dirs of the policy
void replica_backup_manager::clear_backup_checkpoint(const std::string &policy_name)
{
ddebug_replica("clear all checkpoint dirs of policy({})", policy_name);
LOG_INFO_PREFIX("clear all checkpoint dirs of policy({})", policy_name);
auto backup_dir = _replica->_app->backup_dir();
if (!utils::filesystem::directory_exists(backup_dir)) {
return;
Expand All @@ -166,17 +166,17 @@ void replica_backup_manager::clear_backup_checkpoint(const std::string &policy_n
// Find the corresponding checkpoint dirs with policy name
std::vector<std::string> chkpt_dirs;
if (!get_policy_checkpoint_dirs(backup_dir, policy_name, chkpt_dirs)) {
dwarn_replica("get checkpoint dirs in backup dir({}) failed", backup_dir);
LOG_WARNING_PREFIX("get checkpoint dirs in backup dir({}) failed", backup_dir);
return;
}

// Remove these checkpoint dirs
for (const std::string &dirname : chkpt_dirs) {
std::string full_path = utils::filesystem::path_combine(backup_dir, dirname);
if (utils::filesystem::remove_path(full_path)) {
ddebug_replica("remove backup checkpoint dir({}) succeed", full_path);
LOG_INFO_PREFIX("remove backup checkpoint dir({}) succeed", full_path);
} else {
dwarn_replica("remove backup checkpoint dir({}) failed", full_path);
LOG_WARNING_PREFIX("remove backup checkpoint dir({}) failed", full_path);
}
}
}
Expand Down
Loading

0 comments on commit db1761e

Please sign in to comment.