Jksql failover connections: Difference between revisions

From genomewiki
Jump to navigationJump to search
(Created page with "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 ...")
 
No edit summary
 
Line 3: Line 3:
* The main connection data is configured as usual via the db.host/db.password etc settings in hg.conf
* 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 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.
* databases can exist on either only the local connection or the remote connection.
* All queries are run against the local connection first, and if they fail, are run against the failover connection.
** This allows only-local databases loaded by a user but doesn't require the user to have local databases for all UCSC databases.


Database changes:
Connect to a given database:
* 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.
* The main connection is always connected. The failover one is always setup, but only connected if needed.
* If a database does not exist on the main connection, no error is reported and the failover connection is used
* If a db does not exist in the main connection, it is connected but without a DB (It is therefore in an "invalid" state detected by sqlMustDoFailover later)
* If a database does not exist on the failover connection, no error is reported and the main connection is used
** "Invalid" state is detected by comparing the mysql database with the database in sqlConnection->db.  
* 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.
* If a db does not exist in the failover connection, silently allow this


This allows only-local databases loaded by a user but doesn't require the user to have local databases for all UCSC databases.
Query:
* All queries are run against the local connection first if possible, and if they fail, are run against the failover connection.
* If the main connection is in an "invalid" state, go directly to the failover connection
 
Change database:
* Database changes are reflected on both connections
* On failover, connects are "lazy": 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, the main connection is in an "invalid" state
* If a database does not exist on the failover connection, the failover connection is in an "invalid" state


Some examples for a case where only hg19 exists locally:
Some examples for a case where only hg19 exists locally:
Line 18: Line 26:
* connect with hg19, change to ce2:  
* connect with hg19, change to ce2:  
# sqlConnect(hg19): main connected/hg19, failover unconnected/hg19
# sqlConnect(hg19): main connected/hg19, failover unconnected/hg19
# sqlQuery: run against main first, if failed run on failover
# sqlConnChangeDb(ce2): main connected/invalid, failover connected/ce2  
# sqlConnChangeDb(ce2): main connected/invalid, failover connected/ce2  
# sqlQuery: run against failover because main is invalid
# sqlQuery: run against failover because main is invalid
# sqlConnChangeDb(hg19): main connected/hg19, failover connected/hg19
# sqlConnChangeDb(hg19): main connected/hg19, failover connected/hg19
# sqlQuery: run against main first, if failed run on failover


* connect with ce2, change to hg19:
* connect with ce2, change to hg19:
# sqlConnect(ce2): main not connected/ce2, failover connected/ce2
# sqlConnect(ce2): main connected/invalid, failover connected/ce2
# sqlQuery: run against failover
# sqlQuery: run against failover
# sqlConnChangeDb(hg19): main connected/hg19, failover connected/hg19  
# sqlConnChangeDb(hg19): main connected/hg19, failover connected/hg19  
Line 30: Line 38:


* connect with ce2, change to braNey1
* connect with ce2, change to braNey1
# sqlConnect(ce2): main not connected/ce2, failover connected/ce2
# sqlConnect(ce2): main connected/ce2, failover unconnected/ce2
# sqlQuery: run against failover
# sqlQuery: run against main, failover on error
# sqlConnChangeDb(braNey1): main connected/braNey1, failover invalid  
# sqlConnChangeDb(braNey1): main connected/braNey1, failover invalid  
# sqlQuery: run against main, no failover (does this work?)
# sqlQuery: run against main, no failover (does this work?)

Latest revision as of 16:01, 8 February 2014

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
  • databases can exist on either only the local connection or the remote connection.
    • This allows only-local databases loaded by a user but doesn't require the user to have local databases for all UCSC databases.

Connect to a given database:

  • The main connection is always connected. The failover one is always setup, but only connected if needed.
  • If a db does not exist in the main connection, it is connected but without a DB (It is therefore in an "invalid" state detected by sqlMustDoFailover later)
    • "Invalid" state is detected by comparing the mysql database with the database in sqlConnection->db.
  • If a db does not exist in the failover connection, silently allow this

Query:

  • All queries are run against the local connection first if possible, and if they fail, are run against the failover connection.
  • If the main connection is in an "invalid" state, go directly to the failover connection

Change database:

  • Database changes are reflected on both connections
  • On failover, connects are "lazy": 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, the main connection is in an "invalid" state
  • If a database does not exist on the failover connection, the failover connection is in an "invalid" state

Some examples for a case where only hg19 exists locally:

  • connect with hg19, change to ce2:
  1. sqlConnect(hg19): main connected/hg19, failover unconnected/hg19
  2. sqlQuery: run against main first, if failed run on failover
  3. sqlConnChangeDb(ce2): main connected/invalid, failover connected/ce2
  4. sqlQuery: run against failover because main is invalid
  5. sqlConnChangeDb(hg19): main connected/hg19, failover connected/hg19
  • connect with ce2, change to hg19:
  1. sqlConnect(ce2): main connected/invalid, failover connected/ce2
  2. sqlQuery: run against failover
  3. sqlConnChangeDb(hg19): main connected/hg19, failover connected/hg19
  4. sqlQuery: run against main first, if failed run on failover
  • connect with ce2, change to braNey1
  1. sqlConnect(ce2): main connected/ce2, failover unconnected/ce2
  2. sqlQuery: run against main, failover on error
  3. sqlConnChangeDb(braNey1): main connected/braNey1, failover invalid
  4. sqlQuery: run against main, no failover (does this work?)
  • connect braNey1, change to hg19
  1. sqlConnect(braNey1): main connected/braNey1, failover not connected/braNey1
  2. sqlQuery: run against local (does it fail over?)
  3. sqlConnChangeDb(hg19): main connected/hg19, failover not connected/hg19
  4. sqlQuery: run against local, use failover