-
Notifications
You must be signed in to change notification settings - Fork 118
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
Increase size of media.field_file_size #829
Conversation
->fetchAll(); | ||
|
||
// Clean it out for resizing. | ||
$database->truncate($table)->execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems potentially catastrophic, if the process later fails for some reason... different DB with different syntax or whatever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I attempted to resize without cleaning it out and Drupal simply would not let me. Cleaning it out is the only way to save it. I suppose we could create a temporary table instead of relying on an in-memory store... 🤔
According to the Drupal notes this is how you truncate a table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat ambiguous due to nomenclature, but I'm assuming you don't mean a "temporary table" as supported by various DB engines which are automatically deleted at the end of the DB session, as they would exhibit the same issue of losing the stored data if something failed before getting it back in... but yeah, a short-lived table we create/check-for and populate, and delete when we're done... assuming success with in-place alteration with changeField()
doesn't make it irrelevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like Drupal won't let changeField update the table without cleaning it out first either: "[error] The SQL storage cannot change the schema for an existing field (field_file_size in media entity) with data."
I'll see about creating a table to keep this all in, should the update fail and need to be attempted again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a new table I created a temporary file to stash a JSON copy of each table before truncating. I then re-read the file to insert the data back in after the schema is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for using public, I didn't like the alternatives. Not all sites have a private filesystem set (a non-starter for an update hook) and temporary is at the whims of the OS' clean-up, so I'd rather not trust it for keeping our data dump in the case of a failure. At least a site admin knows where public is if they have to go grab it should the site fail. Also, it is just a list of file sizes.... That said, if y'all prefer we use the temporary file-space, it is a simple change; just confirm either way.
Ah, update hook batches (are a pain to use properly). I recently fought with this on a separate internal migration. Batch works best when the first and third steps are performed once and the middle step is repeated. (E.g. moving data from one field to another where the first phase sets up the new field, the middle step gradually copies, and the final step cleans up. Or a single repeatable step like modifying values in place.) Our three phases—dump all the data, make the change, re-import everything—are the inverse where the first and third can be done in chunks but the middle phase can't. Batching isn't suitable for this scenario.
I've attempted to use the strategy suggested by that recipe for in-place editing, but Drupal still balks at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should also note that the pain of creating new tables, copying the data in then out, then dropping them didn't seem worth it compared to doing the same with temporary files briefly in the public filesystem. The attack window (knowing it exists and when) and reward of this is really small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stuck in my head last night; I might be able to use batch on this after all by nesting the batches within stages...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of dumping to files and what not, might it be simpler to:
- rename the target tables (assuming that renaming doesn't break similarly to the
::changeField()
business. - create the new tables using the up-to-date schema
- copy table content using insert/from, from the renamed to the newly created tables
- drop the renamed copies
... if not, couldn't whatever batch structure be accomplished with multiple update hook implementations? A batch update hook followed by a non-batch, followed by a batch, kind of thing?
... any which way... still have the potential issue with the type change not being strictly widening with the move to exclude negative values... are we just ignoring this, or should we check for anything negative before trying to process, or... are we happy just letting it error how however it might?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nice. I had seen references to Schema::copyTable which was no longer available. I hadn't see the rename table function.
As I eluded to in my previous comment, I think we can do the batching in a single hook. Also, with the table rename tactic, we only really need to batch the insert/from, which is manageable.
I do think we need to error, or at least warn, on negative file sizes. I mean, semantically speaking, those values are already broken.
@seth-shaw-unlv I looked into the test fails and it appears to be just syntax: https://github.com/Islandora/islandora/pull/829/checks?check_run_id=2132855766#step:13:13 |
@dannylamb , huh... it was failing on something else earlier. Anyway, did we change something for phpcs? Running it locally with Drupal and DrupalPractice didn't throw that error. |
Smoke tested this and it works as advertised. Table
and after running it:
No warnings/errors anywhere, including when creating a media after the update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smoke tested successfully.
See below...
@adam-vessey OK for me to merge? |
Halt! When I'm in the
Curl shows This error is preceded in the watchdog by the following notice:
Switching back to |
@mjordan, that would be related to @dannylamb's purge of Gemini that was recently merged. I would talk to either him or @elizoller. It isn't related to this PR at all. That said... give me a day or two to see if I can incorporate @adam-vessey's table-rename suggestion to work. |
This new version uses the table renaming strategy recommended by @adam-vessey. Coming up with the full table definition took some work as I couldn't find good documentation on creating it and needed to read through the createTable code to figure it out. It works, but it would create a monster query for existing sites with lots of existing media, so we probably should incorporate batching. I should be able to do that tomorrow; I just wanted this bit safely stowed off my machine before I went to bed. 💤 |
@adam-vessey & @mjordan the PR now includes batch support and should be ready to go. Give it a whirl. |
I can ingest a bunch o'objects to test the batching. Any suggestions on how many would be a miniumum, given that I'll be doing this on a Playbook VM running an a laptop with 16GB of physical RAM? |
@mjordan, it should work on any size system that can run Islandora. The main limitation isn't the box's resources, but your PHP memory limit and time-outs. I hopefully set the batch size to fit the default settings. I ran this on a vanilla islandora-playbook but, granted, I didn't have a lot of media in this test site. Running this as it is on a box with a bunch o'objects to make sure it doesn't die would be great. |
@mjordan, hold the phone! I'm dropping the table too early. Patch coming. |
@mjordan, hopefully this is finally ready to go. 🤦♂️ |
Will test on Sunday (👀).... |
@seth-shaw-unlv I already installed islandora_core_feature_update_8001() when I tested this the first time. Is it OK to change |
That should be fine, although you will eventually want to revert the version back using |
To work around my slightly botched second test from earlier today, I built a brand new Playbook and ingested around 100 images objects. The update hook worked, but on applying the PR, I got an exception related to #826 as documented below. Before running update:
After running update:
Here's the exception related to #826
|
@mjordan, as far as I'm concerned that error is unrelated to this PR and shouldn't impact whether or not we merge it. I think it is ready to merge, but that is up to you and @adam-vessey. |
@seth-shaw-unlv yes, your code worked, that exception is not related to this PR. @adam-vessey OK to merge? If so, I will do it. |
There is one, somewhat unrelated, issue. This branch isn't up to date with 8.x-1.x and it doesn't have the recent captions work. So if you have the most recent islandora_defaults and this branch of islandora, things might be funky such as
|
@mjordan : Should be, I think. |
To confirm, I just ran this update on a very recent Playbook (built last night) and it installed cleanly:
|
GitHub Ticket: Islandora/documentation#1771
What does this Pull Request do?
Increases the size and signed state of media.field_file_size to support files larger than 2.2GB.
What's new?
How should this be tested?
drush eval "\Drupal::entityTypeManager()->getStorage('media')->load(1)->set('field_file_size', 2400000000000)->save();"
This will throw an error.drush updb -y
drush cr
drush eval "\Drupal::entityTypeManager()->getStorage('media')->load(1)->set('field_file_size', 2400000000000)->save();"
will return successfully.Additional Notes:
This PR does not include the bigint module. I can update the PR to include it if folks want it, but it does take some work. It requires updating composer.json and finding all the relevant field configs to update them.
Interested parties
@Islandora/8-x-committers