diff --git a/seaweed-block/core/host/volume/chunk_control.go b/seaweed-block/core/host/volume/chunk_control.go index 9454275e69..f6a364fde1 100644 --- a/seaweed-block/core/host/volume/chunk_control.go +++ b/seaweed-block/core/host/volume/chunk_control.go @@ -334,11 +334,6 @@ func chunkErrorCode(err error) (int, string, bool) { return http.StatusConflict, codeReconciling, true case errors.Is(err, storage.ErrChunkHeadPrecondition): return http.StatusConflict, codeHeadConflict, true - case errors.Is(err, layout.ErrPrecondition): - // 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. - return http.StatusConflict, codeHeadConflict, true case errors.Is(err, storage.ErrChunkLayerDetached): return http.StatusConflict, codeClosing, false // stays closed until a new attach case errors.Is(err, storage.ErrChunkLayerClosed): @@ -366,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 } diff --git a/seaweed-block/core/host/volume/chunk_control_test.go b/seaweed-block/core/host/volume/chunk_control_test.go index b688b7f4c4..9ad1cff430 100644 --- a/seaweed-block/core/host/volume/chunk_control_test.go +++ b/seaweed-block/core/host/volume/chunk_control_test.go @@ -220,6 +220,13 @@ func TestStatusServer_ChunkErrorBodyIsTyped(t *testing.T) { {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},