Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It doesn't send a query to master. Why so? 🤔 #205

Open
artkirienko opened this issue May 23, 2018 · 1 comment
Open

It doesn't send a query to master. Why so? 🤔 #205

artkirienko opened this issue May 23, 2018 · 1 comment

Comments

@artkirienko
Copy link

https://github.com/taskrabbit/makara#common-problems--solutions

database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 10
  host: postgres
  username: postgres

development:
  adapter: 'postgresql_makara'
  encoding: unicode
  pool: 10
  database: jiffyshirts_development
  makara:
    id: postgresql
    blacklist_duration: 5
    master_ttl: 5
    master_strategy: round_robin
    slave_strategy: round_robin
    sticky: false
    connections:
      - role: master
        blacklist_duration: 0
        url: 'postgres://postgres@postgres:5432/jiffyshirts_development'
      - role: slave
        url: 'postgres://postgres@postgres:5432/jiffyshirts_replica'

test:
  database: jiffyshirts_test
  <<: *default

deploy:
  database: jiffyshirts_development
  <<: *default
  1. It uses slave database. It's okay.
> Spree::User.last
  [slave/1] Spree::User Load (1.5ms)  SELECT  "spree_users".* FROM "spree_users" WHERE "spree_users"."deleted_at" IS NULL  ORDER BY "spree_users"."id" DESC LIMIT 1
  1. It is still using slave database. Why so? I've even tried to set master_ttl to 600. Same problem.
> Spree::User.connection.stick_to_master!(true); Spree::User.last
  [slave/1] Spree::User Load (1.2ms)  SELECT  "spree_users".* FROM "spree_users" WHERE "spree_users"."deleted_at" IS NULL  ORDER BY "spree_users"."id" DESC LIMIT 1
@rosa
Copy link
Contributor

rosa commented May 27, 2018

@artkirienko this is working fine for me. For example:

>> User.last # Uses replica
  [replica] User Load (5.5ms)  SELECT  `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
>> User.connection.stick_to_master!
=> 10.0
>> User.last # Uses primary
  [primary] User Load (2.9ms)  SELECT  `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1

Have you tried setting sticky: true in your configuration? I think that's the reason stickiness is being skipped for you after calling stick_to_master!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants