From 65685ee915eff8bfb6555262ecb56ff7edc1c2b9 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 25 Oct 2026 06:18:30 -0700 Subject: [PATCH] mini: lift the post-mint allocation hold on first inventory report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DeferAllocation armed a fixed warmup window whenever the leader minted a fresh topology id, so the first write on a brand-new weed mini blocked for the whole window even though no prior cluster state could exist. The window still has to cover a rebuilt master's veteran servers, which report on their first post-reconnect heartbeat. Mini has exactly one possible reporter — the embedded volume server, whose first heartbeat carries the full inventory — so hold allocation only until that report is applied. The bound raise and topology-id freeze checks run while the heartbeat is processed, so a wiped master state still raises the bound or trips the freeze before the hold lifts. Standalone weed master and weed server keep the fixed window: volume servers outside the process can still be on their way. --- weed/command/master.go | 25 ++++++++++++------- weed/command/mini.go | 5 ++++ weed/server/master_grpc_server.go | 7 ++++++ weed/server/master_server.go | 7 ++++++ weed/topology/growth_freeze_test.go | 26 ++++++++++++++++++++ weed/topology/topology.go | 38 +++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 9 deletions(-) diff --git a/weed/command/master.go b/weed/command/master.go index 64b9883bfa..cdbaee3725 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -81,6 +81,12 @@ type MasterOptions struct { // is cancelled. Used by integration tests and by weed mini; nil for // standalone weed master. shutdownCtx context.Context + // releaseAllocOnFirstReport lifts the post-mint allocation hold as soon as + // one full volume-server inventory has been applied. weed mini sets it: + // the embedded volume server is the only possible reporter, so the warmup + // window after a fresh topology id is dead time. Standalone weed master / + // weed server can face late-arriving veterans and must keep the window. + releaseAllocOnFirstReport bool } func init() { @@ -480,14 +486,15 @@ func (m *MasterOptions) toMasterOption(whiteList []string) *weed_server.MasterOp VacuumIntervalSeconds: *m.vacuumIntervalSeconds, VacuumDeleteEmptyAfterSeconds: *m.vacuumDeleteEmptyAfterSeconds, // PulseSeconds: *m.pulseSeconds, - DefaultReplicaPlacement: *m.defaultReplication, - GarbageThreshold: *m.garbageThreshold, - WhiteList: whiteList, - DisableHttp: *m.disableHttp, - MetricsAddress: *m.metricsAddress, - MetricsIntervalSec: *m.metricsIntervalSec, - TelemetryUrl: *m.telemetryUrl, - TelemetryEnabled: *m.telemetryEnabled, - SingleMaster: isSingleMasterMode(*m.peers), + DefaultReplicaPlacement: *m.defaultReplication, + GarbageThreshold: *m.garbageThreshold, + WhiteList: whiteList, + DisableHttp: *m.disableHttp, + MetricsAddress: *m.metricsAddress, + MetricsIntervalSec: *m.metricsIntervalSec, + TelemetryUrl: *m.telemetryUrl, + TelemetryEnabled: *m.telemetryEnabled, + SingleMaster: isSingleMasterMode(*m.peers), + ReleaseAllocOnFirstReport: m.releaseAllocOnFirstReport, } } diff --git a/weed/command/mini.go b/weed/command/mini.go index 05a2c1f752..dfb99cd0c5 100644 --- a/weed/command/mini.go +++ b/weed/command/mini.go @@ -1521,6 +1521,11 @@ func runMini(cmd *Command, args []string) bool { // tear those services down too. On Ctrl+C they rely on their own // OnInterrupt hooks (see grace's LIFO ordering). miniMasterOptions.shutdownCtx = MiniClusterCtx + // Mini's embedded volume server is the only possible reporter of prior + // cluster state; its first heartbeat already carries the full inventory, so + // the post-mint allocation hold ends there instead of running the whole + // warmup window on every fresh start. + miniMasterOptions.releaseAllocOnFirstReport = true miniOptions.v.shutdownCtx = MiniClusterCtx miniFilerOptions.shutdownCtx = MiniClusterCtx // Mini is a small/dev setup with short-lived RPCs; cap the filer's diff --git a/weed/server/master_grpc_server.go b/weed/server/master_grpc_server.go index 92a2e35161..49cc164f5a 100644 --- a/weed/server/master_grpc_server.go +++ b/weed/server/master_grpc_server.go @@ -356,6 +356,13 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ } } + // A full volume list is the heartbeat section that settles what a + // reporter holds; once applied, a post-mint allocation hold kept for + // prior cluster state has nothing left to wait for. + if len(heartbeat.Volumes) > 0 || heartbeat.HasNoVolumes { + ms.Topo.NoteInventoryApplied() + } + if len(heartbeat.NewEcShards) > 0 || len(heartbeat.DeletedEcShards) > 0 { stats.MasterReceivedHeartbeatCounter.WithLabelValues("newEcShards").Inc() // update master internal volume layouts diff --git a/weed/server/master_server.go b/weed/server/master_server.go index 0fe35ccf2e..797dad815c 100644 --- a/weed/server/master_server.go +++ b/weed/server/master_server.go @@ -70,6 +70,10 @@ type MasterOption struct { TelemetryUrl string TelemetryEnabled bool VolumeGrowthDisabled bool + // ReleaseAllocOnFirstReport lifts the post-mint allocation hold as soon as + // one full volume-server inventory has been applied, for setups whose + // embedded volume server is the only possible reporter (weed mini). + ReleaseAllocOnFirstReport bool } type MasterServer struct { @@ -182,6 +186,9 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.Se ms.Topo.SetAllocationDeferral(d) } } + if option.ReleaseAllocOnFirstReport { + ms.Topo.ReleaseAllocationOnFirstReport() + } ms.Topo.QuarantineVolumeFn = func(dn *topology.DataNode, vid needle.VolumeId, readOnly bool) error { err := operation.WithVolumeServerClient(false, dn.ServerAddress(), ms.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) diff --git a/weed/topology/growth_freeze_test.go b/weed/topology/growth_freeze_test.go index f838010bd9..f2d72ec57e 100644 --- a/weed/topology/growth_freeze_test.go +++ b/weed/topology/growth_freeze_test.go @@ -191,3 +191,29 @@ func TestAllocationDeferralDuration(t *testing.T) { t.Fatalf("negative deferral should restore the default, got %v", d) } } + +func TestAllocationDeferralReleasedByInventory(t *testing.T) { + topo := NewTopology("topo", nil, 128, 3, false) + topo.ReleaseAllocationOnFirstReport() + + topo.DeferAllocation(time.Minute) + topo.NoteInventoryApplied() + if wait := topo.allocationDelay(); wait > 0 { + t.Fatalf("applied inventory should lift the deferral, still waiting %v", wait) + } + + fresh := NewTopology("topo", nil, 128, 3, false) + fresh.ReleaseAllocationOnFirstReport() + fresh.NoteInventoryApplied() + fresh.DeferAllocation(time.Minute) + if wait := fresh.allocationDelay(); wait > 0 { + t.Fatalf("a report applied before the mint should keep the hold unarmed, got %v", wait) + } + + walled := NewTopology("topo", nil, 128, 3, false) + walled.DeferAllocation(time.Minute) + walled.NoteInventoryApplied() + if wait := walled.allocationDelay(); wait <= 0 { + t.Fatal("without opt-in an applied inventory must not lift the deferral") + } +} diff --git a/weed/topology/topology.go b/weed/topology/topology.go index 017f3c8eb1..03b2e17e5c 100644 --- a/weed/topology/topology.go +++ b/weed/topology/topology.go @@ -101,6 +101,14 @@ type Topology struct { allocationDeferral atomic.Int64 topologyInitPending atomic.Bool + // releaseAllocOnReport lifts a post-mint allocation hold as soon as a full + // volume-server inventory has been applied, for single-reporter setups + // (weed mini) whose embedded volume server is the only possible source of + // prior cluster state. inventoryApplied records that at least one full + // volume list has been synced into this topology. + releaseAllocOnReport atomic.Bool + inventoryApplied atomic.Bool + reportedTopologyIdsLock sync.Mutex pendingReportedTopologyIds map[string]struct{} @@ -1582,13 +1590,43 @@ func (t *Topology) SetTopologyInitPending(pending bool) { } } +// ReleaseAllocationOnFirstReport opts the topology into lifting the post-mint +// allocation hold once one full volume-server inventory has been applied. Only +// valid where a single volume server can carry prior cluster state (weed +// mini's embedded server): its first heartbeat already raises the id bound or +// trips the growth freeze, so the quiet-pulse tail is dead time. +func (t *Topology) ReleaseAllocationOnFirstReport() { + t.releaseAllocOnReport.Store(true) +} + +// NoteInventoryApplied marks a heartbeat's full volume list as applied to this +// topology. Under ReleaseAllocationOnFirstReport it also lifts the post-mint +// allocation hold: the bound raise and topology-id freeze checks run while the +// heartbeat is processed, so nothing protected remains pending afterwards. +func (t *Topology) NoteInventoryApplied() { + t.inventoryApplied.Store(true) + if t.releaseAllocOnReport.Load() { + t.allocationNotBefore.Store(0) + } +} + // DeferAllocation holds off new id allocation for d. Called when the leader // mints a fresh topology id: on a rebuilt master that window gives veteran // servers a pulse to raise the bound or trip the freeze. func (t *Topology) DeferAllocation(d time.Duration) { + // Under release-on-report a hold is pointless once inventory has landed: + // the veteran heartbeat that mattered has already been applied. + if t.releaseAllocOnReport.Load() && t.inventoryApplied.Load() { + return + } now := time.Now() t.allocationNotBefore.Store(now.Add(d).UnixNano()) t.allocationEvidenceSince.Store(now.UnixNano()) + // Close the race with a report applied between the check above and the + // store, which would otherwise leave the full window armed. + if t.releaseAllocOnReport.Load() && t.inventoryApplied.Load() { + t.allocationNotBefore.Store(0) + } } // NoteAllocationEvidence records a heartbeat signal that could still carry