Repository navigation
Description
Found while checking #884 end to end (see #838, #883); unrelated to that fix, the same on main.
Steps to reproduce
posix driver, asynchronous postprocessing:
- A file exists with content
C0(11 bytes). - Upload A replaces it with
CA(19 bytes); A's postprocessing is still running. - Upload B replaces it with
CB(21 bytes). - A's postprocessing succeeds, before or after B's (both orders behave the same); B's succeeds too.
Expected: the file has CB, and its versions are C0 and CA, each with its own size and checksums.
Actual: the version with CA has the right bytes on disk (CA-the-older-upload, 19 bytes), and downloads correctly, but its xattrs are B's: user.oc.blobsize is 21 (measured), and, as all user.oc.* xattrs are copied (see below), also B's blob id and checksums. When A succeeds while B is still in postprocessing, that also includes B's user.oc.nodestatus. Clients that check the size or the checksum of that version get B's values for A's content.
Decomposed and decomposeds3 are not affected.
Cause
When B's bytes are received while A is still in postprocessing, the file's metadata at that moment, A's, is kept as a version, named after A's mtime. When A succeeds later, DecomposedFsSession.Finalize finds that version and writes A's blob into it ("uploading to revision node, that was created for us by another upload"):
Finalizereads the version withnode.LockAndReadNode(ctx, …, versionID, …).readNodereads a revision's metadata from the file itself ("use the actual node for the metadata lookup"), caches it in the node, and only then appends the revision suffix to the node's id.Tree.WriteBlob→ posixBlobstore.Upload(n, …)copiesn.Xattrs(ctx)onto the temp file, whichloadXattrsserves from that cache: the file's current xattrs, i.e. B's. The temp file is then renamed onto the version.
With decomposed, the blob store writes the blob by its blob id and copies no xattrs, so the version keeps its own metadata.
Possible fix
In posix's Blobstore.Upload, don't take the xattrs from the node object when it is a revision; read them from the revision's own metadata instead (e.g. MetadataBackend().All of a node.NewBaseNode with the revision id). Alternatively, Finalize could read the revision node without falling back to the file's metadata. Either way, the version should keep its blob id, size and checksums (which updateExistingNode copied from A's metadata when B was received, and which describe A's content).
How to reproduce
I reproduced it with a script (not part of any repository) that runs every order of two overlapping uploads against an OpenCloud server and compares the bytes of the file and of each version with their user.oc.blobsize and user.oc.cs.sha1 xattrs: the two orders where both uploads succeed fail with posix, on main and with #884. Postprocessing is held with POSTPROCESSING_DELAY=1h, and the PostprocessingFinished events are published in the order needed, as described in my comment in #838.
Activity