-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Description
Consider the following setup of database.yml:
development:
database: my_development
adapter: seamless_database_pool
password: my_secret_password
pool_adapter: mysql2
pool: 25
username: root
master:
weight: 0
password: my_production_password
read_pool:
- host: xyz.rds.amazonaws.com
database: my_production_database
weight: 8
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?
SeamlessDatabasePool version 1.0.18
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels