Skip to content

Remove the need for the transaction in the database locking backend - #19098

Merged
DeepDiver1975 merged 3 commits into
masterfrom
db-lock-no-transaction
Sep 18, 2015
Merged

DeepDiver1975 merged 3 commits into
masterfrom
db-lock-no-transaction

Conversation

@icewind1991

Copy link
Copy Markdown
Contributor

transactions lead to errors during concurrent access.

The only reason we required the transaction was to prevent the lock field from being removed between init and update.

Fixes smashbox test_uploadFiles and test_basicSync for me

cc @DeepDiver1975 @PVince81 @nickvergessen

@icewind1991

Copy link
Copy Markdown
Contributor Author

@individual-it relevant for your issues

@icewind1991

Copy link
Copy Markdown
Contributor Author

Note that this means we no longer clean up the database for empty lock entries but we get some performance for that since we can re-use the rows instead of constantly deleting and re-creating them

@PVince81

Copy link
Copy Markdown
Contributor

Fixes the issue 👍

But I'm worried about polluting the database with stray entries, especially when files are deleted/moved or unused for a long time.

@icewind1991 pointed out that big installs should use memcache anyway.

@DeepDiver1975 what do you think ? Should a cron job be added to clear stray DB lock entries ? (in a separate PR). It might be possible to do it in the future as part of the TTL enhancement.

@icewind1991 icewind1991 added this to the 8.2-current milestone Sep 16, 2015
@individual-it

Copy link
Copy Markdown
Member

@icewind1991 so the race conditions that you mention here #18918 (comment) can only happen in the case of removing locks?

If so I would propose:

  1. get rid of the transactions as @icewind1991 proposes in this PR
  2. get rid of if ($this->connection->inTransaction()) as that check will never be true anymore
  3. move cleanEmptyLocks() to cron jobs. That should remove all locks with lock = 0 but only for files that are NOT in the filecache table. That way the lock table would maximum as big as the filecache table. But how can we find out which lock does not correspond to any filecache entry?
  4. put a try/catch in the aquireLock() function, similar like proposed here MySQL 1213 Deadlock when creating a lot of directories in parallel #18918 (comment) and throw an LockedException if something fails
  5. reverse the order or UPDATE and init. In that scenario most likely we would already have an entry in the DB so it would be faster to only update it. And if the Update fails we do an INSERT with the correct values (see PR reduce amount of db calls needed for file-locks #18993) , so we do not loose anything.

Would that solve all problems?

@nickvergessen

Copy link
Copy Markdown
Contributor
  1. get rid of if ($this->connection->inTransaction()) as that check will never be true anymore

Just saying: we still use transactions in other places, but yes it is less dangerous now

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 is spamed quite heavily by the uploadFiles tests and is of less use now?
Degrade to debug or remove?

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.

@icewind1991 what about this ?

@DeepDiver1975

Copy link
Copy Markdown
Contributor

@DeepDiver1975 what do you think ? Should a cron job be added to clear stray DB lock entries ? (in a separate PR). It might be possible to do it in the future as part of the TTL enhancement.

As already stated on IRC:

bildschirmfoto von 2015-09-17 09-00-11

@DeepDiver1975

Copy link
Copy Markdown
Contributor

@DeepDiver1975 what do you think ? Should a cron job be added to clear stray DB lock entries ? (in a separate PR). It might be possible to do it in the future as part of the TTL enhancement.

So - yes - cron job and ttl. go go go ...

@PVince81

Copy link
Copy Markdown
Contributor

@oparoz does this PR fix your locking issues ?

@icewind1991

Copy link
Copy Markdown
Contributor Author

get rid of if ($this->connection->inTransaction())

Is still relevant since we can still be inside a transaction while trying to get a lock

reverse the order or UPDATE and init

Can't do that due to race conditions

@icewind1991

Copy link
Copy Markdown
Contributor Author

It now deletes old rows

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.

So basically the column "ttl" should have been called "expiretime". Too late to change it now.

@individual-it

Copy link
Copy Markdown
Member

get rid of if ($this->connection->inTransaction())

Is still relevant since we can still be inside a transaction while trying to get a lock

cannot see any code that uses transactions on the lock table. And if then something need to be done with that if statement. Throwing a Exception? What is the log entry good for?

reverse the order or UPDATE and init

Can't do that due to race conditions

yes you are right. We could throw an Lock exception in case two inserts happen at the same time an one fails, but I guess it is not worth the little performance advantage.

@PVince81

Copy link
Copy Markdown
Contributor

I'm fine with this PR 👍

DeepDiver1975 added a commit that referenced this pull request Sep 18, 2015
Remove the need for the transaction in the database locking backend
@DeepDiver1975
DeepDiver1975 merged commit bbf128f into master Sep 18, 2015
@DeepDiver1975
DeepDiver1975 deleted the db-lock-no-transaction branch September 18, 2015 15:02
@mmattel

mmattel commented Sep 18, 2015

Copy link
Copy Markdown
Contributor

@icewind1991 @DeepDiver1975 @PVince81

I just tested this PR because of #19150. After removing 'filelocking.enabled' => false, from the config (suggestion of @PVince81), restarting nginx and php5-fpm, and logging on the instance, the log flooding did not occur, but there is an interesting behaviour:

Having a folder in the users home and a SMB mount present. When I change to the local folder, no log entry is written, but if I change to SMB, a bunch of log entries like below are created:

owncloud.log

{"reqId":"xB6orYTkXZx8NvaUXrxM","remoteAddr":"y.y.y.y","app":"no app in context","message":"Trying to acquire a lock for 'files\/78670845017310477a83847c86da56ff' while inside a transition","level":2,"time":"2015-09-18T17:42:24+02:00"}

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 10, 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.

6 participants