Problem/Motivation

I have been working on an installation of Drupal 8 that is making use of the Layout Builder module extensively to build pages with Block Content. After adding about 10 blocks and various layouts to a page the limit for the column is hit resulting in the error:

String data, right truncated: 1406 Data too long for column 'layout_builder__layout_section' at row 2: INSERT INTO {node__layout_builder__layout}

Proposed resolution

Increase the size of the column from 'normal' to 'big'.

For MySQL/MariaDB, this will change the underlying field from a BLOB to a LONGBLOB, which allows much more data to be stored (over 65,000 times more). It's overkill, but Drupal doesn't have support for MEDIUMBLOB which is just a 256x increase over BLOB. The impact of this change on database storage should be very small. MySQL will use an extra 2 bytes of storage for each record when using a longblob vs blob.

Remaining tasks

Write upgrade path tests

User interface changes

N/A

API changes

N/A

Data model changes

Yes, non-disruptive change to field schema.

Release notes snippet

N/A

Issue fork drupal-3030154

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dpfitzsi created an issue. See original summary.

dpfitzsi’s picture

dpfitzsi’s picture

Status: Active » Needs review
dpfitzsi’s picture

Updated patch to update configuration.

Status: Needs review » Needs work
tim.plunkett’s picture

Category: Support request » Task
Issue summary: View changes

Thanks for opening the issue! I'm not sure of the repercussions either, but seems like a reasonable change

dpfitzsi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.99 KB

Thanks tim.plunkett, I'm glad this is an approach we may need to use.

Updated patch to account for tests that are failing.

dpfitzsi’s picture

tim.plunkett’s picture

Note that Layout Builder is entity type agnostic, so this will need to be generic and not tied to nodes

Status: Needs review » Needs work
dpfitzsi’s picture

Status: Needs work » Needs review
StatusFileSize
new2.21 KB

Thanks for that update. I have added a check for all entity types to the function.

dpfitzsi’s picture

tim.plunkett’s picture

Hmmm, in doing some more research this might be way more tricky.
FieldType plugins can be used by much more than just entities. Others include Field Collection, Dynamic Entity Reference, Address, Views Reference, etc.

See #2339855: Handle changes to the schema provided by a field type and #937442: Field type modules cannot maintain their field schema (field type schema change C(R)UD is needed) for more.

I've asked @berdir for some guidance here.

Status: Needs review » Needs work

The last submitted patch, 12: 3030154-layout-builder--layout-section-column-hitting-database-limit-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tim.plunkett’s picture

Here's an example of this from contrib:
https://cgit.drupalcode.org/date_recur/commit/date_recur.install?id=8039...

Crediting @larowlan for the pointer

larowlan credited dpi.

larowlan’s picture

And @dpi wrote that code

dpfitzsi’s picture

Thanks for pointing me in the right direction.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Issue tags: +Blocks-Layouts
phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new3.99 KB

This is terrifying stuff.

Still needs tests, but here's a new version based on the model that date_recur provides. (It's practically copy-and-paste.)

Status: Needs review » Needs work

The last submitted patch, 23: 3030154-23.patch, failed testing. View results

bkosborne’s picture

#23 is setting the new schema to use "normal" size, it should be "big"

tim.plunkett’s picture

Also let's not lose the change to core/modules/layout_builder/src/Plugin/Field/FieldType/LayoutSectionItem.php from the first patch

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new4.63 KB
new1.33 KB

Right you both are. Corrected in this patch, plus another small mistake which I think broke the tests.

johnwebdev’s picture

Hmm, do we really need longblob though?

A blob is 64kb = 0.064 mb
A mediumblob is 16mb.

That's already a 24 900 % increase.

tim.plunkett’s picture

@dpfitzsi Having trouble reproducing your bug.

Inline blocks are not serialized into that field, so I'm not sure why 10 blocks would overflow 64k
Can you share more information about this?

Status: Needs review » Needs work

The last submitted patch, 27: 3030154-27.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Postponed (maintainer needs more info)
dpfitzsi’s picture

I wasn't aware of all of the activity on this. Thanks @phenaproxima for updating the patch.

@tim.plunkett I realize as I looked at this further that this is an issue with how it's been implemented in my installation. The entire BlockContent entity has been shoved into the individual blocks config information so that is why it's so big. I have some tech debt to clean up on my end to resolve this.

Does this still have value (do we foresee a large number of blocks hitting the 64kb limit)?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

cyb_tachyon’s picture

I can confirm this bug by having 12 custom blocks with 50 configured fields apiece in layout builder.

I know that sounds a bit over the top, but consider, many custom modules might ship blocks with that level of configuration that's dependent on context etc. In my situation, the blocks are being created by importing JSON schema, which may include many references to sub-schema. The block's interface makes it easy to add this amount of specific configuration to each instance.

You can work around it by doing the following:

  • Writing custom code for your block that doesn't save defaults - that's an issue if you want the blocks to remain unchanging with their saved default settings when versions of the module / source change
  • Ensuring there is no content in the config data you are saving - sometimes this can be impossible, depending on the use case
  • Implementing a new system for block saving for your module

All of these are labor intensive for module developers vs:

  1. Updating the field size to allow 16mb+ entries
  2. Setting layout builder to not store block config in a single field and instead split it into regular block storage mechanisms

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

johnzzon’s picture

We're hitting this limit on a large university site.

The offending node had a revision whiched crashed the site when viewed. The current revision has 114 components, weighing in at 61 kB of data in the Layout builder field.

johnzzon’s picture

Status: Postponed (maintainer needs more info) » Needs work

Providing some example data:

s:36:"74d1e195-5b37-46c0-9d81-0befc489e6fd";O:38:"Drupal\layout_builder\SectionComponent":5:{s:7:"*uuid";s:36:"74d1e195-5b37-46c0-9d81-0befc489e6fd";s:9:"*region";s:5:"first";s:16:"*configuration";a:8:{s:2:"id";s:19:"inline_block:editor";s:5:"label";s:36:"21f73fa9-aafb-4f14-a9d8-81869ea854ee";s:8:"provider";s:14:"layout_builder";s:13:"label_display";b:0;s:9:"view_mode";s:4:"full";s:17:"block_revision_id";s:5:"27055";s:16:"block_serialized";N;s:15:"context_mapping";a:0:{}}s:9:"*weight";i:0;s:13:"*additional";a:0:{}}

This is a single block placed. This example weighs 520 bytes. Multiplied by 114 equals 59280 bytes.

Setting status back to Needs work. If you think this extreme case is out of scope, feel free to change back.

meanderix’s picture

StatusFileSize
new4.63 KB

The patch in #27 did not properly update the schema in my tests. I had to change to:

$schema_key = "$entity_type_id.field_schema_data.$field_name";

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

andileco’s picture

Added a related issue where large Charts Blocks are not able to be added through Layout Builder. In my case, 'size' => 'big', would definitely be my preference.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tammycao’s picture

StatusFileSize
new4.63 KB

I applied the #38 patch in 9.1.10,but it was missing a reference.Now I uploaded a new one.

tim.plunkett’s picture

Issue summary: View changes
Issue tags: +Needs upgrade path tests
dmitriy.trt’s picture

StatusFileSize
new658 bytes

Patch from #42 fixed an issue for us.

Please ignore the patch I'm attaching here, it's for reference from composer. It contains just the changes needed at runtime, without the hook_update_N(). Could be useful for people who wants to avoid the nightmare with update numbers until the fix is committed to the upstream project. It assumes that you've copied the hook_update_N() from the #42 patch to a custom module.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bkosborne’s picture

Looks like no one addressed #28:

Hmm, do we really need longblob though?

A blob is 64kb = 0.064 mb
A mediumblob is 16mb.

That's already a 24 900 % increase.

A medium blob is 256 times larger than a blob. Not sure where the 24 900% number comes from. But in any case, I think you bring up a good point. Do we need to account for someone storing more than 256 times the amount of data than is currently allowed?. No, I don't think so. Going to a medium size seems totally fine.

However, Drupal does not currently support medium blob sizes (see #3118014: Additional blob field sizes in schema definitions), so we cannot go to medium.

I looked into the implications of using the different sizes. I don't know about other databases, but MySQL will use an extra 2 bytes of storage for each record when using a longblob vs blob. Presumably the same is true for MariaDB. Not sure on Postgres.

So, let's assume there are sites our there with some ridiculous number of entities that use layout builder. Let's say 10 million. That means increasing to a longblob from blob would add just about 10 MB storage requirements to the database. Not a big deal.

effulgentsia’s picture

FYI: I also opened #3267444: To reduce database size, convert layout_builder__layout_section column to a hash of the content for discussion, but please don't let that derail this issue. Even if we end up wanting to do that issue, I don't think that should stop us from changing the column size in the meantime if it makes sense to do so.

I can confirm this bug by having 12 custom blocks with 50 configured fields apiece in layout builder.

I know that sounds a bit over the top, but consider, many custom modules might ship blocks with that level of configuration that's dependent on context etc.

Is it only the context mappings that are in the serialized section data, or is there other stuff that's stored in the section data for each block field as well? Per #29, the block fields themselves should not be getting serialized into there, other than perhaps the context mappings.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mkdok’s picture

Status: Needs work » Reviewed & tested by the community

Patch #42 from @tammycao works as expected and planned to use in production

catch’s picture

Version: 9.5.x-dev » 10.1.x-dev
Category: Task » Bug report
Priority: Normal » Major
Status: Reviewed & tested by the community » Needs work
Issue tags: +Bug Smash Initiative

Still needs test coverage, also the hook_update_N() needs renumbering.

ravi.shankar’s picture

StatusFileSize
new4.63 KB
new685 bytes

Updated hook_update_N(), still needs work for tests.

awset’s picture

Hi all,

this is my first time writing an upgrade path test, I was following this doco,
https://www.drupal.org/docs/drupal-apis/update-api/writing-automated-upd...

need help to review the patch, I also added an interdiff file.

thanks.

awset’s picture

StatusFileSize
new11.43 KB
new6.8 KB

this patch added a test group, ignore #52 above.

awset’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative
+  public function testUpdateHookN() {
+    $this->runUpdates();
+    $this->assertEqualLayoutSectionDataType('longblob');
+  }

Can we add an assertion before the updates run. To test for what it is now.

pooja saraah’s picture

StatusFileSize
new11.43 KB
new651 bytes

Addressed the Comment #55
Attached patch against Drupal 10.1.x

pooja saraah’s picture

Status: Needs work » Needs review
catch’s picture

Status: Needs review » Needs work

#56 isn't quite doing what #55 asked for, but it also shows that the test isn't testing what it thinks it is, since it'll pass even without the update running.

solideogloria’s picture

Consider looking at this related issue, which I think is a better idea.

rohan-sinha’s picture

Status: Needs work » Needs review
StatusFileSize
new11.49 KB
new682 bytes

Addressed #55 adding an assertion after to the check the expected value after test run.

smustgrave’s picture

Status: Needs review » Needs work

Per #58 the tests should be looked at as they don't appear to be testing what's expected.

rohan-sinha’s picture

Status: Needs work » Needs review
StatusFileSize
new9.51 KB

hii, The above patch failed because the branch has been updated with file layout-builder.php, so removing the file from the patch and adding assertion after to the check the expected value after test run, addressed #55.

rohan-sinha’s picture

StatusFileSize
new1.94 KB

Attaching interdiff, thanks.

Status: Needs review » Needs work

The last submitted patch, 62: 3030154-62.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

weseze’s picture

Patch #42 works very well for us on D9.5.

We are using a heavily customized layout builder setup though.
It contains inline block_content for section configuration through https://www.drupal.org/project/layout_block
It also contains a few dozen block_content types for actual section content.
All of these blocks have 50+ fields on them. (some of them coming close to 100 fields)
We only had issues when using the section_library module. Related issue that reference me here: https://www.drupal.org/project/section_library/issues/3232071

finex’s picture

Hi, could this patch considered as "safe" for production environment or is still under development? Thank you very much.

pyrello’s picture

@FiNeX FWIW, we've been using this in production for a while now and I would consider it safe.

heddn made their first commit to this issue’s fork.

heddn’s picture

#3118014: Additional blob field sizes in schema definitions is now in RTBC. If it lands before this, I could easily see us switching from a blob:big to blob:medium.

heddn’s picture

Status: Needs work » Needs review
Issue tags: -Needs upgrade path tests

This is ready for review again after a rebase + some changes. Tests pass green.

smustgrave’s picture

Status: Needs review » Postponed

We should postpone this one then.

But pipeline is green so that's good and probably an easy update when the other lands.

jastraat made their first commit to this issue’s fork.

jastraat’s picture

Status: Postponed » Needs review

I'd like to suggest reopening this issue since the previously linked issue is now needs work and labeled a feature request.

daffie’s picture

Status: Needs review » Postponed

#3118014: Additional blob field sizes in schema definitions needs to land before we can work on this issue.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

ivanbarr’s picture

StatusFileSize
new12.4 KB