filer: normalize the stored entry too when matching IF_ENTRY_EQUAL

A store that keeps the entry as given (the JSON-backed ones) returns
FileSize zero beside chunks, while the expected entry was normalized to
the chunk extent, so an unchanged entry failed the match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-20 05:23:16 -08:00
1 parent a72323d202
commit b8d652cc10
2 files changed
+28 -4

No files matched your search

+6 -4
View File
@@ -90,14 +90,16 @@ func clauseSatisfied(c *filer_pb.WriteCondition_Clause, current *filer.Entry) bo
if !exists || c.ExpectedEntry == nil {
return !exists && c.ExpectedEntry == nil
}
// Compare both sides in serialized form on clones: chunks are matched
// by their fid only — the stored entry may carry the restored file_id
// while an expected one built from a metadata event does not.
// Compare both sides in serialized, normalized form on clones: chunks
// are matched by their fid only — the stored entry may carry the
// restored file_id while an expected one built from a metadata event
// does not — and a store that does not decode through FromPbEntry
// keeps the FileSize it was given.
expected := proto.Clone(c.ExpectedEntry).(*filer_pb.Entry)
filer_pb.BeforeEntrySerialization(expected.Chunks)
actual := proto.Clone(current.ToProtoEntry()).(*filer_pb.Entry)
filer_pb.BeforeEntrySerialization(actual.Chunks)
return proto.Equal(actual, filer.FromPbEntry("", expected).ToProtoEntry())
return proto.Equal(filer.FromPbEntry("", actual).ToProtoEntry(), filer.FromPbEntry("", expected).ToProtoEntry())
default:
// An unrecognized clause kind (e.g. from a newer client) must not be
// treated as satisfied, which would silently bypass the guard. Fail
@@ -230,6 +230,28 @@ func TestIfEntryEqualNormalizesExpected(t *testing.T) {
}
}
// A store that keeps the entry as given (JSON-backed stores) returns FileSize
// zero beside chunks; an expected entry read from it must still match it.
func TestIfEntryEqualUnnormalizedStored(t *testing.T) {
stored := &filer.Entry{
FullPath: "/d/f",
Attr: filer.Attr{Mtime: time.Unix(42, 0)},
Chunks: []*filer_pb.FileChunk{
{Fid: &filer_pb.FileId{VolumeId: 3, FileKey: 1, Cookie: 2}, Size: 4},
},
}
cond := one(&filer_pb.WriteCondition_Clause{
Kind: filer_pb.WriteCondition_IF_ENTRY_EQUAL,
ExpectedEntry: stored.ToProtoEntry(),
})
if !writeConditionSatisfied(cond, stored) {
t.Error("an entry read from the store must equal the stored entry")
}
if stored.FileSize != 0 {
t.Fatalf("the check changed the stored entry's FileSize to %d", stored.FileSize)
}
}
// A stamp built from the metadata-log event carries chunks in serialized
// form (file_id moved into fid), while the stored entry came through
// FindEntry which restores file_id. The comparison must still match.