Class: Tarantool::EMDB::OneShardWrite
- Inherits:
-
Object
- Object
- Tarantool::EMDB::OneShardWrite
- Includes:
- ParseIProto
- Defined in:
- lib/tarantool/em_db.rb
Instance Method Summary collapse
- #call(result = INITIAL) ⇒ Object
-
#initialize(replicas, response, feed) ⇒ OneShardWrite
constructor
A new instance of OneShardWrite.
- #rotate! ⇒ Object
Methods included from ParseIProto
Constructor Details
#initialize(replicas, response, feed) ⇒ OneShardWrite
Returns a new instance of OneShardWrite.
122 123 124 125 126 127 128 |
# File 'lib/tarantool/em_db.rb', line 122 def initialize(replicas, response, feed) @replicas_origin = replicas @replicas = replicas.dup @i = replicas.size @response = response @feed = feed end |
Instance Method Details
#call(result = INITIAL) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/tarantool/em_db.rb', line 137 def call(result=INITIAL) result = _parse_iproto(result) unless result == INITIAL case result when INITIAL, ::IProto::ConnectionError, ::Tarantool::NonMaster rotate! if Exception === result rotate! until @i <= 0 || (repl = @replicas[0]).could_be_connected? if @i <= 0 EM.next_tick Curry1.new(@feed, NoMasterError.new("no available master connections")) return end repl.send_request(@response.request_type, @response.body, self) when Exception @feed.call result else @replicas_origin.replace @replicas @feed.call @response.parse_response_for_cb(result) end end |
#rotate! ⇒ Object
130 131 132 133 134 135 |
# File 'lib/tarantool/em_db.rb', line 130 def rotate! if @i > 0 @i -= 1 @replicas.rotate! end end |