Skip to content
tchandy edited this page Sep 14, 2010 · 23 revisions

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 you application isn’t fully replicated. if you want to make your application fully replicated, the following line needs to be added to shards.yml:

octopus:
  fully_replicated: true

If the application isn’t fully replicated, you need to specify on your models what will be replicated, with this syntax:

#This class is replicated, writes to master and reads to slave.
class Cat < ActiveRecord::Base
  replicated_model()
end

Multiples Slaves

Basically, Octopus supports multiples slaves. Octopus will pick one shard using a round robin algorithm.

Queries to specific shards

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).count

Octopus.using(:slave_1) do
User.count
end

Clone this wiki locally