I'm still relatively new to Tomcat configuration and have search for an answer, but cannot find anything specific, so please let me know if there is a resource for the following.
We have a read/write users (MySQL) database and a read-only backup database (also MySQL). We use the read-only as a failover if we lose connection to the primary to maintain operations. I have successfully configured my Tomcat (6.0.35) with a DataSourceRealm to connect to the primary database by adding the boilerplate in the server.xml file and the specific connection information to a container in it's context.xml
I know I can manually change the context.xml to point to the backup database and restart the server if need be, but is there a way to automate this failover switch?
We currently write a zero-length file to a particular directory every (X) minutes to indicate the heartbeat of the primary (and backup) database servers. I can imagine writing something (in an extended Realm Class, perhaps or "further up" the Tomcat chain?) that checks on these heartbeat files, but I'm not sure how to tell Tomcat to switch over to the backup and restart itself, if this is even possible.
Have you considered using full MySQL clustering? If I'm not mistaken, recent versions of MySQL can do failovers automatically.
An IDE is no substitute for an Intelligent Developer.
Joined: Jun 04, 2013
Thank you for the welcome and response Tim! I have long referred to CodeRanch, and am looking forward to contributing where I can.
You ask a good question which I have forward on to our MySQL admin. I'll report on his response when I get it.
[UPDATE - 20130625]
I spoke with our db admin and he tells me that the resources needed to do MySQL clustering are beyond what we can do. If there is a way that tomcat can automatically check for some sort of "heartbeat" that indicates the health of the user db (as well as the backup db), perform the necessary configuration switch, and restart itself, I would be eager to hear it.
I feel pretty comfortable with extending existing classes, or writing new ones to accomplish this if it is possible. I just don't know enough about the internals of tomcat to know where to start if it is possible.