mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
master: count only ids above the issued bound as prior-state evidence
Heartbeat echoes of volumes and shards this master allocated during the hold refreshed the quiet window, so each growth allocation re-extended the deferral until the hard cap. Evidence now requires an id beyond the bound this leader has issued, a higher reported bound, or a foreign topology id; a joining server (dn == nil) still counts once.
This commit is contained in:
1 parent
d9236a9c7f
commit
ca4e1c76d8
2 files changed
+100
-11
No files matched your search
@@ -104,16 +104,52 @@ func announceVolume(message *master_pb.VolumeLocation, vid uint32, isRemote, isR
|
||||
}
|
||||
|
||||
// reportsPriorClusterState tells whether a heartbeat could come from a server
|
||||
// still carrying cluster state from before this leader's term: it holds
|
||||
// volumes or shards, has seen a nonzero volume id bound, or last synced with
|
||||
// a different topology id.
|
||||
func reportsPriorClusterState(heartbeat *master_pb.Heartbeat, topologyId string) bool {
|
||||
return heartbeat.MaxVolumeIdSeen > 0 ||
|
||||
len(heartbeat.Volumes) > 0 || len(heartbeat.NewVolumes) > 0 ||
|
||||
len(heartbeat.ChangedVolumes) > 0 || len(heartbeat.DeletedVolumes) > 0 ||
|
||||
len(heartbeat.EcShards) > 0 || len(heartbeat.NewEcShards) > 0 ||
|
||||
len(heartbeat.DeletedEcShards) > 0 ||
|
||||
(heartbeat.LastSeenTopologyId != "" && heartbeat.LastSeenTopologyId != topologyId)
|
||||
// still carrying cluster state from before this leader's term: it holds a
|
||||
// volume or shard id above the bound this master has issued, has seen a
|
||||
// higher volume id bound, or last synced with a different topology id.
|
||||
// Echoes of this term's own allocations stay under the bound and do not count.
|
||||
func reportsPriorClusterState(heartbeat *master_pb.Heartbeat, topologyId string, bound needle.VolumeId) bool {
|
||||
if needle.VolumeId(heartbeat.MaxVolumeIdSeen) > bound ||
|
||||
(heartbeat.LastSeenTopologyId != "" && heartbeat.LastSeenTopologyId != topologyId) {
|
||||
return true
|
||||
}
|
||||
unissued := func(id uint32) bool { return needle.VolumeId(id) > bound }
|
||||
for _, v := range heartbeat.Volumes {
|
||||
if unissued(v.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, v := range heartbeat.NewVolumes {
|
||||
if unissued(v.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, v := range heartbeat.ChangedVolumes {
|
||||
if unissued(v.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, v := range heartbeat.DeletedVolumes {
|
||||
if unissued(v.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, s := range heartbeat.EcShards {
|
||||
if unissued(s.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, s := range heartbeat.NewEcShards {
|
||||
if unissued(s.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, s := range heartbeat.DeletedEcShards {
|
||||
if unissued(s.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServer) error {
|
||||
@@ -195,7 +231,7 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ
|
||||
continue
|
||||
}
|
||||
|
||||
if dn == nil || reportsPriorClusterState(heartbeat, ms.Topo.GetTopologyId()) {
|
||||
if dn == nil || reportsPriorClusterState(heartbeat, ms.Topo.GetTopologyId(), ms.Topo.GetMaxVolumeId()) {
|
||||
ms.Topo.NoteAllocationEvidence()
|
||||
}
|
||||
ms.Topo.Sequence.SetMax(heartbeat.MaxFileKey)
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package weed_server
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestReportsPriorClusterState(t *testing.T) {
|
||||
topoId := "topo-1"
|
||||
|
||||
// a quiet heartbeat from a synced server is not evidence
|
||||
assert.False(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
LastSeenTopologyId: topoId,
|
||||
}, topoId, 5))
|
||||
|
||||
// echoes of volume ids this master issued are not evidence
|
||||
assert.False(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
MaxVolumeIdSeen: 5,
|
||||
NewVolumes: []*master_pb.VolumeShortInformationMessage{{Id: 5}},
|
||||
ChangedVolumes: []*master_pb.VolumeInformationMessage{{Id: 3}},
|
||||
LastSeenTopologyId: topoId,
|
||||
}, topoId, 5))
|
||||
|
||||
// ids above the issued bound come from before this term
|
||||
assert.True(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
MaxVolumeIdSeen: 6,
|
||||
}, topoId, 5))
|
||||
assert.True(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
Volumes: []*master_pb.VolumeInformationMessage{{Id: 6}},
|
||||
}, topoId, 5))
|
||||
assert.True(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
NewVolumes: []*master_pb.VolumeShortInformationMessage{{Id: 6}},
|
||||
}, topoId, 5))
|
||||
assert.True(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
DeletedVolumes: []*master_pb.VolumeShortInformationMessage{{Id: 6}},
|
||||
}, topoId, 5))
|
||||
assert.True(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
EcShards: []*master_pb.VolumeEcShardInformationMessage{{Id: 42}},
|
||||
}, topoId, 5))
|
||||
assert.True(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
NewEcShards: []*master_pb.VolumeEcShardInformationMessage{{Id: 42}},
|
||||
}, topoId, 5))
|
||||
assert.True(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
DeletedEcShards: []*master_pb.VolumeEcShardInformationMessage{{Id: 42}},
|
||||
}, topoId, 5))
|
||||
|
||||
// a heartbeat last synced under another topology id is prior state
|
||||
assert.True(t, reportsPriorClusterState(&master_pb.Heartbeat{
|
||||
LastSeenTopologyId: "topo-0",
|
||||
}, topoId, 5))
|
||||
}
|
||||
Reference in new issue
Block a user