poseidon_cluster 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58d3c657309fe7381c8776baa87f54b41f04281f
4
- data.tar.gz: 009a15759814e1c92bdec7e903d9a8fb16a4ce4a
3
+ metadata.gz: 572fd136cb5145934e5c5ee72cd5b679c80284d3
4
+ data.tar.gz: f376b773d60c642603c45756a5626e3b67927037
5
5
  SHA512:
6
- metadata.gz: 1fc88b0a4b8f27cb3314db151956242a1c1e3caaa78fa89a17c15907e28a0cfc6ac0bfeadd26829245a01e331ee1112bf6abf2201357418f5bccef4b0ddb933c
7
- data.tar.gz: 79d9a39b2ab8a424ed3e0d44419e3c021983afb617637db237ce2ee0134ff18dcaca7494ce65bd535b400cfb1ef816cacf20d0a8c7ebe1c32bd1b05356a699c9
6
+ metadata.gz: c09941bb0135cbfd85f6d761b3accae3d5e6bf37265a7afc8eb5cc32cf135d5a5f099d558d8bf8281afb7c7901a7a86eeb3dc5bcfe65acd0615d2683e5dc7dad
7
+ data.tar.gz: ae1cd45aedc7587e7324b34c5a06f9ca1f196a445fc6f2b03cb4a449e396e0713e08102f6d5d85df261ce7320916f9c89398cc48bd702e11c329f4994f350300
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- poseidon_cluster (0.0.5)
10
+ poseidon_cluster (0.1.0)
11
11
  poseidon
12
12
  zk
13
13
 
@@ -42,6 +42,24 @@ class Poseidon::ConsumerGroup
42
42
 
43
43
  end
44
44
 
45
+ # @param [Integer] pnum number of partitions size
46
+ # @param [Array<String>] cids consumer IDs
47
+ # @param [String] id consumer ID
48
+ # @return [Range, NilClass] selectable range, if any
49
+ def self.pick(pnum, cids, id)
50
+ cids = cids.sort
51
+ pos = cids.index(id)
52
+ return unless pos && pos < cids.size
53
+
54
+ step = pnum.fdiv(cids.size).ceil
55
+ frst = pos*step
56
+ last = (pos+1)*step-1
57
+ last = pnum-1 if last > pnum-1
58
+ return if last < 0 || last < frst
59
+
60
+ (frst..last)
61
+ end
62
+
45
63
  # @attr_reader [String] name Group name
46
64
  attr_reader :name
47
65
 
@@ -346,19 +364,14 @@ class Poseidon::ConsumerGroup
346
364
  reload
347
365
  release_all!
348
366
 
349
- cmg = zk.children(registries[:consumer], watch: true).sort
350
- ptm = partitions
351
- pos = cmg.index(id)
352
- break unless ptm.size > pos
353
-
354
- num = ptm.size / cmg.size
355
- num = 1 if num < 1
356
- rng = pos*num..(pos+1)*num-1
367
+ ids = zk.children(registries[:consumer], watch: true)
368
+ pms = partitions
369
+ rng = self.class.pick(pms.size, ids, id)
357
370
 
358
- (ptm[rng] || []).each do |pm|
371
+ pms[rng].each do |pm|
359
372
  consumer = claim!(pm.id)
360
373
  @consumers.push(consumer)
361
- end
374
+ end if rng
362
375
  end
363
376
  end
364
377
 
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.name = File.basename(__FILE__, '.gemspec')
6
6
  s.summary = "Poseidon cluster extensions"
7
7
  s.description = "Cluster extensions for Poseidon, a producer and consumer implementation for Kafka >= 0.8"
8
- s.version = "0.0.5"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.authors = ["Black Square Media"]
11
11
  s.email = "info@blacksquaremedia.com"
@@ -154,6 +154,25 @@ describe Poseidon::ConsumerGroup do
154
154
  c.claimed.should == [0]
155
155
  end
156
156
 
157
+ it "should allocate partitions correctly" do
158
+ subject.claimed.should == [0, 1]
159
+
160
+ b = new_group
161
+ wait_for { subject.claimed.size > 0 }
162
+ wait_for { b.claimed.size > 0 }
163
+ subject.claimed.should == [1]
164
+ b.claimed.should == [0]
165
+
166
+ c = new_group
167
+ b.close
168
+ wait_for { b.claimed.size < 0 }
169
+ wait_for { c.claimed.size > 0 }
170
+
171
+ subject.claimed.should == [1]
172
+ b.claimed.should == []
173
+ c.claimed.should == [0]
174
+ end
175
+
157
176
  end
158
177
 
159
178
  describe "fetch" do
@@ -245,4 +264,29 @@ describe Poseidon::ConsumerGroup do
245
264
  end
246
265
 
247
266
  end
267
+
268
+ describe "pick" do
269
+
270
+ { [3, ["N1", "N2", "N3"], "N1"] => (0..0),
271
+ [3, ["N1", "N2", "N3"], "N2"] => (1..1),
272
+ [3, ["N1", "N2", "N3"], "N3"] => (2..2),
273
+ [4, ["N2", "N4", "N3", "N1"], "N3"] => (2..2),
274
+ [3, ["N1", "N2", "N3"], "N4"] => nil,
275
+ [5, ["N1", "N2", "N3"], "N1"] => (0..1),
276
+ [5, ["N1", "N2", "N3"], "N2"] => (2..3),
277
+ [5, ["N1", "N2", "N3"], "N3"] => (4..4),
278
+ [5, ["N1", "N2", "N3"], "N4"] => nil,
279
+ [2, ["N1", "N2"], "N9"] => nil,
280
+ [1, ["N1", "N2", "N3"], "N1"] => (0..0),
281
+ [1, ["N1", "N2", "N3"], "N2"] => nil,
282
+ [1, ["N1", "N2", "N3"], "N3"] => nil,
283
+ [5, ["N1", "N2"], "N1"] => (0..2),
284
+ [5, ["N1", "N2"], "N2"] => (3..4),
285
+ }.each do |args, expected|
286
+ it "should pick #{expected.inspect} from #{args.inspect}" do
287
+ described_class.pick(*args).should == expected
288
+ end
289
+ end
290
+
291
+ end
248
292
  end
@@ -3,6 +3,7 @@ require 'rspec'
3
3
  require 'fileutils'
4
4
  require 'pathname'
5
5
  require 'coveralls'
6
+ Coveralls.wear_merged!
6
7
 
7
8
  TOPIC_NAME = "my-topic"
8
9
  KAFKA_LOCAL = File.expand_path("../kafka_2.8.0-0.8.0", __FILE__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poseidon_cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: poseidon