mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-82171 core: Rewarm bootstrap.php after a cache purge
This commit is contained in:
parent
4197e50fec
commit
31e0fd81a7
@ -1262,6 +1262,9 @@ function purge_other_caches() {
|
||||
remove_dir($CFG->localcachedir, true);
|
||||
set_config('localcachedirpurged', time());
|
||||
make_localcache_directory('', true);
|
||||
|
||||
// Rewarm the bootstrap.php files so the siteid is always present after a purge.
|
||||
initialise_local_config_cache();
|
||||
\core\task\manager::clear_static_caches();
|
||||
}
|
||||
|
||||
|
@ -680,19 +680,29 @@ if (PHPUNIT_TEST and !PHPUNIT_UTIL) {
|
||||
}
|
||||
|
||||
// Load any immutable bootstrap config from local cache.
|
||||
$bootstrapcachefile = $CFG->localcachedir . '/bootstrap.php';
|
||||
if (is_readable($bootstrapcachefile)) {
|
||||
$bootstraplocalfile = $CFG->localcachedir . '/bootstrap.php';
|
||||
$bootstrapsharedfile = $CFG->cachedir . '/bootstrap.php';
|
||||
|
||||
if (!is_readable($bootstraplocalfile) && is_readable($bootstrapsharedfile)) {
|
||||
// If we don't have a local cache but do have a shared cache then clone it,
|
||||
// for example when scaling up new front ends.
|
||||
make_localcache_directory('', true);
|
||||
copy($bootstrapsharedfile, $bootstraplocalfile);
|
||||
}
|
||||
if (is_readable($bootstraplocalfile)) {
|
||||
try {
|
||||
require_once($bootstrapcachefile);
|
||||
require_once($bootstraplocalfile);
|
||||
// Verify the file is not stale.
|
||||
if (!isset($CFG->bootstraphash) || $CFG->bootstraphash !== hash_local_config_cache()) {
|
||||
// Something has changed, the bootstrap.php file is stale.
|
||||
unset($CFG->siteidentifier);
|
||||
@unlink($bootstrapcachefile);
|
||||
@unlink($bootstraplocalfile);
|
||||
@unlink($bootstrapsharedfile);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
// If it is corrupted then attempt to delete it and it will be rebuilt.
|
||||
@unlink($bootstrapcachefile);
|
||||
@unlink($bootstraplocalfile);
|
||||
@unlink($bootstrapsharedfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -876,9 +876,17 @@ function initialise_cfg() {
|
||||
function initialise_local_config_cache() {
|
||||
global $CFG;
|
||||
|
||||
$bootstrapcachefile = $CFG->localcachedir . '/bootstrap.php';
|
||||
$bootstraplocalfile = $CFG->localcachedir . '/bootstrap.php';
|
||||
$bootstrapsharedfile = $CFG->cachedir . '/bootstrap.php';
|
||||
|
||||
if (!empty($CFG->siteidentifier) && !file_exists($bootstrapcachefile)) {
|
||||
if (!is_readable($bootstraplocalfile) && is_readable($bootstrapsharedfile)) {
|
||||
// If we don't have a local cache but do have a shared cache then clone it,
|
||||
// for example when scaling up new front ends.
|
||||
make_localcache_directory('', true);
|
||||
copy($bootstrapsharedfile, $bootstraplocalfile);
|
||||
}
|
||||
|
||||
if (!empty($CFG->siteidentifier) && !file_exists($bootstrapsharedfile) && defined('SYSCONTEXTID')) {
|
||||
$contents = "<?php
|
||||
// ********** This file is generated DO NOT EDIT **********
|
||||
\$CFG->siteidentifier = " . var_export($CFG->siteidentifier, true) . ";
|
||||
@ -889,10 +897,15 @@ if (\$CFG->bootstraphash === hash_local_config_cache() && !defined('SYSCONTEXTID
|
||||
}
|
||||
";
|
||||
|
||||
$temp = $bootstrapcachefile . '.tmp' . uniqid();
|
||||
// Create the central bootstrap first.
|
||||
$temp = $bootstrapsharedfile . '.tmp' . uniqid();
|
||||
file_put_contents($temp, $contents);
|
||||
@chmod($temp, $CFG->filepermissions);
|
||||
rename($temp, $bootstrapcachefile);
|
||||
rename($temp, $bootstrapsharedfile);
|
||||
|
||||
// Then prewarm the local cache as well.
|
||||
make_localcache_directory('', true);
|
||||
copy($bootstrapsharedfile, $bootstraplocalfile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1922,6 +1935,9 @@ function make_localcache_directory($directory, $exceptiononerror = true) {
|
||||
touch($timestampfile);
|
||||
@chmod($timestampfile, $CFG->filepermissions);
|
||||
clearstatcache();
|
||||
|
||||
// Then prewarm the local boostrap.php file as well.
|
||||
initialise_local_config_cache();
|
||||
}
|
||||
|
||||
if ($directory === '') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user