PHP replication plugin future: eventual consistent, eventual served from cache!
While Andrey is busy implementing partitioned replication infrastructure code for the PHP replication and load balancing plugin (PECL/mysqlnd_ms), I continued my search for ideas to steal. Mr. Robert Hodges, I've robbed the idea of a service level and caching.. If an application is able to function with stale data read from a MySQL replication slave, it can also deal with stale data from a local cache. The replication plugin (PECL/mysqlnd_ms) could, in certain cases, populate the query cache plugin (PECL/mysqlnd_qc) for you and read replies from it.
In the blog posting "Implementing Relaxed Consistency Database Clusters with Tungsten SQL Router" Robert explains from a theoretical standpoint why his product allows application developers to set quality of service. The service level defines if eventual consistency is allowed or not. If so, the system is not required to return current data to all clients. Stale data may be served.
If using MySQL replication for read scale out, dealing with stale data is a standard task. Slaves may lag behind the master and have not the latest updates. Applications must be able to function with stale data. Given that the service level allows stale data, one can replace one stale data source with another. One can replace a MySQL slave possibly lagging behind with a local (TTL) cache.Any PHP MySQL application | | consistent eventual consistent | | | PECL/mysqlnd_ms | | | | Cache (PECL/mysqlnd_qc),
TTL = 2s | | A | Network A Network | A | MySQL master A MySQL slave,
lagging 4 seconds
All that needs to be done is combining PECL/mysqlnd_ms, the replication and load balancing plugin, with PECL/mysqlnd_qc, the query cache plugin. Of course, this should be done on the C level, inside the extensions. Ideally, applications using the combination of the two plugins would not need to bother of populating the cache and deciding when to read from it.
mysqlnd_ms_set_service_level($mysqli, MYSQLND_EVENTUAL_CONSISTENT); $mysqli-query("SELECT id FROM test"); $mysqli-query("SELECT id FROM test");
The replication plugin would just know from the service level that queries may be served from the cache. For example, it could automatically decide to cache the SELECT from the example above. Coulda this is brainstorming. No promises on features and time lines. I'm fishing for feedback.
Dream on, read on at https://wiki.php.net/pecl/mysqlnd_ms#raw_bin_ideas_rfcs. Feel free to edit the wiki pagea