-
Notifications
You must be signed in to change notification settings - Fork 506
Open
Description
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
Metadata
Metadata
Assignees
Labels
No labels