Fix master leader detection when grpc ports change
This commit is contained in:
@@ -360,12 +360,12 @@ func checkPeers(masterIp string, masterPort int, masterGrpcPort int, peers strin
|
||||
|
||||
func isTheFirstOne(self pb.ServerAddress, peers []pb.ServerAddress) bool {
|
||||
slices.SortFunc(peers, func(a, b pb.ServerAddress) int {
|
||||
return strings.Compare(string(a), string(b))
|
||||
return strings.Compare(a.ToHttpAddress(), b.ToHttpAddress())
|
||||
})
|
||||
if len(peers) <= 0 {
|
||||
return true
|
||||
}
|
||||
return self == peers[0]
|
||||
return self.ToHttpAddress() == peers[0].ToHttpAddress()
|
||||
}
|
||||
|
||||
func (m *MasterOptions) toMasterOption(whiteList []string) *weed_server.MasterOption {
|
||||
|
||||
35
weed/command/master_test.go
Normal file
35
weed/command/master_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
)
|
||||
|
||||
func TestIsTheFirstOneIgnoresGrpcPort(t *testing.T) {
|
||||
self := pb.ServerAddress("127.0.0.1:9000.19000")
|
||||
peers := []pb.ServerAddress{
|
||||
"127.0.0.1:9000",
|
||||
"127.0.0.1:9002.19002",
|
||||
"127.0.0.1:9003.19003",
|
||||
}
|
||||
|
||||
if !isTheFirstOne(self, peers) {
|
||||
t.Fatalf("expected first peer match by HTTP address between %q and %+v", self, peers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckPeersAddsSelfWhenGrpcPortMismatches(t *testing.T) {
|
||||
self, peers := checkPeers("127.0.0.1", 9000, 19000, "127.0.0.1:9002,127.0.0.1:9003")
|
||||
|
||||
found := false
|
||||
for _, peer := range peers {
|
||||
if peer.ToHttpAddress() == self.ToHttpAddress() {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected peers %+v to contain self %s by HTTP address", peers, self)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user