I have an app that is read-mostly on MySQL 5.1.x with one master and multiple replication slaves. I would like to use the slaves for all read operations and the master for all write operations. Here are my options and why I don't like any of them:
JBoss Cache, Infinispan, etc: I already have a cache. It's a MySQL slave. I don't want to create an additional cache.
Shards: Maintenance nightmare
com.mysql.jdbc.ReplicationDriver: Requires the developer to setReadOnly(true) for read-only transaction. All of the transactions are mostly reads with only a few writes, so I'd never be able to setReadOnly(true)
The ReplicationDriver solution is close, but it requires mixing in the setReadOnly() call to my business logic, which is undesirable, unreliable and just doesn't work for my case. However, if my entities are using the @Version annotation, I don't see why I can't select all my entities from a slave, and write them all to the master. The @Version annotation will cause Hibernate to throw an OptimisticLockException if my replication lags behind.
Basically, at the beginning of flush() I just want to switch to the master for writes. But how??
|