From c21a37e77af7b997216d004d2e5a2dea2f0930cf Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 20 May 2009 23:29:54 +0000 Subject: [PATCH] - web: the logic for using read-only DB replicas was messed up svn path=/trunk/boinc/; revision=18182 --- checkin_notes | 6 ++++++ html/inc/boinc_db.inc | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/checkin_notes b/checkin_notes index b7728ce436..e890d520d1 100644 --- a/checkin_notes +++ b/checkin_notes @@ -4680,3 +4680,9 @@ Rom 20 May 2009 lib/ stackwalker_win.cpp + +David 20 May 2009 + - web: the logic for using read-only DB replicas was messed up + + html/inc/ + boinc_db.inc diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index c92936c9ff..6ba6a5a974 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -23,6 +23,10 @@ class BoincDb extends DbConn { static $instance; // connect to the database (possibly to a read-only replica) + // NOTE: choice of replica can be made only at the page level. + // If there's a page that's guaranteed to do only reads, put + // BoincDb::get(true); + // at the top of it. // static function get_aux($readonly) { $config = get_config(); @@ -37,13 +41,17 @@ class BoincDb extends DbConn { $instance = new DbConn(); if ($readonly && $replica_host) { $retval = $instance->init_conn($user, $passwd, $replica_host, $name); - if ($retval) return $instance; + if ($retval) { + self::$instance = $instance; + return $instance; + } } $retval = $instance->init_conn($user, $passwd, $host, $name); if (!$retval) { $instance = null; } else { $instance->do_query("use $name"); + // needed for places where we do direct queries } self::$instance = $instance; return $instance;