Browse Source

wait a bit before getting the next volume id if the leader is recently elected

pull/6277/head
chrislu 4 weeks ago
parent
commit
ccf1795e6f
  1. 3
      weed/server/master_server.go
  2. 2
      weed/topology/topology.go
  3. 5
      weed/topology/volume_growth.go

3
weed/server/master_server.go

@ -184,12 +184,15 @@ func (ms *MasterServer) SetRaftServer(raftServer *RaftServer) {
stats.MasterLeaderChangeCounter.WithLabelValues(fmt.Sprintf("%+v", e.Value())).Inc() stats.MasterLeaderChangeCounter.WithLabelValues(fmt.Sprintf("%+v", e.Value())).Inc()
if ms.Topo.RaftServer.Leader() != "" { if ms.Topo.RaftServer.Leader() != "" {
glog.V(0).Infof("[%s] %s becomes leader.", ms.Topo.RaftServer.Name(), ms.Topo.RaftServer.Leader()) glog.V(0).Infof("[%s] %s becomes leader.", ms.Topo.RaftServer.Name(), ms.Topo.RaftServer.Leader())
ms.Topo.LastLeaderChangeTime = time.Now()
} }
}) })
raftServerName = fmt.Sprintf("[%s]", ms.Topo.RaftServer.Name()) raftServerName = fmt.Sprintf("[%s]", ms.Topo.RaftServer.Name())
} else if raftServer.RaftHashicorp != nil { } else if raftServer.RaftHashicorp != nil {
ms.Topo.HashicorpRaft = raftServer.RaftHashicorp ms.Topo.HashicorpRaft = raftServer.RaftHashicorp
raftServerName = ms.Topo.HashicorpRaft.String() raftServerName = ms.Topo.HashicorpRaft.String()
// TODO fix this for hashicorp raft
ms.Topo.LastLeaderChangeTime = time.Now()
} }
ms.Topo.RaftServerAccessLock.Unlock() ms.Topo.RaftServerAccessLock.Unlock()

2
weed/topology/topology.go

@ -55,6 +55,8 @@ type Topology struct {
UuidAccessLock sync.RWMutex UuidAccessLock sync.RWMutex
UuidMap map[string][]string UuidMap map[string][]string
LastLeaderChangeTime time.Time
} }
func NewTopology(id string, seq sequence.Sequencer, volumeSizeLimit uint64, pulse int, replicationAsMin bool) *Topology { func NewTopology(id string, seq sequence.Sequencer, volumeSizeLimit uint64, pulse int, replicationAsMin bool) *Topology {

5
weed/topology/volume_growth.go

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
"github.com/seaweedfs/seaweedfs/weed/server/constants"
"math/rand/v2" "math/rand/v2"
"reflect" "reflect"
"sync" "sync"
@ -126,6 +127,10 @@ func (vg *VolumeGrowth) findAndGrow(grpcDialOption grpc.DialOption, topo *Topolo
if e != nil { if e != nil {
return nil, e return nil, e
} }
for !topo.LastLeaderChangeTime.Add(constants.VolumePulseSeconds * 2).Before(time.Now()) {
glog.V(0).Infof("wait for volume servers to join back")
time.Sleep(constants.VolumePulseSeconds / 2)
}
vid, raftErr := topo.NextVolumeId() vid, raftErr := topo.NextVolumeId()
if raftErr != nil { if raftErr != nil {
return nil, raftErr return nil, raftErr

Loading…
Cancel
Save