Class: Tarantool::BlockDB
Defined Under Namespace
Modules: CommonSpaceBlockingMethods
Classes: Query, SpaceArray, SpaceHash
Constant Summary
collapse
- IPROTO_CONNECTION_TYPE =
:block
Instance Attribute Summary
Attributes inherited from DB
#closed, #connections, #previous_shards_count
Instance Method Summary
collapse
-
#_one_shard_read(replicas, request_type, body) ⇒ Object
-
#_one_shard_write(replicas, request_type, body) ⇒ Object
-
#_send_request(shard_numbers, read_write, response) ⇒ Object
-
#_send_to_one_shard(shard_number, read_write, response) ⇒ Object
-
#_send_to_several_shards(shard_numbers, read_write, response) ⇒ Object
-
#primary_interface ⇒ Object
#_parse_iproto
Methods inherited from DB
#_shard, #_tune_new_connection, #close, #close_connection, #each_connection, #initialize, #insert_with_shards_count, #method_missing, #query, #shards_count, #space, #space_array, #space_hash
Constructor Details
This class inherits a constructor from Tarantool::DB
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Tarantool::DB
Instance Method Details
#_one_shard_read(replicas, request_type, body) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# 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
end
end
end
raise ConnectionError, "no available connections"
end
|
#_one_shard_write(replicas, request_type, body) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# 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
end
end
replicas.rotate!
i -= 1
end
raise NoMasterError, "no available master connections"
end
|
#_send_request(shard_numbers, read_write, response) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# 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) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# 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) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# 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 ⇒ Object
102
103
104
|
# File 'lib/tarantool/block_db.rb', line 102
def primary_interface
:synchronous
end
|