? .DS_Store ? Drupal7.kpf ? ignore_slave.patch ? ignore_slave_3.patch ? ignore_slave_4.patch ? sites/.DS_Store ? sites/default/files ? sites/default/settings.php Index: includes/database/database.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/database.inc,v retrieving revision 1.55 diff -u -p -r1.55 database.inc --- includes/database/database.inc 17 Jun 2009 13:40:26 -0000 1.55 +++ includes/database/database.inc 20 Jun 2009 06:01:23 -0000 @@ -2687,6 +2687,22 @@ function db_rewrite_sql($query, $primary return $query; } +/** + * Helper function to get duration lag from variable + * if one isn't passed, and then set the session variable + * that contains the lag. + * + * @param $duration + * The amount of time to ignore the slave to give it + * time to refresh after an insert or update. + */ +function db_set_ignore_slave($duration = NULL) { + if (!$duration) { + $duration = variable_get('maximum_replication_lag', 10); + } + drupal_set_session('ignore_slave_server', REQUEST_TIME + $duration); +} + /** * @} End of "ingroup database-legacy". Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.723 diff -u -p -r1.723 comment.module --- modules/comment/comment.module 15 Jun 2009 19:28:55 -0000 1.723 +++ modules/comment/comment.module 20 Jun 2009 06:01:23 -0000 @@ -930,6 +930,9 @@ function comment_save($edit) { 'homepage' => $edit['homepage'], )) ->execute(); + // Ignore slave server temporarily to give time for the + // saved node to be propagated to the slave + db_set_ignore_slave(); // Tell the other modules a new comment has been submitted. comment_invoke_comment($edit, 'insert'); // Add an entry to the watchdog log. Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1070 diff -u -p -r1.1070 node.module --- modules/node/node.module 12 Jun 2009 08:39:38 -0000 1.1070 +++ modules/node/node.module 20 Jun 2009 06:01:23 -0000 @@ -1034,6 +1034,10 @@ function node_save($node) { // Clear the page and block caches. cache_clear_all(); + + // Ignore slave server temporarily to give time for the + // saved node to be propagated to the slave + db_set_ignore_slave(); } /** Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.712 diff -u -p -r1.712 system.module --- modules/system/system.module 16 Jun 2009 08:41:35 -0000 1.712 +++ modules/system/system.module 20 Jun 2009 06:01:23 -0000 @@ -842,6 +842,28 @@ 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']); + } + } } /**