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

Update methods sent to read-only database with identity_cache gem #542

Open
gaga5lala opened this issue Nov 13, 2019 · 0 comments
Open

Update methods sent to read-only database with identity_cache gem #542

gaga5lala opened this issue Nov 13, 2019 · 0 comments

Comments

@gaga5lala
Copy link

Hi, I've encountered a shard mismatch problem when using octopus with identity_cache gem.

Environment

Databases:

  • master * 1
  • replica * 1

Config:

  • replicated: true
  • fully_replicated: false (set replicated_model by ourself)

Gems:

  • rails 4.2.11
  • octopus: 0.10.2
  • identity_cache: 0.4.1

Scenario

Model

  • User (replicated_model)
    • has_one :setting
  • Setting (replicated_model)

When I want to update the setting record fetched from cache, the update query will be sent to the replica shard.

# in controller

# first request works, later requests all failed
User.fetch(1).setting.update(some_attribute)

By using binding.pry I found that first time .current_shard will return :master, record fetched by another request will get :replica then the update query sent to wrong replica database.

But if I using normal Active Record method (e.g. Member.find(1).setting.update(some_attribute)) all request are success.

Is there some class variables stored across requests but computing after ActiveRecord instance initialize, but record initialized by IdentityCache cause the problem?

Thanks

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