octopus icon indicating copy to clipboard operation
octopus copied to clipboard

Associations reads from master instead of replicated shard

Open ddh opened this issue 7 years ago • 6 comments

I'm having issues retrieving associations of records that come from my slave shard. Not sure what is going on here and hopefully I can get some help debugging the issue! Might be related to #377

Given:

  • Rails 4.1.16, ar-octopus (0.9.1)
  • A simple has_one/belongs_to relationship (User has one Address)
  • I'm using Octopus only for development; so I can write to my local db but read live data (a read-only replica of our production db)
  • I have a local mysql db (master), assume that it's always behind the slave shard
  • a fully-replicated mysql db of our live production db is the slave/shard

Problem:

  • I can get the latest User from the replica just fine: User.last
    • This uses the slave (replica db). I don't have this record locally either so I know it works.
  • However, User.last.address returns nil, although the associated record is in the replica.
  • I can fix this by explicitly calling User.using(:replica).last.address returns the record, but that defeats the purpose of abstracting knowing where to get the association from

I also noticed if I call on the association (in either direction, user.address or address.user), the associated record is returned only if it was in the master db (ie my local db) to begin with. It doesn't use the slave to make the query. Anyone else having this issue?

ddh avatar Sep 20 '17 20:09 ddh

same issues from my side with octopus 0.9.1 and AR 4.2.8

fertobar avatar Oct 25 '17 22:10 fertobar

Any word on how to fix this? I'm still having this problem Octopus 0.9.1 and A R 4.2.6

etsenake avatar Jan 25 '18 16:01 etsenake

I have the same problem. Octopus 0.9.2 and AR 4.0.0

DanielMuller avatar Mar 23 '18 10:03 DanielMuller

@thiagopradi We're still seeing this as well.

Octopus 0.9.2 | Rails 5.1.5

swordfish444 avatar Mar 25 '18 17:03 swordfish444

@thiagopradi We are hitting this as well; still have a fair amount of reads going to master due to this.

Octopus master (0.9.2) @ https://github.com/thiagopradi/octopus/commit/ba65ba647b7420b482043ead4fe1e729059a14de AR 4.2.8

zpatten avatar Apr 06 '18 05:04 zpatten

Any news about this? am getting the same error.

pablosky avatar Nov 07 '18 16:11 pablosky