I’m working with a Rails app that uses the Octopus gem for database sharding. I have a User model set up and I’m testing this in my development environment.
octopus:
environments:
- development
- staging
- production
replicated: true
fully_replicated: true
development:
replica1:
host: 10.0.1.100
adapter: mysql2
database: app_dev
username: dev_user
password: dev_pass
reconnect: false
staging:
replica1:
host: 10.0.2.50
adapter: mysql2
database: app_staging
username: staging_user
password: staging_secret
reconnect: false
production:
replica1:
host: 10.0.3.25
adapter: mysql2
database: app_prod
username: prod_user
password: prod_secret
reconnect: true
Whenever I run User.all or User.count, I notice that the exact same SQL query gets executed twice on the database. Here’s what I see in the logs:
[Shard: replica1] (0.8ms) SELECT COUNT(*) FROM `users`
[Shard: replica1] (1.2ms) SELECT COUNT(*) FROM `users`
=> 42
Is this expected behavior with the Octopus gem or did I mess up something in my configuration?