diff --git a/seaweed-block/cmd/blockmaster/main.go b/seaweed-block/cmd/blockmaster/main.go index 20d4a3757f..8a969f1aa6 100644 --- a/seaweed-block/cmd/blockmaster/main.go +++ b/seaweed-block/cmd/blockmaster/main.go @@ -245,6 +245,7 @@ func run(f flags) int { ControllerConfig: authority.TopologyControllerConfig{ExpectedSlotsPerVolume: f.expectedSlotsPerVol}, WorkspaceMaxClockSkew: f.workspaceMaxClockSkew, FailbackRuntimeRPC: f.failbackRuntimeRPC, + LifecycleProductLoop: f.lifecycleLoop > 0, FrontendPublicationRuntimeHTTP: f.frontendPublicationRuntimeHTTP, FrontendPublicationRuntimeListen: f.frontendPublicationRuntimeListen, StrictJournalIsolation: f.strictJournalIsolation, diff --git a/seaweed-block/core/host/master/create_rf_mismatch_test.go b/seaweed-block/core/host/master/create_rf_mismatch_test.go index 9abb05bb75..d86109d5b0 100644 --- a/seaweed-block/core/host/master/create_rf_mismatch_test.go +++ b/seaweed-block/core/host/master/create_rf_mismatch_test.go @@ -2,6 +2,7 @@ package master import ( "context" + "strings" "testing" "time" @@ -16,7 +17,7 @@ import ( // RF3 and an RF1 create are admitted; and every existing volume keeps failing // over (no volume of another slot count can stop the controller's decisions). func TestAnRF2CreateOnAnRF3MasterIsRefusedAndFailoverContinues(t *testing.T) { - h := newBootGraceMaster(t, Config{ControllerConfig: authority.TopologyControllerConfig{PrimaryBootGrace: 200 * time.Millisecond}}) + h := newBootGraceMaster(t, Config{LifecycleProductLoop: true, ControllerConfig: authority.TopologyControllerConfig{PrimaryBootGrace: 200 * time.Millisecond}}) defer closeTestMaster(t, h) svc := newServices(h) _, err := svc.CreateVolume(context.Background(), &control.CreateVolumeRequest{VolumeId: "v-rf2", SizeBytes: 1 << 20, ReplicationFactor: 2}) @@ -38,3 +39,29 @@ func TestAnRF2CreateOnAnRF3MasterIsRefusedAndFailoverContinues(t *testing.T) { unsupportedTick(t, h, ineligible) expectFailoverToR2(t, h, "an existing RF3 volume after the refused RF2 create") } + +// The third door: a replicated volume created while the lifecycle product +// loop is off (which alone binds and promotes it) would never get a primary, +// so CreateVolume refuses it naming the flag; with the loop on the same +// create is admitted, and an RF1 create is admitted either way. +func TestAReplicatedCreateWithTheProductLoopOffIsRefused(t *testing.T) { + for _, loop := range []bool{false, true} { + h, err := New(Config{AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), Listen: "127.0.0.1:0", LifecycleProductLoop: loop}) + if err != nil { + t.Fatal(err) + } + h.Start() + svc := newServices(h) + _, err = svc.CreateVolume(context.Background(), &control.CreateVolumeRequest{VolumeId: "v-rf3", SizeBytes: 1 << 20, ReplicationFactor: 3}) + if loop && err != nil { + t.Fatalf("RF3 create with the loop on: %v", err) + } + if !loop && (status.Code(err) != codes.FailedPrecondition || !strings.Contains(err.Error(), "--lifecycle-product-loop-interval")) { + t.Fatalf("RF3 create with the loop off: %v; want FailedPrecondition naming the flag", err) + } + if _, err := svc.CreateVolume(context.Background(), &control.CreateVolumeRequest{VolumeId: "v-rf1", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatalf("RF1 create (loop %v): %v", loop, err) + } + closeTestMaster(t, h) + } +} diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index 0b0aedd3aa..42493cafcd 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -68,6 +68,12 @@ type Config struct { // ControllerConfig tunes controller knobs (retry window etc). ControllerConfig authority.TopologyControllerConfig + // LifecycleProductLoop reports that the host's lifecycle product loop + // runs (blockmaster --lifecycle-product-loop-interval above 0). Only + // that loop binds, mints and promotes a replicated lifecycle volume, so + // CreateVolume refuses a replicated volume while it is off. + LifecycleProductLoop bool + // LifecycleStoreDir, when non-empty, opens product lifecycle // registration stores (desired volumes, node inventory, placement // intents). This is read-only composition for G9D: these stores do @@ -135,7 +141,7 @@ type Host struct { probeSlots slotServers // replica -> server, for the round cfg Config attest *storeAttestations // primaries' attested write-ACK stores - healthMu sync.Mutex // orders replica health events with their accepted heartbeats (#128 rule 6) + healthMu sync.Mutex // orders replica health events with their accepted heartbeats (#128 rule 6) log *log.Logger boot *bootstrap.DurableAuthorityBootstrap ctrl *authority.TopologyController @@ -159,8 +165,8 @@ type Host struct { // without a line being published there. Until the line reaches it, those // survivors refuse the primary, so the gate keeps trying to heal it. fencePending map[string]uint64 - cancel context.CancelFunc - wg sync.WaitGroup + cancel context.CancelFunc + wg sync.WaitGroup started atomic.Bool } diff --git a/seaweed-block/core/host/master/lifecycle_service_test.go b/seaweed-block/core/host/master/lifecycle_service_test.go index 6fa79e0c42..491785d2ba 100644 --- a/seaweed-block/core/host/master/lifecycle_service_test.go +++ b/seaweed-block/core/host/master/lifecycle_service_test.go @@ -92,6 +92,7 @@ func TestRestoreCreateVolumePersistsRequestBeforeTargetAndHealsRetry(t *testing. if _, ok := h.Lifecycle().Volumes.GetVolume("net-target"); ok { t.Fatal("RF2 restore created a target record") } + h.cfg.LifecycleProductLoop = true // a replicated create needs the product loop if _, err := svc.CreateVolume(context.Background(), &control.CreateVolumeRequest{VolumeId: "net-source", SizeBytes: 1 << 20, ReplicationFactor: 3}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index 60050718d5..5356b879ce 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -75,6 +75,11 @@ func (s *services) CreateVolume(ctx context.Context, req *control.CreateVolumeRe // refuses the whole decision when one differs, so a volume of another // replication factor would stop every replicated volume's assignment and // failover. Single-replica volumes never reach that check. + // A replicated lifecycle volume is bound, minted and promoted only by the + // lifecycle product loop: with it off the volume never gets a primary. + if spec.ReplicationFactor > 1 && !s.host.cfg.LifecycleProductLoop { + return nil, status.Errorf(codes.FailedPrecondition, "create volume: %s has replication factor %d but --lifecycle-product-loop-interval is 0 (off): a replicated volume is bound and promoted only by that loop; set --lifecycle-product-loop-interval (for example 100ms)", spec.VolumeID, spec.ReplicationFactor) + } if c := s.host.ctrl; c != nil && spec.ReplicationFactor > 1 && spec.ReplicationFactor != c.ExpectedSlotsPerVolume() { return nil, status.Errorf(codes.FailedPrecondition, "create volume: %s has replication factor %d, but this master decides replicated volumes of %d replicas (--expected-slots-per-volume); one replicated factor per cluster", spec.VolumeID, spec.ReplicationFactor, c.ExpectedSlotsPerVolume()) } diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 3bf9e3e97f..dfce6f9167 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -716,7 +716,7 @@ Notes: |---|---|---|---|---|---|---| | `INV-AUTH-HOLDER-IDENTITY-001` | A primary holder is the pair (server id, replica id): every site that decides holdership (adopting a fact, lease first grant, renew, re-grant, HEAD claim, superseded exit) compares both; a missing server id is refused, never guessed. | AUTHORITY: PRIMARY holdership (supporting replicas are not holders) | `core/host/volume/host.go` `applyFact`, `IsSuperseded`, `recordOtherLine`; `assignment_holder.go` `assignmentNamesSelf`, `observeForeignHolder`, `refusePrimaryAssignment`; `host.go` `IsSuperseded`; `core/host/master/services.go` `SubscribeAssignments`; `workspace_service.go` `holderMatches`, `RenewWorkspaceLease`, `AckWorkspaceRevoked`; `cmd/blockvolume/chunk_remote.go` `chunkHolder`; `core/frontend/chunkstore/layout/start.go` `Start`, `core/frontend/chunkstore/layout/claim.go` `Claim`; superseded exit covered by #409; `core/host/master/workspace_binding.go` `workspaceLineOwner`, `workspaceSourceHost`; `core/authority/assignment_owner.go` `captureAssignmentOwner`; `core/host/master/services.go` `assignmentFact`; `core/host/master/server_host_identity.go` `refuseServerIDFromOtherHost` (from `ReportHeartbeat`), `refuseWorkspaceHolderHost` (from `holderMatches` and, for a workspace volume, `SubscribeAssignments`), `holderSlotFact` (from `QueryVolumeStatus` and `observationVolume`/`observationReplicas`); `core/csi/master_backend.go` `primaryOwnedFrontends` (a CSI target only from a usable primary frontend); `core/authority/snapshot_builder.go` `expectOwnerForLine` (a moved line's replica facts and endpoint refreshes only from its owner, #425) | `TestAssignmentHolderIdentityRestartedOldProcess`, `TestAssignmentHolderIdentityMatchingServerStillAdopts`, `TestAssignmentHolderIdentityFencesPreviouslyHealthySameReplica`, `TestAssignmentHolderIdentityAdoptsAndWarnsCarriedEndpointMismatch`, `TestAssignmentHolderIdentityForeignStreamOrdering`, `TestAssignmentHolderIdentityForcedMoveRefusesEveryDeliveredVersion`, `TestAssignmentHolderIdentitySameEpochCannotChangeServer` (`core/host/volume/assignment_holder_test.go`); `TestWorkspaceLeaseGuardCarriesHolderServerIdentity` (`core/host/volume/workspace_holder_identity_test.go`); `TestWorkspaceLeaseRequiresHolderServerForGrantRenewAndRegrant`, `TestWorkspaceRevocationACKRequiresHolderServer` (`core/host/master/workspace_holder_identity_test.go`); `TestWorkspaceRPCCleanMovePreservesReplicaIdentity` (`core/host/master/workspace_service_test.go`); HEAD claim: `TestChunkHolderIsServerAndReplica` (`cmd/blockvolume/chunk_remote_test.go`), `TestWALStoreChunk_SameReplicaOnAnotherServerIsFenced` (`core/frontend/durable/provider_chunk_holder_test.go`); superseded exit: covered by #409 (server-id/replica-id pair, never replica alone); supporting replicas are not holders; descriptor identity not in this row; `TestWorkspaceLineOwnerIssuedAndHistorical` (`core/host/master/workspace_line_owner_test.go`), `TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation` (`core/host/master/workspace_lease_horizon_test.go`); `TestAssignmentFactKeepsCapturedMoveOwnerWithoutReadableJournal` (`core/host/master/assignment_fact_owner_test.go`), `TestAssignmentOwnerReservedAndIssuedCapture` (`core/authority/assignment_owner_test.go`), `TestWorkspaceCrashAfterJournalBeforeEpochResumesSameGrant` (`core/authority/workspace_test.go`); `TestServerIDRefusedFromAHostOtherThanItsRegisteredOne`, `TestWorkspaceHolderRefusedFromAnotherHostAtRenewAckAndStream`, `TestPortalAndPrimaryComeFromTheLineServerNotTheFreshestHeartbeat`, `TestDisplayedPrimaryIsTheIssuedHolderNotThePlacementSlot`, `TestStatusListsNoFrontendWhenThePrimaryEvidenceIsMissing`, `TestCSIPublishesNoTargetWhenThePrimaryFrontendIsMissingOrRejected`, `TestDeletionReservedWorkspaceVolumeKeepsTheStreamHostCheck` (`core/host/master/server_host_identity_test.go`); `TestPublishTargetIsPrimaryOwned` (`core/csi/primary_owned_frontend_test.go`). Host scope: registered advertised-host consistency, not process uniqueness; a workspace holder's server id must be registered (no first-seen binding: host addresses change); non-workspace heartbeats from an unregistered id are not checked. Limits: with mutual TLS on, a node may act only for the server id bound to its certificate (`TERM-CALLER-001`; `auth.RequireNode` in `ReportHeartbeat`, `SubscribeAssignments`, `RenewWorkspaceLease`, `AckWorkspaceRevoked`, `QueryVolumeStatus`; `TestNodeActsOnlyForItsOwnServerID`, `core/host/master/auth_red_test.go`), and the registered-host check stays beside it (no NAT or proxy between volume and master in OSS); in development mode (plaintext on loopback, no role file) there is no authentication; `TestBuildSnapshotTakesTheMovedLinesReplicaFromItsOwner` (`core/authority/line_owner_snapshot_test.go`); `TestProcedureForcedMoveWithTheOldHostReturning` (`cmd/blockvolume/procedure_gate_integration_test.go`, tags subprocess chunkstore_integration: every forced-epoch line carries the new owner's endpoints) | `WorkspaceRegrant` `NoForeignAdoption`, `TargetNotFencedByOwnLine` (round 4 pinned simulations only; exhaustive combo10 pending) | ACTIVE | | `INV-AUTH-CALLER-ROLE-001` | With mutual TLS on, every blockmaster gRPC call (unary, and before every stream send) is decided by the caller's certificate and the current role file: an unknown caller is refused UNAUTHENTICATED, a role its method's rule does not admit PERMISSION_DENIED, a method without a rule always. | AUTHORITY: control API callers (people, tools, nodes) | `core/auth/identity.go` `Authenticator.PeerIdentity`, `Authenticator.Reload`; `core/auth/authorize.go` `Rule.Allows`, `UnaryInterceptor`, `StreamInterceptor`, `RequireNode`, `RequireRole`; `core/host/master/authz.go` `masterRules`, `serverAuth`; `core/rpc/link/tls.go` `ServerCredentials`, `ClientCredentials`; `cmd/blockmaster/auth.go` `authFlags.validate`, `authFlags.build` | `TestPeerIdentity`, `TestRoleFileReload` (`core/auth/identity_test.go`); `TestRuleAllows`, `TestRequireNodeAndRole`, `TestUnaryInterceptor`, `TestStreamEndsAtTheReloadThatRevokesItsCaller` (`core/auth/authorize_test.go`); `TestMasterAuthorizationTableCoversEveryMethod` (`core/host/master/authz_test.go`); `TestForcedMoveNeedsAnAdmin`, `TestNodeActsOnlyForItsOwnServerID` (`core/host/master/auth_red_test.go`); `TestMasterLinkMutualTLS` (`core/rpc/link/tls_test.go`); `TestAuthFlags` (`cmd/blockmaster/auth_flags_test.go`); `TestMasterTLSFlags` (`cmd/blockvolume/master_tls_test.go`). Also: a mutating operator or admin method writes its audit attempt before it runs or is refused as audit unavailable (`Rule.Strict`; `TestMasterOperatorMethodsAreStrict` (inverted: a new operator or admin method fails unless strict or named with its reason), `core/host/master/authz_test.go`; `TestStrictCallsNeedTheirAttemptLine`, `core/auth/strict_audit_test.go`), node calls never wait on the audit log; a reload that removes a caller, or changes its role so the method's rule no longer admits it, ends its open streams at the reload; a forced move needs an admin; plaintext listens only on loopback without a role file (development mode). Limits: the audit log records outcomes and decides nothing; the volume process's own HTTP routes stay loopback-only and unauthenticated. | `AuthLease` (exhaustive run pending) | ACTIVE | -| `INV-AUTH-ONE-REPLICATED-FACTOR-001` | A replicated volume is created only with the master's one replica-slot count (--expected-slots-per-volume): CreateVolume refuses another replication factor above 1, since one mismatched volume would stop the controller's decisions for every volume. | M2 none → Bound (a created replicated volume's first line) | `core/host/master/services.go` `CreateVolume`; `core/authority/controller.go` `ExpectedSlotsPerVolume`, `validateVolumeTopology` | `TestAnRF2CreateOnAnRF3MasterIsRefusedAndFailoverContinues` (`core/host/master/create_rf_mismatch_test.go`) | — (an admission check). Limits: single-replica volumes are admitted at any slot count (they never reach the check); a cluster spec or topology file with a mismatched volume is not checked at start | ACTIVE | +| `INV-AUTH-ONE-REPLICATED-FACTOR-001` | CreateVolume admits a replicated volume only if the master can decide it: its replication factor equals the master's one slot count (--expected-slots-per-volume) and the lifecycle product loop runs (only that loop binds, mints and promotes it). | M2 none → Bound (a created replicated volume's first line) | `core/host/master/services.go` `CreateVolume`; `core/host/master/host.go` `Config.LifecycleProductLoop`; `core/authority/controller.go` `ExpectedSlotsPerVolume`, `validateVolumeTopology` | `TestAnRF2CreateOnAnRF3MasterIsRefusedAndFailoverContinues`, `TestAReplicatedCreateWithTheProductLoopOffIsRefused` (`core/host/master/create_rf_mismatch_test.go`) | — (an admission check). Limits: single-replica volumes are admitted at any slot count (they never reach the check); a cluster spec or topology file with a mismatched volume is not checked at start | ACTIVE | | `INV-AUTH-EPOCH-MINT-001` | Only the publisher mints epochs; a reassignment takes the per-volume maximum epoch plus one, also after a restart. | M2 Bound → Reassigned | `core/authority/authority.go` `applyWithWorkspaceMove`, `maxPublishedEpochForVolume` | `TestLayoutGrantedEpochIssuerSites`, `TestLayoutEpochEnumerationRejectsANewIssuer`, `TestG8_0_Publisher_ReassignAdvancesPerVolumeEpochAcrossReplicaSlots` (`core/authority/g8_0_authority_failover_test.go`); `TestDurableAuthority_PublisherAdvancesFromReloaded` (`core/authority/authority_restart_test.go`); `TestG9F2_AssignmentRequestShapeHasNoEpochOrEndpointVersion` (`core/host/master/authority_request_bridge_test.go`) | `ControlPlane` `UniqueEpoch` | ACTIVE | | `INV-AUTH-RESTART-REISSUE-001` | A line records the primary process it was issued for (durable); a current primary reporting another process is re-issued its line at a new endpoint version, and a primary adopts no line issued for another process, so a restarted process never reuses the dead one's sessions. | M2 authority (RefreshEndpoint); M3 primary adoption | `core/authority/authority.go` `applyWithWorkspaceMove` (records the ask's or the source's incarnation); `core/authority/controller.go` `endpointStale`, `sameAsk`; `core/authority/workspace.go` `persistWorkspaceTimedLocked`; `core/authority/observation_store.go` `SlotFactAt`; `core/host/master/host.go` (the source); `core/host/volume/host.go` `applyFact` | `TestPublisher_RestartedPrimaryGetsANewEndpointVersion`, `TestPublisher_AskWithoutAProcessIsIssuedForTheReportedOne`, `TestTopologyController_RestartedPrimaryAtTheSameAddressIsReissued`, `TestTopologyController_QueuedRefreshIsReplacedForANewerProcess`, `TestTopologyController_UnnamedLineIsReissuedOnceForTheReportingProcess`, `TestWorkspaceLeaseWriteKeepsTheLinesIncarnationAcrossReload`, `TestObservationStore_SlotFactAtIsTheProcessAtThoseEndpoints` (`core/authority/restart_endpoint_version_test.go`); `TestLinesNameTheirPrimarysProcess`, `TestLineForTheTargetsEndpointsNamesTheTargetsProcess` (`core/host/master/line_incarnation_test.go`); `TestHost_ApplyFact_LineIssuedForAnotherProcessIsNotAdopted`, `TestHost_ApplyFact_UnnamedLineIsNotAdoptedWhereLinesNameTheirProcess` (`core/host/volume/line_incarnation_test.go`); `TestHostConfigAdoptsOnlyLinesNamingThisProcess` (`cmd/blockvolume/lines_name_their_process_test.go`); `TestRestartedPrimaryAtTheSameEpochIsAdmitted` (`core/replication/primary_restart_session_test.go`) | — | ACTIVE | | `INV-AUTH-PERSIST-BEFORE-PUBLISH-001` | With an authority store configured, an assignment is written to the store before memory or any subscriber sees it, a failed write does not publish it, and an unknown outcome (directory fsync after the rename failed) fail-stops blockmaster: see M2 any → (store write first). | M2 any → (store write first) | `core/authority/authority.go` `applyWithWorkspaceMove`; `core/authority/authority_store_file.go` `Put` (`failStopDurabilityUnknown` after a failed directory open or fsync behind the rename, every record; a close error after a good fsync is reported written; Windows keeps its previous behaviour) | `TestDurableAuthority_PutFailureRollsBackInMemoryState` (`core/authority/authority_restart_test.go`); `TestPutFailStopsWhenTheDirectoryFsyncFailsAfterRename`, `TestPutReportsWrittenWhenOnlyTheDirectoryCloseFails` (`core/authority/authority_store_dir_fsync_test.go`) | `ControlPlane` `UniqueEpoch` | ACTIVE |