mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* filer, mount: keep a hard-linked file to one link id and count its names on the filer A hard link's bookkeeping was done by the client. To link a file a mount reads its entry and sends two writes, an update of the source and a create of the new name, both with a link id and a count of the file's names. Two clients that link one file at the same moment each worked from the entry as it was before the other's writes: - With no link id on the entry yet, each made one up. The second update moved the source to its id, the store took the name off the first, and the first client's new name was left alone on it: one file's chunks under two link ids. - With a link id there, both read the same count and sent it plus one. The record counted one name fewer than the file had. Any write through a name carried the client's copy of the count and replaced the record the same way. Either way the delete of the last counted name deleted the record and the chunks while another name still read them. The filer's own store now counts the names of a hard-linked file itself (countLink): one more when the name written did not hold the link before, the same when it did or when a rename moves it there (WithMovedLink), one for a record that starts. The count sent is not used, and the entry gets the count stored, so the response and the event carry it. The lookup of the name, the count, the record and the name are stored as one change of the record (changeLinkRecord), which DeleteHardLink goes through as well: under a lock per link id, and in a transaction where the store refuses a commit over a change made since it began, run again when it does. A wrapper around a copy of some entries, such as a mount's metadata cache, sees only some of the names and stores the count it is given. UpdateEntry refuses to give a name that holds a hard link another link id that no file has yet (refuseSecondHardLink). The mount sends a file's first link's update as a unary RPC, which keeps that refusal apart from an I/O failure, reads the entry again and links under the id the file has by now. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * filer: take a replicated update's link id without refusing it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: look a path-specific name up outside the record's transaction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: check the leveldb open and close it in the hard link test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: send a refused first link again from the entry as stored Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep a first link's refusal over the next filer's error Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: count a hard link's names next to the clients' count instead of in its place The filer's count replaced the one clients send, which lost two things that count did by being worked out ahead: - A link's first write, the update of the source, carries the count with the new name in it already. While the second write is on its way that kept a delete of the source from being taken for the delete of the file's last name (lastLinkDropped goes by the count it read), and the chunks from being deleted under the name about to come. Counted only when it arrived, the new name was stored with chunks that were gone: 104 of 300 rounds of a mount linking a file while another deletes it. - A write of a name the store refused had counted the name already, and sent again counted it once more. The filer now keeps its count of the names in a key of its own next to the record (linkNames), written once the name is stored, and the record gets whichever is higher: the count the client sent or the names counted. It is never lower than what the client alone would have left, and never lower than the names the file has. A record from before has its count recorded as the names when it is first written again. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * mount: send a refused first link again with the file's inline content The second attempt builds the new name's create from the entry as the filer has it by now: attributes, chunks and extended attributes. A file the filer keeps inside its entry has its bytes in Content, and the create is what the filer writes the link's shared record from, so without them the record lost the file's content. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * filer: store a path-specific name before the record's lock is let go A second create of the same new name on this filer took the lock between the first one's count and its name write, missed the name, and counted it again: the file's record and chunks then outlived its last name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: keep a link's names key out of the keys of a directory's entries The key began with the link's random id. One that began as the root's entry keys do in a store keyed by path put the names' 4 bytes in the root's listing, and it failed to decode: listing / and the etcd scan under fsck failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: record a hard link's name before it is stored, and take it off if it is not The names counted for a hard link were recorded once the name was stored. On a store without transactions a failure of that write left the name stored and not counted, and the write sent again found the name there and did not count it either: the names recorded stayed one below the names stored, the side a file is deleted under a name from. They are recorded first now, inside the change of the record that counted them, and a name the store then does not take is counted off again (storeCountedName). A failure halfway leaves them one above the names stored, and the file leaked. A name in a path-specific store is recorded with the record as well, and counted off in a change of its own. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * filer: keep a hard link's name counted when a failed write stored it A write whose deadline passes after the store took the name returns an error, and counting the name off then left the names one below the names stored. A later write with the count from before the link lowered the record to them, and the file was deleted under a name it still had. Read the name back first, and keep it counted where that cannot be told. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: carry the stored RemoteEntry into the name a retried first link adds The retry rebuilds the new name from the entry the file has once another client linked it, but kept the RemoteEntry of the entry first read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: MapleWhiteZZZ <18653045+MapleWhiteZZZ@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Concurrent writers to one file from different mounts require -dlm; without it, a conflicting write fails with EIO and the file may refuse further appends until reopened after the cache drops.