From 454ce62672dea4bd15da5f53ad02dd95b129e5f4 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 6 Mar 2025 12:46:09 +0100 Subject: [PATCH] sources: improve no majority log message Add the number of sources that form an agreement (overlapping intervals), if at least two agree with each other, and number of reachable sources to the "Can't synchronize: no majority" log message to better explain why synchronization is failing and hint that adding more sources might help. --- sources.c | 17 ++++++++++++++--- test/simulation/009-sourceselection | 6 ++++++ test/simulation/148-replacement | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sources.c b/sources.c index 2ba595b..3b1766b 100644 --- a/sources.c +++ b/sources.c @@ -1222,12 +1222,23 @@ SRC_SelectSource(SRC_Instance updated_inst) assert(depth == 0 && trust_depth == 0); assert(2 * n_sel_sources == n_endpoints); - if ((best_trust_depth == 0 && best_depth <= n_sel_sources / 2) || - (best_trust_depth > 0 && best_trust_depth <= n_sel_trust_sources / 2)) { + if (best_trust_depth > 0) { + best_depth = best_trust_depth; + n_sel_sources = n_sel_trust_sources; + } + + if (best_depth <= n_sel_sources / 2) { /* Could not even get half the reachable (trusted) sources to agree */ if (!reported_no_majority) { - log_selection_message(LOGS_WARN, "Can't synchronise: no majority"); + if (best_depth < 2) + log_selection_message(LOGS_WARN, "%s (no agreement among %d %ssources)", + "Can't synchronise: no majority", n_sel_sources, + best_trust_depth > 0 ? "trusted " : ""); + else + log_selection_message(LOGS_WARN, "%s (only %d of %d %ssources agree)", + "Can't synchronise: no majority", best_depth, + n_sel_sources, best_trust_depth > 0 ? "trusted " : ""); reported_no_majority = 1; report_selection_loss = 0; } diff --git a/test/simulation/009-sourceselection b/test/simulation/009-sourceselection index 547c376..139b6aa 100755 --- a/test/simulation/009-sourceselection +++ b/test/simulation/009-sourceselection @@ -24,6 +24,12 @@ for falsetickers in 3 4; do # These check are expected to fail check_source_selection && test_fail check_sync && test_fail + + if [ $falsetickers = 3 ]; then + check_log_messages "Can't synchronise: no majority (only 2 of 5 sources agree)" 1 1 || test_fail + else + check_log_messages "Can't synchronise: no majority (no agreement among 5 sources)" 1 1 || test_fail + fi done # Sources with large asymmetric delay should be excluded diff --git a/test/simulation/148-replacement b/test/simulation/148-replacement index d09fba6..ee8b2e2 100755 --- a/test/simulation/148-replacement +++ b/test/simulation/148-replacement @@ -68,7 +68,7 @@ check_source_selection && test_fail check_packet_interval || test_fail check_sync || test_fail -check_log_messages "Can't synchronise: no majority" 1 1 || test_fail +check_log_messages "Can't synchronise: no majority (no agreement among 2 sources)" 1 1 || test_fail check_log_messages "Detected falseticker" 0 2 || test_fail check_log_messages "Source 192.168.123.. replaced with" 3 60 || test_fail check_log_messages "Source 192.168.123.1 replaced with" 1 25 || test_fail