Create a phpstorage backend that works with a local disk but coordinates across multiple webheads

Created on 10 July 2014, almost 10 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

Drupal saves its service container in the database by default. In some cases (which?), users may want to save the container to disk instead.

The container cache does no checking for a stale container. If the container exists, and the mtime-hash matching is ok, it is loaded.

Thus, any Drupal event that should lead to a new container must take care to remove the old one, so a new one will be built.

For a multiple webhead site, this requires a) that we put the cached php on a shared disk, or b) that we make sure to provide a custom container loader implementation that checks a central location to determine if the locally cached container is stale.

a) is scary for a lot of reasons, so this issue is about making b) work.

Proposed resolution

Keep track of the container state so that Drupal is aware when a local container file needs to be rebuilt. This patch adds Drupal\Core\PhpStorage\CoordinatedMTimeProtectedFileStorage.

CoordinatedMTimeProtectedFileStorage extends MTimeProtectedFileStorage and does two things:

- overrides MTimeProtectedFileStorage::getFullPath() to incorporate a counter, which is fetched from a global store
- overrides MTimeProtectedFileStorage::deleteAll() to increment the counter

Remaining tasks

TBD

User interface changes

None.

API changes

  • Add Drupal\Core\AtomicCounter\AtomicCounterInterface to provide a centralised count interface
  • Add Drupal\Core\PhpStorage\CoordinatedMTimeProtectedFileStorage which utilises the AtomicCounter to mark containers stale on delete

To enable it, add this to settings.php

$settings['php_storage']['service_container'] = array(
  'class' => 'Drupal\Core\PhpStorage\CoordinatedMTimeProtectedFileStorage',
);
πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
CacheΒ  β†’

Last updated about 1 hour ago

Created by

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.69.0 2024