Page MenuHomePhabricator

Abstract DB_MASTER and DB_SLAVE out of core code
Closed, DeclinedPublic

Description

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.


Version: unspecified
Severity: enhancement

Details

Reference
bz28051

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:33 PM
bzimport set Reference to bz28051.
bzimport added a subscriber: Unknown Object (MLST).

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.