MCPcopy
hub / github.com/dgraph-io/dgraph / checkMajority

Function checkMajority

worker/import.go:651–678  ·  view source on GitHub ↗

Calculate majority based on Raft quorum rules with special handling for small clusters

(successfulNodes map[string]bool)

Source from the content-addressed store, hash-verified

649
650// Calculate majority based on Raft quorum rules with special handling for small clusters
651func checkMajority(successfulNodes map[string]bool) bool {
652 totalNodes := len(successfulNodes)
653 successfulCount := 0
654
655 for _, success := range successfulNodes {
656 if success {
657 successfulCount++
658 }
659 }
660
661 // Special cases for small clusters
662 switch totalNodes {
663 case 0:
664 // No nodes - this should never happen
665 glog.Error("[import] No nodes in cluster")
666 return false
667 case 1:
668 // Single node - must succeed
669 return successfulCount == 1
670 case 2:
671 // Two nodes - both must succeed
672 return successfulCount == 2
673 default:
674 // Regular Raft quorum rule for 3+ nodes
675 majority := totalNodes/2 + 1
676 return successfulCount >= majority
677 }
678}

Callers 1

streamInGroupFunction · 0.85

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected