diff --git a/seaweed-block/core/frontend/chunkstore/layout_store.go b/seaweed-block/core/frontend/chunkstore/layout_store.go index b5c325dfa6..7dfd198506 100644 --- a/seaweed-block/core/frontend/chunkstore/layout_store.go +++ b/seaweed-block/core/frontend/chunkstore/layout_store.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math" "path" "strconv" "strings" @@ -64,7 +65,9 @@ func (s *LayoutStore) ReadHeadObserved(ctx context.Context) (h layout.Head, mtim if err != nil { return layout.Head{}, 0, false, err } - if sec := e.GetAttributes().GetMtime(); sec > 0 { + // A time not representable in nanoseconds (past 2262) is unknown, as is + // none: it never wraps to a wrong value. + if sec := e.GetAttributes().GetMtime(); sec > 0 && sec <= math.MaxInt64/int64(1e9) { mtimeNS = sec * int64(1e9) } return h, mtimeNS, true, nil diff --git a/seaweed-block/core/host/master/workspace_layout_head_test.go b/seaweed-block/core/host/master/workspace_layout_head_test.go index 0bbd426508..3d61be18a4 100644 --- a/seaweed-block/core/host/master/workspace_layout_head_test.go +++ b/seaweed-block/core/host/master/workspace_layout_head_test.go @@ -123,6 +123,7 @@ func TestWorkspaceLayoutHEADRefusalsAndStates(t *testing.T) { {name: "detached", valid: true}, {name: "live", state: "live", valid: true}, {name: "unknown mtime", valid: true, alter: func(e *filerpb.Entry) { e.Attributes = nil }}, + {name: "out-of-range mtime", valid: true, alter: func(e *filerpb.Entry) { e.Attributes = &filerpb.FuseAttributes{Mtime: 253402300799} }}, // year 9999 {name: "unclaimed", state: "unclaimed", sentinel: authority.ErrWorkspaceHeadUnclaimed}, {name: "deleted", state: layout.StateDeleted, sentinel: authority.ErrWorkspaceHeadDeleting}, {name: "missing generation", alter: func(e *filerpb.Entry) { delete(e.Extended, "swb.layout.gen") }}, @@ -182,7 +183,7 @@ func TestWorkspaceLayoutHEADRefusalsAndStates(t *testing.T) { } got, err := read(ctx, "v") wantTime := int64(100e9) - if tc.name == "unknown mtime" { + if tc.name == "unknown mtime" || tc.name == "out-of-range mtime" { wantTime = 0 } switch {