You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
1.7.0-beta3 nightly: serious inconsistency and lost file when remote folder renamed while files uploaded to it #2296
I consider this scenario very important if more then one user syncs the same directory at the same time (sharing). However, note that all actions are performed by one only sync client, on a normal oc server folder (not-shared). I have a second client of the same user connected to this repo and passively "watching". The second sync client seems to be completely irrelevant here.
Please also note that we have recently had a similar case from a user (albeit with older server/client versions so I won't bother you with that). But the point is that this is a real problem.
I tried and sometimes it works as expected and sometimes it does not.
One the reason why it might not work is if there was no sync between adding new files and the sync that tries to upate them. This is because we were writing too early to the database to update the permissions. This is now fixed.
But there is still something fishy hapenning sometimes on the server, in which the server reports a 500 Internal Server Error and do not keep properly the file id, which lead that we duplicate some of the files (but we should not loose data)
This is log output in the server log that happens if there is a 500 server error:
{"app":"PHP","message":"Undefined index: extension at \/home\/kf\/oC\/core\/apps\/files_versions\/lib\/versions.php#286","level":3,"time":"2014-10-11T12:32:59+00:00"}
{"app":"core","message":"unable to rename, file is not writable : files\/plop\/V0\/d-4-4.txt.ocTransferId704783747.part","level":3,"time":"2014-10-11T12:32:59+00:00"}
{"app":"webdav","message":"\\OC\\Files\\Filesystem::rename() failed","level":3,"time":"2014-10-11T12:32:59+00:00"}
{"app":"PHP","message":"unlink(\/home\/kf\/oC\/core\/data\/ogo\/files\/plop\/V0\/d-4-4.txt.ocTransferId704783747.part): No such file or directory at \/home\/kf\/oC\/core\/lib\/private\/files\/storage\/local.php#167","level":3,"time":"2014-10-11T12:32:59+00:00"}
{"app":"webdav","message":"Sabre\\DAV\\Exception: Could not rename part file to final file","level":4,"time":"2014-10-11T12:32:59+00:00"}
{"app":"PHP","message":"filemtime(): stat failed for \/home\/kf\/oC\/core\/data\/ogo\/files\/plop\/V0 at \/home\/kf\/oC\/core\/lib\/private\/files\/storage\/local.php#133","level":3,"time":"2014-10-11T12:32:59+00:00"}
{"app":"remote","message":"An exception occurred while executing 'UPDATE `oc_filecache` SET `mtime` = ?, `storage_mtime`=? WHERE `fileid` = ?':\n\nSQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column 'mtime' at row 1","level":4,"time":"2014-10-11T12:32:59+00:00"}
{"app":"PHP","message":"Session has been closed - no further changes to the session as allowed at \/home\/kf\/oC\/core\/lib\/private\/session\/memory.php#80","level":3,"time":"2014-10-11T12:32:59+00:00"}
I don't think that occasional 500 from the server for few files is the main problem for this issue (it is confusing for the user but should not critically affect the client logic).
The upload starts and initially succeeds. Then remote folder is moved so the subsequent PUT requests from the client fail with 404. That's OK because the target path does not exist anymore. [[ At this point I would propose that after few 404s for the PUT you check for existence of the remote parent folder. Like this you can avoid many useless PUT requests in to the remote tree that does not exist anymore. ]]
However, on the next sync run, for some reason you do not detect that the folder was moved. If you correctly detected that you'd then resume PUT requests to the new remote path and everything would be fine even with for those files for which you got 500 before.
BTW. The log entries are confusing: they say "Error downloading...." for the "Up" direction. Could you please fix that? Or does that indicate another, deeper problem?
But also some of the warnings should be looked into like the invalid date format and make such case fail more gracefully without triggering such warnings.
The client had a bug (fixed with commit 9b178c5) That led it believe that some file would have been uploaded sucessfully while there was an error in some rare cases. This bug could have triggered the dataloss that moscicki saw. But hopefully it is now fixed and there should no longer be data loss.
However, we cannot detect a move if the fileid are not kept on the server.
I tried against owncloud7.0.1 and client nightly build 1.7.0-20141020 on MacOSX.
It does not work as expected. Very similar behaviour as originally described (including file loss).
I got 77 files under the folder with original name, and 0 files under the folder with the new name. Same on the server.
I also tried the same test against 1.6.3 -- the exact trace of operations is different but the result equally bad - lost files and full inconsistency.
I guess there is something fundamentally broken here. Could you please check this thoroughly?
I debugged inside "file_put_contents()". There is a very short time window where FS mtime and cache mtime differ. But that window is so short that I doubt it is causing the issue I was able to reproduce easily several times.
I'll add more debug statements and hope to find more clues...
@PVince81 : that's pretty hardcore debugging -- sorry I cannot help out much in php.
However, I can suggest that in case of PUT into inexistent collection you should probably return 409 (Conflict) -- according to the webdav spec.
Here's a piece of the log, starting with the rename operation (request 544960902fa20):
// This is the rename request:
{"reqId":"544960902fa20","app":"core","message":"rename begin: \"\/H\" => \"\/H2","level":0,"time":"2014-10-23T20:09:52+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/rename.php?dir=%2F&newname=H2&file=H"}
// This is another request from an upload which updates the mtime of folder "H", probably from file_put_contents()
{"reqId":"5449608f9da1b","app":"cache","message":"Update cache entry for : \"1983\": {\"mtime\":1414094992,\"etag\":\"5449609031847\"}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"core","message":"Scanning file: \"files\/H\/IMAG0279.jpg\"","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"OC\\Files\\Cache\\Scanner","message":"!!! Path 'files\/H\/IMAG0279.jpg' is not readable !!!","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"core","message":"Scanning file: \"files\/H\/IMAG0279.jpg\" end with data null","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"cache","message":"Update cache entry for : \"1983\": {\"size\":14577457}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
// note 672 is the /files entry
{"reqId":"5449608f9da1b","app":"cache","message":"Update cache entry for : \"672\": {\"size\":14577457}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
// yet another upload request doing its scanning
{"reqId":"54496090729e8","app":"core","message":"Scanning file: \"files\"","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"54496090729e8","app":"OC\\Files\\Cache\\Scanner","message":"!!! No reuse of etag for 'files' !!! \ncache: Array\n(\n [fileid] => 672\n [storage] => home::root\n [path] => files\n [parent] => 670\n [name] => files\n [mimetype] => httpd\/unix-directory\n [mimepart] => httpd\n [size] => 14577457\n [mtime] => 1414094992\n [storage_mtime] => 1414094714\n [encrypted] => \n [unencrypted_size] => 0\n [etag] => 5449609028cba\n [permissions] => 31\n)\n \ndata: Array\n(\n [mimetype] => httpd\/unix-directory\n [mtime] => 1414094992\n [size] => -1\n [etag] => 5449609072c7b\n [storage_mtime] => 1414094992\n [permissions] => 31\n)\n","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"54496090729e8","app":"cache","message":"Update cache entry for : \"672\": {\"size\":-1,\"etag\":\"5449609072c7b\",\"storage_mtime\":1414094992}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"5449608f9da1b","app":"sharing","message":"No fileinfo available for: \/H\/IMAG0279.jpg","level":2,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"core","message":"Scanning file: \"files\/H\"","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"OC\\Files\\Cache\\Scanner","message":"!!! Path 'files\/H' is not readable !!!","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"54496090729e8","app":"core","message":"Scanning file: \"files\" end with data {\"mimetype\":\"httpd\\\/unix-directory\",\"mtime\":1414094992,\"size\":-1,\"etag\":\"5449609072c7b\",\"storage_mtime\":1414094992,\"permissions\":31,\"fileid\":\"672\"}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"54496090729e8","app":"core","message":"Scanning children: \"files\"","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"54496090729e8","app":"core","message":"Scanning file: \"files\/H2\"","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
// and here, very weird: a new entry for "H2" is inserted (which explains the new file id):
{"reqId":"54496090729e8","app":"cache","message":"Put cache entry for : \"files\/H2\": {\"mimetype\":\"httpd\\\/unix-directory\",\"mtime\":1414094991,\"size\":-1,\"etag\":\"5449609077378\",\"storage_mtime\":1414094991,\"permissions\":31,\"parent\":\"672\",\"path\":\"files\\\/H2\",\"name\":\"H2\"}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"54496090729e8","app":"core","message":"Scanning file: \"files\/H2\" end with data {\"mimetype\":\"httpd\\\/unix-directory\",\"mtime\":1414094991,\"size\":-1,\"etag\":\"5449609077378\",\"storage_mtime\":1414094991,\"permissions\":31,\"parent\":\"672\",\"fileid\":1994}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"54496090729e8","app":"core","message":"Scanning file: \"files\/x\"","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"54496090729e8","app":"core","message":"Scanning file: \"files\/x\" end with data {\"mimetype\":\"application\\\/octet-stream\",\"mtime\":1414089876,\"size\":0,\"etag\":\"54494ca1a65ea\",\"storage_mtime\":1414089876,\"permissions\":27,\"parent\":\"672\"}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"5449608f9da1b","app":"core","message":"Scanning file: \"files\/H\" end with data null","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"core","message":"Scanning children: \"files\/H\"","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"PHP","message":"opendir(\/srv\/www\/htdocs\/owncloud\/data\/root\/files\/H): failed to open dir: No such file or directory at \/srv\/www\/htdocs\/owncloud\/lib\/private\/files\/storage\/local.php#75","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"5449608f9da1b","app":"cache","message":"Update cache entry for : \"672\": {\"size\":0}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0279.jpg"}
{"reqId":"54496090729e8","app":"cache","message":"Update cache entry for : \"672\": {\"size\":-1}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/H\/IMAG0392.jpg"}
{"reqId":"544960902fa20","app":"cache","message":"Update cache entry for : \"672\": {\"size\":0}","level":0,"time":"2014-10-23T20:09:52+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/rename.php?dir=%2F&newname=H2&file=H"}
But what happened with 1983 / the original "H" entry ? Maybe one of the concurrent scan requests found it missing and deleted it ? And another one found the new one and created one ?
It almost looks like we'd need some kind of scanner locking... avoid rescanning the same folder if another scanner is running... or something in the likes.
@moscicki I don't think that would help. Maybe it would just make the error messages from the client look less scary.
The main problem is that the folder's etag changes on rename, which makes the client believe that the folder is NOT the same. Goal is to keep the etag after rename (at least the latest version, the one that the client knows of) so that the client knows that it's the same folder but with a different name.
I don't see any other way to debug this except using hard-core debugging. Race conditions are hard and only logging makes it possible for me to see what happens... and every time it's not exactly the same that happens (just got a run where the fileid was kept but the etag changed).
// this here is the rename operation
{"reqId":"544967f36d9b2","app":"cache","message":"Move \"files\/K\" to \"files\/K2\": null","level":0,"time":"2014-10-23T20:41:23+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/rename.php?dir=%2F&newname=K2&file=K"}
// 672 is the "/files" entry
{"reqId":"544967f2b6f50","app":"cache","message":"Update cache entry for : \"672\": {\"mtime\":\"1414096862\",\"etag\":\"544967f3770c8\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0279.jpg"}
{"reqId":"544967f31f3e4","app":"cache","message":"Update cache entry for : \"672\": {\"mtime\":1414096883,\"etag\":\"544967f37e8d3\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f2b6f50","app":"cache","message":"Update cache entry for : \"2150\": {\"mtime\":\"1414096862\",\"etag\":\"544967f380f5a\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0279.jpg"}
{"reqId":"544967f31f3e4","app":"cache","message":"Update cache entry for : \"2150\": {\"mtime\":1414096883,\"etag\":\"544967f383a64\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f2b6f50","app":"connector","message":"Return etag for \"\/K\/IMAG0279.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0279.jpg"}
// here one of the upload requests scans the parent dir (/files)
{"reqId":"544967f388347","app":"core","message":"Scanning file: \"files\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"OC\\Files\\Cache\\Scanner","message":"!!! No reuse of etag for 'files' !!! \ncache: Array\n(\n [fileid] => 672\n [storage] => home::root\n [path] => files\n [parent] => 670\n [name] => files\n [mimetype] => httpd\/unix-directory\n [mimepart] => httpd\n [size] => 15453438\n [mtime] => 1414096883\n [storage_mtime] => 1414096733\n [encrypted] => \n [unencrypted_size] => 0\n [etag] => 544967f37e8d3\n [permissions] => 31\n)\n \ndata: Array\n(\n [mimetype] => httpd\/unix-directory\n [mtime] => 1414096883\n [size] => -1\n [etag] => 544967f3885bb\n [storage_mtime] => 1414096883\n [permissions] => 31\n)\n","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Update cache entry for : \"672\": {\"size\":-1,\"etag\":\"544967f3885bb\",\"storage_mtime\":1414096883}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f31f3e4","app":"connector","message":"put okay for \"\/K\/IMAG0332.jpg.ocTransferId346050858.part\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f31f3e4","app":"connector","message":"Getting file size for: \"\/K\/IMAG0332.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f31f3e4","app":"PHP","message":"filesize(): stat failed for \/srv\/www\/htdocs\/owncloud\/data\/root\/files\/K\/IMAG0332.jpg.ocTransferId346050858.part at \/srv\/www\/htdocs\/owncloud\/lib\/private\/files\/storage\/local.php#117","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f31f3e4","app":"connector","message":"Got file size for: \"\/K\/IMAG0332.jpg\" :","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f31f3e4","app":"cache","message":"Delete \"files\/K\/IMAG0332.jpg.ocTransferId346050858.part\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f31f3e4","app":"cache","message":"Update cache entry for : \"672\": {\"size\":15453438}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f388347","app":"core","message":"Scanning file: \"files\" end with data {\"mimetype\":\"httpd\\\/unix-directory\",\"mtime\":1414096883,\"size\":-1,\"etag\":\"544967f3885bb\",\"storage_mtime\":1414096883,\"permissions\":31,\"fileid\":\"672\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
// another one request that scans "/files"
{"reqId":"544967f388347","app":"core","message":"Scanning children: \"files\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"core","message":"Scanning file: \"files\/K2\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
// here the scanner process found that there's a "new" folder called "K2", so it inserts a new cache entry for it
{"reqId":"544967f388347","app":"cache","message":"Put cache entry for : \"files\/K2\": {\"mimetype\":\"httpd\\\/unix-directory\",\"mtime\":1414096883,\"size\":-1,\"etag\":\"544967f39c4d3\",\"storage_mtime\":1414096883,\"permissions\":31,\"parent\":\"672\",\"path\":\"files\\\/K2\",\"name\":\"K2\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"core","message":"Scanning file: \"files\/K2\" end with data {\"mimetype\":\"httpd\\\/unix-directory\",\"mtime\":1414096883,\"size\":-1,\"etag\":\"544967f39c4d3\",\"storage_mtime\":1414096883,\"permissions\":31,\"parent\":\"672\",\"fileid\":2161}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"core","message":"Scanning file: \"files\/x\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"core","message":"Scanning file: \"files\/x\" end with data {\"mimetype\":\"application\\\/octet-stream\",\"mtime\":1414095864,\"size\":0,\"etag\":\"544963fb473f3\",\"storage_mtime\":1414095864,\"permissions\":27,\"parent\":\"672\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
// and here since K was already renamed to K2, the scanner finds that "K" doesn't exist any more
// so it deletes the cache entry (the scanner doesn't know the relationship between K2 and K)
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K\/1368555495004.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K2\/1391249528060.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K2\/20110610_005.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K\/20130317_001.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K\/DSC05207.JPG\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K2\/DSC_0158.JPG\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K\/Huoguo.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K2\/IMAG0100.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K\/IMAG0156.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f388347","app":"cache","message":"Delete \"files\/K\/IMAG0279.jpg\"","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f31f3e4","app":"cache","message":"Update cache entry for : \"672\": {\"mtime\":1414096883,\"etag\":\"544967f3a9f43\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f36d9b2","app":"cache","message":"Update cache entry for : \"672\": {\"size\":0}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/rename.php?dir=%2F&newname=K2&file=K"}
{"reqId":"544967f388347","app":"cache","message":"Update cache entry for : \"672\": {\"size\":-1}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0392.jpg"}
{"reqId":"544967f31f3e4","app":"cache","message":"Update cache entry for : \"-1\": {\"mtime\":1414096883,\"etag\":\"544967f3c9e39\"}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"PUT","url":"\/owncloud\/remote.php\/webdav\/K\/IMAG0332.jpg"}
{"reqId":"544967f36d9b2","app":"cache","message":"Update cache entry for : \"2161\": {\"size\":0}","level":0,"time":"2014-10-23T20:41:23+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/rename.php?dir=%2F&newname=K2&file=K"}
...
// much later comes the end of the subdir rename operation
{"reqId":"544967f36d9b2","app":"core","message":"rename end: \"\/K\" => \"\/K2","level":0,"time":"2014-10-23T20:41:24+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/rename.php?dir=%2F&newname=K2&file=K"}
So basically this proves my theory about the changing fileid.
It seems that having concurrently running scanners is a bad idea and likely to cause issues. I have the feeling that there are other possible concurrency cases that could go wrong.
So we probably need to either lock at scanner level or at high-level file operation level (high-level as in close to the entry points)
@icewind1991 I'd like to hear your input about how to improve this.
Note: I had a case where the fileid stayed but the etag changed, so it's likely that there are other issues... it all depend on the order of all these operations...
@PVince81: I agree 409 would not help immediately but it would be according to the webdav specs and at some point maybe client guys could profit from a difference between 404 and 409. For now, agreed, it's a rather cosmetic change.
@ogoffart: I tried against our webdav backend on EOS (which apparently does not have this concurrency issue and keeps the fileid stable).
So the first time I tried I thought something was messed up (no file loss, though).
Then I retried 4 times (both with new and previously known files, see #2296 (comment)) and it seems to work!
Unless I fell into lucky race-condition during the 4 retires I would think that indeed the issue has been fixed in the client.
If you want for reference, here is the trace of operations with 1.7.0-beta4 on MacOSX:
I think this bug should not be a release blocker / gold ticket aka showstopper.
I'm pretty sure this already existed in past versions and was just discovered through unluck.
Note that in my case I can reproduce the issue 90% of the time.
So I suggest to remove the gold ticket / showstopper label but keep the ticket to continue investigating. Locking the file scanner and/or file operations is a general thing that needs to be looked into.
Activity
moscicki commentedon Oct 10, 2014
Please also note that we have recently had a similar case from a user (albeit with older server/client versions so I won't bother you with that). But the point is that this is a real problem.
ogoffart commentedon Oct 10, 2014
I was not able to reproduce the problem here with the last git from 1.7 on linux.
Regarding the step "3.": do you rename on the web interface or on the client's file system?
Maybe you can provide the full log?
moscicki commentedon Oct 11, 2014
Step3: rename remote folder via the web page.
I was able to reproduce it every time.
Sync engine: Do not write to the database too early
ogoffart commentedon Oct 11, 2014
I tried and sometimes it works as expected and sometimes it does not.
One the reason why it might not work is if there was no sync between adding new files and the sync that tries to upate them. This is because we were writing too early to the database to update the permissions. This is now fixed.
But there is still something fishy hapenning sometimes on the server, in which the server reports a 500 Internal Server Error and do not keep properly the file id, which lead that we duplicate some of the files (but we should not loose data)
dragotin commentedon Oct 11, 2014
This is log output in the server log that happens if there is a 500 server error:
@DeepDiver1975, @PVince81 can you guys pls. help?
moscicki commentedon Oct 12, 2014
Hello,
I don't think that occasional 500 from the server for few files is the main problem for this issue (it is confusing for the user but should not critically affect the client logic).
The upload starts and initially succeeds. Then remote folder is moved so the subsequent PUT requests from the client fail with 404. That's OK because the target path does not exist anymore. [[ At this point I would propose that after few 404s for the PUT you check for existence of the remote parent folder. Like this you can avoid many useless PUT requests in to the remote tree that does not exist anymore. ]]
However, on the next sync run, for some reason you do not detect that the folder was moved. If you correctly detected that you'd then resume PUT requests to the new remote path and everything would be fine even with for those files for which you got 500 before.
BTW. The log entries are confusing: they say "Error downloading...." for the "Up" direction. Could you please fix that? Or does that indicate another, deeper problem?
PVince81 commentedon Oct 13, 2014
I agree with @moscicki.
But also some of the warnings should be looked into like the invalid date format and make such case fail more gracefully without triggering such warnings.
CC @schiesbn for the files_versions warning.
ogoffart commentedon Oct 13, 2014
The client had a bug (fixed with commit 9b178c5) That led it believe that some file would have been uploaded sucessfully while there was an error in some rare cases. This bug could have triggered the dataloss that moscicki saw. But hopefully it is now fixed and there should no longer be data loss.
However, we cannot detect a move if the fileid are not kept on the server.
ogoffart commentedon Oct 13, 2014
(Regarding the "Error downloading" message, this string comes from Qt. We are trying to fix Qt to change the wording of the message: https://codereview.qt-project.org/83041/ )
moscicki commentedon Oct 15, 2014
Is this moving issue fixed in the latest nightly? Should I try my test again?
moscicki commentedon Oct 20, 2014
I tried against owncloud7.0.1 and client nightly build 1.7.0-20141020 on MacOSX.
It does not work as expected. Very similar behaviour as originally described (including file loss).
I got 77 files under the folder with original name, and 0 files under the folder with the new name. Same on the server.
I also tried the same test against 1.6.3 -- the exact trace of operations is different but the result equally bad - lost files and full inconsistency.
I guess there is something fundamentally broken here. Could you please check this thoroughly?
32 remaining items
PVince81 commentedon Oct 23, 2014
I debugged inside "file_put_contents()". There is a very short time window where FS mtime and cache mtime differ. But that window is so short that I doubt it is causing the issue I was able to reproduce easily several times.
I'll add more debug statements and hope to find more clues...
PVince81 commentedon Oct 23, 2014
How is that even possible ? The file id of the folder changes after paralell upload+rename:
Before:
After:
I understand that the mtime or etag changes, but why the fileid ?!
moscicki commentedon Oct 23, 2014
@PVince81 : that's pretty hardcore debugging -- sorry I cannot help out much in php.
However, I can suggest that in case of PUT into inexistent collection you should probably return 409 (Conflict) -- according to the webdav spec.
PVince81 commentedon Oct 23, 2014
Here's a piece of the log, starting with the rename operation (request 544960902fa20):
But what happened with 1983 / the original "H" entry ? Maybe one of the concurrent scan requests found it missing and deleted it ? And another one found the new one and created one ?
It almost looks like we'd need some kind of scanner locking... avoid rescanning the same folder if another scanner is running... or something in the likes.
PVince81 commentedon Oct 23, 2014
@moscicki I don't think that would help. Maybe it would just make the error messages from the client look less scary.
The main problem is that the folder's etag changes on rename, which makes the client believe that the folder is NOT the same. Goal is to keep the etag after rename (at least the latest version, the one that the client knows of) so that the client knows that it's the same folder but with a different name.
I don't see any other way to debug this except using hard-core debugging. Race conditions are hard and only logging makes it possible for me to see what happens... and every time it's not exactly the same that happens (just got a run where the fileid was kept but the etag changed).
PVince81 commentedon Oct 23, 2014
Ok, I can now confirm the reason for the fileid change (test run K->K2)
Subdir entry before:
+--------+---------+---------+----------------------------------+--------+------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+
| fileid | storage | path | path_hash | parent | name | mimetype | mimepart | size | mtime | storage_mtime | encrypted | unencrypted_size | etag | permissions |
+--------+---------+---------+----------------------------------+--------+------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+
| 2150 | 4 | files/K | 847786f8331086ffa1f8d5425162e042 | 672 | K | 2 | 1 | 0 | 1414096733 | 1414096733 | 0 | 0 | 5449675da2b9d | 31 |
+--------+---------+---------+----------------------------------+--------+------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+
+--------+---------+----------+----------------------------------+--------+------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+
| fileid | storage | path | path_hash | parent | name | mimetype | mimepart | size | mtime | storage_mtime | encrypted | unencrypted_size | etag | permissions |
+--------+---------+----------+----------------------------------+--------+------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+
| 2161 | 4 | files/K2 | 4793549d7aeb00320d1999e03c1dc8ca | 672 | K2 | 2 | 1 | 0 | 1414096883 | 1414096883 | 0 | 0 | 544967f39c4d3 | 31 |
+--------+---------+----------+----------------------------------+--------+------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+
Here is the log, followed by my interpretation:
So basically this proves my theory about the changing fileid.
It seems that having concurrently running scanners is a bad idea and likely to cause issues. I have the feeling that there are other possible concurrency cases that could go wrong.
So we probably need to either lock at scanner level or at high-level file operation level (high-level as in close to the entry points)
@icewind1991 I'd like to hear your input about how to improve this.
PVince81 commentedon Oct 23, 2014
Note: I had a case where the fileid stayed but the etag changed, so it's likely that there are other issues... it all depend on the order of all these operations...
moscicki commentedon Oct 23, 2014
@PVince81: I agree 409 would not help immediately but it would be according to the webdav specs and at some point maybe client guys could profit from a difference between 404 and 409. For now, agreed, it's a rather cosmetic change.
@ogoffart: I tried against our webdav backend on EOS (which apparently does not have this concurrency issue and keeps the fileid stable).
So the first time I tried I thought something was messed up (no file loss, though).
Then I retried 4 times (both with new and previously known files, see #2296 (comment)) and it seems to work!
Unless I fell into lucky race-condition during the 4 retires I would think that indeed the issue has been fixed in the client.
If you want for reference, here is the trace of operations with 1.7.0-beta4 on MacOSX:
https://gist.github.com/moscicki/25bdd9adbef509de6d95#file-rename-while-upload-sync-activity-1-7-0-beta4
PVince81 commentedon Oct 23, 2014
I think this bug should not be a release blocker / gold ticket aka showstopper.
I'm pretty sure this already existed in past versions and was just discovered through unluck.
Note that in my case I can reproduce the issue 90% of the time.
So I suggest to remove the gold ticket / showstopper label but keep the ticket to continue investigating. Locking the file scanner and/or file operations is a general thing that needs to be looked into.
moscicki commentedon Oct 23, 2014
I think it is indeed a server issue now. I can confirm that the client 1.7.0-beta4 works fine (as far as I can test it).
Thanks to all for help. I hope this is also useful to keep on improving both client and server.
moscicki commentedon Oct 23, 2014
@ogoffart: FYI, I also checked the same scenario in the opposite direction i.e.
while files are downloaded from remote folder A to local folder A: rename a local folder A to B (on MacOSX)
works very well! everything ends up in B and also the remote folder gets renamed to B
well done, many thanks! 👍
ogoffart commentedon Oct 24, 2014
(Note that mirall 1.4 and before relied on the 404 to create the directories)
moscicki commentedon Oct 24, 2014
I hope you do not anymore since 1.5 - I am giving you back 409 as in the specs...
PVince81 commentedon Oct 27, 2014
I raised owncloud/core#11795 to follow up on the server.
Closing this hence.