diff --git a/lib/tarantool/block_db.rb b/lib/tarantool/block_db.rb index af43b98..c173ebf 100644 --- a/lib/tarantool/block_db.rb +++ b/lib/tarantool/block_db.rb @@ -23,7 +23,12 @@ def _send_to_one_shard(shard_number, read_write, response) if (replicas = _shard(shard_number)).size == 1 _parse_iproto(replicas[0].send_request(response.request_type, response.body)) 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) else _one_shard_write(replicas, response.request_type, response.body) diff --git a/lib/tarantool/em_db.rb b/lib/tarantool/em_db.rb index e608cf7..0d00781 100644 --- a/lib/tarantool/em_db.rb +++ b/lib/tarantool/em_db.rb @@ -43,7 +43,12 @@ def _send_to_one_shard(shard_number, read_write, response, feed) if (replicas = _shard(shard_number)).size == 1 replicas[0].send_request(response.request_type, response.body, OneReplica.new(response, feed)) 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) else EM.next_tick OneShardWrite.new(replicas, response, feed)