Welcome Guest, Not a member yet? Register   Sign In
High Availability with Master / Master Mysql Setup
#1

[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;
                }
            }
#2

[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?




Theme © iAndrew 2016 - Forum software by © MyBB