desync: `untar` is missing seed support

In our use case, we have an A/B setup where we apply block based system updates with desync extract and use the active partition as a seed. For very small updates, using a block based .caibx introduces a lot of overhead. So we were evaluating to produce file based .caidx updates in those circumstances, as an alternative to speed up the updates when just a handful of files change.

However I noticed that desync untar doesn’t have any seed support at the moment.

Do you have any suggestion on how a seed for untar should be designed? If we produce a .caidx of a local directory, can we grab its corresponding chunks from the filesystem without having to tar the entire local directory first?

FTR I can see that Casync handles .caidx with extract, and if you provide a path as a seed, it starts its process by seeding one by one all the files in the provided directory.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 20 (13 by maintainers)

Most upvoted comments

The way desync mtree works is that it uses the index to reassemble the catar stream in memory (not all at once) and untars the stream. Rather than writing to the filesystem, it just hashes the data in each file. That’s why all it needs is the index and the chunks to produce the mtree output.

I’m not really seeing any good options. I’d rather not introduce a new file-format to describe a file-tree with individually chunked files, though I think it be possible in principle and would provide the seed-capabilities.

If the goal is to avoid writing the content in full during untar, that’s be doable with an incremental mode where it could only replace files that have changed (whole files), something like desync untar --incremental <archive> <target>. It still have to unpack the full stream though (no seeding from existing trees). And it probably couldn’t handle deletions.

Just to align on terminology first.

  • Given dirA with multiple files/dirs in it
  • A catar is simply an archive containing data, metadata, and structure of dirA, very similar to a regular tar
  • When chunking the catar we end up with a number of chunk files and a caidx
  • a caidx is fundamentally the same as a caibx (perhaps with minor differences in header flags), the different suffix is there to indicate that the chunked file was an archive
  • All that caibx/caidx contain is information about which chunk goes where in the underlying blob. They do not contain any information about the blob or what may be inside the archive.

Not sure I fully understand your proposal of having a “delta”, but a form of this could work if a partial catar/caidx could be produced, containing only files that have changed. For example:

  • Given 2 catar files (or caidx+store, doesn’t really matter in this example), dir-v1.catar and dir-v2.catar
  • It’d be possible to extract both at the same time, and storing any file that’s different into a new dir-v1-v2-diff
  • Then one could create a new (presumably smaller) dir-v1-v2-diff.catar which could be distributed to clients
  • The smaller dir-v1-v2-diff.catar would then be untar’ed over the existing tree, overwriting files that have changed
  • This ignores deletions of course, and it would always work on whole files only and not just contain a diff within the file

I suspect there are other tools that can diff a tree more efficiently though and produce a delta one could chunk, transfer with desync and apply client-side.

Disk space and bandwidth are my primary concerns: if I update a 4kB config file or 1MB binary on the 10GB filesystem, I would like to only use a few MB of disk space and bandwidth to update it. This means that I would not want to download a full catar, but rather a caidx and fill most of the chunks with stuff already on-disk.

The main issue is that reflinking happens on files, but chunks in a catar can span file boundaries.

There’s also FICLONERANGE for block-aligned (always 4KiB?) sharing.

One could for example first read the old catar and build an index of which chunk is contained in which file(s) and at what offsets. The while while running untar on the new catar, find out what chunk is producing the data stream for each file, and if that chunk exists in the old image, reflink it from there instead.

To preface this, I am unfamiliar with the layout of the catar format—this is based on my assumption that it is similar to tar.

I was imagining a format that stays on the target that says, for example, “chunk ab3681… is bytes 0x0000 to 0xFFFF of /abc” or “chunk bf5311… is the header (in tar terminology) of /a, then bytes 0x0000 to 0x1000 (the entirety) of /a, then the header of /b, then bytes 0x0000 to 0x1000 (the entirety) of /b”. When extracting untaring the caidx, if chunk bf5311 is requested, files /a and /b could just be reflinked to the destination directory.

(slightly more efficient would be to start with a read-write btrfs snapshot of the seed data and update it because btrfs snapshot is much faster then reflinking every file, but I don’t need this level of efficiency and I imagine it would be hard to maintain consistency since extract/untar would have to delete files)

so perhaps in this case “image” is a directory of multiple files

Yeah, I didn’t word that the best. It’s a Linux root filesystem that is packaged as a GPT disk image for initial factory deployment, but I’d like future updates to happen at the filesystem level.

When dealing with untar and seeds, we’d first need to define what a seed for a directory actually looks like. Perhaps another directory of similar files? But during untar while reading the stream, how would you know that the file being unpacked matches one already on disk. You’d have to fully unpack it first and then compare which doesn’t really help with being fast or efficient.

I was hoping to use the previously deployed filesystem’s actual files as the seed. I should clarify that I deploy this read-only filesystem, then make a writable btrfs snapshot of it. This leaves the originally deployed filesystem intact on-disk, while allowing efficient small changes online. To my understanding,casync extract --sync=/mnt/btrfs/read-only-original-fs would do what I want, just much slower than necessary.

I’m OK with depending on this original read-only directory being unmodified (thus making the created index completely valid). btrfs requires explicitly changing a subvolume to read-write, and even then it updates a UUID that I can verify myself before attempting an update. This logic is used by btrfs’s built-in send & receive feature to ensure its seed data is intact without checking every file.

Alternatively, I could store the output of desync tar in the filesystem. I hope that the chunk store should be able to reflink most of the actual files on disk, making it only take up dirent space.

Perhaps this seed index could be produced as part of the untar operation, to then help find chunks during future untar.

Given that on the target we just have the extracted archive files around, unless I’m missing something, the actual steps will end up being:

On the source:

  1. desync tar --no-time

On the target: 2. desync tar --no-time, to create a usable seed from the files in the currently active partition 3. desync extract 4. desync untar 5. Delete the generated seed catar and the downloaded catar update

And in order to successfully apply that we would need a free space that is at least 2x the full update size. That’s a substantial tradeoff compared to the caibx where we don’t need any reserved free space at all.

To skip the step 2. we would need to keep the seed catar always around, but always using all that disk space is probably unfeasible.

The more I look and this, the more I suspect caidx will sadly not help us to speed up small system updates.

Our primary goals are to reduce the download size and speed up the whole update process. Reducing I/O is nice to have, but not a primary concern at the moment.

If we produce two system images where just a few files changed, a .caibx will still require to download a lot of chunks from the store because, for example, the metadata of all the files changed too.

With .caidx (and --no-time) I noticed that instead we were able to significantly reduce the number of required chunks, especially for small system updates. Whether that translates to faster updates or not is still unclear. I’ll run some benchmark to confirm.

Wrt the untar stage, the issue is that with seeds you can check if a chunk is present or not. But there aren’t any chunks available if the target is a directory. A caidx is just a caibx of an archive (catar), and there’s no concept of chunks of the target. A chunk inside an archive can span over multiple files so you couldn’t really say a file is changed or not until it’s unpacked. If the file inside the archive is large, there’s a chance that chunking the target files individually first may give you some overlap of chaunkIDs, but it’s not going to work for smaller files.

If you have the disk space, can you maintain the caidx+catar file on the target with make/extract, then use untar (without -i) to restore the directory? This will let you use a seed. Or are you trying to save write I/O?

Is this basically what Casync is doing? But instead of writing the catar file on disk they keep it in memory? I can check Casync implementation to see exactly how they are handling the seed part there.

I’ll also try to create a catar as a first step and benchmark how long that takes. If creating a catar and extracting a caidx doesn’t bring any real speed advantage, that might not be worth for us. In that case we’ll probably just stick with caibx and evaluate how to further reduce images differences.