mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
Merge pull request #830 from seaweedfs/fix/delete-head-conflict
v1.0.1 gate fix: a raced snapshot delete answers head_conflict
This commit is contained in:
commit
aa16ffa7a5
6 files changed
+161
-1
No files matched your search
@@ -361,6 +361,13 @@ func chunkErrorCode(err error) (int, string, bool) {
|
||||
return http.StatusServiceUnavailable, codeHostSlotBusy, true
|
||||
case errors.Is(err, storage.ErrChunkCaptureRefused):
|
||||
return http.StatusServiceUnavailable, "capture_refused", true
|
||||
case errors.Is(err, layout.ErrPrecondition):
|
||||
// Last before default: a catalog transition (a snapshot delete) lost
|
||||
// its conditional HEAD write to another writer (a cleaning's begin);
|
||||
// nothing of it applied, and a retry reads HEAD again. Every other
|
||||
// cause an error also carries (terminal, uncertain or retryable)
|
||||
// decides first.
|
||||
return http.StatusConflict, codeHeadConflict, true
|
||||
default:
|
||||
return http.StatusInternalServerError, codeInternal, false
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/engine"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
@@ -218,6 +219,14 @@ func TestStatusServer_ChunkErrorBodyIsTyped(t *testing.T) {
|
||||
{fmt.Errorf("%w: %w", storage.ErrChunkReconciling, context.DeadlineExceeded), "reconciling", 409, true},
|
||||
{fmt.Errorf("x: %w", storage.ErrChunkCASOutcomeUnknown), "outcome_unknown", 503, true},
|
||||
{fmt.Errorf("x: %w", storage.ErrChunkHeadPrecondition), "head_conflict", 409, true},
|
||||
{fmt.Errorf("x: %w", layout.ErrPrecondition), "head_conflict", 409, true}, // a raced catalog transition (snapshot delete)
|
||||
// The precondition is the last cause to decide: joined with any
|
||||
// terminal one, that one is reported.
|
||||
{errors.Join(storage.ErrChunkLayerClosed, layout.ErrPrecondition), "closing", 503, false},
|
||||
{errors.Join(storage.ErrChunkLayerDetached, layout.ErrPrecondition), "closing", 409, false},
|
||||
{errors.Join(errFrozenDetachUnsupported, layout.ErrPrecondition), "frozen_detach_unsupported", 409, false},
|
||||
{errors.Join(storage.ErrInvalidFreezeBudget, layout.ErrPrecondition), "invalid_freeze_budget", 400, false},
|
||||
{errors.Join(durable.ErrNotChunkVolume, layout.ErrPrecondition), "not_chunk_volume", 409, false},
|
||||
{fmt.Errorf("save: %w", storage.ErrCutCOWAborted), "cut_aborted", 503, true},
|
||||
// Local capacity abort cancels the in-flight remote PUT.
|
||||
{errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkRemoteUnavailable, context.Canceled, errors.New("storage: saver capacity")), "cut_aborted", 503, true},
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package volume
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
)
|
||||
|
||||
// racingHeadFiler runs between, before each HEAD update it forwards, while
|
||||
// armed: another writer's HEAD update landing between a transition's HEAD
|
||||
// read and its conditional write. times bounds how many updates it races
|
||||
// (-1: every one).
|
||||
type racingHeadFiler struct {
|
||||
*adapterManifestFiler
|
||||
mu sync.Mutex
|
||||
times int
|
||||
between func()
|
||||
busy bool
|
||||
}
|
||||
|
||||
func (f *racingHeadFiler) UpdateEntry(ctx context.Context, dir string, e *filerpb.Entry, expected map[string][]byte) error {
|
||||
f.mu.Lock()
|
||||
run := !f.busy && f.times != 0 && e.GetName() == layout.HeadName && f.between != nil
|
||||
if run {
|
||||
f.busy = true
|
||||
if f.times > 0 {
|
||||
f.times--
|
||||
}
|
||||
}
|
||||
f.mu.Unlock()
|
||||
if run {
|
||||
f.between() // its own HEAD update is forwarded unraced (busy)
|
||||
f.mu.Lock()
|
||||
f.busy = false
|
||||
f.mu.Unlock()
|
||||
}
|
||||
return f.adapterManifestFiler.UpdateEntry(ctx, dir, e, expected)
|
||||
}
|
||||
|
||||
// deleteRaceFixture is a live volume, held by me, with snapshot "a", and a
|
||||
// filer that can race its HEAD updates.
|
||||
func deleteRaceFixture(t *testing.T) (context.Context, *racingHeadFiler, *chunkstore.BCatalog, chunkstore.VolumeRef, layout.HolderID) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
f := &racingHeadFiler{adapterManifestFiler: &adapterManifestFiler{Filer: chunkstore.NewMemFiler(), blobs: map[string][]byte{}}}
|
||||
cat, err := chunkstore.NewBCatalog(f, f, "/chunks")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id, _ := layout.ParseVolumeID("00112233445566778899aabbccddeeff")
|
||||
ref := chunkstore.VolumeRef{Name: "v1", ID: id}
|
||||
if _, err := cat.CreateVolume(ctx, ref, layout.Geometry{SizeBytes: 64 * 4096, BlockSize: 4096, ChunkBytes: 4 * 4096}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h, _, err := cat.ReadHead(ctx, ref)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
me := layout.HolderID{Epoch: 1, Holder: "a", ClaimID: "k"}
|
||||
h.Epoch, h.Holder, h.ClaimID, h.State = me.Epoch, me.Holder, me.ClaimID, layout.StateLive
|
||||
h.Snapshots = map[string]layout.Snapshot{"a": {Root: layout.RootName{Hash: layout.Sum([]byte("root"))}}}
|
||||
s, _ := cat.Store(ref)
|
||||
if err := s.UpdateHead(ctx, h.Gen, h, layout.CauseCommit); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return ctx, f, cat, ref, me
|
||||
}
|
||||
|
||||
// The holder's cleaning begins (a HEAD update) between a snapshot delete's
|
||||
// HEAD read and its conditional write. The delete is refused as
|
||||
// head_conflict (409, retryable), never internal; HEAD keeps the snapshot
|
||||
// (nothing of the delete applied); a retry completes the delete.
|
||||
func TestSnapshotDeleteRacedByACleanBeginIsAHeadConflict(t *testing.T) {
|
||||
ctx, f, cat, ref, me := deleteRaceFixture(t)
|
||||
s, _ := cat.Store(ref)
|
||||
f.mu.Lock()
|
||||
f.times, f.between = 1, func() {
|
||||
if _, err := layout.RunBeginClean(ctx, s, me, "clean-1"); err != nil {
|
||||
t.Errorf("the racing clean-begin: %v", err)
|
||||
}
|
||||
}
|
||||
f.mu.Unlock()
|
||||
p := &fakeChunkProvider{}
|
||||
ctl := NewChunkControl(p, cat, ref)
|
||||
_, err := ctl.DeleteSnapshot(ctx, "v1", "a")
|
||||
if !errors.Is(err, layout.ErrPrecondition) {
|
||||
t.Fatalf("setup: the raced delete: %v; want the HEAD precondition", err)
|
||||
}
|
||||
if status, code, retryable := chunkErrorCode(err); status != http.StatusConflict || code != codeHeadConflict || !retryable {
|
||||
t.Fatalf("a raced delete maps to %d %q retryable=%v; want 409 head_conflict retryable", status, code, retryable)
|
||||
}
|
||||
h, _, err := cat.ReadHead(ctx, ref)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := h.Snapshots["a"]; !ok || h.Activity.Kind != layout.ActClean || len(p.kicks) != 0 {
|
||||
t.Fatalf("after the refused delete: snapshots %v, activity %v, kicks %v; want the snapshot kept, the cleaning's activity, no kick", h.Snapshots, h.Activity, p.kicks)
|
||||
}
|
||||
if _, err := ctl.DeleteSnapshot(ctx, "v1", "a"); err != nil {
|
||||
t.Fatalf("the retry: %v", err)
|
||||
}
|
||||
h, _, err = cat.ReadHead(ctx, ref)
|
||||
if _, still := h.Snapshots["a"]; err != nil || still {
|
||||
t.Fatalf("after the retry: %v %v; want the snapshot gone", h.Snapshots, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A conflict that persists (every attempt raced) stays head_conflict: the
|
||||
// operator sees a retryable conflict, never an internal error.
|
||||
func TestSnapshotDeleteUnderAPersistentConflictIsNeverInternal(t *testing.T) {
|
||||
ctx, f, cat, ref, _ := deleteRaceFixture(t)
|
||||
s, _ := cat.Store(ref)
|
||||
f.mu.Lock()
|
||||
f.times, f.between = -1, func() {
|
||||
h, _, err := s.ReadHead(ctx)
|
||||
if err != nil {
|
||||
t.Errorf("racing read: %v", err)
|
||||
return
|
||||
}
|
||||
if err := s.UpdateHead(ctx, h.Gen, h, layout.CauseCommit); err != nil {
|
||||
t.Errorf("racing write: %v", err)
|
||||
}
|
||||
}
|
||||
f.mu.Unlock()
|
||||
ctl := NewChunkControl(&fakeChunkProvider{}, cat, ref)
|
||||
for attempt := 0; attempt < 3; attempt++ {
|
||||
_, err := ctl.DeleteSnapshot(ctx, "v1", "a")
|
||||
if status, code, retryable := chunkErrorCode(err); err == nil || status != http.StatusConflict || code != codeHeadConflict || !retryable {
|
||||
t.Fatalf("attempt %d under a persistent conflict: %v -> %d %q retryable=%v; want 409 head_conflict retryable", attempt, err, status, code, retryable)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -950,6 +950,7 @@ Notes:
|
||||
| `INV-CUT-PAYLOAD-SPILL-SOURCE-001` | Only a COW save made before a store mutation (`WriteContext`, `WriteBatchContext` or `applyEntryV3`) consumes side-file bytes; copy and upload workers never write the side file. | M5 Copy (COW save) | `core/storage/chunk_cut_cow.go` `beforeCOWMutation`, `copyCOWEntry`; `core/storage/walstore.go` `WriteContext`, `WriteBatchContext`; `core/storage/base_install_v3.go` `applyEntryV3` | `TestCutCOWV3_SpillWithinCapIsAccounted` (`core/storage/chunk_cut_cow_spillcap_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-PAYLOAD-JOIN-001` | Every upload worker of a cut or staging round has returned before that round's intents are cleaned up or its outcome is settled, also after an upload failure or cancellation. | M5 Upload → Closed, Aborted | `core/storage/chunk_upload.go` `uploadBatch`; `core/storage/chunk_layer.go` `captureLocked` | `TestChunkUploads_FailureJoinsBeforeIntentCleanup` (`core/storage/chunk_upload_parallel_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-ERROR-PRECEDENCE-001` | A chunk-control error body reports `cut_aborted` for a local cut abort even when the abort cancelled a remote upload, but an unknown CAS outcome, a fence or a closed or detached layer joined to it keeps its own code (`outcome_unknown`, `fenced`, `closing`). | M5 Copy, Upload → Aborted (HTTP error body) | `core/host/volume/chunk_control.go` `chunkErrorCode` | `TestStatusServer_ChunkErrorBodyIsTyped` (`core/host/volume/chunk_control_test.go`) | — | ACTIVE |
|
||||
| `INV-CATALOG-HEAD-CONFLICT-001` | A catalog transition that lost its conditional HEAD write (`layout.ErrPrecondition`, such as a snapshot delete raced by a cleaning's begin) reports `head_conflict` (409, retryable), never `internal`; it decides last, so any other cause joined to it keeps its own code. | M6 snapshot delete (HTTP error body) | `core/host/volume/chunk_control.go` `chunkErrorCode` | `TestSnapshotDeleteRacedByACleanBeginIsAHeadConflict`, `TestSnapshotDeleteUnderAPersistentConflictIsNeverInternal` (`core/host/volume/chunk_delete_head_conflict_test.go`); `TestStatusServer_ChunkErrorBodyIsTyped` (`core/host/volume/chunk_control_test.go`) | — | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-001` | A cooperating cut process holds a host OS slot from its admission, before staging or the capture barrier: see M7 free → admitted. | M7 free → admitted | `core/hostlimit/limiter.go` `Admit`; `core/storage/chunk_cut_budget.go`; blockvolume host-limit flags | `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`); `TestHostCutLimitDoesNotGateGuestIO` (`core/frontend/durable/host_limit_test.go`) | `HostBudget` HeldUntilJoined/PayloadBound/SpillBound (bounded OS-lock abstraction; fallback excluded) | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-RESERVE-001` | Each admitted slot, urgent included, carries at most PayloadBytes of cut payload and at most COWBytes of COW side bytes; a reservation beyond COWBytes revokes the slot and aborts its cut. | M7 admitted | `core/hostlimit/limiter.go` `Admit`, `ReserveCOW`; `core/storage/chunk_cut_budget.go` | `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | `HostBudget` PayloadBound/SpillBound | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-SETTLE-001` | A slot's OS lock is released only after its cut's workers settle and Release is called; cancellation, hold expiry and limiter Close abort the cut but keep the slot until then. | M7 draining → joined → released | `core/hostlimit/limiter.go` `Release`, `releaseLoop`, `revoke`, `Close`; `core/storage/chunk_layer.go` `captureLocked` | `TestCOWAbortHoldsSlotUntilWorkerSettlement`, `TestHoldExpiryAndCloseDoNotSteal`, `TestKilledProcessReleasesButLiveHolderDoesNot` (`core/hostlimit/limiter_test.go`); `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`) | `HostBudget` HeldUntilJoined | ACTIVE |
|
||||
|
||||
@@ -386,6 +386,10 @@ the snapshot name exists only after a request for it succeeds (check with `sw-bl
|
||||
(`TestKnownDefectSnapshotRetryAfterAGenuineConflictCommitsTheDataUnnamed`). A retry that names the snapshot at once is
|
||||
planned for a later release.
|
||||
|
||||
A snapshot delete can answer `head_conflict` (HTTP 409, retryable) too: another write to the volume's HEAD, such as the
|
||||
holder's cleaning beginning, landed between the delete's read of HEAD and its write. Nothing of the delete applied;
|
||||
retry it (`TestSnapshotDeleteRacedByACleanBeginIsAHeadConflict`).
|
||||
|
||||
A snapshot's time grows with the data changed since the volume's last cut. `sw-block ops chunk snapshot` waits 60 s by default, so pass `--timeout` above the expected time; the
|
||||
server bounds one request at 5 minutes whatever `--timeout` says. A request that runs
|
||||
out of time answers a retryable code: `remote_unavailable` or `deadline_exceeded` when it ran out before its commit,
|
||||
|
||||
@@ -133,7 +133,8 @@ limits and the rare holder crash listed in v1.0.0's Known limits.
|
||||
- A volume-delete refused with `snapshot_has_dependents` has already reserved the volume; delete or release the
|
||||
restored volume first, then run the same delete again.
|
||||
- A snapshot that meets a concurrent HEAD change answers `head_conflict`: retry it (and once more if the retry answers
|
||||
`snapshot "NAME" of VOL is not in HEAD after its commit`).
|
||||
`snapshot "NAME" of VOL is not in HEAD after its commit`). A snapshot delete that meets one (for example the
|
||||
holder's cleaning beginning) answers `head_conflict` too, where it answered `internal` before: nothing applied, retry it.
|
||||
- A restored volume that has only been read fetches all of its chunks again after any restart; writing to it, or its
|
||||
next checkpoint, records what it has fetched (no data is lost).
|
||||
- A guest's NVMe/TCP connection waits about 181 s (holder stopped, host up) or about 464 s (holder's host powered off)
|
||||
|
||||
Reference in new issue
Block a user