Last modified: 2011-03-15 00:41:52 UTC
The master/slave logic could easily be pushed into db-specific code, as has been done with db/LoadBalancer. It is an installation-specific concept, and I believe it should be decoupled from core code. Most queries can be directed to the correct server based on Database::isWriteQuery, and in exceptional cases a flag could be provided, to select from master.
There are important caveats involving reading from slave servers. We expose the master/slave distinction in the interface to ensure that developers writing calling code are aware of the distinction. For instance, it is not generally possible to read data from a slave server and then to write it to memcached, because the stale data would be cached indefinitely. It's necessary to either do such read queries against the master, or to check the data returned by the slave for freshness using a separate query against the master. The flag would need to be set not just in exceptional cases, but in large amounts of code that depends on transactions and consistent reads in order to do accurate write queries. Saving the flag in object state with wfGetDB(), instead of providing it separately for each query, makes such code simpler and less prone to errors.