-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chunk file disappears from cache during sync #24653
Comments
I'd also suspect that. Then cleanup job is triggered at login time (login hook) and would discard all chunks which mtime is < now. Maybe the timestamp / timezone of the server is causing the mtime to be wrong ? |
Yes - the offending chunk files are definitely created on the filesystem, and are visible to a sftp client (I'm running on shared hosting).
I'm looking into this now. While the chunk file is being written to the mtime ~= now. The mtime is only set 24hrs into the future after the file handle has been closed, in OC\Cache\File::set. |
Hmmmm, indeed. But then there shouldn't be a huge time window during the time the file is written and the Also the code uses a Were you able to observe the time between the moment where the part file is being written, does it exist ? You might be onto something, keep posting your findings 😄 |
I did some debugging and found out that this |
So basically there's a loop that copies the bytes 8k by 8k, and for every |
@Marginal great debugging, thank you! |
A possible fix would be to not use |
Yep - I added some logging to OC\Cache\File::gc and I can see this happening:
I guess the chunk file should be locked while being written? |
I just realized that the @Marginal let's examine your idea about locking. |
Hmmm, I went through with a debugger and found out that both However from what I remember the locking provider was limited to work only on the "files/" entries, not the "cache/" entries. If we make it work on the latter as well, it should prevent such situations. |
I can see that OC\Files\View::file_put_contents is creating locks, but I'm not seeing any "Could not cleanup locked chunk" debug messages from OC\Cache\File::gc so they're not being applied. |
I'm not so happy about using locking here because in some environments the DB locking provider is likely to be much slower when uploading many chunks. For every chunks it needs to allocate locks and change them during the course of the file operation. Also the locking approach isn't backportable to OC < 8.1 where locking wasn't available yet. Let's list the possible approaches:
@icewind1991 @schiesbn @nickvergessen @DeepDiver1975 any insights ? |
Thanks, I'll try #24672. IMHO your solution 1 seems cleanest - it's weird having mtimes in the future, and even weirder relying on this. |
@Marginal yep, I agree on the weirdness. This is very very old code so there might have been an reason in the past. I'll make a POC for solution 1) too so you can try it too on your magic env 😄 |
Oh noes 😦 :
It looks like this is part of the public API, which means there could be apps using this and expecting the Another idea I got was to add the expected mtime value into the file name, but then it makes it difficult to find that file name again when only the |
Okay, yet another idea: if we assume that the mtime of a finished chunk is always correct but the one of a part chunk might be wrong, then add an extra 24 hours tolerance for part chunks in the |
I guess that explains the "mtimes in the future" implementation.
Kinda ugly to special-case .part files in gc, but if you don't want the overhead of locking the chunk files this might be the only practical solution. |
Steps to reproduce the original issue
|
I'd like @icewind1991's wisdom regarding locking overhead to make a decision between solution 2 (enable locking for "cache" folder) and solution 4 (extra expire time in GC for part files). For the backport to 8.0 which doesn't have the locking code, I'd go for 4 anyway. |
Testing your solution 2 #24672:
The sync is still proceeding happily 'though! |
Okay, looks like I might have missed something. |
Looks like there are assumptions that locked files only reside under /files in OC\Files\View::getPathRelativeToFiles and ::getUidAndFilename . Perhaps also elsewhere? |
@icewind1991 popped up on IRC and suggested we just add But this would assume that an @Marginal you're right, might need special handling for the cache folder 😦 |
Simplified fix with extra time tolerance is here: #24676 |
@Marginal if you say several minutes per chunk: one chunk is usually 20 MB I believe (or was it reduced to 10 ?). Several minutes, ok let's say 8 minutes which means 2.5 MB a minute, ~41 KB a second. So within that one second the |
The default chunk size is now 5MB for the 2.1 client. You're correct that the mtime is updated every 8KB, so 1hr leeway should be fine. |
🍸 Let me know if the new PR works for you and we can move it forward to the fixing pipeline / backports, etc |
#24676 works for me - I uploaded 6 x 100MB files with no "expected filesize 5242880 got 0" errors. |
Awersome to see this fixed! |
Yep. The reason why we didn't find it earlier is because it's hidden behind a |
I'm going to link all other related tickets to this one for the solution. For those of you arriving here from other tickets, please try this PR #24691 or one of the related backports #24691 (comment). Alternatively you can just wait for the next maintenance releases 😄 |
@RealRancor if you see people on the forums with the error "Expected filesize X got 0", you might want to direct them to this solution. Thanks 😄 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Syncing large files with the 2.1.1 (build 3107) client on OSX against ownCloud 9.0.2 on a slowish 384KB/s link I'm getting an "expected filesize 5242880 got 0" exception on about 5% of the chunk uploads. I've added some additional logging to OC\Files\View::file_put_contents() (see owncloud.log below) and it appears that apache is receiving the file chunk contents OK, ownCloud is writing the contents to the filesystem cache OK, but the chunk files are occasionally disappearing from the filesystem before OC_FileChunking::store() returns.
Any pointers on how to debug this gratefully received. On the assumption that the underlying filesystem isn't randomly losing files, my working hypothesis is that the cache is occasionally clearing up chunk files too aggressively while they're still being written.
Also, I'm aware of #9832 but that issue seems a mess of various problems, and of #11778 but this seems to be a different problem. Could be related to owncloud/client#4421.
Steps to reproduce
Expected behaviour
Files sync OK.
Actual behaviour
Client reports "Error download https://xxx/xxx-chunking-xxx-y-z - server replied: Bad Request (expected filesize 5242880 got 0)"
Server configuration
Operating system: Linux
Web server: Apache 2.4.16
Database: MariaDB 10.1.14
PHP version: 5.5.32
ownCloud version: 9.0.2.2
Updated from an older ownCloud or fresh install: Updated incrementally from 5.0.7
Where did you install ownCloud from: https://download.owncloud.org/community/owncloud-9.0.2.zip
Signing status (ownCloud 9.0 and above):
No errors have been found.
List of activated apps:
Files
Gallery
Contacts
Calendar
The content of config/config.php:
Are you using external storage, if yes which one: Local
Are you using encryption: No
Are you using an external user-backend, if yes which one: None
Client configuration
Browser: Firefox 46.0.1
Operating system: OSX 10.10.5
Logs
Web server access log
ownCloud log (data/owncloud.log)
Browser log
n/a
The text was updated successfully, but these errors were encountered: