Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update to work with the latest doozerd

  • Loading branch information...
commit a08476f9e854243af9f87ae0efb1b3597f799971 1 parent 09cc5e0
Phil Whelan philwhln authored
6 README.md
Source Rendered
@@ -24,3 +24,9 @@ A synchronous Ruby client for [Doozer](https://github.com/ha/doozer).
24 24 => nil
25 25
26 26 See [examples](https://github.com/dylanegan/fraggle-block/tree/master/examples) for more.
  27 +
  28 +
  29 +# Generate ProtoBuf code
  30 +
  31 +BEEFCAKE_NAMESPACE=Fraggle::Block protoc --beefcake_out lib/fraggle/block/ -I . msg.proto
  32 +
27 lib/fraggle/block/client.rb
@@ -12,6 +12,9 @@ class OutOfNodes < StandardError; end
12 12
13 13 def initialize(addrs = [])
14 14 @addrs = addrs
  15 + if not @addrs or @addrs.length == 0
  16 + raise "No doozer servers to connect to"
  17 + end
15 18 connect
16 19 end
17 20
@@ -40,9 +43,22 @@ def del(path, rev)
40 43 send(request).first
41 44 end
42 45
43   - def walk(path, rev = nil)
44   - request = Request.new(:path => path, :rev => rev, :verb => WALK)
45   - send(request)
  46 + def walk(path, rev = nil, offset = 0)
  47 + all_responses = []
  48 + done = false
  49 + while not done
  50 + request = Request.new(:path => path, :rev => rev, :verb => WALK, :offset => offset)
  51 + responses = send(request)
  52 + responses.each do |response|
  53 + if response.err_code == Response::Err::RANGE
  54 + done = true
  55 + break
  56 + end
  57 + all_responses.push response
  58 + offset += 1
  59 + end
  60 + end
  61 + return all_responses
46 62 end
47 63
48 64 def disconnect
@@ -57,7 +73,7 @@ def reconnect
57 73 def connect
58 74 begin
59 75 host, port = @addrs.shift.split(':')
60   - @connection = connection_to(host, port)
  76 + @connection = connection_to(host, port.to_i)
61 77 find_all_of_the_nodes
62 78 rescue => e
63 79 retry if @addrs.any?
@@ -70,7 +86,8 @@ def connection_to(host, port)
70 86 end
71 87
72 88 def find_all_of_the_nodes
73   - walk('/ctl/node/*/addr').each do |node|
  89 + response = rev()
  90 + walk('/ctl/node/*/addr', response.rev).each do |node|
74 91 @addrs << node.value unless @addrs.include? node.value
75 92 end
76 93 end
15 lib/fraggle/block/connection.rb
@@ -25,7 +25,7 @@ def connect
25 25 begin
26 26 sock.connect_nonblock(Socket.pack_sockaddr_in(@port, addr[0][3]))
27 27 rescue Errno::EINPROGRESS
28   - resp = IO.select([sock],nil, nil, timeout.to_i)
  28 + resp = IO.select(nil, [sock], nil, timeout.to_i)
29 29 if resp.nil?
30 30 raise Errno::ECONNREFUSED
31 31 end
@@ -50,14 +50,11 @@ def send(req)
50 50
51 51 def read
52 52 responses = []
53   - loop do
54   - head = @sock.read(4)
55   - length = head.unpack("N")[0]
56   - data = @sock.read(length)
57   - response = Response.decode(data)
58   - responses << response if response.valid?
59   - break if response.done?
60   - end
  53 + head = @sock.read(4)
  54 + length = head.unpack("N")[0]
  55 + data = @sock.read(length)
  56 + response = Response.decode(data)
  57 + responses << response if response.valid?
61 58 responses
62 59 end
63 60 end
9 lib/fraggle/block/response.rb
... ... @@ -1,15 +1,8 @@
1 1 module Fraggle
2 2 module Block
3 3 class Response
4   - VALID = 1
5   - DONE = 2
6   -
7 4 def valid?
8   - (flags & VALID) > 0
9   - end
10   -
11   - def done?
12   - (flags & DONE) > 0
  5 + true
13 6 end
14 7 end
15 8 end

0 comments on commit a08476f

Please sign in to comment.
Something went wrong with that request. Please try again.