[ovs-dev] [PATCH] raft: Avoid annoying debug logs if raft is connected.

Ilya Maximets i.maximets at ovn.org
Mon Oct 26 00:34:57 UTC 2020


If debug logs enabled, "raft_is_connected: true" printed on every
call to raft_is_connected() which is way too frequently.
These messages are not very informative and only litters the log.

Let's log only disconnected state in a rate-limited way and only
log positive case once at the moment cluster becomes connected.

Fixes: 923f01cad678 ("raft.c: Set candidate_retrying if no leader elected since last election.")
Signed-off-by: Ilya Maximets <i.maximets at ovn.org>
---
 ovsdb/raft.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/ovsdb/raft.c b/ovsdb/raft.c
index 728d60175..657eed813 100644
--- a/ovsdb/raft.c
+++ b/ovsdb/raft.c
@@ -1044,13 +1044,22 @@ raft_get_memory_usage(const struct raft *raft, struct simap *usage)
 bool
 raft_is_connected(const struct raft *raft)
 {
+    static bool last_state = false;
     bool ret = (!raft->candidate_retrying
             && !raft->joining
             && !raft->leaving
             && !raft->left
             && !raft->failed
             && raft->ever_had_leader);
-    VLOG_DBG("raft_is_connected: %s\n", ret? "true": "false");
+
+    if (!ret) {
+        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 5);
+        VLOG_DBG_RL(&rl, "raft_is_connected: false");
+    } else if (!last_state) {
+        VLOG_DBG("raft_is_connected: true");
+    }
+    last_state = ret;
+
     return ret;
 }
 
-- 
2.25.4



More information about the dev mailing list