Problem/Motivation
According to Drupal's advice, when we change the default transaction isolation level from "REPEATABLE READ" to READ-COMMITTED for databases, the following error is reported.
Transaction isolation level:READ-COMMITTED
Error:
For this to work correctly, all tables must have a primary key. The following table(s) do not have a primary key: forum_index. See the setting MySQL transaction isolation level page for more information.
Steps to reproduce
Install forum module in Drupal 10.1
Visit admin/reports/status
View warning about forum_index table missing primary key.
Proposed resolution
Add a primary key to the forum_index table
Remaining tasks
Review
Commit
User interface changes
API changes
Data model changes
Release notes snippet
A new index is added to the forum_index table to make it compatible with the recommended READ-COMMITTED transaction isolation level.
Comments
Comment #1
Anonymous (not verified) commentederdm created an issue. See original summary.
Comment #2
larowlanComment #3
larowlanComment #4
larowlanI think we could make the 'forum_topics' index the primary key
Comment #7
sakthi_dev commentedPlease review.
Comment #8
larowlanThanks, left a comment on the MR
Comment #9
sakthi_dev commentedPlease review.
Comment #10
daffie commentedNow we need 2 tests:
1. A kernel test, that after we install the forum module and have created its tables, the table "forum_index" has a primary key and that it is based on the fields "nid" and "tid"
2. A update test, that before we run the update process the table does not have a primary key and the we run the update it does.
Comment #11
Anonymous (not verified) commentedComment #12
klemendev commentedIs it possible to use forum module under Drupal 10.1.x given it throws errors about this?
My test update page from 10.0.x to 10.1.x now shows this error on status page about this problem and I am not sure what exactly this means for the website operation?
If this breaks websites using forum, shouldn't this be higher than normal priority?
Comment #13
Anonymous (not verified) commentedActually, I opened this message separately under the forum module. Because in the new drupal plans, forum module will be separated from the core and I thought it would be more accurate to follow it there. But it is taken here to be followed under D9.5 dev version. There should be something they know. Not a big deal.
I didn't use the one in the Core module, I installed it with composer and patched it in the separate forum module.
Maybe it is necessary to create a separate node type for forums. Considering for the future, maybe the support will be completely removed.
When I create it as a node type, the error goes away, but I'm not sure if it will get as much performance as the forum module.
Comment #14
klemendev commentedHmm, I am a bit confused. I use D10 and the Forum is still in the core. I also don't recall the forum module being marked as deprecated compared to other modules moved to the contrib.
Comment #15
larowlanWe made a copy into contrib in preparation for removal from core but it didn't get done in time.
We still plan to do it during the D11 cycle, its just proven tricky
Comment #16
larowlanComment #17
klemendev commentedI am sorry for asking that much, but I think I did not get the answer yet, it may also be relevant to others (all other people updating to Drupal 10.1.x and using forum module):
Should I keep D 10.0.x, not use READ-COMMITED, ignore the error, manually add primary key to the table (which columns?) or what action is recommended to the users of D10+forum until this gets merged?
Comment #18
larowlan@KlemenDEV ideally we all work to get this into the next bugfix release of 10.1 (July)
Comment #19
larowlanBumping priority now that 10.1 is out
Comment #20
larowlan#10 lists remaining items, I'll copy that to the issue summary
Comment #21
klemendev commentedOk, thank you for the clarification and the work on this issue :) I will wait for the next 10.1 release
Comment #22
larowlanRebased the MR off 11.x and added those tests
Comment #28
smustgrave commentedCould the namespaces be off? Not sure "Unable to generate test groups" mean.
Comment #29
larowlanAdded the missing @group
Comment #30
smustgrave commentedThanks!
Don't mind marking this
Only question should MR be updated for 11.x and update hook 10201 instead for 10.2
Comment #31
larowlanI think we might want to consider backporting this, so I went with a 10.1 series update hook number.
But obviously can easily update if needs be.
Comment #32
masipila commentedI don't have a strong opinion whether this should target 10.x or 11 since the SQL transaction isolation level stuff is a bit too low level stuff for me. But with this background and disclaimer:
1. Do we have concerns or policies why we would NOT include this in the 10.x series?
2. If yes, should we at least then update the issue summary so that we explain the impact what this error in the status report means?
Cheers,
Markus
Comment #33
catchWe normally avoid backporting update hooks to patch releases because even simple update hooks can cause problems on updating.
Adding an index is however one of the more simple things we can add, and the worst that happens if it goes wrong is the error message persists.
If we didn't backport, another option would be removing the hook_requiremenths() message and/or filtering out forum_index from it, but in this case I think backport is probably the right option.
One comment on the MR about the update message in the case there's no table.
Comment #34
larowlanNW for the change to the message
Comment #35
larowlanMade that change, thanks
Comment #36
daffie commentedAll code changes look good to me.
The PK has been added.
An update hook has been added.
For both testing has been added.
For me it is RTBC.
Comment #37
klemendev commentedWill this now target 10.1 or 11.x? It is a bit concerning if target is 11 as this means all users using forum module and MYSQL will have to live with error on status page for the whole D10 lifetime.
Comment #38
daffie commented@KlemenDEV: We are first doing 10.1 and 11.x. After that has landed we will backport it to 10.0 and 9.5.
Comment #42
quietone commentedClosed #2979425: Table forum_index needs a primary key to work on Percona as a duplicate, adding credit.
Comment #45
catchCommitted/pushed to 11.x and cherry-picked to 10.1.x, thanks!
I don't think we should backport the update to 10.0.x/9.5.x, but maybe we should exclude forum_index from the error message, so leaving open against 10.0.x to discuss.
Comment #46
larowlanI could be wrong, but I don't see the message about isolation level/PKs in 10.0.x so perhaps this is fixed? I.e the issue doesn't exist in 10.0
Comment #49
quietone commentedClosed #2931620: Forum module can generate integrity constraint violations (duplicate primary key) when saving changes to existing non-default node revisions (can be triggered by d6_term_node_revision migrations) as a duplicate, moving credit.
Comment #50
spokjeLooks like these commits broke HEAD of
10.1.xand11.xon both pgsql and sqlite with a friendly:and
Comment #53
larowlanReverted this
Comment #54
klemendev commentedChecking Drupal commit history, this error message was introduced in 10.1, thus not being shown in 10.0, although the problem itself was present there already
Comment #55
catchLeft a comment on the MR - think we need to run a query to remove duplicates before adding the index. Not sure if this is related to the failures but it needs doing anyway.
That will also make the update more complex than it currently is, so I think for 10.0.x we should suppress the warning just for forum_index rather than fixing it there, then the update will run in 10.1.
Comment #56
larowlanI'm confused, the test passes on pgsql and sqlite (for 11.x)
Comment #57
spokjeThe UI is a disaster zone when multiple MRs are on the same core-dev-branch, but if I look at this snippet from the dispatcher log of the sqllite passing test:
I think (the closed) MR!4162, and not the needed and probably expected from the UI MR!4278 was tested and passed.
Comment #58
larowlanUpdated both branches to use a DB agnostic approach
Comment #59
smustgrave commentedSeemed to cause a failure for pgsql and sqlite
Comment #60
larowlanFixed the other test too
Comment #61
daffie commentedLooks good to me.
The testbot passes for all 3 databases.
Back to RTBC.
Comment #62
catchSorry still think we need to do #55 here too.
Comment #63
sakthi_dev commentedPlease review.
Comment #64
smustgrave commentedComment #65
Anonymous (not verified) commentedError with Merge request !4279
Comment #66
klemendev commentedIs there any workaround that we can use until this gets fixed in the core? This issue is holding back us from updating to Drupal 10.1
Comment #67
larowlanThe patch from comment 60 should be fine to apply.
Comment #68
larowlanHere's the push from #60 as a patch
Comment #69
klemendev commentedThanks, will try it out!
Comment #70
tjtj commentedThis needs a fix in the 10.1 release asap. Uninstalling the module failed, saying that the content had to be deleted, but there is no forum content! I did delete the forums.
So forum, a very important feature of Drupal, is dead.
Comment #71
klemendev commentedGiven #60, is this needs review, or still needs work?
Comment #72
klemendev commentedComment #73
smustgrave commentedSeems there are still open threads in MR 4279
Comment #74
klemendev commentedI have tested the patch from #60 (#68) on copies of some of our websites and it seems to work correctly. Hoping the remaining issues get fixed and this gets into 10.1.x. Forum functionality works and I did not notice anything problematic logged.
As this is holding back the update of many of the websites, could someone with more knowledge on this confirm whether we can use 10.1.x without this patch applied and ignore the status page error, or are there other consequences?
Comment #75
larowlanAddressed the chance of duplicates in latest push with a new fixture and additional update hook and test coverage
Comment #76
daffie commentedThe remark from @catch has been addressed.
The testbot is green for all 3 by core supported databases.
Back to RTBC.
Its a lot of code for "just" adding a primary key.
Comment #77
klemendev commentedVery glad to see this in RTBC :)
Comment #78
catchMore comments on the MR..
Comment #79
larowlanAt first I thought we could use ->limit with a delete query, but we can't so we have to delete all the rows that are duplicates because there's no way with the delete query to only delete the duplicates.
So I'm doing that, then keeping track of the nids we need to recreate via state and looping over those in a post update hook to add back the missing values.
Ready for review again
Comment #80
catchThat looks better now.
Only other idea I had to save the rebuild would be selecting the value of the duplicate rows, deleting it, then writing one row back, but given the duplicate rows it's likely some of the data is inaccurate anyway, so better to have the more complete implementation. Back to RTBC.
Comment #81
alexpottCouple of small comments on the MR.
Comment #82
larowlanMade those changes, nice one re the use of progress 👌
Comment #83
daffie commentedAll points of @alexpott have been addressed.
Back to RTBC.
Comment #84
xjmThe issue summary is very confusing here; there are two MRs. The one that I would guess is for 11.x says it is closed -- which usually makes them disappear from the UI -- and the 10.1.x one appears to be failing PHPCS.
Could we please:
Thanks! Tagging for issue summary update.
Comment #86
larowlanRemoved patches, closed 10.1.x MR
Updated issue summary.
Comment #87
larowlanFailing test in the pipeline looked to be random JS failure in throbber.
Reran.
Back to NR
Comment #90
smustgrave commentedFor the record MR is 4278 for review.
Comment #91
alexpottI think this is still broken on postgres. When I run locally on postgres I see the following error:
I think you could fix this by doing
Instead.
Comment #92
aditi saraf commentedi am not getting such error
Comment #93
joamos commentedGreetings,
Installed D10 all good.
Drupal Version 10.1.5
Web Server Apache/2.4.52 (Ubuntu)
PHP Version 8.2.11
Database Version 8.0.34-0ubuntu0.22.04.1
Did this
To change the database transaction isolation level to "READ COMMITTED" add the following to the database connection array:
'init_commands' => [
'isolation_level' => 'SET SESSION tx_isolation=\'READ-COMMITTED\'',
],
Then activated the forum and got the error as described in the first post.
FYI
Jo
Comment #94
larowlanNice nice, gitlab ci had the same fail as reported by @alexpott
https://git.drupalcode.org/project/drupal/-/pipelines/27221/test_report
Pushed a fix for that and manually queued tests on pgsql/sqlite
Comment #95
smustgrave commentedSeems there are fetch errors in the MR?
Comment #96
larowlanPassing in gitlab
Comment #97
smustgrave commentedAny concern this ran on 8.1 sqlite 3 vs 8.2?
Comment #98
catchI kicked off extra runs on various environments, can't have too many environment runs on this issue.
Comment #99
smustgrave commentedAll the test runs seemed to have passed.
Comment #100
jedgar1mx commentedJust upgrade to Drupal 10 and started to get similar errors.
The recommended level for Drupal is "READ COMMITTED". For this to work correctly, all tables must have a primary key. The following table(s) do not have a primary key: taxonomy_term_field_data_delme, taxonomy_term_hierarchy_delme, url_alias_20180508_19, url_alias_20180509_11, url_alias_20180509_12, url_alias_20180510_14, url_alias_20180510_18, url_alias_20180511_11, url_alias_20180511_17, url_alias_20180514_12, url_alias_20180515_11, url_alias_20180515_18, url_alias_20180516_19, url_alias_20180517_11, url_alias_20180518_12, url_alias_20180521_12, url_alias_20180522_13, url_alias_20180523_12, url_alias_20180604.No issues on 9.5.11 and this patch https://www.drupal.org/project/drupal/issues/1650930
Drupal 10.1.6
PHP 8.1
MySQL 5.7.29
Comment #101
alexpottI think we need to test the batching in forum_post_update_recreate_forum_index_rows(). I think drupal-10.1.0.empty.testing.forum.gz needs contain more than 1 duplicate row and we need to run the update with the
entity_update_batch_sizesetting set to 1.Comment #102
mkimmet commentedThe forum seems to work on 10.1.6 despite the error. Since it is an error, is the current advice to not use the forum with 10.1 until this issue is fixed? Is it ok to use the patch from comment 68 to get around the error? Any advice on what to do before this is fixed in 11 would be appreciated. Thanks!
Comment #103
larowlanThe patch from the MR (add .diff to the MR URL) is the best option.
Please report back any issues you have.
I'll try to address the latest feedback today
Comment #104
mkimmet commented@larowlan, thanks for the heads up on ".diff" on the MR URL. I hadn't done that before so I used the following url for the patch, hopefully that was what you meant:
https://git.drupalcode.org/project/drupal/-/merge_requests/4278.diff
I applied the patch and there were no errors, then I ran the database updates and the three updates ran with no errors (there were no duplicates found on update 10101). The error message no longer appears on the status page. Then I did some basic testing, adding forum topics, comments, editing and deleting and everything seemed to work, but like I mentioned everything seemed to work without the patch. Looked at the Drupal logs and don't see any errors or warnings.
I'm running Drupal 10.1.6, Apache/2.4.38 (Debian), PHP 8.1.14, mysql 8.0.33
Do you suggest I proceed with that MR diff patch for production?
Thanks!
Comment #105
larowlan@mkimmet I think it is safe - the remaining work is about adding more testing to the update path.
There is one scenario that might trip you up, if in the process of expanding the tests we find an issue and have to add an additional update hook, that might conflict with your site that has run the old update hooks. If that's the case I'll comment here and can help you resolve that (there are workarounds). It feels unlikely, but I'd be remiss if I didn't flag the possibility.
Thank you for reporting back your results in testing the patch, adding issue credit for that as it is valuable.
One thing to highlight, if you're using https://github.com/cweagans/composer-patches to apply the patch, you should not reference the MR URL directly - instead you should download the file from https://git.drupalcode.org/project/drupal/-/merge_requests/4278.diff, save it in your codebase and apply it using a relative path.
For example if you save the file into a PATCHES folder at the root of your project, in your composer patches entry you would refer to it using
./PATCHES/path-to-the-file.patch.Anyone can push to a MR and there is the risk of a supply chain attack if someone pushed something malicious and your build system is blindly fetching the current diff.
Comment #106
larowlanUpdated the MR, will queue the other DB engines, but they pass locally
Comment #107
ivnishThe patch from MR works for me
Comment #108
smustgrave commentedSeems the MR failed SqlLite and postgreSql
Comment #109
larowlanReran the failing jobs, looks random
Comment #110
smustgrave commentedAh gotcha
Comment #111
brunodboAs described in #105, I downloaded the patch from the MR, saved it to a file, then tried applying it using https://github.com/cweagans/composer-patches, but that failed. The patch in #60 did work. I was using Drupal 10.1.6 when testing.
Using a checkout of core's 10.1 branch, I applied the patch from the MR manually, and it produced the following output:
Could this be an issue with https://github.com/cweagans/composer-patches not handling the test fixtures properly?
Comment #112
larowlanYou need to use
git apply --binarywhen there are binary filesComment #113
alexpottRepeating my comment from #101
I think we need to test the batching in forum_post_update_recreate_forum_index_rows(). I think drupal-10.1.0.empty.testing.forum.gz needs contain more than 1 duplicate row and we need to run the update with the entity_update_batch_size setting set to 1.
Comment #114
larowlanThat was added in https://git.drupalcode.org/project/drupal/-/merge_requests/4278/diffs?co..., unless I misunderstood what is being asked
Comment #115
alexpottBah... missed it. Thanks @larowlan
Comment #116
alexpottCommitted f00184d and pushed to 11.x. Thanks!
Comment #118
alexpottDiscussed backporting this to 10.2.x with @catch and we agreed to do it because a user can not get around the warning and it avoids "major release crossover hell".
Comment #120
ivnishYeah, thanks for 10.2.x !
Comment #121
leeksoup commentedI'm having the same problem with Drupal 10.1.6. So just to check, this will be fixed in later versions 10.2 and after? Is it OK to continue to use the site until then, or do I need to disable the Forum module for now?
Thanks.
Comment #122
larowlanYes, you're fine to keep running the patch/MR diff here until 10.2 is released.
Comment #123
leeksoup commented@larowlan - sorry, which patch / MR? The one in #68 or something else? Nvm this question - I see the answer at #105.
Can I just wait until 10.2 comes out, or will that break something?
Thanks.
Comment #124
larowlanThis was the MR https://git.drupalcode.org/project/drupal/-/merge_requests/4278
Comment #125
leeksoup commentedThank you. I applied the patch and it fixed the error.
Posting the link for how to patch with composer here in case it's of use to others. https://www.drupal.org/docs/develop/using-composer/manage-dependencies#p...
Comment #127
b_sharpe commentedJust adding a 10.1 patch for composer.