From ca4e1c76d8c6353a95f0e9f6588178ee297dbca4 Mon Sep 17 00:00:00 2001 From: "user.email" Date: Sun, 25 Oct 2026 03:06:18 -0700 Subject: [PATCH] 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. --- weed/server/master_grpc_server.go | 58 +++++++++++++++---- .../master_grpc_server_prior_state_test.go | 53 +++++++++++++++++ 2 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 weed/server/master_grpc_server_prior_state_test.go diff --git a/weed/server/master_grpc_server.go b/weed/server/master_grpc_server.go index 7a4b70cea1..54ae903037 100644 --- a/weed/server/master_grpc_server.go +++ b/weed/server/master_grpc_server.go @@ -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) diff --git a/weed/server/master_grpc_server_prior_state_test.go b/weed/server/master_grpc_server_prior_state_test.go new file mode 100644 index 0000000000..21e53272dc --- /dev/null +++ b/weed/server/master_grpc_server_prior_state_test.go @@ -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)) +}