slyphon-zookeeper 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,48 @@
1
+ zookeeper
2
+
3
+ An interface to the Zookeeper distributed configuration server.
4
+
5
+ For a higher-level interface with a slightly more convenient API and features
6
+ such as locks, have a look at [ZK](https://github.com/slyphon/zk) (also
7
+ available is [ZK-EventMachine](https://github.com/slyphon/zk-eventmachine) for
8
+ those who prefer async).
9
+
10
+ ## License
11
+
12
+ Copyright 2008 Phillip Pearson, and 2010 Twitter, Inc. Licensed under the
13
+ MIT License. See the included LICENSE file. Portions copyright 2008-2010
14
+ the Apache Software Foundation, licensed under the Apache 2 license, and
15
+ used with permission.
16
+
17
+ ## Install
18
+
19
+ sudo gem install zookeeper
20
+
21
+ ## Usage
22
+
23
+ Connect to a server:
24
+
25
+ require 'rubygems'
26
+ require 'zookeeper'
27
+ z = Zookeeper.new("localhost:2181")
28
+ z.get_children(:path => "/")
29
+
30
+ ## Idioms
31
+
32
+ The following methods are initially supported:
33
+ * get
34
+ * set
35
+ * get\_children
36
+ * stat
37
+ * create
38
+ * delete
39
+ * get\_acl
40
+ * set\_acl
41
+
42
+ All support async callbacks. get, get\_children and stat support both
43
+ watchers and callbacks.
44
+
45
+ Calls take a dictionary of parameters. With the exception of set\_acl, the
46
+ only required parameter is :path. Each call returns a dictionary with at
47
+ minimum two keys :req\_id and :rc.
48
+
data/ext/.gitignore CHANGED
@@ -3,3 +3,4 @@ include
3
3
  lib
4
4
  *.bundle
5
5
 
6
+ c
data/ext/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+
2
+ task :clean do
3
+ if File.exists?('Makefile')
4
+ sh 'make clean'
5
+ else
6
+ $stderr.puts "nothing to clean, no Makefile"
7
+ end
8
+ end
9
+
10
+ task :clobber => :clean do
11
+ rm_rf %w[Makefile c lib bin include]
12
+ end
13
+
14
+ task :build_zkc do
15
+ ruby 'extconf.rb'
16
+ end
17
+
18
+ file 'Makefile' => :build_zkc
19
+
20
+ task :build => 'Makefile' do
21
+ sh 'make'
22
+ end
23
+
24
+ task :default => :build
25
+
data/ext/extconf.rb CHANGED
@@ -11,6 +11,7 @@ $LDFLAGS = "#{RbConfig::CONFIG['LDFLAGS']} #{$LDFLAGS}".gsub("$(ldflags)", "").g
11
11
  $CXXFLAGS = " -std=gnu++98 #{$CFLAGS}"
12
12
  $CPPFLAGS = $ARCH_FLAG = $DLDFLAGS = ""
13
13
 
14
+
14
15
  if ENV['DEBUG']
15
16
  $stderr.puts "*** Setting debug flags. ***"
16
17
  $CFLAGS << " -O0 -ggdb3 -DHAVE_DEBUG"
@@ -25,23 +26,31 @@ $LDFLAGS = "#{$libraries} #{$LDFLAGS}"
25
26
  $LIBPATH = ["#{HERE}/lib"]
26
27
  $DEFLIBPATH = []
27
28
 
29
+ def safe_sh(cmd)
30
+ puts cmd
31
+ system(cmd)
32
+ unless $?.exited? and $?.success?
33
+ raise "command failed! #{cmd}"
34
+ end
35
+ end
36
+
28
37
  Dir.chdir(HERE) do
29
38
  if File.exist?("lib")
30
39
  puts "Zkc already built; run 'rake clean' first if you need to rebuild."
31
40
  else
32
41
  puts "Building zkc."
33
- puts(cmd = "tar xzf #{BUNDLE} 2>&1")
34
- raise "'#{cmd}' failed" unless system(cmd)
35
42
 
36
- Dir.chdir(BUNDLE_PATH) do
37
- puts(cmd = "env CC=gcc CXX=g++ CFLAGS='-fPIC #{$CFLAGS}' LDFLAGS='-fPIC #{$LDFLAGS}' ./configure --prefix=#{HERE} --without-cppunit --disable-dependency-tracking #{$EXTRA_CONF} 2>&1")
38
- raise "'#{cmd}' failed" unless system(cmd)
39
- puts(cmd = "make CXXFLAGS='#{$CXXFLAGS}' CFLAGS='-fPIC #{$CFLAGS}' LDFLAGS='-fPIC #{$LDFLAGS}' || true 2>&1")
40
- raise "'#{cmd}' failed" unless system(cmd)
41
- puts(cmd = "make install || true 2>&1")
43
+ unless File.exists?('c')
44
+ puts(cmd = "tar xzf #{BUNDLE} 2>&1")
42
45
  raise "'#{cmd}' failed" unless system(cmd)
43
46
  end
44
47
 
48
+ Dir.chdir(BUNDLE_PATH) do
49
+ safe_sh("./configure --prefix=#{HERE} --with-pic --without-cppunit --disable-dependency-tracking #{$EXTRA_CONF} 2>&1")
50
+ safe_sh("make 2>&1")
51
+ safe_sh("make install 2>&1")
52
+ end
53
+
45
54
  system("rm -rf #{BUNDLE_PATH}") unless ENV['DEBUG'] or ENV['DEV']
46
55
  end
47
56
  end
data/ext/zookeeper_c.c CHANGED
@@ -140,17 +140,13 @@ static VALUE method_init(int argc, VALUE* argv, VALUE self) {
140
140
  zoo_set_debug_level(0); // no log messages
141
141
  } else {
142
142
  Check_Type(log_level, T_FIXNUM);
143
- zoo_set_debug_level(log_level);
143
+ zoo_set_debug_level((int)log_level);
144
144
  }
145
145
 
146
146
 
147
147
  VALUE data;
148
148
  struct zkrb_instance_data *zk_local_ctx;
149
- data = Data_Make_Struct(Zookeeper,
150
- struct zkrb_instance_data,
151
- 0,
152
- free_zkrb_instance_data,
153
- zk_local_ctx);
149
+ data = Data_Make_Struct(Zookeeper, struct zkrb_instance_data, 0, free_zkrb_instance_data, zk_local_ctx);
154
150
  zk_local_ctx->queue = zkrb_queue_alloc();
155
151
 
156
152
  zoo_deterministic_conn_order(0);
@@ -292,10 +288,11 @@ static VALUE method_create(VALUE self, VALUE reqid, VALUE path, VALUE data, VALU
292
288
  int rc;
293
289
  switch (call_type) {
294
290
  case SYNC:
295
- rc = zoo_create(zk->zh, RSTRING_PTR(path), data_ptr, data_len, aclptr, FIX2INT(flags), realpath, sizeof(realpath));
291
+ // casting data_len to int is OK as you can only store 1MB in zookeeper
292
+ rc = zoo_create(zk->zh, RSTRING_PTR(path), data_ptr, (int)data_len, aclptr, FIX2INT(flags), realpath, sizeof(realpath));
296
293
  break;
297
294
  case ASYNC:
298
- rc = zoo_acreate(zk->zh, RSTRING_PTR(path), data_ptr, data_len, aclptr, FIX2INT(flags), zkrb_string_callback, data_ctx);
295
+ rc = zoo_acreate(zk->zh, RSTRING_PTR(path), data_ptr, (int)data_len, aclptr, FIX2INT(flags), zkrb_string_callback, data_ctx);
299
296
  break;
300
297
  default:
301
298
  /* TODO(wickman) raise proper argument error */
@@ -394,10 +391,10 @@ static VALUE method_set(VALUE self, VALUE reqid, VALUE path, VALUE data, VALUE a
394
391
  int rc;
395
392
  switch (call_type) {
396
393
  case SYNC:
397
- rc = zoo_set2(zk->zh, RSTRING_PTR(path), data_ptr, data_len, FIX2INT(version), &stat);
394
+ rc = zoo_set2(zk->zh, RSTRING_PTR(path), data_ptr, (int)data_len, FIX2INT(version), &stat);
398
395
  break;
399
396
  case ASYNC:
400
- rc = zoo_aset(zk->zh, RSTRING_PTR(path), data_ptr, data_len, FIX2INT(version),
397
+ rc = zoo_aset(zk->zh, RSTRING_PTR(path), data_ptr, (int)data_len, FIX2INT(version),
401
398
  zkrb_stat_callback, data_ctx);
402
399
  break;
403
400
  default:
@@ -507,16 +504,8 @@ static VALUE method_get_next_event(VALUE self, VALUE blocking) {
507
504
  int fd = zk->queue->pipe_read;
508
505
  ssize_t bytes_read = 0;
509
506
 
510
- fd_set rset; // a file descriptor set for use w/ select()
511
-
512
- FD_ZERO(&rset); // FD_ZERO clears the set
513
- FD_SET(fd, &rset); // FD_SET adds fd to the rset
514
-
515
- // first arg is nfds: "the highest-numbered file descriptor in any of the three sets, plus 1"
516
- // why? F*** you, that's why!
517
-
518
- if (rb_thread_select(fd + 1, &rset, NULL, NULL, NULL) == -1)
519
- rb_raise(rb_eRuntimeError, "select failed: %d", errno);
507
+ // wait for an fd to become readable, opposite of rb_thread_fd_writable
508
+ rb_thread_wait_fd(fd);
520
509
 
521
510
  bytes_read = read(fd, buf, sizeof(buf));
522
511
 
data/ext/zookeeper_lib.c CHANGED
@@ -522,11 +522,12 @@ VALUE zkrb_acl_to_ruby(struct ACL *acl) {
522
522
  }
523
523
 
524
524
  #warning [wickman] TODO test zkrb_ruby_to_aclvector
525
+ #warning [slyphon] TODO size checking on acl_ary (cast to int)
525
526
  struct ACL_vector * zkrb_ruby_to_aclvector(VALUE acl_ary) {
526
527
  Check_Type(acl_ary, T_ARRAY);
527
528
 
528
529
  struct ACL_vector *v = malloc(sizeof(struct ACL_vector));
529
- allocate_ACL_vector(v, RARRAY_LEN(acl_ary));
530
+ allocate_ACL_vector(v, (int)RARRAY_LEN(acl_ary));
530
531
 
531
532
  int k;
532
533
  for (k = 0; k < v->count; ++k) {
data/lib/zookeeper.rb CHANGED
@@ -56,6 +56,7 @@ class Zookeeper < ZookeeperBase
56
56
  assert_open
57
57
  assert_supported_keys(options, [:path, :data, :version, :callback, :callback_context])
58
58
  assert_required_keys(options, [:path])
59
+ assert_valid_data_size!(options[:data])
59
60
  options[:version] ||= -1
60
61
 
61
62
  req_id = setup_call(options)
@@ -93,6 +94,7 @@ class Zookeeper < ZookeeperBase
93
94
  assert_open
94
95
  assert_supported_keys(options, [:path, :data, :acl, :ephemeral, :sequence, :callback, :callback_context])
95
96
  assert_required_keys(options, [:path])
97
+ assert_valid_data_size!(options[:data])
96
98
 
97
99
  flags = 0
98
100
  flags |= ZOO_EPHEMERAL if options[:ephemeral]
@@ -219,6 +221,16 @@ protected
219
221
  Zookeeper.logger
220
222
  end
221
223
 
224
+ def assert_valid_data_size!(data)
225
+ return if data.nil?
226
+
227
+ data = data.to_s
228
+ if data.length >= 1048576 # one megabyte
229
+ raise ZookeeperException::DataTooLargeException, "data must be smaller than 1 MiB, your data starts with: #{data[0..32].inspect}"
230
+ end
231
+ nil
232
+ end
233
+
222
234
  private
223
235
  def setup_call(opts)
224
236
  req_id = nil
@@ -57,6 +57,7 @@ module ZookeeperExceptions
57
57
  class ConnectionClosed < ZookeeperException; end
58
58
  class NotConnected < ZookeeperException; end
59
59
  class ShuttingDownException < ZookeeperException; end
60
+ class DataTooLargeException < ZookeeperException; end
60
61
 
61
62
  def self.by_code(code)
62
63
  case code
@@ -3,15 +3,18 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "slyphon-zookeeper"
6
- s.version = '0.2.4'
6
+ s.version = '0.2.5'
7
7
 
8
8
  s.authors = ["Phillip Pearson", "Eric Maland", "Evan Weaver", "Brian Wickman", "Neil Conway", "Jonathan D. Simms"]
9
9
  s.email = ["slyphon@gmail.com"]
10
10
  s.summary = %q{twitter's zookeeper client}
11
11
  s.description = s.summary
12
+ s.homepage = 'https://github.com/slyphon/zookeeper'
12
13
 
13
14
  s.add_development_dependency "rspec", ">= 2.0.0"
14
15
  s.add_development_dependency 'flexmock', '~> 0.8.11'
16
+ s.add_development_dependency 'eventmachine', '1.0.0.beta.4'
17
+ s.add_development_dependency 'evented-spec', '~> 0.9.0'
15
18
 
16
19
  s.files = `git ls-files`.split("\n")
17
20
  s.require_paths = ["lib"]
data/spec/em_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../spec_helper', __FILE__)
2
2
  require 'zookeeper/em_client'
3
3
 
4
- gem 'evented-spec', '~> 0.4.1'
4
+ gem 'evented-spec', '~> 0.9.0'
5
5
  require 'evented-spec'
6
6
 
7
7
 
@@ -203,6 +203,14 @@ describe Zookeeper do
203
203
  @rv[:stat].exists.should be_false
204
204
  end
205
205
  end
206
+
207
+ describe 'error' do
208
+ it %[should barf if the data size is too large], :input_size => true do
209
+ large_data = '0' * (1024 ** 2)
210
+
211
+ lambda { @zk.set(:path => @path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
212
+ end
213
+ end
206
214
  end # sync
207
215
 
208
216
  describe :async do
@@ -269,8 +277,17 @@ describe Zookeeper do
269
277
  @cb.stat.exists.should be_false
270
278
  end
271
279
  end
272
- end
273
- end
280
+
281
+ describe 'error' do
282
+ it %[should barf if the data size is too large], :input_size => true do
283
+ large_data = '0' * (1024 ** 2)
284
+
285
+ lambda { @zk.set(:path => @path, :data => large_data, :callback => @cb, :callback_context => @path) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
286
+ end
287
+ end
288
+
289
+ end # async
290
+ end # set
274
291
 
275
292
  describe :get_children do
276
293
  before do
@@ -538,6 +555,14 @@ describe Zookeeper do
538
555
  end
539
556
 
540
557
  describe :sync do
558
+ describe 'error' do
559
+ it %[should barf if the data size is too large], :input_size => true do
560
+ large_data = '0' * (1024 ** 2)
561
+
562
+ lambda { @zk.create(:path => @path, :data => large_data) }.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
563
+ end
564
+ end
565
+
541
566
  describe :default_flags do
542
567
  it_should_behave_like "all success return values"
543
568
 
@@ -655,6 +680,17 @@ describe Zookeeper do
655
680
  end
656
681
  end
657
682
 
683
+ describe 'error' do
684
+ it %[should barf if the data size is too large], :input_size => true do
685
+ large_data = '0' * (1024 ** 2)
686
+
687
+ lambda do
688
+ @zk.create(:path => @path, :data => large_data, :callback => @cb, :callback_context => @path)
689
+ end.should raise_error(ZookeeperExceptions::ZookeeperException::DataTooLargeException)
690
+ end
691
+ end
692
+
693
+
658
694
  describe :ephemeral do
659
695
  it_should_behave_like "all success return values"
660
696
 
@@ -736,15 +772,9 @@ describe Zookeeper do
736
772
 
737
773
  st[:stat].ephemeral_owner.should_not be_zero
738
774
  end
739
- end
740
-
741
- describe :acl do
742
- it %[should work] do
743
- pending "need to write acl tests"
744
- end
745
- end
746
- end
747
- end
775
+ end # ephemeral_sequence
776
+ end # async
777
+ end # create
748
778
 
749
779
  describe :delete do
750
780
  describe :sync do
@@ -846,7 +876,7 @@ describe Zookeeper do
846
876
  @cb.return_code.should == Zookeeper::ZBADVERSION
847
877
  end
848
878
  end
849
- end
879
+ end # async
850
880
  end # delete
851
881
 
852
882
  describe :get_acl do
metadata CHANGED
@@ -1,15 +1,10 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: slyphon-zookeeper
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Phillip Pearson
14
9
  - Eric Maland
15
10
  - Evan Weaver
@@ -19,61 +14,70 @@ authors:
19
14
  autorequire:
20
15
  bindir: bin
21
16
  cert_chain: []
22
-
23
- date: 2011-06-29 00:00:00 +00:00
24
- default_executable:
25
- dependencies:
26
- - !ruby/object:Gem::Dependency
17
+ date: 2011-11-14 00:00:00.000000000 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
27
20
  name: rspec
28
- prerelease: false
29
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ requirement: &70134739892840 !ruby/object:Gem::Requirement
30
22
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- hash: 15
35
- segments:
36
- - 2
37
- - 0
38
- - 0
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
39
26
  version: 2.0.0
40
27
  type: :development
41
- version_requirements: *id001
42
- - !ruby/object:Gem::Dependency
43
- name: flexmock
44
28
  prerelease: false
45
- requirement: &id002 !ruby/object:Gem::Requirement
29
+ version_requirements: *70134739892840
30
+ - !ruby/object:Gem::Dependency
31
+ name: flexmock
32
+ requirement: &70134739892020 !ruby/object:Gem::Requirement
46
33
  none: false
47
- requirements:
34
+ requirements:
48
35
  - - ~>
49
- - !ruby/object:Gem::Version
50
- hash: 41
51
- segments:
52
- - 0
53
- - 8
54
- - 11
36
+ - !ruby/object:Gem::Version
55
37
  version: 0.8.11
56
38
  type: :development
57
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: *70134739892020
41
+ - !ruby/object:Gem::Dependency
42
+ name: eventmachine
43
+ requirement: &70134739891420 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - =
47
+ - !ruby/object:Gem::Version
48
+ version: 1.0.0.beta.4
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: *70134739891420
52
+ - !ruby/object:Gem::Dependency
53
+ name: evented-spec
54
+ requirement: &70134739890760 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: 0.9.0
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *70134739890760
58
63
  description: twitter's zookeeper client
59
- email:
64
+ email:
60
65
  - slyphon@gmail.com
61
66
  executables: []
62
-
63
- extensions:
67
+ extensions:
64
68
  - ext/extconf.rb
65
69
  extra_rdoc_files: []
66
-
67
- files:
70
+ files:
68
71
  - .gitignore
69
72
  - CHANGELOG
70
73
  - Gemfile
71
74
  - LICENSE
72
75
  - Manifest
73
- - README
76
+ - README.markdown
74
77
  - Rakefile
75
78
  - examples/cloud_config.rb
76
79
  - ext/.gitignore
80
+ - ext/Rakefile
77
81
  - ext/extconf.rb
78
82
  - ext/zkc-3.3.3.tar.gz
79
83
  - ext/zookeeper_base.rb
@@ -102,42 +106,32 @@ files:
102
106
  - test/test_esoteric.rb
103
107
  - test/test_watcher1.rb
104
108
  - test/test_watcher2.rb
105
- has_rdoc: true
106
- homepage:
109
+ homepage: https://github.com/slyphon/zookeeper
107
110
  licenses: []
108
-
109
111
  post_install_message:
110
112
  rdoc_options: []
111
-
112
- require_paths:
113
+ require_paths:
113
114
  - lib
114
115
  - ext
115
- required_ruby_version: !ruby/object:Gem::Requirement
116
+ required_ruby_version: !ruby/object:Gem::Requirement
116
117
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 3
121
- segments:
122
- - 0
123
- version: "0"
124
- required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
123
  none: false
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- hash: 3
130
- segments:
131
- - 0
132
- version: "0"
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
133
128
  requirements: []
134
-
135
129
  rubyforge_project:
136
- rubygems_version: 1.6.2
130
+ rubygems_version: 1.8.10
137
131
  signing_key:
138
132
  specification_version: 3
139
133
  summary: twitter's zookeeper client
140
- test_files:
134
+ test_files:
141
135
  - spec/default_watcher_spec.rb
142
136
  - spec/em_spec.rb
143
137
  - spec/log4j.properties
data/README DELETED
@@ -1,42 +0,0 @@
1
- zookeeper
2
-
3
- An interface to the Zookeeper distributed configuration server.
4
-
5
- == License
6
-
7
- Copyright 2008 Phillip Pearson, and 2010 Twitter, Inc. Licensed under the
8
- MIT License. See the included LICENSE file. Portions copyright 2008-2010
9
- the Apache Software Foundation, licensed under the Apache 2 license, and
10
- used with permission.
11
-
12
- == Install
13
-
14
- sudo gem install zookeeper
15
-
16
- == Usage
17
-
18
- Connect to a server:
19
-
20
- require 'rubygems'
21
- require 'zookeeper'
22
- z = Zookeeper.new("localhost:2181")
23
- z.get_children(:path => "/")
24
-
25
- == Idioms
26
-
27
- The following methods are initially supported:
28
- get
29
- set
30
- get_children
31
- stat
32
- create
33
- delete
34
- get_acl
35
- set_acl
36
-
37
- All support async callbacks. get, get_children and stat support both
38
- watchers and callbacks.
39
-
40
- Calls take a dictionary of parameters. With the exception of set_acl, the
41
- only required parameter is :path. Each call returns a dictionary with at
42
- minimum two keys :req_id and :rc.