mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
master: write a recovered TopologyId into the hashicorp raft log on leadership
A hashicorp raft leader whose TopologyId came from the max_volume_id mirror never wrote it to the raft log, so followers kept an empty id. The next leader then minted a new one, and the first master crashed with split-brain on its next restart when it read the old id back from its mirror. Sync the id after the barrier, as the goraft path already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
20854b3a66
commit
84941f16e9
1 file changed
+25
-1
@@ -61,7 +61,9 @@ func (s *RaftServer) monitorLeaderLoop(updatePeers bool) {
|
||||
updatePeers = false
|
||||
}
|
||||
|
||||
s.topo.DoBarrier()
|
||||
if s.topo.DoBarrier() {
|
||||
s.syncRaftForTopologyId()
|
||||
}
|
||||
|
||||
EnsureTopologyId(s.topo, func() bool {
|
||||
return s.RaftHashicorp.State() == hashicorpRaft.Leader
|
||||
@@ -93,6 +95,28 @@ func (s *RaftServer) monitorLeaderLoop(updatePeers bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// syncRaftForTopologyId writes the leader's TopologyId into the raft log. An id
|
||||
// restored from the max_volume_id mirror is otherwise known to this master
|
||||
// only, and the next leader would mint a different one.
|
||||
func (s *RaftServer) syncRaftForTopologyId() {
|
||||
topologyId := s.topo.GetTopologyId()
|
||||
if topologyId == "" {
|
||||
return
|
||||
}
|
||||
for s.RaftHashicorp.State() == hashicorpRaft.Leader {
|
||||
b, err := json.Marshal(topology.NewMaxVolumeIdCommand(s.topo.GetMaxVolumeId(), topologyId))
|
||||
if err != nil {
|
||||
glog.Errorf("marshal TopologyId %s: %v", topologyId, err)
|
||||
return
|
||||
}
|
||||
if err = s.RaftHashicorp.Apply(b, 5*time.Second).Error(); err == nil {
|
||||
return
|
||||
}
|
||||
glog.Errorf("failed to sync raft for topologyId %s, retrying in 1s: %v", topologyId, err)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *RaftServer) updatePeers() {
|
||||
peerLeader := raftServerID(s.serverAddr)
|
||||
desiredPeers := make(map[string]pb.ServerAddress, len(s.peers))
|
||||
|
||||
Reference in new issue
Block a user