promiscuous-poseidon_cluster 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9fc0d8c24c41642e703279f9feeb80e10c788b8
4
- data.tar.gz: 6c35c729adac40669cbb915542810ab107f7dd07
3
+ metadata.gz: f0a3206a576efca5e80710de7873bdf951b4fda0
4
+ data.tar.gz: 588e34330624b29fa6a127b67c24eaafb679a60f
5
5
  SHA512:
6
- metadata.gz: 2b7f1477c8fe08586939a90af7a6b7ee4f03a97e59140afb5252d8442f0ad99926bd644848a40fc844116982460a20ded382c0a1ac1493d5c292acb70ca2979a
7
- data.tar.gz: d7c875b13cce867d3f43e9969419efc6db74b6fd9e97e3e116c16a3e09b18445cd90564eb44224ca657ef773c5c264d97e95e72b44f4cf9c7777a3133d8bd5fb
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] pnum number of partitions size
53
- # @param [Array<String>] cids consumer IDs
54
- # @param [String] id consumer ID
55
- # @return [Range, NilClass] selectable range, if any
56
- def self.pick(pnum, cids, id)
57
- cids = cids.sort
58
- pos = cids.index(id)
59
- return unless pos && pos < cids.size
60
-
61
- step = pnum.fdiv(cids.size).ceil
62
- frst = pos*step
63
- last = (pos+1)*step-1
64
- last = pnum-1 if last > pnum-1
65
- return if last < 0 || last < frst
66
-
67
- (frst..last)
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
- { [3, ["N1", "N2", "N3"], "N1"] => (0..0),
290
- [3, ["N1", "N2", "N3"], "N2"] => (1..1),
291
- [3, ["N1", "N2", "N3"], "N3"] => (2..2),
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
- [3, ["N1", "N2", "N3"], "N4"] => nil,
294
- [5, ["N1", "N2", "N3"], "N1"] => (0..1),
295
- [5, ["N1", "N2", "N3"], "N2"] => (2..3),
296
- [5, ["N1", "N2", "N3"], "N3"] => (4..4),
297
- [5, ["N1", "N2", "N3"], "N4"] => nil,
298
- [2, ["N1", "N2"], "N9"] => nil,
299
- [1, ["N1", "N2", "N3"], "N1"] => (0..0),
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.2
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-07 00:00:00.000000000 Z
12
+ date: 2015-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: poseidon