Problem/Motivation

cache.backend.chainedfast doesn't like it if the fast and persistent backend is set to the same thing.

This is unsupported so we can't make it 'work'.

Steps to reproduce:

1. Append to your services.yml:

services:
  cache.backend.chainedfast:
    class: Drupal\Core\Cache\ChainedFastBackendFactory
    arguments: ['@settings', 'cache.backend.database', 'cache.backend.database']
    calls:
      - [setContainer, ['@service_container']]

2. drush cr --yes
3. Enable aggregator module.
4. You get a undefined entity exception

Proposed resolution

Originally, the patch triggered an error when this configuration was found, but this is too low level to be safe - see comments from @chx.

The new approach in the MR detects this case and only sets the persistent backend, leaving the fast backend unset, so this will 'silently work'.

Remaining tasks

Add test coverage if possible.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork drupal-2662844

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

penyaskito created an issue. See original summary.

penyaskito’s picture

Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

if the goal is to remove the usage of using APC you can achieve something similar using:

services:
  cache.backend.chainedfast:
    class: Drupal\Core\Cache\DatabaseBackendFactory
    arguments: ['@database', '@cache_tags.invalidator.checksum']

This will just replace the cache backend with the database one always.

alexpott’s picture

Hmmm... drush and APC - this sounds like a CLI vs webhead issue.

dawehner’s picture

Well, I'm seriously wondering whether its a good idea to use the same backend for both fast and non fast cache backend.

In theory the hosting environment though should be able to deal with APC in the first place.

dawehner’s picture

Here is my theory why the snipped above isn't working at all, nor was ever tried out:

Given:

The fast chained backend doesn't implement cache tags support, but rather relies on a timestamp which is set, once any invalidation/set function is triggered.
In that case, the fast chained backend falls back to the less fast backend, which implements cache tags, so in theory cache tag invalidation continues to work.

What happens:

In the particular case above for entity types, we use a cache ID entity_type and the cache tag entity_types. We have the same cache backend injected for both the fast and the non fast backend. Given that we store cache entries in the fast backend with no cache tags, we override the entries in the non fast backend with cache tags. This results in having effectively no invalidations on the slow backend anymore at all, which results, in this particular example, that we retrieve a cache entry from before the invalidation, and by that an old list of entity types.

We could apply some level of validation: Don't inject the same cache backend twice into the chained fast backend. We could implement some level of invalidation on container build time, to tell people, that this is BS.

anavarre’s picture

Just noting that #2722615: Chained fast caching interferes with field creation might be a similar bug report.

danepowell’s picture

Per #2722615: Chained fast caching interferes with field creation, a more serious sort of misbehavior is that with the snippet in the OP added to services.yml, you can no longer create new fields on content types, block types, etc.... You get an error like this:

There was a problem creating field foo: Attempt to create a field field_foo that does not exist on entity type node.

dawehner’s picture

Per #2722615: Chained fast caching interferes with field creation, a more serious sort of misbehavior is that with the snippet in the OP added to services.yml, you can no longer create new fields on content types, block types, etc.... You get an error like this:

Well yeah, I don't know who came up with that snippet in the first place, but its clearly just wrong. The only thing we can do is to check in the constructor,
when the two different backends are the same and throw some exception or so.

penyaskito’s picture

Status: Active » Needs review
StatusFileSize
new2.03 KB

Nice idea, @dawehner. Here is a patch that does exactly that.

dawehner’s picture

Would work for me, given it solves issues out there. Its still sort of a small BC break.

catch’s picture

trigger_error() would avoid the fatal while still warning site owners that something is wrong. It's not impossible that this configuration could exist only on production via site specific services, so it'd be a nasty surprise if you updated and got this.

We could then change it to an exception another minor release out, since by then no existing installs should have the issue.

dawehner’s picture

Status: Needs review » Needs work

This is a good plan. Let's see when @penyaskito has time to do that.

/me shakes the head about 8MB, just 8MB, yes just 8MB

penyaskito’s picture

Status: Needs work » Needs review
Issue tags: +DrupalNorth2016
StatusFileSize
new2.23 KB

Had some time.
No interdiff, as the interdiff was bigger than the patch itself.
I don't know how to document a trigger_error in phpdoc, so left the @throws in place. It won't hurt, and will be true as soon as we can do that responsibly.

penyaskito’s picture

Created follow-up in #2751847: Throw exception if the same service is injected twice in ChainedFastBackend for throwing an exception in future releases as catch suggested in #13.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

This addresses the feedback from catch, great!

  • catch committed 4eb87a2 on 8.2.x
    Issue #2662844 by penyaskito, dawehner, catch: cache.backend.chainedfast...

  • catch committed 9d7f33f on 8.1.x
    Issue #2662844 by penyaskito, dawehner, catch: cache.backend.chainedfast...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!

alexpott’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

chx’s picture

If you have the config in services.yml as mentioned in the IS then you can't upgrade from 8.1 to 8.2 as the first drupal_rebuild() will trigger_error which sends the logger into a circular dependency and thus the whole thing collapses with multiple fatals.

chx’s picture

I can't reopen this one so I reopened the followup.

dawehner’s picture

dawehner’s picture

Status: Closed (fixed) » Needs review

We need to revert that one as well. I'm trying to write a regression test for that.

dawehner’s picture

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

Here is kind of a start

  • alexpott committed 2766d1a on 8.3.x
    Revert "Issue #2662844 by penyaskito, dawehner, catch: cache.backend....

  • alexpott committed d10d629 on 8.2.x
    Revert "Issue #2662844 by penyaskito, dawehner, catch: cache.backend....
catch’s picture

Title: cache.backend.chainedfast misbehaves in some situations » cache.backend.chainedfast misbehaves when both fast and consistent backends point to the same storage
Version: 8.1.x-dev » 8.2.x-dev

This was released in 8.1.4 - people have either run into that regression and resolved it, or haven't upgraded yet. If they haven't upgraded yet, they're more likely to upgrade to 8.2.x when it comes out anyway.

So moving up to 8.2.x

  • catch committed 4eb87a2 on 8.4.x
    Issue #2662844 by penyaskito, dawehner, catch: cache.backend.chainedfast...
  • alexpott committed 2766d1a on 8.4.x
    Revert "Issue #2662844 by penyaskito, dawehner, catch: cache.backend....

  • catch committed 4eb87a2 on 8.4.x
    Issue #2662844 by penyaskito, dawehner, catch: cache.backend.chainedfast...
  • alexpott committed 2766d1a on 8.4.x
    Revert "Issue #2662844 by penyaskito, dawehner, catch: cache.backend....

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

anavarre’s picture

Version: 8.3.x-dev » 8.4.x-dev
jibran’s picture

Should we combine #27 and #15.

dinesh18’s picture

StatusFileSize
new2.71 KB

Re-rolled patch #27

dinesh18’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 36: 2662844-32.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new2.62 KB
new643 bytes

Maybe this will fix test issue & also added an interdiff.

Status: Needs review » Needs work

The last submitted patch, 39: 2662844-39.patch, failed testing. View results

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new2.64 KB
new580 bytes

Hopefully this will solve the test issue & also added an interdiff.

Status: Needs review » Needs work

The last submitted patch, 41: 2662844-41.patch, failed testing. View results

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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.

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.

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.

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.

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.

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.

gapple’s picture

Not sure what's up with the patch in #27 and rebases in #36, #39, and #41 - it looks to me like some unrelated test cases, and a test class for ChainedFastBackend that doesn't do anything yet.

----

#14 modified ChainedFastBackend, which appeared to cause problems and was reverted. Maybe still useful to be strict in ChainedFastBackend, but I think having ChainedFastBackendFactory handle checking that the configured backends are different would be safer.

gapple’s picture

Title: cache.backend.chainedfast misbehaves when both fast and consistent backends point to the same storage » 2662844-chainedfast-same-storage
Status: Needs work » Needs review
gapple’s picture

Title: 2662844-chainedfast-same-storage » cache.backend.chainedfast misbehaves when both fast and consistent backends point to the same storage

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.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Think the issue summary needs an update.

Research why this happens and fix.

What was found and how was it fixed?

catch’s picture

Issue summary: View changes

The approach in the merge request looks OK to me, but none of the previous attempts at test coverage will be relevant with that approach.

Yogesh Sahu’s picture

StatusFileSize
new25.45 KB

Attached patch against Drupal 10.1.x

gapple’s picture

@Yogesh Sahu, your patch looks like it's done a PSR-2 reformatting of the entire file, and it's unclear what changes your patch is based on.

gapple’s picture

Status: Needs work » Needs review

Rebased the MR, and added tests for the ChainedFastBackendFactory class.

smustgrave’s picture

Status: Needs review » Needs work

Seems close to ready just some CI failures in the MR

gapple’s picture

Status: Needs work » Needs review

Hopefully just the quick fix to pass spellcheck

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs issue summary update

Removing issue summary update as that looks completed in #59

When I ran the tests locally without the fix

testIdenticalService failed with "Symfony\Component\DependencyInjection\ContainerInterface::get('cache.backend.test', 1): object was not expected to be called more than once." = GOOD

testDifferentServices = Passed.

Shouldn't both tests fail?

If I got that wrong then think this is good to be marked RTBC

gapple’s picture

Status: Needs work » Reviewed & tested by the community

testDifferentServices() uses the correct way to instantiate the factory, so should pass both before and after.

  • catch committed 91247936 on 10.1.x
    Issue #2662844 by gapple, yogeshmpawar, penyaskito, dawehner, catch,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 9124793 and pushed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.