Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord 5.2 StatementCache Pins Queries to Shards #554

Open
bschmeck opened this issue Jun 2, 2020 · 0 comments
Open

ActiveRecord 5.2 StatementCache Pins Queries to Shards #554

bschmeck opened this issue Jun 2, 2020 · 0 comments

Comments

@bschmeck
Copy link

bschmeck commented Jun 2, 2020

A change was made in ActiveRecord 5.2 such that in addition to the generated AST for a query, the class used to execute that query is cached. The StatementCache grabs that class via relation.klass which would normally be an ActiveRecord model. However, Octopus wraps the relation in a RelationProxy and that proxy object is the return value of relation.klass.

The next time a query that has a cached statement (e.g. find_by(id:)) the query is executed using that RelationProxy object. This is problematic because that RelationProxy object stores the shard it queried the first time and will send all subsequent queries to that shard.

I have been able to get our test suite to pass by monkey patching StatementCache::create to pull the underlying AR model via relation.klass.klass.klass but I would prefer to find a solution that modifies Octopus instead of ActiveRecord.

We are very late in upgrading to 5.2, I had assumed Octopus was widely used with AR 5.2 and am surprised to have encountered this bug. Is this a known issue for Octopus and is there a recommended workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant