CodeIgniter Forums
High Availability with Master / Master Mysql Setup - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: High Availability with Master / Master Mysql Setup (/showthread.php?tid=43657)



High Availability with Master / Master Mysql Setup - El Forum - 07-19-2011

[eluser]Eric Brown[/eluser]
I'm trying to implement failover logic into my code. I'd like to get some opinions on how to best do this. Essentially all of my writes should go to "DB01" but if the connection is unavailable because the server crashed or it's under high load or there is a routing issue, I'd like the app to fail over to DB02. Here's what I have. Thanks for your comments and suggestions

Code:
//Load DB01 Master
            $this->db = $this->load->database('db01',TRUE);
            if($this->db->conn_id!=""){
                // verify DB01 master connected
                $this->db_connected == TRUE;
            }
            else{
                // if not connected, fail over to second master
                // Load DB02 Master
                $this->db = $this->load->database('db02',TRUE);
                if($this->db->conn_id!=""){
                    $this->db_connected == TRUE;
                }
                else{
                    // if not connected, no database connection available
                    $this->db_connected == FALSE;
                }
            }



High Availability with Master / Master Mysql Setup - El Forum - 07-21-2011

[eluser]LynxCoder[/eluser]
Ironically, i looked through the forum before I posted my query, which is almost identical(!), and never saw your posting!

Looks a good idea ... and at first glance would work - your manually loading the database each time? Whats the thought for if the primary database fails after you've loaded but between queries?