backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 40 forks source link

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'backdrop.simpletestXXXXXXcache_admin_bar' doesn't exist: #6049

Open klonos opened 1 year ago

klonos commented 1 year ago

While working on #2450 , a PR which included multiple calls to cache('admin_bar')->flush(); has been trowing these failures/errors:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'backdrop.simpletest508566cache_admin_bar' doesn't exist:
    TRUNCATE {cache_admin_bar} ; Array

I have followed a trail of the following d.org issues (in no particular order):

...which have lead me to https://drupal.stackexchange.com/questions/193879/drush-cache-clear-corrupting-database, which in turn suggests a possible issue with certain versions on MySQL:

...this error can be related to newer version of MySQL, as of 5.5.7, InnoDB always uses the fast truncation technique (which is equivalent to DROP TABLE and CREATE TABLE). So it no longer performs a row-by-row delete for tables with parent-child foreign key relationships, therefore TRUNCATE TABLE returns an error for such tables.

See: 2.11.1.1 Changes Affecting Upgrades to 5.5

The KB article suggests (among other things):

  • ...
  • You may also consider the condition like
    if ($mysqlversion > 5.57 AND $cache_table_type = 'innodb') { // DELETE } else { // TRUNCATE }
  • or wait until the fix is provided for Drupal core (https://www.drupal.org/node/2229013)

The last link to that core d.org issue has been closed as a duplicate of https://www.drupal.org/project/drupal/issues/2684359

Opening this issue in order to not derail #2450 with troubleshooting that, and because this might end up being another MySQL-related (version-specific) issue, like #5496.

klonos commented 1 year ago

...I plan to test the PR at https://github.com/backdrop/backdrop/pull/4377 with various MySQL/MariaDB versions on my local, and report back if tests only fail with specific versions.

argiepiano commented 1 year ago

Is this somewhat related to https://github.com/backdrop/backdrop-issues/issues/5943?

klonos commented 1 year ago

Yes, it could be related/similar @argiepiano, although not the same I think. The queries that throw the errors in #5943 seem to be different.

klonos commented 1 year ago

Well, the fix was as simple as wrapping cache('admin_bar')->flush(); with a if (db_table_exists('cache_admin_bar')) conditional (see this commit). That fixed the failing tests, however, I then thought that since we need to be doing that (and we are doing it in many other places as well), then why not add that check in the cache_flush() function. I attempted to do that with this commit here, but that started causing other test failures in book.test, taxonomy.test, and user.test. So instead of diving deeper into that rabbit hole, I have reverted and thought that we'd leave that for further investigation/troubleshooting/experimentation here.