@@ -3324,7 +3324,7 @@ func (n *raft) runAsCandidate() {
33243324 n .RLock ()
33253325 nterm := n .term
33263326 csz := n .csz
3327- repairing , initializing := n .repairing , n .initializing
3327+ repairing , initializing , pindex , group := n .repairing , n .initializing , n . pindex , n . group
33283328 n .RUnlock ()
33293329
33303330 if vresp .granted && nterm == vresp .term {
@@ -3346,7 +3346,20 @@ func (n *raft) runAsCandidate() {
33463346 // Become LEADER if we've got voted in by ALL servers.
33473347 // We couldn't get quorum based on just our normal votes.
33483348 // But, we have heard from the full cluster, and some servers came up empty.
3349- // We know for sure we have the most up-to-date log.
3349+ // We know for sure we have the most up-to-date log, but that log could also be empty.
3350+ if group == defaultMetaGroupName || initializing {
3351+ n .warn ("Self got voted leader by all servers, restarting WAL with %d entries" , pindex )
3352+ } else {
3353+ // If we are here, this means all logs required reparation (so none were complete),
3354+ // and we were the one with the most up-to-date log. We have either lost "all" or "some" data,
3355+ // but instead of halting, we prefer to become available again. All servers will agree on the
3356+ // new state of the log.
3357+ lost := "all"
3358+ if pindex > 0 {
3359+ lost = "some"
3360+ }
3361+ n .warn ("Self got voted leader by all servers, restarting WAL with %d entries, %s data was lost" , pindex , lost )
3362+ }
33503363 n .switchToLeader ()
33513364 return
33523365 }
0 commit comments