fix(volume): the layout precondition decides last

The layout.ErrPrecondition case moves to the last position before default,
so every other cause an error carries decides first, the non-retryable
ones (closed, detached, frozen detach unsupported, an invalid freeze
budget, not a chunk volume) included. Controls: each joined with the
precondition reports its own code; with the case moved back to its
earlier place the closed, detached and frozen-detach rows fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 64eddb3484)
This commit is contained in:
pingqiu committed 2026-11-30 08:06:07 -08:00
1 parent 2fb4ffee6e
commit c6528d7740
2 files changed
+14 -5

No files matched your search

@@ -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
}
@@ -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},