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.
| Comment | File | Size | Author |
|---|
Issue fork drupal-2662844
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
Comment #2
penyaskitoComment #4
dawehnerif the goal is to remove the usage of using APC you can achieve something similar using:
This will just replace the cache backend with the database one always.
Comment #5
alexpottHmmm... drush and APC - this sounds like a CLI vs webhead issue.
Comment #6
dawehnerWell, 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.
Comment #7
dawehnerHere 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_typeand the cache tagentity_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.
Comment #8
anavarreJust noting that #2722615: Chained fast caching interferes with field creation might be a similar bug report.
Comment #9
danepowell commentedPer #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:
Comment #10
dawehnerWell 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.
Comment #11
penyaskitoNice idea, @dawehner. Here is a patch that does exactly that.
Comment #12
dawehnerWould work for me, given it solves issues out there. Its still sort of a small BC break.
Comment #13
catchtrigger_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.
Comment #14
dawehnerThis is a good plan. Let's see when @penyaskito has time to do that.
/me shakes the head about 8MB, just 8MB, yes just 8MBComment #15
penyaskitoHad 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.
Comment #16
penyaskitoCreated 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.
Comment #17
dawehnerThis addresses the feedback from catch, great!
Comment #20
catchCommitted/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!
Comment #21
alexpottComment #23
chx commentedIf 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.
Comment #24
chx commentedI can't reopen this one so I reopened the followup.
Comment #25
dawehnerOPened #2808569: Ensure that ChainedFastBackend doesn't cause a fatal
Comment #26
dawehnerWe need to revert that one as well. I'm trying to write a regression test for that.
Comment #27
dawehnerHere is kind of a start
Comment #30
catchThis 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
Comment #34
anavarreComment #35
jibranShould we combine #27 and #15.
Comment #36
dinesh18 commentedRe-rolled patch #27
Comment #37
dinesh18 commentedComment #39
yogeshmpawarMaybe this will fix test issue & also added an interdiff.
Comment #41
yogeshmpawarHopefully this will solve the test issue & also added an interdiff.
Comment #52
gappleNot 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 inChainedFastBackend, but I think havingChainedFastBackendFactoryhandle checking that the configured backends are different would be safer.Comment #54
gappleComment #55
gappleComment #58
smustgrave commentedThis 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.
What was found and how was it fixed?
Comment #59
catchThe approach in the merge request looks OK to me, but none of the previous attempts at test coverage will be relevant with that approach.
Comment #60
Yogesh Sahu commentedAttached patch against Drupal 10.1.x
Comment #61
gapple@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.
Comment #62
gappleRebased the MR, and added tests for the
ChainedFastBackendFactoryclass.Comment #63
smustgrave commentedSeems close to ready just some CI failures in the MR
Comment #64
gappleHopefully just the quick fix to pass spellcheck
Comment #65
smustgrave commentedRemoving 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
Comment #66
gappletestDifferentServices()uses the correct way to instantiate the factory, so should pass both before and after.Comment #68
catchCommitted 9124793 and pushed to 10.1.x. Thanks!