-
Notifications
You must be signed in to change notification settings - Fork 505
Replication
If you have replicated database configured in shards.yml (see Config File for more info), Octopus will send all writes to master, and all reads to slaves. You should specify if you application is fully replicated, or just some models are replicated. For default, Octopus will assume that your application is fully replicated. Here is how your config file should look:
octopus: replicated: true environments: - staging - production staging: slave1: database: octopus_shard2 <<: *mysql slave2: database: octopus_shard3 <<: *mysql production: slave3: database: octopus_shard4 <<: *mysql slave4: database: octopus_shard5 <<: *mysql
If the application isn’t fully replicated, you need to specify on your config file, and also in your models what will be replicated:
octopus: replicated: true fully_replicated: false environments: - staging - production staging: slave1: database: octopus_shard2 <<: *mysql slave2: database: octopus_shard3 <<: *mysql production: slave3: database: octopus_shard4 <<: *mysql slave4: database: octopus_shard5 <<: *mysql
#This class is replicated, writes to master and reads to slave. class Cat < ActiveRecord::Base replicated_model() end
Octopus supports multiples slaves. Octopus will pick one shard using a round robin algorithm.
Also, if you want to send some queries to a specific slave or to a master, you could use normal sharding feature, examples:
#sends the query to master
User.using(:master).count#Sends the query to specific slave
User.using(:slave_1).countOctopus.using(:slave_1) do
User.count
end