diff --git a/weed/command/master.go b/weed/command/master.go index dcb24b2fdb..ef002f08e7 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -86,19 +86,16 @@ type MasterOptions struct { // 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 in - // single-master mode, with singleReporterAddr pinning the embedded volume - // server as the only admitted reporter: any other volume server is refused, - // so the warmup window after a fresh topology id is dead time. - // Standalone weed master can face late-arriving veterans and must keep - // the window; a single-master weed server releases on its embedded - // volume server's clean report through expectedReporterAddr instead. + // one full volume-server inventory has been applied, with + // singleReporterAddr pinning the only admitted reporter: any other volume + // server is refused, so the warmup window after a fresh topology id is + // dead time. releaseAllocOnFirstReport bool singleReporterAddr string // expectedReporterAddr names the reporter whose first clean inventory // collapses the post-mint allocation hold to a confirm pulse without - // refusing others: a single-master weed server points it at its - // embedded volume server. + // refusing others: a single-master weed server or weed mini points it at + // its embedded volume server. expectedReporterAddr string } diff --git a/weed/command/mini.go b/weed/command/mini.go index 8140d86564..399ae69e55 100644 --- a/weed/command/mini.go +++ b/weed/command/mini.go @@ -606,6 +606,20 @@ func miniMqBrokerAddress() string { return util.JoinHostPort(*miniIp, *miniMqBrokerOptions.port) } +// setMiniExpectedReporter mirrors a single-master weed server: the embedded +// volume server's first clean inventory collapses the post-mint allocation +// hold to a confirm pulse, while volume servers started later against this +// master are still admitted. Multi-master minis keep the regular hold. +// Re-derived on every run: the package-level options survive in-process +// reruns, so a multi-master mini after a single-master one must not inherit +// the expected reporter. +func setMiniExpectedReporter() { + miniMasterOptions.expectedReporterAddr = "" + if isSingleMasterMode(*miniMasterOptions.peers) { + miniMasterOptions.expectedReporterAddr = util.JoinHostPort(*miniIp, *miniOptions.v.port) + } +} + // initMiniWebDAVFlags initializes WebDAV server flag options func initMiniWebDAVFlags() { miniWebDavOptions.port = cmdMini.Flag.Int("webdav.port", 7333, "webdav server http listen port") @@ -1698,23 +1712,8 @@ 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 - // In single-master mode mini's embedded volume server is the only 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. The master pins - // the embedded address and refuses any other volume server, keeping the - // single-reporter assumption true. Multi-master minis can field - // late-reporting volume servers and keep the regular hold. - // Both fields are re-derived on every run: the package-level options - // survive in-process reruns, so a multi-master mini after a - // single-master one must not inherit the release or the stale pin. - singleMaster := isSingleMasterMode(*miniMasterOptions.peers) - miniMasterOptions.releaseAllocOnFirstReport = singleMaster - miniMasterOptions.singleReporterAddr = "" - miniFilerOptions.skipEmptyMembershipConfirm = singleMaster - if singleMaster { - miniMasterOptions.singleReporterAddr = util.JoinHostPort(*miniIp, *miniOptions.v.port) - } + setMiniExpectedReporter() + miniFilerOptions.skipEmptyMembershipConfirm = isSingleMasterMode(*miniMasterOptions.peers) 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/command/mini_master_reporter_test.go b/weed/command/mini_master_reporter_test.go new file mode 100644 index 0000000000..636498c10f --- /dev/null +++ b/weed/command/mini_master_reporter_test.go @@ -0,0 +1,31 @@ +package command + +import "testing" + +// A single-master mini names its embedded volume server only as the reporter +// whose inventory lifts the post-mint hold; it must not pin it as the only +// admitted one, or volume servers added to the mini are refused. +func TestMiniSingleMasterAdmitsOutsideVolumeServers(t *testing.T) { + oldPeers, oldIp, oldPort := *miniMasterOptions.peers, *miniIp, *miniOptions.v.port + oldExpected := miniMasterOptions.expectedReporterAddr + defer func() { + *miniMasterOptions.peers, *miniIp, *miniOptions.v.port = oldPeers, oldIp, oldPort + miniMasterOptions.expectedReporterAddr = oldExpected + }() + *miniIp, *miniOptions.v.port = "10.0.0.1", 8080 + + *miniMasterOptions.peers = "none" + setMiniExpectedReporter() + if miniMasterOptions.releaseAllocOnFirstReport || miniMasterOptions.singleReporterAddr != "" { + t.Fatalf("single-master mini pins its embedded volume server: release=%v reporter=%q", miniMasterOptions.releaseAllocOnFirstReport, miniMasterOptions.singleReporterAddr) + } + if got := miniMasterOptions.expectedReporterAddr; got != "10.0.0.1:8080" { + t.Fatalf("expected reporter = %q, want 10.0.0.1:8080", got) + } + + *miniMasterOptions.peers = "10.0.0.1:9333,10.0.0.2:9333,10.0.0.3:9333" + setMiniExpectedReporter() + if got := miniMasterOptions.expectedReporterAddr; got != "" { + t.Fatalf("multi-master mini kept expected reporter %q", got) + } +} diff --git a/weed/server/master_grpc_server_heartbeat_admit_test.go b/weed/server/master_grpc_server_heartbeat_admit_test.go index 8d91eeecda..f6db439982 100644 --- a/weed/server/master_grpc_server_heartbeat_admit_test.go +++ b/weed/server/master_grpc_server_heartbeat_admit_test.go @@ -108,3 +108,26 @@ func TestSendHeartbeatRejectsAddresslessFirstHeartbeat(t *testing.T) { assert.Zero(t, uint32(ms.Topo.GetMaxVolumeId())) assert.Empty(t, stream.sent) } + +// The expected-reporter release a single-master weed server or weed mini +// uses gates only which report lifts the allocation hold: volume servers +// started beside the embedded one are still admitted and applied. +func TestSendHeartbeatAdmitsOutsideReporterBesideExpected(t *testing.T) { + ms := newLeaderMaster() + ms.Topo.RaftServer = admitTestRaftServer{} + ms.Topo.ReleaseAllocationOnReport("10.0.0.1:8080") + + stream := &fakeHeartbeatStream{heartbeats: []*master_pb.Heartbeat{{ + Ip: "10.0.0.2", + Port: 8080, + MaxVolumeIdSeen: 7, + HasNoVolumes: true, + }}} + + err := ms.SendHeartbeat(stream) + if err != nil { + assert.NotContains(t, err.Error(), "rejected") + } + assert.EqualValues(t, 7, ms.Topo.GetMaxVolumeId()) + assert.NotEmpty(t, stream.sent) +} diff --git a/weed/server/master_server.go b/weed/server/master_server.go index 06843a016f..229ff2347e 100644 --- a/weed/server/master_server.go +++ b/weed/server/master_server.go @@ -72,14 +72,15 @@ type MasterOption struct { 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). + // embedded volume server is the only possible reporter. // SingleVolumeReporter pins that reporter's ip:port; any other volume // server trying to register is rejected. ReleaseAllocOnFirstReport bool SingleVolumeReporter string // ExpectedReporterAddr names the one volume server whose first clean full - // inventory lifts the post-mint allocation hold (a single-master weed - // server's embedded volume server). Other reporters are still admitted. + // inventory lifts the post-mint allocation hold (the embedded volume + // server of a single-master weed server or weed mini). Other reporters + // are still admitted. ExpectedReporterAddr string } diff --git a/weed/topology/topology.go b/weed/topology/topology.go index 86220fa541..10c4863cb7 100644 --- a/weed/topology/topology.go +++ b/weed/topology/topology.go @@ -2045,8 +2045,8 @@ 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, and // pins the admitted volume-server reporter: the early release is only sound -// when a single embedded server (weed mini) can carry prior cluster state, so -// every other reporter must be refused rather than silently trusted. +// when a single embedded server can carry prior cluster state, so every other +// reporter must be refused rather than silently trusted. func (t *Topology) ReleaseAllocationOnFirstReport(onlyReporter ...string) { if len(onlyReporter) > 0 { t.singleReporter.Store(onlyReporter[0])