Opened at 2015-04-22T00:14:03Z
Last modified at 2015-07-17T18:59:18Z
#2409 new defect
tolerate simultaneous uploads better
Reported by: | warner | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | undecided |
Component: | code-encoding | Version: | 1.10.0 |
Keywords: | upload usability performance immutable reliability | Cc: | |
Launchpad Bug: |
Description
In the Nuts+Bolts meeting this morning, we discussed what would happen if an application (in particular the "magic folder / drop-upload" feature) were to upload two copies of the same file at the same time. We thought about this a long time ago, but I can't seem to find a ticket on the particular issue.
I believe there's a race condition on the storage servers which would make the upload go less smoothly than we'd like. The first upload will see no shares for each storage index, so it will allocate a BucketWriter and start writing the share. The second upload will compute the storage-index, ask the server about pre-existing shares, and then.. probably get a yes?
The answer is uncertain, and depends upon the server implementation. The server's read-side might look on disk for the partially-written files, or the server's write-side might be using the write-to-tempfile atomic-swap technique, or the read-side might be looking in a leasedb for evidence of the share. Some of these will result in a "no" answer to the DYHB, in which case the second upload will try to allocate new BucketWriters to fill the shares (which might fail because of the existing writers, or might succeed with hilarious results as the two writers attempt to write the same file with hopefully the same data). It might get a "yes", in which case I think the uploader will ignore the shares and assume that they'll be present in the future.
We should probably:
- nail down exactly what the server does in this situation
- change the Uploader to be more cautious about pre-existing shares
The Uploader could read the pre-existing shares as it goes, comparing them against locally-generated ones. If they match, great, those shares can count against the servers-of-happiness criteria. If they don't, or if they aren't complete, then oops. The simplest way to deal with such problems is to treat them like a share write that failed (as if the server disconnected before the upload was complete), which may flunk the shares-of-happiness test and mark the upload as failing. A more sophisticated approach (which hopefully is ticketed elsewhere) is to have a second pass which writes out a new copy of any share that wasn't successfully placed during the first pass.
If we implement that verify-during-upload thing, we'll need to think carefully about how simultaneous uploads ought to work. I think we'll need a way to mark shares as "in-progress", which tells the second uploader that they can't verify the share now, but maybe they shouldn't upload it anyways.
This will get better when we make the storage-index be a hash of the share (or the root of a merkle tree with the shares in the leaves), because then the storage-index won't even be defined until the upload is complete, and the intermediate in-progress state will disappear. Simultaneous uploads will then turn into two uploads of the exact same share, detected at close(), which is inefficient but sound, I think.
Related tickets:
Change History (3)
comment:1 Changed at 2015-04-27T19:19:17Z by daira
- Keywords upload usability performance added
- Priority changed from normal to major
comment:2 Changed at 2015-04-27T19:19:50Z by daira
comment:3 Changed at 2015-07-17T18:59:18Z by daira
- Keywords immutable reliability added
zooko wrote in #952: