This is an automated email from the ASF dual-hosted git repository.

wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new be9119e75 fix: fix errors in format string for logging and macro 
(#1588)
be9119e75 is described below

commit be9119e75f27b9f0563acaf33f5c96edf0051307
Author: Dan Wang <[email protected]>
AuthorDate: Mon Aug 28 14:45:00 2023 +0800

    fix: fix errors in format string for logging and macro (#1588)
    
    https://github.com/apache/incubator-pegasus/issues/1587
    
    Fix some wrong format string in logging and macro that are:
    
    - still using c-style format string, which would not print the correct 
messages;
    - calling `to_string()` method for the classes which have implemented 
`operator<<`.
---
 src/meta/meta_backup_service.cpp   | 13 +++----------
 src/meta/meta_data.cpp             | 12 ++++--------
 src/meta/partition_guardian.cpp    | 14 +++++---------
 src/meta/test/backup_test.cpp      |  1 -
 src/replica/replica.cpp            |  6 ++----
 src/replica/replica_2pc.cpp        |  6 +-----
 src/runtime/task/task.cpp          |  4 ++--
 src/server/pegasus_server_impl.cpp |  2 +-
 8 files changed, 18 insertions(+), 40 deletions(-)

diff --git a/src/meta/meta_backup_service.cpp b/src/meta/meta_backup_service.cpp
index db2afe1d9..8a28ffaf3 100644
--- a/src/meta/meta_backup_service.cpp
+++ b/src/meta/meta_backup_service.cpp
@@ -1036,10 +1036,7 @@ void policy_context::sync_remove_backup_info(const 
backup_info &info, dsn::task_
                 0,
                 _backup_service->backup_option().meta_retry_delay_ms);
         } else {
-            CHECK(false,
-                  "{}: we can't handle this right now, error({})",
-                  _policy.policy_name,
-                  err.to_string());
+            CHECK(false, "{}: we can't handle this right now, error({})", 
_policy.policy_name, err);
         }
     };
 
@@ -1373,9 +1370,7 @@ void backup_service::do_add_policy(dsn::message_ex *req,
                                  _opt.meta_retry_delay_ms);
                 return;
             } else {
-                CHECK(false,
-                      "we can't handle this when create backup policy, 
err({})",
-                      err.to_string());
+                CHECK(false, "we can't handle this when create backup policy, 
err({})", err);
             }
         },
         value);
@@ -1411,9 +1406,7 @@ void backup_service::do_update_policy_to_remote_storage(
                                  0,
                                  _opt.meta_retry_delay_ms);
             } else {
-                CHECK(false,
-                      "we can't handle this when create backup policy, 
err({})",
-                      err.to_string());
+                CHECK(false, "we can't handle this when create backup policy, 
err({})", err);
             }
         });
 }
diff --git a/src/meta/meta_data.cpp b/src/meta/meta_data.cpp
index 48ab6ccd3..23dba0c92 100644
--- a/src/meta/meta_data.cpp
+++ b/src/meta/meta_data.cpp
@@ -159,10 +159,7 @@ bool construct_replica(meta_view view, const gpid &pid, 
int max_replica_count)
     // we put max_replica_count-1 recent replicas to last_drops, in case of 
the DDD-state when the
     // only primary dead
     // when add node to pc.last_drops, we don't remove it from our cc.drop_list
-    CHECK(pc.last_drops.empty(),
-          "last_drops of partition({}.{}) must be empty",
-          pid.get_app_id(),
-          pid.get_partition_index());
+    CHECK(pc.last_drops.empty(), "last_drops of partition({}) must be empty", 
pid);
     for (auto iter = drop_list.rbegin(); iter != drop_list.rend(); ++iter) {
         if (pc.last_drops.size() + 1 >= max_replica_count)
             break;
@@ -402,10 +399,9 @@ int config_context::collect_drop_replica(const rpc_address 
&node, const replica_
     iter = find_from_dropped(node);
     if (iter == dropped.end()) {
         CHECK(!in_dropped,
-              "adjust position of existing node({}) failed, this is a bug, 
partition({}.{})",
-              node.to_string(),
-              config_owner->pid.get_app_id(),
-              config_owner->pid.get_partition_index());
+              "adjust position of existing node({}) failed, this is a bug, 
partition({})",
+              node,
+              config_owner->pid);
         return -1;
     }
     return in_dropped ? 1 : 0;
diff --git a/src/meta/partition_guardian.cpp b/src/meta/partition_guardian.cpp
index 09b0862c4..44e0017f6 100644
--- a/src/meta/partition_guardian.cpp
+++ b/src/meta/partition_guardian.cpp
@@ -102,9 +102,8 @@ void partition_guardian::reconfig(meta_view view, const 
configuration_update_req
     if (!cc->lb_actions.empty()) {
         const configuration_proposal_action *current = cc->lb_actions.front();
         CHECK(current != nullptr && current->type != config_type::CT_INVALID,
-              "invalid proposal for gpid({}.{})",
-              gpid.get_app_id(),
-              gpid.get_partition_index());
+              "invalid proposal for gpid({})",
+              gpid);
         // if the valid proposal is from cure
         if (!cc->lb_actions.is_from_balancer()) {
             finish_cure_proposal(view, gpid, *current);
@@ -132,7 +131,7 @@ void partition_guardian::reconfig(meta_view view, const 
configuration_update_req
 
                 CHECK(cc->record_drop_history(request.node),
                       "node({}) has been in the dropped",
-                      request.node.to_string());
+                      request.node);
             }
         });
     }
@@ -241,8 +240,7 @@ pc_status partition_guardian::on_missing_primary(meta_view 
&view, const dsn::gpi
 
         for (int i = 0; i < pc.secondaries.size(); ++i) {
             node_state *ns = get_node_state(*(view.nodes), pc.secondaries[i], 
false);
-            CHECK_NOTNULL(
-                ns, "invalid secondary address, address = {}", 
pc.secondaries[i].to_string());
+            CHECK_NOTNULL(ns, "invalid secondary address, address = {}", 
pc.secondaries[i]);
             if (!ns->alive())
                 continue;
 
@@ -607,9 +605,7 @@ pc_status 
partition_guardian::on_missing_secondary(meta_view &view, const dsn::g
         // if not emergency, only try to recover last dropped server
         const dropped_replica &server = cc.dropped.back();
         if (is_node_alive(*view.nodes, server.node)) {
-            CHECK(!server.node.is_invalid(),
-                  "invalid server address, address = {}",
-                  server.node.to_string());
+            CHECK(!server.node.is_invalid(), "invalid server address, address 
= {}", server.node);
             action.node = server.node;
         }
 
diff --git a/src/meta/test/backup_test.cpp b/src/meta/test/backup_test.cpp
index 35b88bb97..70062ba69 100644
--- a/src/meta/test/backup_test.cpp
+++ b/src/meta/test/backup_test.cpp
@@ -29,7 +29,6 @@
 #include <set>
 #include <string>
 #include <thread>
-#include <type_traits>
 #include <utility>
 #include <vector>
 
diff --git a/src/replica/replica.cpp b/src/replica/replica.cpp
index be2a0177b..f159d7699 100644
--- a/src/replica/replica.cpp
+++ b/src/replica/replica.cpp
@@ -28,11 +28,10 @@
 
 #include <fmt/core.h>
 #include <fmt/ostream.h>
-#include <inttypes.h>
+#include <rocksdb/status.h>
 #include <algorithm>
 #include <functional>
 #include <iosfwd>
-#include <rocksdb/status.h>
 #include <set>
 
 #include "backup/replica_backup_manager.h"
@@ -285,8 +284,7 @@ void replica::on_client_read(dsn::message_ex *request, bool 
ignore_throttling)
 
         // a small window where the state is not the latest yet
         if (last_committed_decree() < 
_primary_states.last_prepare_decree_on_new_primary) {
-            LOG_ERROR_PREFIX("last_committed_decree(%" PRId64
-                             ") < last_prepare_decree_on_new_primary(%" PRId64 
")",
+            LOG_ERROR_PREFIX("last_committed_decree({}) < 
last_prepare_decree_on_new_primary({})",
                              last_committed_decree(),
                              
_primary_states.last_prepare_decree_on_new_primary);
             response_client_read(request, ERR_INVALID_STATE);
diff --git a/src/replica/replica_2pc.cpp b/src/replica/replica_2pc.cpp
index e0cff3868..6138ad7e7 100644
--- a/src/replica/replica_2pc.cpp
+++ b/src/replica/replica_2pc.cpp
@@ -259,11 +259,7 @@ void replica::init_prepare(mutation_ptr &mu, bool 
reconciliation, bool pop_all_c
     }
 
     mu->_tracer->set_name(fmt::format("mutation[{}]", mu->name()));
-    dlog(level,
-         "%s: mutation %s init_prepare, mutation_tid=%" PRIu64,
-         name(),
-         mu->name(),
-         mu->tid());
+    dlog_f(level, "{}: mutation {} init_prepare, mutation_tid={}", name(), 
mu->name(), mu->tid());
 
     // child should prepare mutation synchronously
     mu->set_is_sync_to_child(_primary_states.sync_send_write_request);
diff --git a/src/runtime/task/task.cpp b/src/runtime/task/task.cpp
index 6e08bd714..7d83948f3 100644
--- a/src/runtime/task/task.cpp
+++ b/src/runtime/task/task.cpp
@@ -120,8 +120,8 @@ task::task(dsn::task_code code, int hash, service_node 
*node)
     } else {
         auto p = get_current_node();
         CHECK_NOTNULL(p,
-                      "tasks without explicit service node "
-                      "can only be created inside threads which is attached to 
specific node");
+                      "tasks without explicit service node can only be created 
"
+                      "inside threads which is attached to specific node");
         _node = p;
     }
 
diff --git a/src/server/pegasus_server_impl.cpp 
b/src/server/pegasus_server_impl.cpp
index 998b4873f..5bc03eafe 100644
--- a/src/server/pegasus_server_impl.cpp
+++ b/src/server/pegasus_server_impl.cpp
@@ -2308,7 +2308,7 @@ bool 
pegasus_server_impl::validate_filter(::dsn::apps::filter_type::type filter_
         }
     }
     default:
-        CHECK(false, "unsupported filter type: %d", filter_type);
+        CHECK(false, "unsupported filter type: {}", filter_type);
     }
     return false;
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to