Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[livejournal] r17414: Better handling of DB pairs wihtout "ina...

Committer: gariev
Better handling of DB pairs wihtout "inactive" server
U   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;

Tags: gariev, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments