Now, I am running simple select queries, trying to fetch from read replica:
Loading development environment (Rails 4.2.7.1)
2.3.3 :001 > SeamlessDatabasePool.use_random_read_connection { User.last.id }
User Load (0.4ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
7549411 # went to master
2.3.3 :002 > SeamlessDatabasePool.use_random_read_connection { User.last.id }
User Load (0.5ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
7549411 # went to master
2.3.3 :003 > SeamlessDatabasePool.use_random_read_connection { User.last.id }
User Load (341.8ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
50420982 # went to slave as expected
2.3.3 :004 > SeamlessDatabasePool.use_random_read_connection { User.last.id }
User Load (328.8ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
50420982 # went to slave as expected
2.3.3 :005 > SeamlessDatabasePool.use_random_read_connection { User.last.id }
User Load (301.3ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
50420982 # went to slave as expected
2.3.3 :006 > SeamlessDatabasePool.use_random_read_connection { User.last.id }
User Load (0.4ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
7549411 # went to master
As you may see from above it is randomly choosing to use master, even if I have pass SeamlessDatabasePool.use_random_read_connection block. I writed the same with use_persistent_read_connection it has the same behavior. During this test the replica was available & was not down.
Expected behaviour
If we tell it to use the replica connection, it should not switch to master. Is this a bug or this is how the gem works?
Consider the following setup of database.yml:
Now, I am running simple select queries, trying to fetch from read replica:
As you may see from above it is randomly choosing to use master, even if I have pass
SeamlessDatabasePool.use_random_read_connection
block. I writed the same withuse_persistent_read_connection
it has the same behavior. During this test the replica was available & was not down.Expected behaviour If we tell it to use the replica connection, it should not switch to master. Is this a bug or this is how the gem works?
SeamlessDatabasePool version 1.0.18