zookeeper-ng 1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.ctags_paths +1 -0
  3. data/.dotfiles/ruby-gemset +1 -0
  4. data/.dotfiles/ruby-version +1 -0
  5. data/.dotfiles/rvmrc +2 -0
  6. data/.gitignore +19 -0
  7. data/.gitmodules +3 -0
  8. data/.travis.yml +25 -0
  9. data/CHANGELOG +395 -0
  10. data/Gemfile +30 -0
  11. data/Guardfile +8 -0
  12. data/LICENSE +23 -0
  13. data/Manifest +29 -0
  14. data/README.markdown +85 -0
  15. data/Rakefile +121 -0
  16. data/cause-abort.rb +117 -0
  17. data/ext/.gitignore +6 -0
  18. data/ext/Rakefile +41 -0
  19. data/ext/c_zookeeper.rb +398 -0
  20. data/ext/common.h +17 -0
  21. data/ext/dbg.h +53 -0
  22. data/ext/depend +5 -0
  23. data/ext/event_lib.c +740 -0
  24. data/ext/event_lib.h +175 -0
  25. data/ext/extconf.rb +103 -0
  26. data/ext/generate_gvl_code.rb +321 -0
  27. data/ext/patches/zkc-3.3.5-network.patch +24 -0
  28. data/ext/patches/zkc-3.4.5-fetch-and-add.patch +16 -0
  29. data/ext/patches/zkc-3.4.5-logging.patch +41 -0
  30. data/ext/patches/zkc-3.4.5-out-of-order-ping.patch +163 -0
  31. data/ext/patches/zkc-3.4.5-overflow.patch +11 -0
  32. data/ext/patches/zkc-3.4.5-yosemite-htonl-fix.patch +102 -0
  33. data/ext/zkc-3.4.5.tar.gz +0 -0
  34. data/ext/zkrb.c +1075 -0
  35. data/ext/zkrb_wrapper.c +775 -0
  36. data/ext/zkrb_wrapper.h +350 -0
  37. data/ext/zkrb_wrapper_compat.c +15 -0
  38. data/ext/zkrb_wrapper_compat.h +11 -0
  39. data/ext/zookeeper_base.rb +256 -0
  40. data/java/java_base.rb +503 -0
  41. data/lib/zookeeper.rb +115 -0
  42. data/lib/zookeeper/acls.rb +44 -0
  43. data/lib/zookeeper/callbacks.rb +108 -0
  44. data/lib/zookeeper/client.rb +30 -0
  45. data/lib/zookeeper/client_methods.rb +282 -0
  46. data/lib/zookeeper/common.rb +122 -0
  47. data/lib/zookeeper/common/queue_with_pipe.rb +110 -0
  48. data/lib/zookeeper/compatibility.rb +138 -0
  49. data/lib/zookeeper/constants.rb +97 -0
  50. data/lib/zookeeper/continuation.rb +223 -0
  51. data/lib/zookeeper/core_ext.rb +58 -0
  52. data/lib/zookeeper/em_client.rb +55 -0
  53. data/lib/zookeeper/exceptions.rb +135 -0
  54. data/lib/zookeeper/forked.rb +19 -0
  55. data/lib/zookeeper/latch.rb +34 -0
  56. data/lib/zookeeper/logger.rb +39 -0
  57. data/lib/zookeeper/logger/forwarding_logger.rb +84 -0
  58. data/lib/zookeeper/monitor.rb +19 -0
  59. data/lib/zookeeper/rake_tasks.rb +165 -0
  60. data/lib/zookeeper/request_registry.rb +153 -0
  61. data/lib/zookeeper/stat.rb +21 -0
  62. data/lib/zookeeper/version.rb +4 -0
  63. data/notes.txt +14 -0
  64. data/scripts/upgrade-1.0-sed-alike.rb +46 -0
  65. data/spec/c_zookeeper_spec.rb +51 -0
  66. data/spec/chrooted_connection_spec.rb +83 -0
  67. data/spec/compatibilty_spec.rb +8 -0
  68. data/spec/default_watcher_spec.rb +41 -0
  69. data/spec/em_spec.rb +51 -0
  70. data/spec/ext/zookeeper_base_spec.rb +19 -0
  71. data/spec/forked_connection_spec.rb +124 -0
  72. data/spec/latch_spec.rb +24 -0
  73. data/spec/log4j.properties +17 -0
  74. data/spec/shared/all_success_return_values.rb +10 -0
  75. data/spec/shared/connection_examples.rb +1077 -0
  76. data/spec/spec_helper.rb +61 -0
  77. data/spec/support/00_logging.rb +38 -0
  78. data/spec/support/10_spawn_zookeeper.rb +24 -0
  79. data/spec/support/progress_formatter.rb +15 -0
  80. data/spec/support/zookeeper_spec_helpers.rb +96 -0
  81. data/spec/zookeeper_spec.rb +24 -0
  82. data/zookeeper.gemspec +38 -0
  83. data/zoomonkey/duplicates +3 -0
  84. data/zoomonkey/zoomonkey.rb +194 -0
  85. metadata +157 -0
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake', '~> 0.9.0'
6
+
7
+ group :test do
8
+ gem "rspec" , "~> 2.11"
9
+ gem 'eventmachine', '1.0.4'
10
+ gem 'evented-spec', '~> 0.9.0'
11
+ gem 'zk-server', '~> 1.0', :git => 'https://github.com/zk-ruby/zk-server.git'
12
+ end
13
+
14
+ # ffs, :platform appears to be COMLETELY BROKEN so we just DO THAT HERE
15
+ # ...BY HAND
16
+
17
+ if RUBY_VERSION != '1.8.7' && !defined?(JRUBY_VERSION)
18
+ gem 'simplecov', :group => :coverage, :require => false
19
+ gem 'yard', '~> 0.8.0', :group => :docs
20
+ gem 'redcarpet', :group => :docs
21
+
22
+ group :development do
23
+ gem 'pry'
24
+ gem 'guard', :require => false
25
+ gem 'guard-rspec', :require => false
26
+ gem 'guard-shell', :require => false
27
+ end
28
+ end
29
+
30
+ # vim:ft=ruby
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+
2
+ guard 'rspec', :version => 2, :cli => '-c -f progress --fail-fast' do
3
+ watch(%r{^spec/.+_spec.rb$})
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| %w[spec/zookeeper_spec.rb spec/chrooted_connection_spec.rb] }
5
+ watch(%r{^ext/zookeeper_c.bundle}) { %w[spec/c_zookeeper_spec.rb] }
6
+ watch(%r{^ext/zookeeper_base.rb}) { "spec" }
7
+ end
8
+
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ (The MIT License)
2
+
3
+ Copyright (C) 2008 Phillip Pearson
4
+ Copyright (C) 2010 Twitter, Inc.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ 'Software'), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,29 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README
5
+ Rakefile
6
+ examples/cloud_config.rb
7
+ ext/extconf.rb
8
+ ext/zkc-3.3.4.tar.gz
9
+ ext/zookeeper_base.rb
10
+ ext/zookeeper_c.c
11
+ ext/zookeeper_lib.c
12
+ ext/zookeeper_lib.h
13
+ java/zookeeper_base.rb
14
+ lib/zookeeper.rb
15
+ lib/zookeeper/acls.rb
16
+ lib/zookeeper/callbacks.rb
17
+ lib/zookeeper/common.rb
18
+ lib/zookeeper/constants.rb
19
+ lib/zookeeper/exceptions.rb
20
+ lib/zookeeper/stat.rb
21
+ spec/log4j.properties
22
+ spec/spec_helper.rb
23
+ spec/zookeeper_spec.rb
24
+ test/test_basic.rb
25
+ test/test_callback1.rb
26
+ test/test_close.rb
27
+ test/test_esoteric.rb
28
+ test/test_watcher1.rb
29
+ test/test_watcher2.rb
data/README.markdown ADDED
@@ -0,0 +1,85 @@
1
+ # zookeeper #
2
+
3
+ [![Build Status](https://secure.travis-ci.org/zk-ruby/zookeeper.png?branch=master)](http://travis-ci.org/zk-ruby/zookeeper)
4
+
5
+ An interface to the Zookeeper cluster coordination server.
6
+
7
+ For a higher-level interface with a more convenient API and features such as locks, have a look at [ZK](https://github.com/zk-ruby/zk).
8
+
9
+ ## Fork Safety! ##
10
+
11
+ As of 1.1.0, this library is fork-safe (which was not easy to accomplish). This means you can use it without worry in unicorn, resque, and whatever other fork-philic frameworks you sick little monkeys are using this week. The only rule is that after a fork(), you need to call `#reopen` on the client ASAP, because if you try to peform any other action, an exception will be raised. Other than that, there is no special action that is needed in the parent.
12
+
13
+ ## Big Plans for 1.0 ##
14
+
15
+ The 1.0 release will feature a reorganization of the heirarchy. There will be a single top-level `Zookeeper` namespace (as opposed to the current layout, with 5-6 different top-level constants), and for the next several releases, there will be a backwards compatible require for users that still need to use the old names.
16
+
17
+ ## License
18
+
19
+ Copyright 2008 Phillip Pearson, and 2010 Twitter, Inc.
20
+ Licensed under the MIT License. See the included LICENSE file.
21
+
22
+ Portions copyright 2008-2010 the Apache Software Foundation, licensed under the
23
+ Apache 2 license, and used with permission.
24
+
25
+ Portions contributed to the open source community by HPDC, L.P.
26
+
27
+ ## Install
28
+
29
+ sudo gem install zookeeper
30
+
31
+ ### rbenv is awesome
32
+
33
+ UPDATE: this appears to have been fixed by @eric in [this patch](http://git.io/PEPgnA). If you use rbenv, please report any issues, but I believe it should work now.
34
+
35
+ Let me start out by saying I prefer rvm, and that I really don't know a whole lot about linking on OS X. Or Linux. Any suggestions or constructive insults would be greatly appreciated if you have insight into what i'm doing wrong here.
36
+
37
+ So, it seems that [ruby-build][] doesn't use `--enable-shared` by default. I'm told this is for speed.
38
+
39
+ If you run into problems with installing this gem (specifically with linking ex. `Undefined symbols for architecture x86_64`) and you're using rbenv, for now you need to ensure that your ruby was built with `--enable-shared`. I'm sorry for the inconvenience. (no, really)
40
+
41
+ ```shell
42
+ ~ $ CONFIGURE_OPTS='--enable-shared --disable-install-doc' rbenv install 1.9.3-p194
43
+ ```
44
+
45
+ [ruby-build]: https://github.com/sstephenson/ruby-build
46
+
47
+ ### A note for REE users
48
+
49
+ The zookeeper client is required to send a heartbeat packet every N seconds to the server. If it misses its deadline 3 times in a row, the session will be lost. The way the client is implemented in versions `>= 1.2`, a *ruby* thread acts as the event thread (this was necessary to provide a fork-safe client with a parent process that is able to preserve state). Some users have reported issues where under load in "massive codebases," they have problems where calls will time out. Given the nature of the thread scheduler in 1.8, one should be careful if upgrading from `0.4.4` to `>= 1.2`.
50
+
51
+ ## Usage
52
+
53
+ Connect to a server:
54
+
55
+ require 'rubygems'
56
+ require 'zookeeper'
57
+ z = Zookeeper.new("localhost:2181")
58
+ z.get_children(:path => "/")
59
+
60
+ ## Idioms
61
+
62
+ The following methods are initially supported:
63
+ * `get`
64
+ * `set`
65
+ * `get_children`
66
+ * `stat`
67
+ * `create`
68
+ * `delete`
69
+ * `get_acl`
70
+ * `set_acl`
71
+
72
+ All support async callbacks. `get`, `get_children` and `stat` support both watchers and callbacks.
73
+
74
+ Calls take a dictionary of parameters. With the exception of set\_acl, the only required parameter is `:path`. Each call returns a dictionary with at minimum two keys :req\_id and :rc.
75
+
76
+ ### A Bit about this repository ###
77
+
78
+ Twitter's open source office was kind enough to transfer this repository to facilitate development and administration of this repository. The `zookeeper` gem's last three releases were recorded in branches `v0.4.2`, `v0.4.3` and `v0.4.4`. Releases of the `slyphon-zookeeper` gem were cut off of the fork, and unfortunately (due to an oversight on my part) were tagged with unrelated versions. Those were tagged with names `release/0.9.2`.
79
+
80
+ The plan is to keep the `slyphon-zookeeper` tags, and to tag the `zookeeper` releases `twitter/release/0.4.x`.
81
+
82
+ Further work will be carried out on this repository. The `0.9.3` release of the zookeeper gem will be released under the 'zookeeper' name, and will bring the two divergent (conceptual) branches of development together.
83
+
84
+
85
+
data/Rakefile ADDED
@@ -0,0 +1,121 @@
1
+ release_ops_path = File.expand_path('../releaseops/lib', __FILE__)
2
+
3
+ # if the special submodule is availabe, use it
4
+ # we use a submodule because it doesn't depend on anything else (*cough* bundler)
5
+ # and can be shared across projects
6
+ #
7
+ if File.exists?(release_ops_path)
8
+ require File.join(release_ops_path, 'releaseops')
9
+
10
+ # sets up the multi-ruby zk:test_all rake tasks
11
+ ReleaseOps::TestTasks.define_for(*%w[1.8.7 1.9.2 jruby rbx ree 1.9.3])
12
+
13
+ # sets up the task :default => 'spec:run' and defines a simple
14
+ # "run the specs with the current rvm profile" task
15
+ ReleaseOps::TestTasks.define_simple_default_for_travis
16
+
17
+ # Define a task to run code coverage tests
18
+ ReleaseOps::TestTasks.define_simplecov_tasks
19
+
20
+ # set up yard:server, yard:gems, and yard:clean tasks
21
+ # for doing documentation stuff
22
+ ReleaseOps::YardTasks.define
23
+
24
+ task :clean => 'yard:clean'
25
+
26
+ namespace :zk do
27
+ namespace :gems do
28
+ desc "Build gems to prepare for a release. Requires TAG="
29
+ task :build do
30
+ require 'tmpdir'
31
+
32
+ raise "You must specify a TAG" unless ENV['TAG']
33
+
34
+ ReleaseOps.with_tmpdir(:prefix => 'zookeeper') do |tmpdir|
35
+ tag = ENV['TAG']
36
+
37
+ sh "git clone . #{tmpdir}"
38
+
39
+ orig_dir = Dir.getwd
40
+
41
+ cd tmpdir do
42
+ sh "git co #{tag} && git reset --hard && git clean -fdx"
43
+
44
+ ENV['JAVA_GEM'] = nil
45
+ sh "gem build zookeeper.gemspec"
46
+ sh "env JAVA_GEM=1 gem build zookeeper.gemspec"
47
+
48
+ mv FileList['*.gem'], orig_dir
49
+ end
50
+ end
51
+ end
52
+
53
+ desc "Release gems that have been built"
54
+ task :push do
55
+ gems = FileList['*.gem']
56
+ raise "No gemfiles to push!" if gems.empty?
57
+
58
+ gems.each do |gem|
59
+ sh "gem push #{gem}"
60
+ end
61
+ end
62
+
63
+ task :clean do
64
+ rm_rf FileList['*.gem']
65
+ end
66
+
67
+ task :all => [:build, :push, :clean]
68
+ end
69
+ end
70
+ end
71
+
72
+ task :clobber do
73
+ rm_rf 'tmp'
74
+ end
75
+
76
+ # cargo culted from http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
77
+ VALGRIND_BASIC_OPTS = '--num-callers=50 --error-limit=no --partial-loads-ok=yes --undef-value-errors=no --trace-children=yes'
78
+
79
+ task 'valgrind' do
80
+ cd 'ext' do
81
+ sh "rake clean build"
82
+ end
83
+
84
+ sh "valgrind #{VALGRIND_BASIC_OPTS} bundle exec rspec spec"
85
+ end
86
+
87
+ namespace :build do
88
+ task :clean do
89
+ cd 'ext' do
90
+ sh 'rake clean'
91
+ end
92
+
93
+ Rake::Task['build'].invoke
94
+ end
95
+
96
+ task :clobber do
97
+ cd 'ext' do
98
+ sh 'rake clobber'
99
+ end
100
+
101
+ Rake::Task['build'].invoke
102
+ end
103
+ end
104
+
105
+ desc "Build C component"
106
+ task :build do
107
+ cd 'ext' do
108
+ sh "rake"
109
+ end
110
+ end
111
+
112
+ task 'spec:run' => 'build:clean' unless defined?(::JRUBY_VERSION)
113
+
114
+ task 'ctags' do
115
+ sh 'bundle-ctags'
116
+ end
117
+
118
+ # because i'm a creature of habit
119
+ task 'mb:test_all' => 'zk:test_all'
120
+
121
+
data/cause-abort.rb ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'zookeeper'
4
+ require File.expand_path('../spec/support/zookeeper_spec_helpers', __FILE__)
5
+
6
+ class CauseAbort
7
+ include Zookeeper::Logger
8
+ include Zookeeper::SpecHelpers
9
+
10
+ attr_reader :path, :pids_root, :data
11
+
12
+ def initialize
13
+ @path = "/_zktest_"
14
+ @pids_root = "#{@path}/pids"
15
+ @data = 'underpants'
16
+ end
17
+
18
+ def before
19
+ @zk = Zookeeper.new('localhost:2181')
20
+ rm_rf(@zk, path)
21
+ logger.debug { "----------------< BEFORE: END >-------------------" }
22
+ end
23
+
24
+ def process_alive?(pid)
25
+ Process.kill(0, @pid)
26
+ true
27
+ rescue Errno::ESRCH
28
+ false
29
+ end
30
+
31
+ def wait_for_child_safely(pid, timeout=5)
32
+ time_to_stop = Time.now + timeout
33
+
34
+ until Time.now > time_to_stop
35
+ if a = Process.wait2(@pid, Process::WNOHANG)
36
+ return a.last
37
+ else
38
+ sleep(0.01)
39
+ end
40
+ end
41
+
42
+ nil
43
+ end
44
+
45
+ def try_pause_and_resume
46
+ @zk.pause
47
+ logger.debug { "paused" }
48
+ @zk.resume
49
+ logger.debug { "resumed" }
50
+ @zk.close
51
+ logger.debug { "closed" }
52
+ end
53
+
54
+ def run_test
55
+ logger.debug { "----------------< TEST: BEGIN >-------------------" }
56
+ @zk.wait_until_connected
57
+
58
+ mkdir_p(@zk, pids_root)
59
+
60
+ # the parent's pid path
61
+ @zk.create(:path => "#{pids_root}/#{$$}", :data => $$.to_s)
62
+
63
+ @latch = Zookeeper::Latch.new
64
+ @event = nil
65
+
66
+ cb = proc do |h|
67
+ logger.debug { "watcher called back: #{h.inspect}" }
68
+ @event = h
69
+ @latch.release
70
+ end
71
+
72
+ @zk.stat(:path => "#{pids_root}/child", :watcher => cb)
73
+
74
+ logger.debug { "-------------------> FORK <---------------------------" }
75
+
76
+ @pid = fork do
77
+ rand_sleep = rand()
78
+
79
+ $stderr.puts "sleeping for rand_sleep: #{rand_sleep}"
80
+ sleep(rand_sleep)
81
+
82
+ logger.debug { "reopening connection in child: #{$$}" }
83
+ @zk.reopen
84
+ logger.debug { "creating path" }
85
+ rv = @zk.create(:path => "#{pids_root}/child", :data => $$.to_s)
86
+ logger.debug { "created path #{rv[:path]}" }
87
+ @zk.close
88
+
89
+ logger.debug { "close finished" }
90
+ exit!(0)
91
+ end
92
+
93
+ event_waiter_th = Thread.new do
94
+ @latch.await(5) unless @event
95
+ @event
96
+ end
97
+
98
+ logger.debug { "waiting on child #{@pid}" }
99
+
100
+ status = wait_for_child_safely(@pid)
101
+ raise "Child process did not exit, likely hung" unless status
102
+
103
+ if event_waiter_th.join(5) == event_waiter_th
104
+ logger.warn { "event waiter has not received events" }
105
+ end
106
+
107
+ exit(@event.nil? ? 1 : 0)
108
+ end
109
+
110
+ def run
111
+ before
112
+ run_test
113
+ # try_pause_and_resume
114
+ end
115
+ end
116
+
117
+ CauseAbort.new.run
data/ext/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ bin
2
+ include
3
+ lib
4
+ *.bundle
5
+
6
+ c
data/ext/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require 'rbconfig'
2
+
3
+ ZKRB_WRAPPER = %w[zkrb_wrapper.c zkrb_wrapper.h]
4
+
5
+ namespace :zkrb do
6
+ task :clean do
7
+ if File.exists?('Makefile')
8
+ sh 'make clean'
9
+ rm 'Makefile' # yep, regenerate this
10
+ else
11
+ $stderr.puts "nothing to clean, no Makefile"
12
+ end
13
+ end
14
+
15
+ task :clobber => :clean do
16
+ rm_rf %w[Makefile c lib bin include ._c] + ZKRB_WRAPPER
17
+ end
18
+ end
19
+
20
+ task :clean => 'zkrb:clean'
21
+ task :clobber => 'zkrb:clobber'
22
+ task :wrappers => ZKRB_WRAPPER
23
+ task :default => :build
24
+
25
+ file 'zkrb_wrapper.c' => 'generate_gvl_code.rb' do
26
+ sh "ruby generate_gvl_code.rb code"
27
+ end
28
+
29
+ file 'zkrb_wrapper.h' => 'generate_gvl_code.rb' do
30
+ sh "ruby generate_gvl_code.rb headers"
31
+ end
32
+
33
+ file 'Makefile' do
34
+ sh "ruby extconf.rb"
35
+ end
36
+
37
+ task :build => [ 'Makefile', :wrappers ] do
38
+ sh 'make'
39
+ end
40
+
41
+