Skip to content

Commit badd1a9

Browse files
authored
Merge pull request #198 from arangodb-helper/bug-fix/recovery-new-address
Accept an address change in RECOVERY in more cases.
2 parents 15b1c83 + 56e872d commit badd1a9

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

service/service.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,15 +900,30 @@ func (s *Service) HandleHello(ownAddress, remoteAddress string, req *HelloReques
900900
// ID already found, update peer data
901901
for i, p := range s.myPeers.AllPeers {
902902
if p.ID == req.SlaveID {
903-
s.myPeers.AllPeers[i].Port = req.SlavePort
904903
if s.cfg.AllPortOffsetsUnique {
905904
s.myPeers.AllPeers[i].Address = slaveAddr
906905
} else {
907-
// Slave address may not change
908-
if p.Address != slaveAddr {
906+
// Need to check if this particular address does appear in
907+
// another peer, if so, we forbid to change the address:
908+
addrFoundInOtherPeer := false
909+
for _, pp := range s.myPeers.AllPeers {
910+
if pp.ID != req.SlaveID && pp.Address == slaveAddr {
911+
addrFoundInOtherPeer = true
912+
break
913+
}
914+
}
915+
// Slave address may not change in this case
916+
if addrFoundInOtherPeer && p.Address != slaveAddr {
909917
return ClusterConfig{}, maskAny(client.NewBadRequestError("Cannot change slave address while using an existing ID."))
910918
}
919+
// We accept the new address (it might be the old one):
920+
s.myPeers.AllPeers[i].Address = slaveAddr
921+
// However, since we also accept the port, we must set the
922+
// port ofset of that replaced peer to 0 such that the AllPeers
923+
// information actually contains the right port.
924+
s.myPeers.AllPeers[i].PortOffset = 0
911925
}
926+
s.myPeers.AllPeers[i].Port = req.SlavePort
912927
s.myPeers.AllPeers[i].DataDir = req.DataDir
913928
}
914929
}

0 commit comments

Comments
 (0)