misha-ar-octopus 0.8.5 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/octopus.rb +2 -2
- data/lib/octopus/proxy.rb +16 -13
- data/lib/octopus/slave_group.rb +2 -2
- data/lib/octopus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 281daf3f746620c9c532e375151dc38b60723410
|
4
|
+
data.tar.gz: 8ec2145b1f7a5ad70b28eb28afcc6648bb929f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 567b3f257582d25174cbc5665de939f606236bf6646049db6fa29b13f0e05bfeb704589fd0182cbb95bc27c2c7dd6f5beb8117395d64c2b31efbbfa1b9e5ba4d
|
7
|
+
data.tar.gz: 87817bf90a7e1dc94404440c348c79b670afa4afce2080dbe31b94e1f272131a7ea7ba6613d66560c43b56b796bd74c80f8522161b83a67bc4ccedbd378ca3dd
|
data/lib/octopus.rb
CHANGED
@@ -117,11 +117,11 @@ module Octopus
|
|
117
117
|
ActiveRecord::Base.connection.initialize_shards(@config)
|
118
118
|
end
|
119
119
|
|
120
|
-
def self.using(shard,
|
120
|
+
def self.using(shard, &block)
|
121
121
|
conn = ActiveRecord::Base.connection
|
122
122
|
|
123
123
|
if conn.is_a?(Octopus::Proxy)
|
124
|
-
conn.run_queries_on_shard(shard,
|
124
|
+
conn.run_queries_on_shard(shard, &block)
|
125
125
|
else
|
126
126
|
yield
|
127
127
|
end
|
data/lib/octopus/proxy.rb
CHANGED
@@ -10,7 +10,7 @@ module Octopus
|
|
10
10
|
CURRENT_SHARD_KEY = 'octopus.current_shard'.freeze
|
11
11
|
CURRENT_GROUP_KEY = 'octopus.current_group'.freeze
|
12
12
|
CURRENT_SLAVE_GROUP_KEY = 'octopus.current_slave_group'.freeze
|
13
|
-
|
13
|
+
CURRENT_LOAD_BALANCE_OPTIONS_KEY = 'octopus.current_load_balance_options'.freeze
|
14
14
|
BLOCK_KEY = 'octopus.block'.freeze
|
15
15
|
LAST_CURRENT_SHARD_KEY = 'octopus.last_current_shard'.freeze
|
16
16
|
FULLY_REPLICATED_KEY = 'octopus.fully_replicated'.freeze
|
@@ -118,6 +118,7 @@ module Octopus
|
|
118
118
|
hash = shard_symbol
|
119
119
|
shard_symbol = hash[:shard]
|
120
120
|
slave_group_symbol = hash[:slave_group]
|
121
|
+
load_balance_options = hash[:load_balance_options]
|
121
122
|
|
122
123
|
if shard_symbol.nil? && slave_group_symbol.nil?
|
123
124
|
fail 'Neither shard or slave group must be specified'
|
@@ -134,6 +135,7 @@ module Octopus
|
|
134
135
|
end
|
135
136
|
end
|
136
137
|
self.current_slave_group = slave_group_symbol
|
138
|
+
self.current_load_balance_options = load_balance_options
|
137
139
|
else
|
138
140
|
fail "Nonexistent Shard Name: #{shard_symbol}" if @shards[shard_symbol].nil?
|
139
141
|
end
|
@@ -160,14 +162,15 @@ module Octopus
|
|
160
162
|
|
161
163
|
def current_slave_group=(slave_group_symbol)
|
162
164
|
Thread.current[CURRENT_SLAVE_GROUP_KEY] = slave_group_symbol
|
165
|
+
Thread.current[CURRENT_LOAD_BALANCE_OPTIONS_KEY] = nil if slave_group_symbol.nil?
|
163
166
|
end
|
164
167
|
|
165
|
-
def
|
166
|
-
Thread.current[
|
168
|
+
def current_load_balance_options
|
169
|
+
Thread.current[CURRENT_LOAD_BALANCE_OPTIONS_KEY]
|
167
170
|
end
|
168
171
|
|
169
|
-
def
|
170
|
-
Thread.current[
|
172
|
+
def current_load_balance_options=(options)
|
173
|
+
Thread.current[CURRENT_LOAD_BALANCE_OPTIONS_KEY] = options
|
171
174
|
end
|
172
175
|
|
173
176
|
def block
|
@@ -237,9 +240,9 @@ module Octopus
|
|
237
240
|
@adapters.size > 1
|
238
241
|
end
|
239
242
|
|
240
|
-
def run_queries_on_shard(shard,
|
243
|
+
def run_queries_on_shard(shard, &_block)
|
241
244
|
keeping_connection_proxy(shard) do
|
242
|
-
using_shard(shard
|
245
|
+
using_shard(shard) do
|
243
246
|
yield
|
244
247
|
end
|
245
248
|
end
|
@@ -438,7 +441,7 @@ module Octopus
|
|
438
441
|
|
439
442
|
def send_queries_to_selected_slave(method, *args, &block)
|
440
443
|
if current_model.replicated || fully_replicated?
|
441
|
-
selected_slave = @slaves_load_balancer.next
|
444
|
+
selected_slave = @slaves_load_balancer.next current_load_balance_options
|
442
445
|
else
|
443
446
|
selected_slave = Octopus.master_shard
|
444
447
|
end
|
@@ -466,7 +469,7 @@ module Octopus
|
|
466
469
|
# Temporarily switch `current_shard` to the next slave in a slave group and send queries to it
|
467
470
|
# while preserving `current_shard`
|
468
471
|
def send_queries_to_balancer(balancer, method, *args, &block)
|
469
|
-
send_queries_to_slave(balancer.next(
|
472
|
+
send_queries_to_slave(balancer.next(current_load_balance_options), method, *args, &block)
|
470
473
|
end
|
471
474
|
|
472
475
|
# Temporarily switch `current_shard` to the specified slave and send queries to it
|
@@ -493,21 +496,21 @@ module Octopus
|
|
493
496
|
end
|
494
497
|
|
495
498
|
# Temporarily switch `current_shard` and run the block
|
496
|
-
def using_shard(shard,
|
499
|
+
def using_shard(shard, &_block)
|
497
500
|
older_shard = current_shard
|
498
501
|
older_slave_group = current_slave_group
|
499
|
-
|
502
|
+
older_load_balance_options = current_load_balance_options
|
503
|
+
|
500
504
|
|
501
505
|
begin
|
502
506
|
unless current_model && !current_model.allowed_shard?(shard)
|
503
507
|
self.current_shard = shard
|
504
|
-
self.current_options = options
|
505
508
|
end
|
506
509
|
yield
|
507
510
|
ensure
|
508
511
|
self.current_shard = older_shard
|
509
512
|
self.current_slave_group = older_slave_group
|
510
|
-
self.
|
513
|
+
self.current_load_balance_options = older_load_balance_options
|
511
514
|
end
|
512
515
|
end
|
513
516
|
|
data/lib/octopus/slave_group.rb
CHANGED
data/lib/octopus/version.rb
CHANGED