From 8bdbc05ba9876e583ae8b45ff828afd583b874e3 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 00:06:55 -0800 Subject: [PATCH] layout: omit an empty ext from Head's own JSON Head's Go JSON (the status and CLI show output) wrote a nil Ext as null, which reads back as the bytes null, and the ext check then refused the HEAD as a v1.0 record carrying ext. Ext is now omitted when empty, so a HEAD without ext reads back without one; a v1.1 HEAD keeps its ext. Co-Authored-By: Claude Opus 5.5 --- .../core/frontend/chunkstore/layout/head.go | 4 ++- .../chunkstore/layout/head_version_test.go | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/frontend/chunkstore/layout/head.go b/seaweed-block/core/frontend/chunkstore/layout/head.go index 08ed17133d..9c896a8023 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/head.go +++ b/seaweed-block/core/frontend/chunkstore/layout/head.go @@ -169,7 +169,9 @@ type Head struct { // back verbatim (the ext contract: only additive facts that a writer // keeping them verbatim while it changes the known fields cannot make // wrong; anything an older writer could break bumps Version instead). - Ext json.RawMessage + // Omitted when empty in Head's own JSON (status and CLI output), so a + // HEAD without ext reads back without one, never as the bytes null. + Ext json.RawMessage `json:",omitempty"` } // HeadVersion1 is the v1.1 HEAD format; MaxHeadVersion the newest this diff --git a/seaweed-block/core/frontend/chunkstore/layout/head_version_test.go b/seaweed-block/core/frontend/chunkstore/layout/head_version_test.go index c81cee655d..f20a41ccca 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/head_version_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout/head_version_test.go @@ -148,3 +148,31 @@ func TestHeadExtIsACanonicalObject(t *testing.T) { } } } + +// Head's own JSON (status and CLI output, not the HEAD codec) round-trips +// to a HEAD that still encodes: a v1.0 HEAD has no ext there, never the +// bytes null, and a v1.1 HEAD keeps its ext. +func TestHeadJSONRoundTripKeepsTheExt(t *testing.T) { + root := RootName{Hash: Sum([]byte("image"))} + v1 := idleHead() + v1.Current, v1.Position = &root, 9 + v1.Version, v1.CurrentBytes, v1.Ext = HeadVersion1, u64(10), json.RawMessage(`{"a":1}`) + for name, h := range map[string]Head{"v1.0": idleHead(), "v1.1": v1} { + raw, err := json.Marshal(h) + if err != nil { + t.Fatal(err) + } + var back Head + if err := json.Unmarshal(raw, &back); err != nil { + t.Fatal(err) + } + want, err := h.Encode() + if err != nil { + t.Fatal(err) + } + got, err := back.Encode() + if err != nil || !bytes.Equal(got, want) { + t.Fatalf("%s: Head JSON %s encodes to %s, %v; want %s", name, raw, got, err, want) + } + } +}