promiscuous-poseidon_cluster 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/poseidon/consumer_group.rb +19 -16
- data/spec/lib/poseidon/consumer_group_spec.rb +22 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0a3206a576efca5e80710de7873bdf951b4fda0
|
4
|
+
data.tar.gz: 588e34330624b29fa6a127b67c24eaafb679a60f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cccda6adc5aade31d9c90fbac1c175cd261848e44d15e2658fde60259ba334a67cfe1b60f2a38c00ba89dbe981b6d97b60bae3a3036260949e48f95530d0dbd2
|
7
|
+
data.tar.gz: 6ba006802533829e84ff1b2a25f175d4803af498e500dd1f0be4d9b0ff905e5b016b11ff09f301afb399af0c39d8a8aaba631e3842a94506b0a2f20f5f217166
|
@@ -49,22 +49,25 @@ class Poseidon::ConsumerGroup
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
# @param [Integer]
|
53
|
-
# @param [Array<String>]
|
54
|
-
# @param [String]
|
55
|
-
# @return [
|
56
|
-
def self.pick(
|
57
|
-
|
58
|
-
|
59
|
-
return unless
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
return if
|
66
|
-
|
67
|
-
(
|
52
|
+
# @param [Integer] partition_count number of partitions size
|
53
|
+
# @param [Array<String>] consumer_ids consumer IDs
|
54
|
+
# @param [String] consumer_id consumer ID
|
55
|
+
# @return [Array, NilClass] array of partitions the consumer is responsible for, if any
|
56
|
+
def self.pick(partition_count, consumer_ids, consumer_id)
|
57
|
+
consumer_ids = consumer_ids.sort
|
58
|
+
index = consumer_ids.index(consumer_id)
|
59
|
+
return unless index && index < consumer_ids.size
|
60
|
+
|
61
|
+
partitions_per_consumer = partition_count / consumer_ids.size
|
62
|
+
extra_partitions = partition_count % consumer_ids.size
|
63
|
+
|
64
|
+
partitions_for_me = partitions_per_consumer + (index+1 > extra_partitions ? 0 : 1)
|
65
|
+
return if partitions_for_me == 0
|
66
|
+
|
67
|
+
first = partitions_per_consumer * index + (index < extra_partitions ? index : extra_partitions)
|
68
|
+
last = first + partitions_for_me - 1
|
69
|
+
|
70
|
+
(first..last)
|
68
71
|
end
|
69
72
|
|
70
73
|
# @attr_reader [String] name Group name
|
@@ -286,21 +286,29 @@ describe Poseidon::ConsumerGroup do
|
|
286
286
|
|
287
287
|
describe "pick" do
|
288
288
|
|
289
|
-
{
|
290
|
-
[
|
291
|
-
[
|
289
|
+
{
|
290
|
+
[1, ["N1"], "N1"] => (0..0),
|
291
|
+
[1, ["N1"], "N2"] => nil,
|
292
|
+
|
293
|
+
[1, ["N1", "N2"], "N1"] => (0..0),
|
294
|
+
[1, ["N1", "N2"], "N2"] => nil,
|
295
|
+
|
296
|
+
[2, ["N1", "N2"], "N1"] => (0..0),
|
297
|
+
[2, ["N1", "N2"], "N2"] => (1..1),
|
298
|
+
|
299
|
+
[3, ["N1", "N2", "N3"], "N1"] => (0..0),
|
300
|
+
[3, ["N1", "N2", "N3"], "N2"] => (1..1),
|
301
|
+
[3, ["N1", "N2", "N3"], "N3"] => (2..2),
|
302
|
+
[3, ["N1", "N2", "N3"], "N4"] => nil,
|
303
|
+
|
292
304
|
[4, ["N2", "N4", "N3", "N1"], "N3"] => (2..2),
|
293
|
-
|
294
|
-
[5, ["N1", "N2"
|
295
|
-
[5, ["N1", "N2"
|
296
|
-
|
297
|
-
[5, ["N1", "N2", "N3"], "
|
298
|
-
[
|
299
|
-
[
|
300
|
-
[1, ["N1", "N2", "N3"], "N2"] => nil,
|
301
|
-
[1, ["N1", "N2", "N3"], "N3"] => nil,
|
302
|
-
[5, ["N1", "N2"], "N1"] => (0..2),
|
303
|
-
[5, ["N1", "N2"], "N2"] => (3..4),
|
305
|
+
|
306
|
+
[5, ["N1", "N2"], "N1"] => (0..2),
|
307
|
+
[5, ["N1", "N2"], "N2"] => (3..4),
|
308
|
+
|
309
|
+
[5, ["N1", "N2", "N3"], "N1"] => (0..1),
|
310
|
+
[5, ["N1", "N2", "N3"], "N2"] => (2..3),
|
311
|
+
[5, ["N1", "N2", "N3"], "N3"] => (4..4),
|
304
312
|
}.each do |args, expected|
|
305
313
|
it "should pick #{expected.inspect} from #{args.inspect}" do
|
306
314
|
described_class.pick(*args).should == expected
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: promiscuous-poseidon_cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Black Square Media
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: poseidon
|