From 8eb8dcc8425295d1a4278613031812bff7d98c15 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 1 Jul 2009 08:11:27 +0000 Subject: - Patch #314358 by wonder95, Crell, killes, et al: add option to ignore slave servers. Finally. --- modules/system/system.module | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'modules/system/system.module') diff --git a/modules/system/system.module b/modules/system/system.module index 7a2667457..567cf8989 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -872,8 +872,32 @@ function system_init() { drupal_add_css(drupal_get_path('module', 'system') . '/defaults.css'); drupal_add_css(drupal_get_path('module', 'system') . '/system.css'); drupal_add_css(drupal_get_path('module', 'system') . '/system-menus.css'); + + + // Ignore slave database servers for this request. + // + // In Drupal's distributed database structure, new data is written to the master + // and then propagated to the slave servers. This means there is a lag + // between when data is written to the master and when it is available on the slave. + // At these times, we will want to avoid using a slave server temporarily. + // For example, if a user posts a new node then we want to disable the slave + // server for that user temporarily to allow the slave server to catch up. + // That way, that user will see their changes immediately while for other + // users we still get the benefits of having a slave server, just with slightly + // stale data. Code that wants to disable the slave server should use the + // db_set_ignore_slave() function to set $_SESSION['ignore_slave_server'] to + // the timestamp after which the slave can be re-enabled. + if (isset($_SESSION['ignore_slave_server'])) { + if ($_SESSION['ignore_slave_server'] >= REQUEST_TIME) { + Database::ignoreTarget('default', 'slave'); + } + else { + unset($_SESSION['ignore_slave_server']); + } + } } + /** * Implement MODULE_preprocess_HOOK(). */ -- cgit v1.2.3