[livejournal] r17414: Better handling of DB pairs wihtout "ina...
Committer: gariev
Better handling of DB pairs wihtout "inactive" serverU trunk/cgi-bin/LJ/DBUtil.pm
Modified: trunk/cgi-bin/LJ/DBUtil.pm
===================================================================
--- trunk/cgi-bin/LJ/DBUtil.pm 2010-09-20 10:26:54 UTC (rev 17413)
+++ trunk/cgi-bin/LJ/DBUtil.pm 2010-09-20 10:55:01 UTC (rev 17414)
@@ -46,4 +46,27 @@
return 1;
}
+## get cluster DB handler, preferred order: inactive DB, active DB
+sub connect_to_cluster {
+ my $class = shift;
+ my $clid = shift;
+ my $verbose = shift;
+
+ my $dbr = ($LJ::IS_DEV_SERVER) ?
+ LJ::get_cluster_reader($clid) : LJ::DBUtil->get_inactive_db($clid);
+ unless ($dbr) {
+ warn "Using master database for cluster #$clid"
+ if $verbose;
+ $dbr = LJ::get_cluster_reader($clid);
+ }
+
+ die "Can't get DB connection for cluster #$clid"
+ unless $dbr;
+ $dbr->{RaiseError} = 1;
+
+ warn "Connected to cluster #$clid" if $verbose;
+
+ return $dbr;
+}
+
1;
