Repository navigation
don't update identical values - #15549
Conversation
The UPDATE oc_filecache statement blindly overwrites identical data. Databases like Postgres that create a new row on an update and mark the old one as dead will suffer from the previous behaviour, as millions of "new" rows are created in the database. This patch changes the WHERE clause to test for identical values and not updating if the values in the DB are identical to the ones being passed.
|
@icewind1991 @DeepDiver1975 What do you think? |
|
@karlitschek , @icewind1991 , @DeepDiver1975 : This is how our DB server looked like like the last 24 hours. The vertical bar marks the time when the patch went live. Note the "tupes edited" and "IO Idx" graphs. This graph illustrates the problem: "Dead" tuples are those that got superseeded by an update: Red areas are dead. Large vertical drops where manual cleanup processes that locked the whole DB for 15-20 minutes. We managed to get "AUTOVACUUM" to run on friday (many small drops) but this needs the table to be relatively quiet. When too many updates happen to the Table autovacuum can't run and performace degrades severely. Last steep vertical drop was due to the patch which calmed the table and let the autovacuum do it's job. |
There was a problem hiding this comment.
This line looks unrelated and if I'm not mistaken will actually do nothing. Can you remove this or elaborate what was the intention behind this?
There was a problem hiding this comment.
It actually does something: it duplicates the params array [ 123, 567 ] -> [ 123, 567, 123, 567 ]
This is need because we now pass the params twice to the SQL builder - once for the SET part, once for the WHERE part:
UPDATE oc_filecache SET foo = 123, bar = 567 WHERE ( foo <> 123 OR bar <> 567) AND fileid = 9876;
There was a problem hiding this comment.
That makes sense. Thanks!
There was a problem hiding this comment.
(can you add this as comment above? – It can be confusing otherwise)
|
What I'm a bit worried about, is that the tests passed with this change. Looking at the test cases for this file, I see that there are no specific test cases for that method call. I haven't trawled through the code to find all places where it is called and see if there are specific tests for it. Do any of you @karlitschek , @LukasReschke, @icewind1991 , @DeepDiver1975 know that his method is tested |
|
actually - not totally worried: The change doesn't change the behavior of the |
|
The inspection completed: No new issues |
|
Refer to this link for build results (access rights to CI server needed): |
|
Tested and works 👍 |
|
@LukasReschke can you please review the sql-fu regarding injection? THX |
General documentation on PHPUnit mock objects etc: https://phpunit.de/manual/current/en/test-doubles.html Various examples on how we mock: https://github.com/owncloud/core/blob/master/tests/lib/files/storage/wrapper/encryption.php#L20-L68 But mocking will not help when it comes down to database interactions. I'm asking myself on how to do this properly ... |
|
Well - from my experience I would factor out the SQL generation into its own method and test that to make sure it returns valid SQL based on the inputs. IF the SQL is valid, then that is a first step. As for the correct semantics (for example to make sure that the SQL is doing an UPDATE instead of a DELETE ;) ) I guess that there are some high-level tests that work against a real database and would catch that. |
Should be good, since only stuff is used, which was used before. |
|
Does it make sense to check |
|
@nickvergessen - don't assume that the DB will evaluate these things in the order they are written. The query planner will rewrite them for maximal performance. I wrote it like this in order to make the duplication code of the params array simpler (otherwise, I would have had to introduce another variable and insert the fileid in the middle) |
right, makes sense as well, as long as the db is intelligent enough to do that ;) Another questions, do WHERE statements of UPDATE queries use indexes? If so the query should be much slower now? (does it make sense to extend the WHERE on postgres only?) |
|
of course the WHERE statement use the indexes: Also - the UPDATE is much faster because it won't happen in n% of the time (where I suspect n is a rather larger number). All databases should benefit from this optimization The case without the additional WHERE is exactly identical in expense of the lookup |
|
After having this patch in for some time now, I'm not sure that there are that many superfluous updates after all. We are seeing "zombie" php processes hammering the database (but haven't found out yet what they are doing). These zombies could explain the high load on the database. We are continuing to investigate |
|
I'm fine in merging this into master for 8.1 👍 |
don't update identical values
|
@DeepDiver1975 @karlitschek Backport or not backport? |
|
@MorrisJobke please open pr - THX |
|
backport please. Thanks |
don't update identical values
|
Could this be back ported to the next release of 7 please? |
|
|
Just a quick note @scolebrook . I'm not sure that this will really help a lot. The big problem (as we have later discovered) is the fact, the oC starts a DB transaction before beginning deletion tasks. Due to the stupid way the deletion is written, there are zillions of superfluous DB updates taking place (ETAG and size recalculations after every deleted file, for the complete upwards directory structure times the number of people this is shared with). This takes extremely long (it doesn't help that files are copied to the trashbin, instead of moved). All the while the DB is in a transaction. Therefore the DB is in an internal state where it cannot perform any cleanups. This is why you see these dead tuples accumulating. |
@jcfischer I'm very much aware of the frustrating situation you are in - but I see no need in calling us stupid - right? |
|
@MorrisJobke 7 and 8 please |
|
Stable7 backport PR: #16969 |
|
Thanks for the back port. We are hoping to upgrade to 8 soon but when you have to training help desk staff and develop internal training material there's a lot of pushing required for something that is otherwise relatively simple. |
|
@DeepDiver1975 - sorry for ranting and venting. We just had a case where a user trying to delete a folder took down our whole service before I wrote this. Also, on a bright note: We have created a new smash box test to test this: cernbox/smashbox@d6786aa and I'm happy to report, that 8.1 in it's current form takes 6 seconds to do the deletion vs. > 1 minute for ownCloud 7. |
No worries - sometimes you need to express your feelings - I know that 🙊
Thanks - we will add this to our own test suite asap (FYI: this is the current development state where we test upcoming 8.1 on a nightly basis: https://ci.owncloud.org/job/smashbox/) |



The UPDATE oc_filecache statement blindly overwrites identical data.
Databases like Postgres that create a new row on an update
and mark the old one as dead will suffer from the previous
behaviour, as millions of "new" rows are created in the database.
This patch changes the WHERE clause to test for identical
values and not updating if the values in the DB are identical
to the ones being passed.