Skip to content

Commit 454ce62

Browse files
committed
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.
1 parent ab850d4 commit 454ce62

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

sources.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,12 +1222,23 @@ SRC_SelectSource(SRC_Instance updated_inst)
12221222
assert(depth == 0 && trust_depth == 0);
12231223
assert(2 * n_sel_sources == n_endpoints);
12241224

1225-
if ((best_trust_depth == 0 && best_depth <= n_sel_sources / 2) ||
1226-
(best_trust_depth > 0 && best_trust_depth <= n_sel_trust_sources / 2)) {
1225+
if (best_trust_depth > 0) {
1226+
best_depth = best_trust_depth;
1227+
n_sel_sources = n_sel_trust_sources;
1228+
}
1229+
1230+
if (best_depth <= n_sel_sources / 2) {
12271231
/* Could not even get half the reachable (trusted) sources to agree */
12281232

12291233
if (!reported_no_majority) {
1230-
log_selection_message(LOGS_WARN, "Can't synchronise: no majority");
1234+
if (best_depth < 2)
1235+
log_selection_message(LOGS_WARN, "%s (no agreement among %d %ssources)",
1236+
"Can't synchronise: no majority", n_sel_sources,
1237+
best_trust_depth > 0 ? "trusted " : "");
1238+
else
1239+
log_selection_message(LOGS_WARN, "%s (only %d of %d %ssources agree)",
1240+
"Can't synchronise: no majority", best_depth,
1241+
n_sel_sources, best_trust_depth > 0 ? "trusted " : "");
12311242
reported_no_majority = 1;
12321243
report_selection_loss = 0;
12331244
}

test/simulation/009-sourceselection

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ for falsetickers in 3 4; do
2424
# These check are expected to fail
2525
check_source_selection && test_fail
2626
check_sync && test_fail
27+
28+
if [ $falsetickers = 3 ]; then
29+
check_log_messages "Can't synchronise: no majority (only 2 of 5 sources agree)" 1 1 || test_fail
30+
else
31+
check_log_messages "Can't synchronise: no majority (no agreement among 5 sources)" 1 1 || test_fail
32+
fi
2733
done
2834

2935
# Sources with large asymmetric delay should be excluded

test/simulation/148-replacement

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ check_source_selection && test_fail
6868
check_packet_interval || test_fail
6969
check_sync || test_fail
7070

71-
check_log_messages "Can't synchronise: no majority" 1 1 || test_fail
71+
check_log_messages "Can't synchronise: no majority (no agreement among 2 sources)" 1 1 || test_fail
7272
check_log_messages "Detected falseticker" 0 2 || test_fail
7373
check_log_messages "Source 192.168.123.. replaced with" 3 60 || test_fail
7474
check_log_messages "Source 192.168.123.1 replaced with" 1 25 || test_fail

0 commit comments

Comments
 (0)