Files
seaweedfs/weed/filer
ef0967bead filer: read the entry path once per write (#13090)
* filer: read the entry path once per write

A create looks the path up to decide what it makes of the entry: the inode and
crtime to keep, the chunks the write leaves behind, the old side of the metadata
event. The store wrapper looked the same path up again, in
handleUpdateToHardLinks, to learn the hard link the name carried before. Both
reads happen under the same per-path lock, a moment apart, and for a file written
without a hard link the second one decides nothing at all: its result is
discarded. An overwrite pays for it twice over, because that read decodes the row
being replaced -- gunzip included above CountEntryChunksForGzip -- and it is the
row the create already holds.

Neither read shows up as a second find in the store metrics: the wrapper's goes
to the actual store, and FilerStoreCounter counts only FilerStoreWrapper.FindEntry.

The wrapper now takes the caller's word. InsertEntryReplaces and
UpdateEntryReplaces carry the entry a caller read to handleUpdateToHardLinks,
which keeps to it instead of reading the path again. An insert whose lookup found
the path empty goes the way #13006 opened with InsertEntryKnownAbsent, which
rename alone used.

Which word may be taken is the delicate part, so Filer.findEntry reports whether
its answer is what the store holds at the path:

- a lazy fetch from a remote mount serves an object the store does not have and
  writes nothing to it, so it says nothing about the row there;
- inside a store transaction a lookup hides an expired S3 entry whose row the
  transaction keeps until the commit, and a write replacing it still owes that
  entry its hard link -- which is why FindEntryForOverwrite exists;
- where the expiry check deleted the row, the delete dropped its link already, so
  an answer of "empty" is honest.

The write also reads the path itself whenever there is a link to take off, for
two reasons. A file with a hard link has its record changed again when the store
refused a commit (changeLinkRecord runs its change up to linkRecordAttempts
times), and each run must judge the name as the store holds it by then. And a row
that carries a link is the row whose link this write drops: plain creates are not
routed to the write owner, so another filer may have replaced the same name
already and dropped that link, and dropping it twice deletes the record under the
file's remaining names. What is trusted is the case with nothing to decide --
no link on either side -- which is an ordinary file write, since a mount makes a
link id only when a file is linked or copied.

The HTTP append path read the entry three times: once to merge with it, once to
prove it had not changed while the chunks were uploaded, and once in the create.
The create takes the recheck's entry now.

A 20-chunk entry on leveldb2 goes from 343 to 286 allocs/op and from 44.6 to
38.3 KiB/op per overwrite, the difference being the decode of the replaced row.
Where the store is reached over the network, the read saved is a round trip per
write.

Tests count the reads one write makes at the store, pin that a dropped link is
dropped once against a row another filer has already replaced, and keep the
create using the entry it is handed. #9645's own guard expected the create's
lookup to be what separates passing existing from passing nil; both are one read
now, so it requires one read either way and checks the crtime came from the entry
passed in.

Issue #5067.

Review of the first version caught one more case. The known-absent shortcut must
not take an entry that carries a link: InsertEntryKnownAbsent counts the name as
joining without reading it, so another filer storing that name for the same link
between this lookup and the write would have it counted twice, and the count
would run one above the names. The regular insert reads the name inside the
change of the record. CreateEntry and ReplaceFileForRename keep the write's own
read for a linked entry; TestNewLinkedNameStillReadsThePath pins it.

* filer: drop issue numbers from the write-read test comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer: say a plain-over-plain write can miss a link stored after the read

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: whitefox <whitefox@mayflower.work>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 15:33:51 -08:00
..
2023-04-13 22:32:45 -07:00
2026-04-10 17:31:14 -07:00