Skip to content

Acquire read lock when getting file or directory info - #16963

Merged
PVince81 merged 4 commits into
masterfrom
fileinfo-lock
Jun 18, 2015
Merged

PVince81 merged 4 commits into
masterfrom
fileinfo-lock

Conversation

@icewind1991

Copy link
Copy Markdown
Contributor

Prevents cache data being changed while a file is being written or a folder is being renamed.

For #13391

cc @DeepDiver1975 @PVince81

Comment thread lib/private/files/view.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this is debug stuff. Or is this for some future performance improvements? ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This reduces the risk of race conditions 🙊 😆

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also reduces server load by giving the cpu some time to catch up

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all, we need to add more of such statements.

@MorrisJobke MorrisJobke added this to the 8.1-current milestone Jun 16, 2015

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me that we should add locking info to the webdav interface.

@icewind1991 @PVince81 I guess this is off scope for 8.1 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised #16968

@icewind1991

Copy link
Copy Markdown
Contributor Author

@owncloud-bot retest this please

@PVince81

Copy link
Copy Markdown
Contributor

Cannot test properly, requires #16959 (#16955) to fix upload

@ghost

ghost commented Jun 16, 2015

Copy link
Copy Markdown

💣 Test FAILed. 💣
nooo432

@PVince81

Copy link
Copy Markdown
Contributor

Ok I managed to upload the files using another way.

Renaming the folder while the sync client is running still lead to loss of its contents (after 5 test runs).

I'll do another run where I merge #16729 into this one to see if it improves it.

@PVince81

Copy link
Copy Markdown
Contributor

Ok sorry, wrong branch... will retest again.

@PVince81

Copy link
Copy Markdown
Contributor

Data loss still occurring (renamed folder empty), with the following in the log:

{"reqId":"CTjGU7ARO9ANbFxO0f5O","remoteAddr":"127.0.0.1","app":"core","message":"Exception while scanning file \"files\/re\": An exception occurred while executing 'INSERT INTO `oc_filecache` (`mimepart`,`mimetype`,`mtime`,`size`,`etag`,`storage_mtime`,`permissions`,`parent`,`path_hash`,`path`,`name`,`storage`) SELECT ?,?,?,?,?,?,?,?,?,?,?,? FROM `oc_filecache` WHERE `storage` = ? AND `path_hash` = ? HAVING COUNT(*) = 0' with params [\"1\", \"2\", 1434466525, -1, \"55803938d795e\", 1434466525, 31, \"2\", \"ade12aa9a2fcb78d16c649c813e122c6\", \"files\\\/re\", \"re\", \"1\", \"1\", \"ade12aa9a2fcb78d16c649c813e122c6\"]:\n\nSQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction","level":0,"time":"2015-06-16T14:57:33+00:00","method":"PROPFIND","url":"\/owncloud\/remote.php\/webdav\/"}

Next up: same test steps with #16729 merged

@PVince81

Copy link
Copy Markdown
Contributor

Hmm, too bad. Even with this PR and #16729 together, the contents of the renamed folder appeared empty again in my test case.

This appeared in the log:

{"reqId":"J79porgAwfcvfd0WcVdh","remoteAddr":"127.0.0.1","app":"index","message":"Exception: {\"Exception\":\"Doctrine\\\\DBAL\\\\Exception\\\\DriverException\",\"Message\":\"An exception occurred while executing 'DELETE FROM `oc_filecache` WHERE `parent` = ?' with params [288]:\\n\\nSQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction\",\"Code\":0,\"Trace\":\"#0 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/DBALException.php(116): Doctrine\\\\DBAL\\\\Driver\\\\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOException))\\n#1 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/Statement.php(172): Doctrine\\\\DBAL\\\\DBALException::driverExceptionDuringQuery(Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOMySql\\\\Driver), Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOException), 'DELETE FROM `oc...', Array)\\n#2 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/db\\\/statementwrapper.php(73): Doctrine\\\\DBAL\\\\Statement->execute(Array)\\n#3 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/db.php(147): OC_DB_StatementWrapper->execute(Array)\\n#4 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/cache.php(500): OC_DB::executeAudited('DELETE FROM `*P...', Array)\\n#5 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/cache.php(471): OC\\\\Files\\\\Cache\\\\Cache->removeChildren(Array)\\n#6 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/scanner.php(200): OC\\\\Files\\\\Cache\\\\Cache->remove('files\\\/re')\\n#7 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/scanner.php(352): OC\\\\Files\\\\Cache\\\\Scanner->removeFromCache('files\\\/re')\\n#8 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/scanner.php(257): OC\\\\Files\\\\Cache\\\\Scanner->scanChildren('files', false, 3, Array)\\n#9 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/watcher.php(91): OC\\\\Files\\\\Cache\\\\Scanner->scan('files', false)\\n#10 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/view.php(1173): OC\\\\Files\\\\Cache\\\\Watcher->checkUpdate('files', Array)\\n#11 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/filesystem.php(861): OC\\\\Files\\\\View->getFileInfo('\\\/', false)\\n#12 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/helper.php(968): OC\\\\Files\\\\Filesystem::getFileInfo('\\\/', false)\\n#13 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files\\\/lib\\\/helper.php(45): OC_Helper::getStorageInfo('\\\/')\\n#14 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files\\\/ajax\\\/getstoragestats.php(37): OCA\\\\Files\\\\Helper::buildFileStorageStatistics('\\\/')\\n#15 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/route\\\/route.php(153) : runtime-created function(1): require_once('\\\/srv\\\/www\\\/htdocs...')\\n#16 [internal function]: __lambda_func(Array)\\n#17 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/route\\\/router.php(274): call_user_func('\\\\x00lambda_4', Array)\\n#18 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/base.php(867): OC\\\\Route\\\\Router->match('\\\/apps\\\/files\\\/aja...')\\n#19 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/index.php(40): OC::handleRequest()\\n#20 {main}\",\"File\":\"\\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/Driver\\\/AbstractMySQLDriver.php\",\"Line\":115}","level":4,"time":"2015-06-16T15:18:14+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/getstoragestats.php?dir=%2F"}

This seems similar to what I observed in the original issue (a failed DELETE followed by a successful one) #13391

@icewind1991 let me know if you need more details to reproduce this.
Most important is having at least 100 files in the folder and the sleep(1) in place, see #13391 (comment)

@PVince81

Copy link
Copy Markdown
Contributor

I'd say the key is having the rename operation slow enough so that the running sync client can do update checks several times within that time. One of them is likely to cause the data loss. Other cases will cause redownloads. In my env, there chance is 70% of data loss.

@icewind1991

Copy link
Copy Markdown
Contributor Author

@owncloud-bot retest this please

@icewind1991

Copy link
Copy Markdown
Contributor Author

@owncloud-bot retest this please

@icewind1991

Copy link
Copy Markdown
Contributor Author

switched to an approach where when getting the lock fails it uses the old cache data since it looks like there are to many code path relying on being able to get the cache data during the operation

@PVince81

Copy link
Copy Markdown
Contributor

Have you managed to reproduce the issue this time ?

@icewind1991

Copy link
Copy Markdown
Contributor Author

No, what are the steps you're using to reproduce?

@PVince81

Copy link
Copy Markdown
Contributor

Come on, I already mentioned them so many times every time I tell you that it did not fix the issue. Here #13391 (comment)

@ghost

ghost commented Jun 17, 2015

Copy link
Copy Markdown

💣 Test FAILed. 💣
nooo432

@PVince81

Copy link
Copy Markdown
Contributor
  • BUG: cannot create directory (master is fine with the same steps)
  1. Reset ownCloud
  2. Clear redis cache with "flushall"
  3. Setup ownCloud
  4. Enable experimental file locking
  5. Setup sync client for admin user (make sure it's from scratch, empty sync data dir)
  6. Run sync, it downloads "welcome.txt"
  7. Create a folder "food"
  8. Wait for sync
{"reqId":"nPBfl1MbxpzqmPh+mTub","remoteAddr":"127.0.0.1","app":"webdav","message":"Exception: {\"Message\":\"HTTP\\\/1.1 423 \\\"food\\\" is locked\",\"Code\":0,\"Trace\":\"#0 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(1177): OC\\\\Connector\\\\Sabre\\\\Directory->createDirectory('food')\\n#1 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/CorePlugin.php(583): Sabre\\\\DAV\\\\Server->createCollection('food', Array, Array)\\n#2 [internal function]: Sabre\\\\DAV\\\\CorePlugin->httpMkcol(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#3 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/event\\\/lib\\\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\\n#4 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(469): Sabre\\\\Event\\\\EventEmitter->emit('method:MKCOL', Array)\\n#5 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(254): Sabre\\\\DAV\\\\Server->invokeMethod(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#6 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files\\\/appinfo\\\/remote.php(83): Sabre\\\\DAV\\\\Server->exec()\\n#7 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/remote.php(84): require_once('\\\/srv\\\/www\\\/htdocs...')\\n#8 {main}\",\"File\":\"\\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/connector\\\/sabre\\\/directory.php\",\"Line\":147}","level":4,"time":"2015-06-17T13:14:36+00:00","method":"MKCOL","url":"\/owncloud\/remote.php\/webdav\/food"}

@PVince81

Copy link
Copy Markdown
Contributor

Still does not fix the rename folder + data loss issue #13391 (comment).
Reproduced after 3 tries.
This appeared in the log:

{"reqId":"vO5YWrSJQ48S7tx5HqNr","remoteAddr":"127.0.0.1","app":"webdav","message":"Exception: {\"Message\":\"An exception occurred while executing 'DELETE FROM `oc_filecache` WHERE `parent` = ?' with params [9]:\\n\\nSQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction\",\"Code\":0,\"Trace\":\"#0 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/DBALException.php(116): Doctrine\\\\DBAL\\\\Driver\\\\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOException))\\n#1 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/Statement.php(172): Doctrine\\\\DBAL\\\\DBALException::driverExceptionDuringQuery(Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOMySql\\\\Driver), Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOException), 'DELETE FROM `oc...', Array)\\n#2 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/db\\\/statementwrapper.php(73): Doctrine\\\\DBAL\\\\Statement->execute(Array)\\n#3 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/db.php(147): OC_DB_StatementWrapper->execute(Array)\\n#4 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/cache.php(500): OC_DB::executeAudited('DELETE FROM `*P...', Array)\\n#5 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/cache.php(471): OC\\\\Files\\\\Cache\\\\Cache->removeChildren(Array)\\n#6 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/scanner.php(200): OC\\\\Files\\\\Cache\\\\Cache->remove('files\\\/re2')\\n#7 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/scanner.php(352): OC\\\\Files\\\\Cache\\\\Scanner->removeFromCache('files\\\/re2')\\n#8 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/cache\\\/scanner.php(257): OC\\\\Files\\\\Cache\\\\Scanner->scanChildren('files', false, 3, Array)\\n#9 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/view.php(1257): OC\\\\Files\\\\Cache\\\\Scanner->scan('files', false)\\n#10 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/connector\\\/sabre\\\/directory.php(196): OC\\\\Files\\\\View->getDirectoryContent('\\\/')\\n#11 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Tree.php(195): OC\\\\Connector\\\\Sabre\\\\Directory->getChildren()\\n#12 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(878): Sabre\\\\DAV\\\\Tree->getChildren('')\\n#13 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(928): Sabre\\\\DAV\\\\Server->addPathNodesRecursively(Array, Object(Sabre\\\\DAV\\\\PropFind))\\n#14 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/CorePlugin.php(327): Sabre\\\\DAV\\\\Server->getPropertiesForPath('', Array, 1)\\n#15 [internal function]: Sabre\\\\DAV\\\\CorePlugin->httpPropfind(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#16 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/event\\\/lib\\\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\\n#17 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(469): Sabre\\\\Event\\\\EventEmitter->emit('method:PROPFIND', Array)\\n#18 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(254): Sabre\\\\DAV\\\\Server->invokeMethod(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#19 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files\\\/appinfo\\\/remote.php(83): Sabre\\\\DAV\\\\Server->exec()\\n#20 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/remote.php(84): require_once('\\\/srv\\\/www\\\/htdocs...')\\n#21 {main}\",\"File\":\"\\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/doctrine\\\/dbal\\\/lib\\\/Doctrine\\\/DBAL\\\/Driver\\\/AbstractMySQLDriver.php\",\"Line\":115}","level":4,"time":"2015-06-17T13:21:32+00:00","method":"PROPFIND","url":"\/owncloud\/remote.php\/webdav\/"}

It looks like somehow the scanner still detected the missing file and tried and delete the entries.

@icewind1991

Copy link
Copy Markdown
Contributor Author

From what I can tell this doesn't fix the issue with your reproduction steps because atm only a read lock is hold around the cache rename, I'll experiment further with it

@icewind1991

Copy link
Copy Markdown
Contributor Author

BUG: cannot create directory (master is fine with the same steps)

Should be fixed now

@icewind1991

Copy link
Copy Markdown
Contributor Author

@owncloud-bot retest this please

@PVince81

Copy link
Copy Markdown
Contributor

Fixes #16998

@PVince81

Copy link
Copy Markdown
Contributor

@icewind1991 I'm still seeing #16963 (comment), cannot create directory in the root with the sync client. "Locked"

@PVince81

Copy link
Copy Markdown
Contributor

Wait, I mismanipulated the branches. Trying again.

@PVince81

Copy link
Copy Markdown
Contributor

Works now 👍

@nickvergessen

Copy link
Copy Markdown
Contributor

PR fixes the failing smashbox tests

Comment thread lib/private/files/view.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be covered by Filesystem::normalizePath($absolutePath) nowerdays?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. @icewind1991 probably forgot to remove it after rebasing ? (normalizePath wasn't there originally)

@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@nickvergessen

Copy link
Copy Markdown
Contributor

I will test all smashbox tests agains this. So far it looks promising

@icewind1991

Copy link
Copy Markdown
Contributor Author

@owncloud-bot retest this please

@ghost

ghost commented Jun 18, 2015

Copy link
Copy Markdown

🚀 Test PASSed.🚀
chuck

@nickvergessen

Copy link
Copy Markdown
Contributor
Test Result
test_reshareDir -a ✅
test_shareDir -a ✅
test_shareFile -a ✅
test_shareGroup -a ✅
test_uploadFiles -a ✅
test_basicSync -a ✅

sharePermissions fails, so I split it up for details:

Test Result
test_sharePermissions -t=0 (ALL) ❌ move_in, move_in_overwrite and move_out fail
test_sharePermissions -t=1 (READ) ✅
test_sharePermissions -t=2 (READ + CREATE) ❌ move_in
test_sharePermissions -t=3 (READ + UDPATE) ✅
test_sharePermissions -t=4 (READ + DELETE) ❌ move_out
test_sharePermissions -t=5 (READ + CREATE + UPDATE) ❌ move_in
test_sharePermissions -t=6 (READ + CREATE + DELETE) ❌ move_in, move_in_overwrite and move_out
test_sharePermissions -t=7 (READ + UPDATE + DELETE) ❌ move_out

Note: move_in_overwrite deletes + creates thats why READ+UPDATE is okay.

@nickvergessen

Copy link
Copy Markdown
Contributor

So 👍 since it fixes 3 out of the 4 failing tests.
sharePermissions will be dealt with in another ticket

@nickvergessen

Copy link
Copy Markdown
Contributor

New issue created #17029

PVince81 pushed a commit that referenced this pull request Jun 18, 2015
Acquire read lock when getting file or directory info
@PVince81
PVince81 merged commit 6697f95 into master Jun 18, 2015
@PVince81
PVince81 deleted the fileinfo-lock branch June 18, 2015 16:27
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants