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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/poseidon/consumer_group.rb +23 -10
- data/poseidon_cluster.gemspec +1 -1
- data/spec/lib/poseidon/consumer_group_spec.rb +44 -0
- data/spec/spec_helper.rb +1 -0
- 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: 572fd136cb5145934e5c5ee72cd5b679c80284d3
|
4
|
+
data.tar.gz: f376b773d60c642603c45756a5626e3b67927037
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c09941bb0135cbfd85f6d761b3accae3d5e6bf37265a7afc8eb5cc32cf135d5a5f099d558d8bf8281afb7c7901a7a86eeb3dc5bcfe65acd0615d2683e5dc7dad
|
7
|
+
data.tar.gz: ae1cd45aedc7587e7324b34c5a06f9ca1f196a445fc6f2b03cb4a449e396e0713e08102f6d5d85df261ce7320916f9c89398cc48bd702e11c329f4994f350300
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
350
|
-
|
351
|
-
|
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
|
-
|
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
|
|
data/poseidon_cluster.gemspec
CHANGED
@@ -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
|
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
|
data/spec/spec_helper.rb
CHANGED
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
|
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-
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: poseidon
|