Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to subfolders for preview files #19214

Merged
merged 1 commit into from
Apr 19, 2020
Merged

Conversation

rullzer
Copy link
Member

@rullzer rullzer commented Jan 30, 2020

My take on #16747 @gbmaster please have a look as well.

Else the number of files can grow very large very quickly in the preview
folder. Esp on large systems.

This generates the md5 of the fileid. And then creates folders of the
first 7 charts. In that folder is then a folder with the fileid. And
inside there are the previews.

Since this is just an abstraction as to how things are stored. i chose to just extend appdata to handle it. This was non of the code touching it needs to be concerned with how things are stored. As long as they are stored (think of it as a poor mans objectstore).

@kesselb
Copy link
Contributor

kesselb commented Jan 30, 2020

  1. How do you delete previews of deleted files?
  2. Another "most wanted" feature is to move previews somewhere else in the filesystem. Is that something you could implementation with the abstracted storage?

@rullzer
Copy link
Member Author

rullzer commented Jan 30, 2020

1. How do you delete previews of deleted files?

Ah right I need to add the same logic to the background job to use the proper location.

2. Another "most wanted" feature is to move previews somewhere else in the filesystem. Is that something you could implementation with the abstracted storage?

Nope. Nextcloud expect data to be under the data directory.

@kesselb
Copy link
Contributor

kesselb commented Jan 30, 2020

Ah right I need to add the same logic to the background job to use the proper location.

That's the tricky part 😞 Have fun 😃

@gbmaster
Copy link

Adding the logic to the background job is also where I stopped, as my Nextcloud DB schema knowledge was not enough to find a proper solution.
Feel free to use part of my commits, if you find them useful.

I am glad that you took over this task. Thank you very much!

@rullzer
Copy link
Member Author

rullzer commented Jan 30, 2020

I think I have an idea... lets see ;)

@rullzer
Copy link
Member Author

rullzer commented Jan 30, 2020

I think I have an idea... lets see ;)

seems to work... 27e0ded

@rullzer
Copy link
Member Author

rullzer commented Feb 7, 2020

Addressed. Please check and test

@kesselb
Copy link
Contributor

kesselb commented Feb 7, 2020

Can we have a test for the old and new way in https://github.com/nextcloud/server/blob/master/tests/lib/Preview/BackgroundCleanupJobTest.php?

@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Apr 2, 2020
@rullzer
Copy link
Member Author

rullzer commented Apr 2, 2020

All good I think
Please review. I'll squash once done :)

@icewind1991
Copy link
Member

Not quite

  1. Test\Preview\BackgroundCleanupJobTest::testCleanupSystemCron
    Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'SELECTDISTINCT "a"."name" FROM "oc_filecache" "a" LEFT JOIN "oc_filecache" "b" ON CAST("a"."name" AS INT) = "b"."fileid" LEFT JOIN "oc_filecache" "c" ON "a"."fileid" = "c"."parent" WHERE ("b"."fileid" IS NULL) AND ("a"."parent" = ?) AND ("a"."mimetype" = ?) AND ("c"."mimetype" <> ?)' with params [2709, 2, 2]:
    SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "b"

@rullzer rullzer mentioned this pull request Apr 4, 2020
80 tasks
Copy link
Member

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

A few interesting comments, but code looks great so far! 🐘

This was referenced Apr 15, 2020
@rullzer
Copy link
Member Author

rullzer commented Apr 16, 2020

So now finally good I think.
Another review please

@skjnldsv
Copy link
Member

Another review please

Still 👍 from me

@kesselb
Copy link
Contributor

kesselb commented Apr 18, 2020

Lint / php-cs check (pull_request) Failing after 1m — php-cs check

Would you mind to run composer cs:fix?

Submodule 3rdparty updated 2540 files

🤔

@kesselb
Copy link
Contributor

kesselb commented Apr 18, 2020

Seems to do the trick 👍 but a rebase is needed 😨

I don't like that after deleting a preview the folder structure stays even if there are no more previews 🤷‍♂️

@rullzer
Copy link
Member Author

rullzer commented Apr 19, 2020

I don't like that after deleting a preview the folder structure stays even if there are no more previews man_shrugging

Yeah fair enough. I guess checking for that is rather straight forward to do.
BUt lets do that separately. As this has been idling long enough ;)

Else the number of files can grow very large very quickly in the preview
folder. Esp on large systems.

This generates the md5 of the fileid. And then creates folders of the
first 7 charts. In that folder is then a folder with the fileid. And
inside there are the previews.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@rullzer rullzer merged commit 56a0700 into master Apr 19, 2020
@rullzer rullzer deleted the enh/preview_folder_tree branch April 19, 2020 09:22
$this->assertSame(1, $this->countPreviews($root, $fileIds));
$job->run([]);

$root = $this->getRoot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented that line locally and the test failed 🤔 Would you mind to explain why a new instance is needed?

MorrisJobke added a commit that referenced this pull request Aug 6, 2020
…re to a subfolder structure

* `php occ preview:repair` - a preview migration tool that moves existing previews into the new location introduced with #19214
* moves `appdata_INSTANCEID/previews/FILEID` to `appdata_INSTANCEID/previews/0/5/8/4/c/e/5/FILEID`
* migration tool can be stopped during migration via `CTRL+C` - it then finishes the current folder (with the previews of one file) and stops gracefully
* if a PHP memory limit is set in the `php.ini` then it will stop automatically once it has less than 25 MiB memory left (this is to avoid hard crashes in the middle of a migration)
* the tool can be used during operation - possible drawbacks:
    * there is the chance of a race condition that a new preview is generated in the moment the folder is already migrated away - so the old folder with the newly cached preview is deleted and one cached preview needs to be re-generated
    * there is the chance of a race condition during access of a preview while it is migrated to the other folder - then no preview can be shown and results in a 404 (as of now this is an accepted risk)

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
@MorrisJobke
Copy link
Member

A tool to migrate existing previews into this new format can be found at #22135.

MorrisJobke added a commit that referenced this pull request Aug 6, 2020
…re to a subfolder structure

* `php occ preview:repair` - a preview migration tool that moves existing previews into the new location introduced with #19214
* moves `appdata_INSTANCEID/previews/FILEID` to `appdata_INSTANCEID/previews/0/5/8/4/c/e/5/FILEID`
* migration tool can be stopped during migration via `CTRL+C` - it then finishes the current folder (with the previews of one file) and stops gracefully
* if a PHP memory limit is set in the `php.ini` then it will stop automatically once it has less than 25 MiB memory left (this is to avoid hard crashes in the middle of a migration)
* the tool can be used during operation - possible drawbacks:
    * there is the chance of a race condition that a new preview is generated in the moment the folder is already migrated away - so the old folder with the newly cached preview is deleted and one cached preview needs to be re-generated
    * there is the chance of a race condition during access of a preview while it is migrated to the other folder - then no preview can be shown and results in a 404 (as of now this is an accepted risk)

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke added a commit that referenced this pull request Aug 6, 2020
…re to a subfolder structure

* `php occ preview:repair` - a preview migration tool that moves existing previews into the new location introduced with #19214
* moves `appdata_INSTANCEID/previews/FILEID` to `appdata_INSTANCEID/previews/0/5/8/4/c/e/5/FILEID`
* migration tool can be stopped during migration via `CTRL+C` - it then finishes the current folder (with the previews of one file) and stops gracefully
* if a PHP memory limit is set in the `php.ini` then it will stop automatically once it has less than 25 MiB memory left (this is to avoid hard crashes in the middle of a migration)
* the tool can be used during operation - possible drawbacks:
    * there is the chance of a race condition that a new preview is generated in the moment the folder is already migrated away - so the old folder with the newly cached preview is deleted and one cached preview needs to be re-generated
    * there is the chance of a race condition during access of a preview while it is migrated to the other folder - then no preview can be shown and results in a 404 (as of now this is an accepted risk)

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke added a commit that referenced this pull request Aug 7, 2020
…re to a subfolder structure

* `php occ preview:repair` - a preview migration tool that moves existing previews into the new location introduced with #19214
* moves `appdata_INSTANCEID/previews/FILEID` to `appdata_INSTANCEID/previews/0/5/8/4/c/e/5/FILEID`
* migration tool can be stopped during migration via `CTRL+C` - it then finishes the current folder (with the previews of one file) and stops gracefully
* if a PHP memory limit is set in the `php.ini` then it will stop automatically once it has less than 25 MiB memory left (this is to avoid hard crashes in the middle of a migration)
* the tool can be used during operation - possible drawbacks:
    * there is the chance of a race condition that a new preview is generated in the moment the folder is already migrated away - so the old folder with the newly cached preview is deleted and one cached preview needs to be re-generated
    * there is the chance of a race condition during access of a preview while it is migrated to the other folder - then no preview can be shown and results in a 404 (as of now this is an accepted risk)

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke added a commit that referenced this pull request Aug 7, 2020
…re to a subfolder structure

* `php occ preview:repair` - a preview migration tool that moves existing previews into the new location introduced with #19214
* moves `appdata_INSTANCEID/previews/FILEID` to `appdata_INSTANCEID/previews/0/5/8/4/c/e/5/FILEID`
* migration tool can be stopped during migration via `CTRL+C` - it then finishes the current folder (with the previews of one file) and stops gracefully
* if a PHP memory limit is set in the `php.ini` then it will stop automatically once it has less than 25 MiB memory left (this is to avoid hard crashes in the middle of a migration)
* the tool can be used during operation - possible drawbacks:
    * there is the chance of a race condition that a new preview is generated in the moment the folder is already migrated away - so the old folder with the newly cached preview is deleted and one cached preview needs to be re-generated
    * there is the chance of a race condition during access of a preview while it is migrated to the other folder - then no preview can be shown and results in a 404 (as of now this is an accepted risk)

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants