1

I'm having a problem with octopus replication. I use table-based sessions and when a user logs in the session is created in my master table but the next request tries to read session data from the slave db and it fails because the session data is not replicated to the slave db before the second request is made. How can I tell octopus to read and write session records from/to the same table? I don't have a Session Model, should I create one?

Rocky
  • 57
  • 5
  • How are you reading/writing to the session table if you don't have a session model? – goodmanship Feb 15 '13 at 20:25
  • Rails does it automatically. – Rocky Feb 15 '13 at 22:55
  • Can you include the relevant code and the error message or something? I have used octopus a fair amount, but I don't quite understand your setup or what you are trying to do. Are you just using normal rails session vars (session[:param])? why are you looking for the session info in a slave db? – goodmanship Feb 16 '13 at 22:53
  • I have activerecord sessions on my rails app and when a session is created it is saved to my master database (all writes go to master), but have octopus setup to do all reads on the slave database. The problem is that sometimes the server is faster than the database replication and the session is not available on the slave database when I try to read it. – Rocky Feb 22 '13 at 07:50
  • Anyway, I'm going to try using makara gem which is actually based on octopus but does a better job at failover and on-the-fly switching between master and slave databases. – Rocky Feb 22 '13 at 07:52
  • @Rocky - I am having one question regarding octopus gem. can u answer it here http://stackoverflow.com/questions/29445495/rails-how-to-split-write-read-query-across-master-slave-database?noredirect=1#comment47064893_29445495 – Sanjay Salunkhe Apr 11 '15 at 06:00

1 Answers1

0

You can specify which db to use like this:

Model.using(:master).find(id)

or

Model.using(:slave_name).find(id)
goodmanship
  • 334
  • 1
  • 13
  • Right, but I do not have a Session model, Rails handles sessions internally and does not create a Session Model. – Rocky Feb 15 '13 at 22:56