Open aks opened 7 years ago
Thank you for showing the problem raising and solving method. I also think that I need to think about this problem properly. I m thinking about solutions to Rails 5.1 as well. Please give me some time.
Hi Tsukasa-san, ひさしぶりですね。
Have you considered how to maintain cache-coherency in the replica caches when master-writes occur?
Hello Mr.Stebbens. Good to see you again. QueryCache problem has already been solved.
This PR adds support for syncing query cache changes from the master connection cache to the replica query caches.
The new test script confirms that a cache syncing problems exists, with
replica_query_cache_sync
disabled, and then confirms that the problem does not occur whenreplica_query_cache_sync
is enabled.The feature is controlled by a class variable
@@replica_query_cache_sync
that is false by default -- in order to maintain backward compatibility and not provide any query cache behavior by default.This PR was tested with the support for
fake_replica
enabled, which has been submitted as a separate PR.Note: this PR supports both Rails 4.2+ and Rails 5
Also: I'm not happy with this PR as it currently stands. I wanted to show the problem, and a solution, but am not sure that this is the Right solution.
For example, I think query cache syncing should turn on automatically if query caching is enabled. What value would there be in not syncing when query caching is enabled?
Also, the tests pass most of the time, but once in a while, one of the tests fail, with the symptom of a recursive loop starting with the
clear_query_cache
method. Due to other urgencies, haven't had time to dig in a identify the root cause of this infrequent, spurious test failure.Lastly, there needs to be a way to select the appropriate corresponding replica connection pool from any given master connection -- so that when the master connection invokes
clear_query_cache
(after anupdate
orinsert
on that connection), it is easy (low-cost) to also triggerclear_query_cache
on the replica connections in the replica connection pool.