mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
Merge branch 'p339' into train/20261121-8
This commit is contained in:
commit
66e0ed494d
6 files changed
+143
-9
No files matched your search
@@ -42,6 +42,33 @@ var dialChunkFiler = func(addr string) (chunkstore.Filer, func() error, error) {
|
||||
return c, c.Close, nil
|
||||
}
|
||||
|
||||
// checkSingleFiler is the start check of a command that writes chunk
|
||||
// metadata: block metadata goes through exactly one filer, the
|
||||
// same rule blockvolume enforces at start. Tests replace it.
|
||||
var checkSingleFiler = func(ctx context.Context, f chunkstore.Filer) error {
|
||||
if s, ok := f.(*chunkstore.SWFS); ok {
|
||||
return s.CheckSingleFiler(ctx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// refuseUnlessSingleFiler runs the start check within the command's own
|
||||
// timeout (a stalled filer or master cannot hold the command longer); exit
|
||||
// >= 0 means refused.
|
||||
func refuseUnlessSingleFiler(name string, f chunkstore.Filer, timeout time.Duration, stdout, stderr io.Writer) int {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
err := checkSingleFiler(ctx, f)
|
||||
switch {
|
||||
case err == nil:
|
||||
return -1
|
||||
case errors.Is(err, chunkstore.ErrNotSingleFiler):
|
||||
return chunkFail(name, stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, err.Error(), false)
|
||||
default:
|
||||
return chunkFail(name, stdout, stderr, chunkExitFailed, codeUnavailableCLI, "single-filer start check: "+err.Error(), true)
|
||||
}
|
||||
}
|
||||
|
||||
func runOpsChunk(args []string, stdout, stderr io.Writer) int {
|
||||
if len(args) == 0 {
|
||||
return chunkFail("", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "expected cut|snapshot|snapshots|snapshot-delete|fork|detach|show|gc|usage|retain|volume-delete", false)
|
||||
@@ -259,7 +286,9 @@ func chunkDetach(args []string, stdout, stderr io.Writer) int {
|
||||
|
||||
// chunkCatalog opens the catalog under --chunk-path on --chunk-filer.
|
||||
// It returns exit -1 on success, else the exit code after reporting.
|
||||
func chunkCatalog(name, filer, base string, stdout, stderr io.Writer) (*chunkstore.Catalog, func() error, int) {
|
||||
// chunkCatalog dials the filer and opens the catalog; a command that writes
|
||||
// (writes) first passes the single-filer start check.
|
||||
func chunkCatalog(name, filer, base string, writes bool, timeout time.Duration, stdout, stderr io.Writer) (*chunkstore.Catalog, func() error, int) {
|
||||
if filer == "" {
|
||||
return nil, nil, chunkFail(name, stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "--chunk-filer is required", false)
|
||||
}
|
||||
@@ -267,6 +296,12 @@ func chunkCatalog(name, filer, base string, stdout, stderr io.Writer) (*chunksto
|
||||
if err != nil {
|
||||
return nil, nil, chunkFail(name, stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, err.Error(), false)
|
||||
}
|
||||
if writes {
|
||||
if exit := refuseUnlessSingleFiler(name, f, timeout, stdout, stderr); exit >= 0 {
|
||||
_ = closeFn()
|
||||
return nil, nil, exit
|
||||
}
|
||||
}
|
||||
cat, err := chunkstore.NewCatalog(f, base)
|
||||
if err != nil {
|
||||
_ = closeFn()
|
||||
@@ -364,7 +399,7 @@ func chunkSnapshots(args []string, stdout, stderr io.Writer) int {
|
||||
if volumeID == "" {
|
||||
return chunkFail("snapshots", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "--volume is required", false)
|
||||
}
|
||||
cat, closeFn, exit := chunkCatalog("snapshots", filer, base, stdout, stderr)
|
||||
cat, closeFn, exit := chunkCatalog("snapshots", filer, base, false, timeout, stdout, stderr)
|
||||
if exit >= 0 {
|
||||
return exit
|
||||
}
|
||||
@@ -392,7 +427,7 @@ func chunkSnapshotDelete(args []string, stdout, stderr io.Writer) int {
|
||||
if volumeID == "" || name == "" {
|
||||
return chunkFail("snapshot-delete", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "--volume and --name are required", false)
|
||||
}
|
||||
cat, closeFn, exit := chunkCatalog("snapshot-delete", filer, base, stdout, stderr)
|
||||
cat, closeFn, exit := chunkCatalog("snapshot-delete", filer, base, true, timeout, stdout, stderr)
|
||||
if exit >= 0 {
|
||||
return exit
|
||||
}
|
||||
@@ -428,7 +463,7 @@ func chunkFork(args []string, stdout, stderr io.Writer) int {
|
||||
requestID = newRequestID()
|
||||
fmt.Fprintf(stderr, "sw-block ops chunk fork: request id %s (reuse it to retry)\n", requestID)
|
||||
}
|
||||
cat, closeFn, exit := chunkCatalog("fork", filer, base, stdout, stderr)
|
||||
cat, closeFn, exit := chunkCatalog("fork", filer, base, true, timeout, stdout, stderr)
|
||||
if exit >= 0 {
|
||||
return exit
|
||||
}
|
||||
@@ -456,7 +491,7 @@ func chunkShow(args []string, stdout, stderr io.Writer) int {
|
||||
if volumeID == "" {
|
||||
return chunkFail("show", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "--volume is required", false)
|
||||
}
|
||||
cat, closeFn, exit := chunkCatalog("show", filer, base, stdout, stderr)
|
||||
cat, closeFn, exit := chunkCatalog("show", filer, base, false, timeout, stdout, stderr)
|
||||
if exit >= 0 {
|
||||
return exit
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ func chunkGC(args []string, stdout, stderr io.Writer) int {
|
||||
return chunkResult("gc", nil, e, stdout, stderr)
|
||||
}
|
||||
defer closeFn()
|
||||
if apply {
|
||||
if exit := refuseUnlessSingleFiler("gc", f, timeout, stdout, stderr); exit >= 0 {
|
||||
return exit
|
||||
}
|
||||
}
|
||||
blobs, ok := f.(chunkstore.BlobDeleter)
|
||||
if !ok {
|
||||
return chunkFail("gc", stdout, stderr, chunkExitFailed, codeInternalCLI, "chunk store cannot delete immutable blobs", false)
|
||||
|
||||
@@ -31,7 +31,7 @@ func chunkUsage(args []string, stdout, stderr io.Writer) int {
|
||||
if volumeID == "" {
|
||||
return chunkFail("usage", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "--volume is required", false)
|
||||
}
|
||||
cat, closeFn, exit := chunkCatalog("usage", filer, base, stdout, stderr)
|
||||
cat, closeFn, exit := chunkCatalog("usage", filer, base, false, timeout, stdout, stderr)
|
||||
if exit >= 0 {
|
||||
return exit
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func chunkRetain(args []string, stdout, stderr io.Writer) int {
|
||||
if setPolicy && dryRun {
|
||||
return chunkFail("retain", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "--set-policy and --dry-run do not combine", false)
|
||||
}
|
||||
cat, closeFn, exit := chunkCatalog("retain", filer, base, stdout, stderr)
|
||||
cat, closeFn, exit := chunkCatalog("retain", filer, base, !dryRun, timeout, stdout, stderr)
|
||||
if exit >= 0 {
|
||||
return exit
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
)
|
||||
|
||||
// Every ops chunk command that writes chunk metadata runs the
|
||||
// single-filer start check before it reads or writes anything, and refuses
|
||||
// when the filer is not the only one of its group; read-only commands (and
|
||||
// read-only modes) do not run it.
|
||||
func TestOpsChunk_WritingCommandsRunTheSingleFilerCheck(t *testing.T) {
|
||||
mem := chunkstore.NewMemFiler()
|
||||
prevDial, prevCheck := dialChunkFiler, checkSingleFiler
|
||||
t.Cleanup(func() { dialChunkFiler, checkSingleFiler = prevDial, prevCheck })
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return mem, func() error { return nil }, nil }
|
||||
checks := 0
|
||||
checkSingleFiler = func(context.Context, chunkstore.Filer) error {
|
||||
checks++
|
||||
return chunkstore.ErrNotSingleFiler
|
||||
}
|
||||
filer := []string{"--chunk-filer", "filer:18888"}
|
||||
writing := map[string][]string{
|
||||
"snapshot-delete": append([]string{"ops", "chunk", "snapshot-delete", "--volume", "v1", "--name", "s1"}, filer...),
|
||||
"fork": append([]string{"ops", "chunk", "fork", "--source", "v1", "--snapshot", "s1", "--target", "v2", "--request-id", "r"}, filer...),
|
||||
"retain": append([]string{"ops", "chunk", "retain", "--volume", "v1"}, filer...),
|
||||
"volume-delete": append([]string{"ops", "chunk", "volume-delete", "--volume", "v1", "--master", "m:1", "--request-id", "r"}, filer...),
|
||||
"gc --apply": append([]string{"ops", "chunk", "gc", "--master", "m:1", "--apply"}, filer...),
|
||||
}
|
||||
for name, args := range writing {
|
||||
before := checks
|
||||
var out, errb bytes.Buffer
|
||||
code := run(args, &out, &errb)
|
||||
if checks != before+1 {
|
||||
t.Errorf("%s: start check ran %d times; want once", name, checks-before)
|
||||
}
|
||||
if code == 0 || !strings.Contains(out.String()+errb.String(), "exactly one filer") {
|
||||
t.Errorf("%s: exit %d, out %q err %q; want the single-filer refusal", name, code, out.String(), errb.String())
|
||||
}
|
||||
}
|
||||
readOnly := map[string][]string{
|
||||
"snapshots": append([]string{"ops", "chunk", "snapshots", "--volume", "v1"}, filer...),
|
||||
"show": append([]string{"ops", "chunk", "show", "--volume", "v1"}, filer...),
|
||||
"usage": append([]string{"ops", "chunk", "usage", "--volume", "v1"}, filer...),
|
||||
"retain --dry-run": append([]string{"ops", "chunk", "retain", "--volume", "v1", "--dry-run"}, filer...),
|
||||
"gc (read-only)": append([]string{"ops", "chunk", "gc", "--master", "m:1"}, filer...),
|
||||
}
|
||||
for name, args := range readOnly {
|
||||
before := checks
|
||||
var out, errb bytes.Buffer
|
||||
run(args, &out, &errb)
|
||||
if checks != before {
|
||||
t.Errorf("%s: a read-only command ran the start check", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The start check runs within the command's own --timeout: a check stalled
|
||||
// on its filer or master (here one that blocks until its context ends) ends
|
||||
// the command at the timeout, as a retryable refusal.
|
||||
func TestOpsChunk_StartCheckIsBoundedByTheTimeout(t *testing.T) {
|
||||
mem := chunkstore.NewMemFiler()
|
||||
prevDial, prevCheck := dialChunkFiler, checkSingleFiler
|
||||
t.Cleanup(func() { dialChunkFiler, checkSingleFiler = prevDial, prevCheck })
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return mem, func() error { return nil }, nil }
|
||||
checkSingleFiler = func(ctx context.Context, _ chunkstore.Filer) error {
|
||||
<-ctx.Done()
|
||||
return ctx.Err()
|
||||
}
|
||||
filer := []string{"--chunk-filer", "filer:18888", "--timeout", "200ms"}
|
||||
for name, args := range map[string][]string{
|
||||
"snapshot-delete": append([]string{"ops", "chunk", "snapshot-delete", "--volume", "v1", "--name", "s1"}, filer...),
|
||||
"gc --apply": append([]string{"ops", "chunk", "gc", "--master", "m:1", "--apply"}, filer...),
|
||||
} {
|
||||
done := make(chan struct{})
|
||||
var out, errb bytes.Buffer
|
||||
var code int
|
||||
go func() { code = run(args, &out, &errb); close(done) }()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatalf("%s: a stalled start check held the command past its 200ms --timeout", name)
|
||||
}
|
||||
if code == 0 || !strings.Contains(out.String(), "remote_unavailable") || !strings.Contains(out.String(), `"retryable":true`) {
|
||||
t.Errorf("%s: exit %d, out %q; want a retryable remote_unavailable refusal", name, code, out.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int {
|
||||
if volumeID == "" || master == "" || requestID == "" || timeout <= 0 {
|
||||
return chunkFail("volume-delete", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "a volume, --master and --request-id are required; --timeout must be positive", false)
|
||||
}
|
||||
cat, closeFn, exit := chunkCatalog("volume-delete", filer, base, stdout, stderr)
|
||||
cat, closeFn, exit := chunkCatalog("volume-delete", filer, base, true, timeout, stdout, stderr)
|
||||
if exit >= 0 {
|
||||
return exit
|
||||
}
|
||||
|
||||
@@ -501,7 +501,7 @@ Notes:
|
||||
| `INV-WS-CAS-UNKNOWN-001` | An unknown HEAD CAS outcome is settled by re-reading HEAD, never by a blind retry; until it is settled the proposal stays pending and its intents stay. | M5 CAS → Pending | `core/storage/chunk_layer.go` `captureLocked`, `resolvePending`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestChunkRemote_UncertainCASIsNotPrecondition` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestChunkLayer_C6_UnknownNotAppliedNeverClaimsSuccess` (`core/storage/chunk_layer_contract_test.go`); `TestClaimChunkHeadSettlesUnknownWithoutReplay` (`core/storage/chunk_restore_test.go`); `TestChunkIntent_UncertainCASKeepsIntentUntilSettled` (`core/storage/chunk_layer_intent_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-CLAIM-BEFORE-SERVE-001` | A new holder claims HEAD at its master-issued epoch before I/O opens; a HEAD with a higher epoch, or another holder at the same epoch, fences the claim. | M4 Claiming → Holder \| Fenced | `core/storage/chunk_restore.go` `ClaimChunkHead`; `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestClaimChunkHeadRefusesStaleAuthorityAndAdmissionDrift` (`core/storage/chunk_restore_test.go`); `TestRestoreSeedPrecedesTakeoverCAS` (`core/frontend/durable/provider_seed_order_test.go`); `TestWorkspaceMoveRestoresLazilyAndFencesOldHost` (`core/host/master/workspace_restore_test.go`) | `WorkspaceTakeover` `SeedMatchesTakeover` | ACTIVE |
|
||||
| `INV-WS-STALE-LOCAL-ROOT-001` | An existing local root whose HEAD another holder has published is not served or cut; the attach fails closed with `ErrChunkStaleLocalRoot`. | M4 Claiming → Refused | `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestWALStoreChunk_MoveBackOntoAnOldRootIsRefused`, `TestWALStoreChunk_MoveBackRefusedOnDeferredAttach` (`core/frontend/durable/provider_chunk_moveback_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-SINGLE-FILER-001` | A chunk volume starts only when `--chunk-filer` is the only filer of its group: a master listing another filer or several refuses at once, whichever master answers first; a filer no master lists within 60 s is refused. A startup census, not a fence: a filer added to the group later is not detected. | M4 (startup) → Refused | `core/frontend/chunkstore/single_filer.go` `CheckSingleFiler`; `cmd/blockvolume/chunk_remote.go` `newChunkWiring` | `TestCheckSingleFilerRefusesAnotherOrSeveralFilers`, `TestCheckSingleFilerFailsClosed`, `TestCheckSingleFilerFavourableThenStalledRefuses`, `TestIsTargetComparesScopedAddresses`, `TestCheckSingleFilerPasses` (`core/frontend/chunkstore/single_filer_test.go`), `TestChunkWiringRefusesAMultiFilerGroup` (`cmd/blockvolume/single_filer_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-SINGLE-FILER-001` | A chunk volume starts only when `--chunk-filer` is the only filer of its group: a master listing another filer or several refuses at once, whichever master answers first; a filer no master lists within 60 s is refused. A startup census, not a fence: a filer added to the group later is not detected. | M4 (startup) → Refused | `core/frontend/chunkstore/single_filer.go` `CheckSingleFiler`; `cmd/blockvolume/chunk_remote.go` `newChunkWiring`; `cmd/sw-block/chunk.go` `refuseUnlessSingleFiler` | `TestCheckSingleFilerRefusesAnotherOrSeveralFilers`, `TestCheckSingleFilerFailsClosed`, `TestCheckSingleFilerFavourableThenStalledRefuses`, `TestIsTargetComparesScopedAddresses`, `TestCheckSingleFilerPasses` (`core/frontend/chunkstore/single_filer_test.go`), `TestChunkWiringRefusesAMultiFilerGroup` (`cmd/blockvolume/single_filer_test.go`), `TestOpsChunk_WritingCommandsRunTheSingleFilerCheck` (`cmd/sw-block/chunk_start_check_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-LEASE-001` | A host admits frontend I/O and cuts only under an unexpired lease for its exact `{volume, replica, epoch}`; a fenced guard never reopens, even on a late renewal reply. | M4 lease guard: Valid → Fenced | `core/host/volume/workspace_lease.go` `permits`, `Refresh` | `TestWorkspaceLeaseExpiryFencesWithoutTimerAndCannotReopen`, `TestWorkspaceDelayedRenewalCannotUndoExpiry` (`core/host/volume/workspace_lease_test.go`); `TestWorkspaceHostRequiresLeaseBeforeFrontendAndCut` (`core/host/volume/workspace_runtime_test.go`); `TestWorkspacePausedGranteeRefusedAtAttach` (`core/host/master/workspace_paused_grantee_test.go`) | `WorkspaceTakeover` `NoDualServing` | ACTIVE |
|
||||
| `INV-WS-REVOKE-ACK-001` | A host acknowledges a revocation only after its frontend and cuts have stopped; a cancelled or expired drain sends no acknowledgement. | M4 lease guard: Revoking → Acked | `core/host/volume/workspace_lease.go` `drain` | `TestWorkspaceRevocationAckOnlyAfterFrontendAndCutsStop` (`core/host/volume/workspace_lease_test.go`); `TestWorkspaceHostCancelOrExpiryDuringRevokeDrainNeverACKs` (`core/host/volume/workspace_runtime_test.go`) | `WorkspaceTakeover` `CleanNoLoss` | ACTIVE |
|
||||
| `INV-WS-STOP-PENDING-001` | Stop-pending changes only when the lease guard renews, never what it admits or acknowledges: from the start of a chunk detach until the guard fences, its sleep after a completed renewal is at most 250 ms; it returns to the normal renewal delay only when that same (latest) detach attempt provably did not happen and serving resumed. It bounds scheduling, not the time from a revocation to its acknowledgement. | M4 lease guard: Valid → StopPending → Valid \| Fenced | `core/frontend/durable/provider_chunk.go` `DetachVolume`, `resumeAfterDetach`; `core/host/volume/workspace_runtime.go` `WorkspaceStopPending`, `WorkspaceStopResumed`; `core/host/volume/workspace_lease.go` `StopPending`, `ClearStopPending`, `renewDelay` | `TestWorkspaceLeaseStopPendingSchedule`, `TestWorkspaceHostStopResumedClearsOnlyTheLatestAttempt`, `TestWorkspaceHostFailedDetachStopPendingByOutcome`, `TestWorkspaceHostDetachHookFencesWithinPoll` (`core/host/volume/workspace_lease_stop_pending_test.go`); `TestWALStoreChunk_DetachHookPrecedesDrain`, `TestWALStoreChunk_DetachResumeHookOnlyOnProvenAbort`, `TestWALStoreChunk_DetachCallsStopHook` (`core/frontend/durable/provider_chunk_detach_hook_test.go`) | — | ACTIVE |
|
||||
@@ -512,6 +512,7 @@ Notes:
|
||||
|
||||
Notes:
|
||||
|
||||
- `INV-WS-SINGLE-FILER-001`: the same census runs in every `sw-block ops chunk` command that writes chunk metadata (snapshot-delete, fork, retain, volume-delete, gc --apply) before it reads or writes; read-only commands and modes do not run it.
|
||||
- `INV-WS-HEAD-CAS-001`: The integration test needs build tag `chunkstore_integration` and a pinned `weed` binary.
|
||||
- `INV-WS-CAS-UNKNOWN-001`: An unknown-outcome CAS is not in the TLA+ models (`docs/spec/README.md`, Limits).
|
||||
- `INV-WS-FORCED-MOVE-001`: TLA+: `W4_drift` found the gap before #158; the skew margin itself is not in the model. Extended for a new holder that dies between its grant and its HEAD claim: the move issue starts its lease, admission uses that grant's lease, HEAD is read after admission, an older-epoch HEAD is accepted (its generation and remote LSN may have moved by an earlier holder's late claim), and a returning holder is refused by two fences, its lease-gated attach and the higher HEAD epoch. `WorkspaceTakeover` models one move from A to B and does not cover a second move away from an unclaimed grant; that model check is open and not claimed here.
|
||||
|
||||
Reference in new issue
Block a user