Class: Tarantool::Client::Pool
- Inherits:
-
Object
- Object
- Tarantool::Client::Pool
- Defined in:
- tarantool-client/lib/tarantool/client/pool.rb,
tarantool-client/lib/tarantool/client/pool/member.rb,
tarantool-client/lib/tarantool/client/pool/member_role.rb,
tarantool-client/lib/tarantool/client/pool/member_fork_safety.rb
Overview
Clients for the instances of one replica set. Each request goes to an instance picked by mode from the role it reports through box.status, round-robin among the matches. Starts with the addresses that answer; the others keep being retried in the background.
Constant Summary collapse
- MODES =
%i[rw ro prefer_ro prefer_rw any].freeze
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(addresses, **options) ⇒ Pool
constructor
A new instance of Pool.
- #inspect ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(addresses, **options) ⇒ Pool
Returns a new instance of Pool.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'tarantool-client/lib/tarantool/client/pool.rb', line 11 def initialize(addresses, **) raise ArgumentError, 'a pool needs at least one address' if addresses.empty? @members = addresses.map { |address| Member.new(address, ) } @lock = Mutex.new @reinit_lock = Mutex.new @turns = Hash.new(0) @pid = Process.pid start_members rescue StandardError close raise end |
Instance Method Details
#close ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'tarantool-client/lib/tarantool/client/pool.rb', line 36 def close errors = (@members || []).filter_map do |member| member.close nil rescue StandardError => e e end raise errors.first if errors.any? end |
#inspect ⇒ Object
47 48 49 |
# File 'tarantool-client/lib/tarantool/client/pool.rb', line 47 def inspect "#<#{self.class.name} #{@members.map(&:address).join(', ')}>" end |
#transaction ⇒ Object
32 33 34 |
# File 'tarantool-client/lib/tarantool/client/pool.rb', line 32 def transaction(**, &) client_for(:rw).transaction(**, &) end |