Repository navigation
manifest: add new "join" command for joining multiple manifests into one - #44612
poettering wants to merge 5 commits into
Conversation
|
Reviewed b32fcbb (api, architecture, correctness, lifetimes, security, style, tests). All findings are resolved 🎉 Must fix
|
7178d4c to
f4511a6
Compare
f4511a6 to
b100d8c
Compare
b100d8c to
51457ce
Compare
91a853c to
dd56779
Compare
|
codex review: Reviewed at dd56779. I built it and ran the new unit tests (they pass) and tried the cases below against the built Bugs1. Can
d=t; for i in $(seq 1 99); do d=$d/a; done; mkdir -p $d; echo x >$d/f
systemd-manifest make t m # succeeds
systemd-manifest join m out # Maximum directory depth reached at 'a/a/…/f', refusing.With 98 levels both succeed. Other producers can emit names with up to ~2047 components, and the failure only shows up after all inputs were written to the database. Should the walk use a larger explicit bound, with input names capped to match? Related: with a name nested deeper than 2. Should objects be compared as raw JSON?
And since 3. Is the conflict count meant to count objects?
Design4. Is
5. Is the union of hardlink groups intended even when the inputs disagree? mkdir h1 h2; echo x >h1/a; ln h1/a h1/b; echo x >h2/a; echo x >h2/b
systemd-manifest make h1 hm1; systemd-manifest make h2 hm2
systemd-manifest join hm1 hm2 hj
systemd-manifest verify --verify-signature=no h2 hj # b: Inode token 1 in manifest already used by a different inode, not a hardlink.So joining a manifest of a tree with one of the same tree after a hardlink was broken yields a manifest that doesn't match the new tree. Hardlinks are the only field where disagreement neither conflicts nor resolves to one input. Would treating it as a conflict, or dropping the token where inputs disagree, fit better? 6. How large are the manifests this is meant for? Each object costs a file in Simplifications
Docs, comments, tests
Open questions
|
dd56779 to
26c322c
Compare
|
I addressed many of codex' points (but it seems to me the quality is a bit lower than claude's), and rebased on top of your certificate/priv key loading work. ptal. |
26c322c to
17065b1
Compare
path_is_normalized() accepts trailing slashes, which is generally the right thing to do, since a trailing slash carries meaning: the path must refer to a directory. However, sometimes we want the fully canonical form of a path, where the same path written with and without the slash is not considered two distinct normalized paths. Add a flag for that. The root directory "/" is accepted even with the flag set, since it has no other form.
The specification requires object names to be normalized paths. Let's insist on the fully canonical form, so that the same object cannot be named in two different ways, with and without trailing slash.
This rewinds the directory fd before reading it. That's useful if the fd was read before, but also if entries were added to the directory since it was opened: btrfs only returns entries that existed when the directory was opened, until the fd is rewound. recurse_dir() only rewinds the top-level fd, subdirectories are opened freshly anyway.
Uapi16Object deliberately omits a bunch of fields the specification defines, as well as any extension fields. Consumers that need to look at or pass along the complete object (such as the upcoming manifest joining logic) hence had no way to get at it. Let's keep a reference to the JSON object the structure was parsed from.
This joins multiple UAPI.16 manifests into one. Objects listed in more than one input must be identical (except for their inode tokens), otherwise the join fails. The only exception are modification times: if two definitions of an object differ in that only, the newest one wins. Hardlink groups are combined across inputs, transitively: if one input says X and Y are hardlinked, and another one says Y and Z are, all three end up in the same group. The inputs are not verified in any way: signatures are ignored and dropped, and beyond the identity of objects listed multiple times no consistency checks are made. That's what "verify" is for. The output is signed if --private-key= is specified. To process manifests of arbitrary size without holding them in memory, the objects are collected in a temporary database directory below /var/tmp/. It mirrors the object names as a directory tree, so that walking it sorted yields the objects in the very same order "make" generates them. Hence the output is deterministic, regardless of the order of the inputs and of the objects within them, and joining the manifest of a tree with a manifest of the same tree after files have been added to it results in the latter. With a single input this is a way to sign, re-sign or unsign a manifest.
17065b1 to
b32fcbb
Compare
brauner
left a comment
There was a problem hiding this comment.
After our discussion on Sunday, I looked at how join behaves with very large
manifests since as I have similar design questions in ufat.
So really, I had this gun cocked and loaded. I'm sorry.
So let's say you have a manifest describing the dataset for an LLM with tens
of millions of objects. I had Claude build the PR and measured
systemd-manifest join on xfs with an LD_PRELOAD shim that counts calls and
stops the process right before it removes its database.
The union-find for the hardlink groups can go quadratic. join_group_find()
does neither path compression nor union by rank. Instead, a merge always links
the higher root to the lower one so the chain from a group to its root can get
as long as the number of groups, and join_group_find() walks it with one
readlinkat() per hop. join_write_object() does that walk for every object
that has an inode token.
The first lists n pairs of hardlinked files, b1/c1 up to bn/cn, in name
order. The second lists only b1 to bn, all hardlinked to each other, in
reverse name order. The man page says the order of objects within an input
doesn't matter so that's a valid input:
objects readlinkat() time
2000 1.5M 2.0s
4000 6.0M 6.9s
8000 24M 27s
16000 96M 104s
At a million objects that's about 4 * 10^11 calls, which going by these numbers
takes days...
A single input does it too if it repeats names with the inode tokens of other
objects. uapi16_manifest_read() doesn't refuse duplicate names and the two
definitions compare equal once the inode token is filtered out. 8000 such
objects take 36s.
With both inputs sorted it stays at 8 calls per object, 16000 objects in 3.7s.
I tried pointing every group join_group_find() walks past at the root (with
symlinkat_atomic_full()) and that fixes it. Then it's 12 calls per object,
4.0s for the 16000 objects in reverse order and 2.3s for the 8000 repeated
names, with the same output as before.
The space needed is another problem. Every object costs a file in objects/
and a directory in tree/. So joining a single manifest with 1M objects (142
MiB) peaked at about 4 GiB and 2M inodes in the database and took 4m20s, 58s of
which went to removing the database again.
On ext4 it should be about twice the space since every directory gets a block
of its own. IOW, a manifest with 10M objects is a couple of GB but needs 40-80
GB and 20M inodes in /var/tmp.
And since var_tmp_dir() prefers $TMPDIR all of that ends up in memory if
$TMPDIR is on tmpfs. So 200k objects took 781 MiB of tmpfs, a page per object
plus inodes and dentries, so 40 GB and more for 10M objects.
Memory also still grows with the input. recurse_dir() with RECURSE_DIR_SORT
reads each directory of tree/ in full and keeps the listings of all parents
alive while descending. With 1M files in one directory join peaks at 54 MiB,
with the same files in directories of 1000 at 12 MiB. So a flat 10M file
dataset needs about half a GB for that alone.
Also, a file with 100 components fails with "Failed to enumerate join database:
Too many levels of symbolic links", and only after all inputs have been copied
into the database. So a join that gets killed, for example by SIGPIPE when its
output goes to head, leaves its database behind in /var/tmp until tmpfiles
ages it out. For a large join that's tens of GB.
And objects/ is a single flat directory with a 64 character name per object.
Without large_dir, which isn't enabled by default, ext4's htree has two
levels and I think that runs out somewhere around 10M such names.
Since make writes objects sorted anyway I wonder whether this wouldn't be
better done as an external merge sort? Sort runs that fit into a fixed memory
budget, spill them to a temporary file, and k-way merge them. That's sequential
I/O, about the size of the inputs in temporary space, and memory that doesn't
grow with the input.
Sorted inputs wouldn't need the run phase at all. The hardlink groups don't fit
into a single merge pass because output tokens are numbered by first appearance
and a later object can still tie two groups together. But objects with inode
tokens are usually a small fraction of a manifest and could get a pass of their
own.
|
Yep, sounds like the approach with db under /var/tmp is not the right way. |
No description provided.