# File lib/tarantool/block_db.rb, line 102 def primary_interface :synchronous end
class Tarantool::BlockDB
Constants
- IPROTO_CONNECTION_TYPE
Public Instance Methods
_one_shard_read(replicas, request_type, body)
click to toggle source
# File lib/tarantool/block_db.rb, line 39 def _one_shard_read(replicas, request_type, body) for conn in replicas if conn.could_be_connected? begin res = _parse_iproto(conn.send_request(request_type, body)) raise res if Exception === res return res rescue ::IProto::ConnectionError # pass end end end raise ConnectionError, "no available connections" end
_one_shard_write(replicas, request_type, body)
click to toggle source
# File lib/tarantool/block_db.rb, line 54 def _one_shard_write(replicas, request_type, body) i = replicas.size while i > 0 conn = replicas[0] if conn.could_be_connected? begin res = _parse_iproto(conn.send_request(request_type, body)) raise res if Exception === res return res rescue ::IProto::ConnectionError, ::Tarantool::NonMaster # pass end end replicas.rotate! i -= 1 end raise NoMasterError, "no available master connections" end
_send_request(shard_numbers, read_write, response)
click to toggle source
# File lib/tarantool/block_db.rb, line 6 def _send_request(shard_numbers, read_write, response) if @closed response.cb.call ::IProto::Disconnected.new("Tarantool is closed") else response.call_callback begin 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) else _send_to_one_shard(shard_numbers, read_write, response) end end end end
_send_to_one_shard(shard_number, read_write, response)
click to toggle source
# File lib/tarantool/block_db.rb, line 21 def _send_to_one_shard(shard_number, read_write, response) response.parse_response( if (replicas = _shard(shard_number)).size == 1 _parse_iproto(replicas[0].send_request(response.request_type, response.body)) elsif read_write == :read 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) end ) end
_send_to_several_shards(shard_numbers, read_write, response)
click to toggle source
# File lib/tarantool/block_db.rb, line 73 def _send_to_several_shards(shard_numbers, read_write, response) results = [] unless read_write == :replace for shard in shard_numbers res = _send_to_one_shard(shard, read_write, response) Array === res ? results.concat(res) : results << res end else for shard in shard_numbers begin res = _send_to_one_shard(shard, read_write, response) Array === res ? results.concat(res) : results << res rescue ::Tarantool::TupleDoesntExists => e results << e end end if results.all?{|r| ::Tarantool::TupleDoesntExists === r} raise results.first else results.delete_if{|r| ::Tarantool::TupleDoesntExists === r} end end if Integer === results.first results = results.inject(0){|s, i| s + i} end results end
primary_interface()
click to toggle source