Jksql failover connections
From genomewiki
Jump to navigationJump to search
For the browser-in-a-box several changes were made to jksql.c that allow a union of two mysql servers over the same connection. They transparently look like one mysql connection from the point of view of the browser. This means that one sqlConnection object can have mysql connections to two servers: a main (or local) one, and a failover (or slow) one.
- The main connection data is configured as usual via the db.host/db.password etc settings in hg.conf
- The failover/slow connection is configured via slow-db.host,slow-db.password/etc settings in hg.conf
- The local one is always connected, if possible. The failover one is always setup, but only connected if needed.
- All queries are run against the local connection first, and if they fail, are run against the failover connection.
Database changes:
- Database changes are sent to all connections that are actually connected. If a connection is not connected, the database change is noted in sqlConnection->db, but not sent to mysql.
- If a database does not exist on the main connection, no error is reported and the failover connection is used
- If a database does not exist on the failover connection, no error is reported and the main connection is used
- This means that a connection can be connected but on an invalid database. This is detected by comparing the mysql database with the database in sqlConnection->db. I call this an invalid database in the following.
This allows only-local databases loaded by a user but doesn't require the user to have local databases for all UCSC databases.
Some examples for a case where only hg19 exists locally:
- connect with hg19, change to ce2:
- sqlConnect(hg19): main connected/hg19, failover unconnected/hg19
- sqlConnChangeDb(ce2): main connected/invalid, failover connected/ce2
- sqlQuery: run against failover because main is invalid
- sqlConnChangeDb(hg19): main connected/hg19, failover connected/hg19
- sqlQuery: run against main first, if failed run on failover
- connect with ce2, change to hg19:
- sqlConnect(ce2): main not connected/ce2, failover connected/ce2
- sqlQuery: run against failover
- sqlConnChangeDb(hg19): main connected/hg19, failover connected/hg19
- sqlQuery: run against main first, if failed run on failover
- connect with ce2, change to braNey1
- sqlConnect(ce2): main not connected/ce2, failover connected/ce2
- sqlQuery: run against failover
- sqlConnChangeDb(braNey1): main connected/braNey1, failover invalid
- sqlQuery: run against main, no failover (does this work?)
- connect braNey1, change to hg19
- sqlConnect(braNey1): main connected/braNey1, failover not connected/braNey1
- sqlQuery: run against local (does it fail over?)
- sqlConnChangeDb(hg19): main connected/hg19, failover not connected/hg19
- sqlQuery: run against local, use failover