Skip to content

Commit

Permalink
prefer_slave replica_strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
funny-falcon committed Oct 22, 2013
1 parent 9477d6f commit 9cd2f1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/tarantool/block_db.rb
Expand Up @@ -23,7 +23,12 @@ def _send_to_one_shard(shard_number, read_write, response)
if (replicas = _shard(shard_number)).size == 1 if (replicas = _shard(shard_number)).size == 1
_parse_iproto(replicas[0].send_request(response.request_type, response.body)) _parse_iproto(replicas[0].send_request(response.request_type, response.body))
elsif read_write == :read elsif read_write == :read
replicas = replicas.shuffle if @replica_strategy == :round_robin case @replica_strategy
when :round_robin
replicas = replicas.shuffle
when :prefer_slave
replicas = replicas[1..-1].shuffle << replicas[0]
end
_one_shard_read(replicas, response.request_type, response.body) _one_shard_read(replicas, response.request_type, response.body)
else else
_one_shard_write(replicas, response.request_type, response.body) _one_shard_write(replicas, response.request_type, response.body)
Expand Down
7 changes: 6 additions & 1 deletion lib/tarantool/em_db.rb
Expand Up @@ -43,7 +43,12 @@ def _send_to_one_shard(shard_number, read_write, response, feed)
if (replicas = _shard(shard_number)).size == 1 if (replicas = _shard(shard_number)).size == 1
replicas[0].send_request(response.request_type, response.body, OneReplica.new(response, feed)) replicas[0].send_request(response.request_type, response.body, OneReplica.new(response, feed))
elsif read_write == :read elsif read_write == :read
replicas = replicas.shuffle if @replica_strategy == :round_robin case @replica_strategy
when :round_robin
replicas = replicas.shuffle
when :prefer_slave
replicas = replicas[1..-1].shuffle << replicas[0]
end
EM.next_tick OneShardRead.new(replicas, response, feed) EM.next_tick OneShardRead.new(replicas, response, feed)
else else
EM.next_tick OneShardWrite.new(replicas, response, feed) EM.next_tick OneShardWrite.new(replicas, response, feed)
Expand Down

0 comments on commit 9cd2f1b

Please sign in to comment.