Skip to content

fix update to remove shares where file doesn't exist on postgres - #7293

Merged
PVince81 merged 7 commits into
masterfrom
update-shares-postgres
Apr 1, 2014
Merged

PVince81 merged 7 commits into
masterfrom
update-shares-postgres

Conversation

@MorrisJobke

Copy link
Copy Markdown
Contributor

This is just a cherry pick of the changes from #6016 to be able to add unit tests to this PR.

credit for the fix goes to @jmcclelland

@MorrisJobke MorrisJobke added Bug and removed Bug labels Feb 19, 2014
@MorrisJobke MorrisJobke self-assigned this Feb 19, 2014
@karlitschek

Copy link
Copy Markdown
Contributor

makes sense 👍

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

I added the unit test. Ready to review and merge. cc @PVince81 @schiesbn

@schiessle

Copy link
Copy Markdown
Contributor

code looks good, I also executed the test successfully on my local sqlite... Let's wait for Jenkins tests with the other databases... otherwise 👍

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@PVince81 It's broken, because previous tests doesn't clean up the database :(

@DeepDiver1975 Should I just clear the tables in "setup" or should I try to find the cause of the data?

@DeepDiver1975

Copy link
Copy Markdown
Contributor

Should I just clear the tables in "setup"

yes - that's acceptable - thx

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

Test_Files_Sharing_Updater::testRemoveBrokenShares
But this is the name of that column. @butonic How does Oracle handle column names in a way that this is a problem?

Column definition: https://github.com/owncloud/core/blob/master/db_structure.xml#L840

Doctrine\DBAL\DBALException: An exception occurred while executing 'INSERT INTO "oc_share" (file_source, id, item_type, uid_owner) VALUES (?, ?, 'file', 1)':

ORA-00904: "UID_OWNER": invalid identifier

@PVince81

Copy link
Copy Markdown
Contributor

Maybe the field backticks are missing. I'll see if I can fix it, I can run the test against the Stuttgart Oracle instance.

@PVince81

Copy link
Copy Markdown
Contributor

@MorrisJobke I've fixed the backticks, the tests can now run on Oracle (they did locally).
Nevertheless, one of the tests is failing:

There was 1 failure:

1) Test_Files_Sharing_Updater::testRemoveBrokenShares
Failed asserting that '1' matches expected 0.

/home/vincent/workspace/owncloud/apps/files_sharing/tests/updater.php:82

@ghost

ghost commented Feb 28, 2014

Copy link
Copy Markdown

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@PVince81 Seems to be related to a misinterpreted SQL statement on oracle. Is anybody here who can try the actual SQL statement on oracle? I don't have an oracle DB here.

Steps to do:

  1. Add a entry to oc_share with a reference to a not existant item in oc_filescache
  2. Run the SQL statement of fixBrokenSharesOnAppUpdate
  3. The entry added in 1) should be gone

cc @butonic

@PVince81

PVince81 commented Mar 1, 2014

Copy link
Copy Markdown
Contributor

The deletion worked but it seems to be the one with fileid=3 that was deleted, not 2.
Maybe Oracle generates the ids in a different order ?

@PVince81

PVince81 commented Mar 1, 2014

Copy link
Copy Markdown
Contributor

@MorrisJobke can you change the code and make it "id proof" ? Maybe put a name in "item_target" and select on the string instead of the id when checking whether it was deleted correctly.

@butonic

butonic commented Mar 3, 2014

Copy link
Copy Markdown
Contributor

@MorrisJobke the query runs fine:

SELECT "oc_share"."id"
FROM "oc_share" LEFT JOIN "oc_filecache" ON "file_source" = "oc_filecache"."fileid"
WHERE "oc_filecache"."fileid" IS NULL AND "oc_share"."item_type" IN ('file', 'folder');

    id
----------
    34

Instead of first querying the database for all shares on files that don't exist and then deleting every obsolete share individually, you should let the database handle all of it:

DELETE FROM "oc_share" WHERE "file_source" NOT IN (
    SELECT "fileid" FROM "oc_filecache" WHERE "item_type" IN ('file','folder')
);

Everything executed in one query to the DB.

@PVince81

PVince81 commented Mar 3, 2014

Copy link
Copy Markdown
Contributor

I think at some point @bantu mentionned that we can't use subqueries ? (might have been something else)

@schiessle

Copy link
Copy Markdown
Contributor

also keep in mind that we are talking about a update script. This gets executed exactly once for every user. I don't think this need to be highly optimized, let's take the safe way.

@butonic

butonic commented Mar 3, 2014

Copy link
Copy Markdown
Contributor

@PVince81 Yes, on mysql there is a problem with modifying a table when you already used it in a subselect: http://stackoverflow.com/a/12969601. The workaround is tu use a virtual table as I did in search_lucene. Anyway, that workaround is not necessary in this case.

@schiesbn If you consider going through the php stack - with all it's typelessness - safer ... ;) Also, users with millions of files tend to complain when migration takes ages. Ask @felixboehm for details. Which is why I prefer letting the database handle it natively and if necessary take spacial care of mysql as in search_lucene.

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@butonic I will give your subselect idea a try and jenkins will show us the problems, right?

@jmcclelland

Copy link
Copy Markdown
Contributor

We've been down this road before with this very patch. See: #6016

Tests passed with the sub-query, but instead of committing the patch, a request was made to do it over again without the subquery.

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@jmcclelland Sorry for that back and forth. I just checked the PR and the subquery there contains a needless JOIN and this one here is covered by an unit test, which hopefully covers the relevant cases. Maybe we can find together the correct solution. :)

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@karlitschek Your opinion?

@karlitschek

Copy link
Copy Markdown
Contributor

Let's go with the simple approach. Performance is not important in this case.

@DeepDiver1975

Copy link
Copy Markdown
Contributor

@owncloud-bot retest this please

@PVince81

PVince81 commented Mar 5, 2014

Copy link
Copy Markdown
Contributor

@MorrisJobke looks like now all the shares were deleted ?

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@PVince81 It's weird... will have another try tomorrow

@PVince81

Copy link
Copy Markdown
Contributor

Any update ?

@PVince81

Copy link
Copy Markdown
Contributor

@MorrisJobke did you have any luck with the VM ?
I tried downloading it, it took a few hours and in the end the file was corrupt. 😕

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@PVince81 Not yet ... internet connection is sort of unstable and resume doesn't work 😕

@PVince81

Copy link
Copy Markdown
Contributor

@MorrisJobke I've discovered that Oracle ignores the ids you give for primary keys, I had this in another PR. Maybe that's what's happening here.

@PVince81

Copy link
Copy Markdown
Contributor

Better use \OC_DB::insertId('PREFIX'table') after the INSERT to retrieve whichever id Oracle decided to give instead of yours.

@PVince81

Copy link
Copy Markdown
Contributor

Seems it's the mapping between filecache entries and share entries might be wrong because of that generated id issue.

I'll give it a try.

Now using \OC_DB::insertId() to retrieve the generated ids because
Oracle ignores the passed values.
@PVince81

Copy link
Copy Markdown
Contributor

Here you go, it should work now.

@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@PVince81

Copy link
Copy Markdown
Contributor

@owncloud-bot retest this please

@PVince81

Copy link
Copy Markdown
Contributor

Something was wrong with the tests and the wrong ids were used. I'm surprised that the tests still passed locally. "Fortunately" Oracle has spotted these...

Now let's hope that they pass on Jenkins!

@scrutinizer-notifier

Copy link
Copy Markdown

The inspection completed: 34 new issues, 33 updated code elements

@ghost

ghost commented Mar 26, 2014

Copy link
Copy Markdown

@PVince81

Copy link
Copy Markdown
Contributor

The code has been changed since the last review, so please re-review

@jancborchardt

Copy link
Copy Markdown
Contributor

@MorrisJobke @jmcclelland @schiesbn can you please review @PVince81’s new changes?

@jancborchardt

Copy link
Copy Markdown
Contributor

Also cc'ing @julienfastre for review because you commented on the previous pull request #6016

@MorrisJobke

Copy link
Copy Markdown
Contributor Author

👍 Works

My steps (for SQLite): (123456 and mjob should be replaced with a corresponding value - first must NOT exists in oc_filecache - second is just a user id)

> select * from oc_appconfig where appid = 'files_sharing';
files_sharing|installed_version|0.3.5
files_sharing|types|filesystem
files_sharing|enabled|yes
> insert into oc_share (file_source, item_type, uid_owner) values (1234567, 'file', 'mjob');
// this inserts a broken share - which should be removed

Checkout this branch and load your ownCloud instance to update the app.

> select * from oc_appconfig where appid = 'files_sharing';
files_sharing|installed_version|0.3.5.6
files_sharing|types|filesystem
files_sharing|enabled|yes
> select * from oc_share where file_source = 123456;
// should result in nothing as this is removed by the script

@PVince81

PVince81 commented Apr 1, 2014

Copy link
Copy Markdown
Contributor

Ok, that should be enough, merging now.
Thanks everyone.

PVince81 pushed a commit that referenced this pull request Apr 1, 2014
fix update to remove shares where file doesn't exist on postgres
@PVince81
PVince81 merged commit 27eff1a into master Apr 1, 2014
@PVince81
PVince81 deleted the update-shares-postgres branch April 1, 2014 12:56
@MorrisJobke

Copy link
Copy Markdown
Contributor Author

@PVince81 Awesome ...it gets into master \o/

@MorrisJobke MorrisJobke added this to the ownCloud 7 milestone Apr 1, 2014
@MorrisJobke MorrisJobke removed their assignment Oct 5, 2015
@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.

9 participants