class Tarantool::EMDB
Constants
- INITIAL
- IPROTO_CONNECTION_TYPE
Public Instance Methods
_send_request(shard_numbers, read_write, response)
click to toggle source
# File lib/tarantool/em_db.rb, line 39 def _send_request(shard_numbers, read_write, response) if @closed exc = ::IProto::Disconnected.new("Tarantool is closed") if EM.reactor_running? EM.next_tick Curry1.new(response.cb, exc) else response.cb.call exc end else feed = FeedResponse.new(response) shard_numbers = shard_numbers[0] if Array === shard_numbers && shard_numbers.size == 1 if Array === shard_numbers _send_to_several_shards(shard_numbers, read_write, response, feed) else _send_to_one_shard(shard_numbers, read_write, response, feed) end end end
_send_to_one_shard(shard_number, read_write, response, feed)
click to toggle source
# File lib/tarantool/em_db.rb, line 58 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 case @replica_strategy when :round_robin replicas = replicas.shuffle.sort_by!{|con| con.waiting_requests_size/5} when :prefer_slave master = replicas[0] replicas = replicas[1..-1].shuffle.sort_by!{|con| con.waiting_requests_size/5} replicas << master end EM.next_tick OneShardRead.new(replicas, response, feed) else EM.next_tick OneShardWrite.new(replicas, response, feed) end end
_send_to_several_shards(shard_numbers, read_write, response, feed)
click to toggle source
# File lib/tarantool/em_db.rb, line 222 def _send_to_several_shards(shard_numbers, read_write, response, feed) concat = read_write != :replace ? Concatter.new(shard_numbers.size, feed) : ConcatterReplace.new(shard_numbers.size, feed) for shard in shard_numbers _send_to_one_shard(shard, read_write, response, concat) end end
_tune_new_connection(con)
click to toggle source
Calls superclass method
Tarantool::DB#_tune_new_connection
# File lib/tarantool/em_db.rb, line 18 def _tune_new_connection(con) super con.comm_inactivity_timeout = inactivity_timeout end
inactivity_timeout()
click to toggle source
# File lib/tarantool/em_db.rb, line 7 def inactivity_timeout @inactivity_timeout ||= 0 end
inactivity_timeout=(v)
click to toggle source
# File lib/tarantool/em_db.rb, line 11 def inactivity_timeout=(v) @inactivity_timeout = v || 0 each_connection do |c| c.comm_inactivity_timeout = @inactivity_timeout end end