zookeeper 1.3.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -10,6 +10,8 @@ before_install:
10
10
  env:
11
11
  - SPAWN_ZOOKEEPER='true'
12
12
 
13
+ language: ruby
14
+
13
15
  rvm:
14
16
  - 1.9.3
15
17
  - 1.9.2
@@ -17,6 +19,12 @@ rvm:
17
19
  - ree
18
20
  - jruby-18mode
19
21
  - jruby-19mode
22
+ - rbx-18mode
23
+ - rbx-19mode
24
+ matrix:
25
+ allow_failures:
26
+ - rvm: rbx-18mode
27
+ - rvm: rbx-19mode
20
28
 
21
29
  bundler_args: --without development docs coverage
22
30
 
data/CHANGELOG CHANGED
@@ -1,3 +1,16 @@
1
+ v1.4.1 merge pull request 29 - fix exception handling in jruby 1.7.x
2
+
3
+ * h/t to @dynamix for the patch
4
+
5
+
6
+ v1.4.0 Removed the 'logging' gem
7
+
8
+ * At the request of a user, use of the logging gem has been discontinued as
9
+ it appears to cause a fair amount of RSS memory bloating (8MB was
10
+ reported). It's been replaced by a fairly simple ad-hoc implementation
11
+ using the stdlib 'logger' class. No user impact is expected unless you were
12
+ adjusting the Loggers on components of zookeeper.
13
+
1
14
  v1.3.0 much needed refactor of event and async result delivery
2
15
 
3
16
  * event and async blocks were previously mixed in with a bunch of other
data/Gemfile CHANGED
@@ -5,11 +5,10 @@ gemspec
5
5
  gem 'rake', '~> 0.9.0'
6
6
 
7
7
  group :test do
8
- gem "rspec", "~> 2.8.0"
9
- gem 'eventmachine', '1.0.0.beta.4'
8
+ gem "rspec" , "~> 2.11"
9
+ gem 'eventmachine', '1.0.0'
10
10
  gem 'evented-spec', '~> 0.9.0'
11
-
12
- gem 'zk-server', '~> 1.0.0'
11
+ gem 'zk-server', '~> 1.0'
13
12
  end
14
13
 
15
14
  # ffs, :platform appears to be COMLETELY BROKEN so we just DO THAT HERE
data/README.markdown CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  An interface to the Zookeeper cluster coordination server.
6
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/slyphon/zk) (also available is [ZK-EventMachine](https://github.com/slyphon/zk-eventmachine) for those who prefer async).
7
+ For a higher-level interface with a more convenient API and features such as locks, have a look at [ZK](https://github.com/slyphon/zk).
8
8
 
9
9
  ## Fork Safety! ##
10
10
 
data/java/java_base.rb CHANGED
@@ -440,17 +440,26 @@ class JavaBase
440
440
  @mutex.synchronize { @jzk }
441
441
  end
442
442
 
443
- def handle_keeper_exception
444
- yield
445
- rescue JZK::KeeperException => e
446
- if e.respond_to?(:cause) and e.cause and e.cause.respond_to?(:code) and e.cause.code and e.cause.code.respond_to?(:intValue)
447
- e.cause.code.intValue
448
- else
449
- raise e # dunno what happened, just raise it
443
+ # java exceptions are not wrapped anymore in JRuby 1.7+
444
+ if JRUBY_VERSION >= '1.7.0'
445
+ def handle_keeper_exception
446
+ yield
447
+ rescue JZK::KeeperException => e
448
+ # code is an enum and always set -> we don't need any additional checks here
449
+ e.code.intValue
450
+ end
451
+ else
452
+ def handle_keeper_exception
453
+ yield
454
+ rescue JZK::KeeperException => e
455
+ if e.respond_to?(:cause) and e.cause and e.cause.respond_to?(:code) and e.cause.code and e.cause.code.respond_to?(:intValue)
456
+ e.cause.code.intValue
457
+ else
458
+ raise e # dunno what happened, just raise it
459
+ end
450
460
  end
451
461
  end
452
462
 
453
-
454
463
  def call_type(callback, watcher)
455
464
  if callback
456
465
  watcher ? :async_watch : :async
data/lib/zookeeper.rb CHANGED
@@ -5,7 +5,6 @@ require 'monitor'
5
5
  require 'forwardable'
6
6
  require 'logger'
7
7
  require 'benchmark'
8
- require 'logging'
9
8
 
10
9
  module Zookeeper
11
10
  ZOOKEEPER_ROOT = File.expand_path('../..', __FILE__)
@@ -33,6 +32,7 @@ Zookeeper.require_lib(
33
32
  'zookeeper/core_ext',
34
33
  'zookeeper/monitor',
35
34
  'zookeeper/logger',
35
+ 'zookeeper/logger/forwarding_logger',
36
36
  'zookeeper/forked',
37
37
  'zookeeper/latch',
38
38
  'zookeeper/acls',
@@ -165,7 +165,7 @@ module ClientMethods
165
165
  options[:callback] ? rv : rv.merge(:acl => acls, :stat => Stat.new(stat))
166
166
  end
167
167
 
168
- # close this client and any underyling connections
168
+ # close this client and any underlying connections
169
169
  def close
170
170
  super
171
171
  end
@@ -27,4 +27,32 @@ class ::Exception
27
27
  end
28
28
  end
29
29
 
30
+ # this is borrowed from the excellent Logging gem: https://github.com/TwP/logging
31
+ # @private
32
+ class ::Module
33
+ # @private
34
+ # Returns a predictable logger name for the current module or class. If
35
+ # used within an anonymous class, the first non-anonymous class name will
36
+ # be used as the logger name. If used within a meta-class, the name of the
37
+ # actual class will be used as the logger name. If used within an
38
+ # anonymous module, the string 'anonymous' will be returned.
39
+ def _zk_logger_name
40
+ return name unless name.nil? or name.empty?
41
+
42
+ # check if this is a metaclass (or eigenclass)
43
+ if ancestors.include? Class
44
+ inspect =~ %r/#<Class:([^#>]+)>/
45
+ return $1
46
+ end
47
+
48
+ # see if we have a superclass
49
+ if respond_to? :superclass
50
+ return superclass.logger_name
51
+ end
52
+
53
+ # we are an anonymous module
54
+ return 'anonymous'
55
+ end
56
+ end
57
+
30
58
 
@@ -1,30 +1,29 @@
1
1
  module Zookeeper
2
2
  module Logger
3
- def self.included(mod)
4
- return false if mod < self # avoid infinite recursion
5
- mod.class_eval do
6
- def self.logger
7
- ::Zookeeper.logger || ::Logging.logger[logger_name]
8
- end
3
+ def self.wrapped_logger
4
+ if defined?(@@wrapped_logger)
5
+ @@wrapped_logger
6
+ else
7
+ @@wrapped_logger = ::Logger.new(STDERR).tap { |l| l.level = ::Logger::FATAL }
9
8
  end
10
- mod.extend(self)
11
9
  end
12
10
 
13
- def self.set_default
14
- ::Logging.logger['Zookeeper'].tap do |ch_root|
15
- ::Logging.appenders.stderr.tap do |serr|
16
- serr.layout = ::Logging.layouts.pattern(
17
- :pattern => '%.1l, [%d] %c30.30{2}: %m\n',
18
- :date_pattern => '%Y-%m-%d %H:%M:%S.%6N'
19
- )
20
-
21
- ch_root.add_appenders(serr)
22
- end
11
+ def self.wrapped_logger=(log)
12
+ @@wrapped_logger = log
13
+ end
23
14
 
24
- ch_root.level = ENV['ZOOKEEPER_DEBUG'] ? :debug : :off
15
+ # @private
16
+ module ClassMethods
17
+ def logger
18
+ ::Zookeeper.logger || ForwardingLogger.for(::Zookeeper::Logger.wrapped_logger, _zk_logger_name)
25
19
  end
26
20
  end
27
21
 
22
+ def self.included(base)
23
+ # return false if base < self # avoid infinite recursion
24
+ base.extend(ClassMethods)
25
+ end
26
+
28
27
  private
29
28
  def log_realtime(what)
30
29
  logger.debug do
@@ -34,8 +33,7 @@ module Zookeeper
34
33
  end
35
34
 
36
35
  def logger
37
- @logger ||= (::Zookeeper.logger || ::Logging.logger[self.class.logger_name]) # logger_name defined in ::Logging::Utils
36
+ @logger ||= (::Zookeeper.logger || self.class.logger)
38
37
  end
39
- end
40
- end
41
-
38
+ end # Logger
39
+ end # Zookeeper
@@ -0,0 +1,84 @@
1
+ module Zookeeper
2
+ module Logger
3
+ # h/t _eric and Papertrail
4
+ # @private
5
+ class ForwardingLogger
6
+ attr_accessor :level, :formatter
7
+
8
+ @@mutex = Monitor.new unless defined?(@@mutex)
9
+ @@loggers = {} unless defined?(@@loggers)
10
+
11
+ def self.for(logger, name)
12
+ @@mutex.synchronize do
13
+ @@loggers.fetch(name) do |k|
14
+ @@loggers[k] = new(logger, :formatter => lambda { |m| "%25.25s: #{m}" % name })
15
+ end
16
+ end
17
+ end
18
+
19
+ def initialize(logger, options = {})
20
+ @level = ::Logger::DEBUG
21
+ @logger = logger
22
+ @formatter = options[:formatter]
23
+ end
24
+
25
+ def add(severity, message = nil, progname = nil, &block)
26
+ severity ||= ::Logger::UNKNOWN
27
+ if !@logger || severity < @level
28
+ return true
29
+ end
30
+
31
+ message = (message || (block && block.call) || progname).to_s
32
+
33
+ if @formatter && @formatter.respond_to?(:call)
34
+ message = @formatter.call(message)
35
+ end
36
+
37
+ # If a newline is necessary then create a new message ending with a newline.
38
+ # Ensures that the original message is not mutated.
39
+ # message = "#{message}\n" unless message[-1] == ?\n
40
+
41
+ @logger.add(severity, message)
42
+ end
43
+
44
+ def <<(msg); @logger << msg; end
45
+ def write(msg); @logger.write(msg); end
46
+
47
+ def debug(progname = nil, &block)
48
+ add(::Logger::DEBUG, nil, progname, &block)
49
+ end
50
+
51
+ def info(progname = nil, &block)
52
+ add(::Logger::INFO, nil, progname, &block)
53
+ end
54
+
55
+ def warn(progname = nil, &block)
56
+ add(::Logger::WARN, nil, progname, &block)
57
+ end
58
+
59
+ def error(progname = nil, &block)
60
+ add(::Logger::ERROR, nil, progname, &block)
61
+ end
62
+
63
+ def fatal(progname = nil, &block)
64
+ add(::Logger::FATAL, nil, progname, &block)
65
+ end
66
+
67
+ def unknown(progname = nil, &block)
68
+ add(::Logger::UNKNOWN, nil, progname, &block)
69
+ end
70
+
71
+ def debug?; @level <= DEBUG; end
72
+
73
+ def info?; @level <= INFO; end
74
+
75
+ def warn?; @level <= WARN; end
76
+
77
+ def error?; @level <= ERROR; end
78
+
79
+ def fatal?; @level <= FATAL; end
80
+ end # ForwardingLogger
81
+ end # Logger
82
+ end # Zookeeper
83
+
84
+
@@ -1,4 +1,4 @@
1
1
  module Zookeeper
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.1'
3
3
  DRIVER_VERSION = '3.3.5'
4
4
  end
@@ -13,7 +13,7 @@ unless defined?(::JRUBY_VERSION)
13
13
  end
14
14
  end
15
15
 
16
- def wait_until_connected(timeout=2)
16
+ def wait_until_connected(timeout=10)
17
17
  wait_until(timeout) { @czk.state == Zookeeper::Constants::ZOO_CONNECTED_STATE }
18
18
  end
19
19
 
@@ -38,7 +38,7 @@ unless defined?(::JRUBY_VERSION)
38
38
  end
39
39
 
40
40
  it %[should have a connection event after being connected] do
41
- event = wait_until(2) { @event_queue.pop }
41
+ event = wait_until(10) { @event_queue.pop }
42
42
  event.should be
43
43
  event[:req_id].should == Zookeeper::Constants::ZKRB_GLOBAL_CB_REQ
44
44
  event[:type].should == Zookeeper::Constants::ZOO_SESSION_EVENT
data/spec/spec_helper.rb CHANGED
@@ -20,7 +20,7 @@ if ENV['ZKRB_DEBUG']
20
20
  end
21
21
 
22
22
  if ENV['ZKRB_NOLOG']
23
- ::Logging.logger['Zookeeper'].level = :off
23
+ SpecGlobalLogger.logger.level = ::Logger::FATAL
24
24
  Zookeeper.set_debug_level(0)
25
25
  end
26
26
 
@@ -35,7 +35,7 @@ RSpec.configure do |config|
35
35
  require 'zk-server'
36
36
 
37
37
  config.before(:suite) do
38
- ::Logging.logger['spec'].debug { "Starting zookeeper service" }
38
+ SpecGlobalLogger.logger.debug { "Starting zookeeper service" }
39
39
  ZK::Server.run do |c|
40
40
  c.base_dir = File.expand_path('../../.zkserver', __FILE__)
41
41
  c.client_port = Zookeeper.test_port
@@ -45,7 +45,7 @@ RSpec.configure do |config|
45
45
  end
46
46
 
47
47
  config.after(:suite) do
48
- ::Logging.logger['spec'].debug { "stopping zookeeper service" }
48
+ SpecGlobalLogger.logger.debug { "stopping zookeeper service" }
49
49
  ZK::Server.shutdown
50
50
  end
51
51
  end
@@ -1,33 +1,34 @@
1
1
  module Zookeeper
2
2
  TEST_LOG_PATH = File.expand_path('../../../test.log', __FILE__)
3
- end
4
3
 
5
- layout = Logging.layouts.pattern(
6
- :pattern => '%.1l, [%d #%p] %25.25c{2}: %m\n',
7
- :date_pattern => '%Y-%m-%d %H:%M:%S.%6N'
8
- )
4
+ def self.setup_test_logger
5
+ log =
6
+ if (ENV['ZOOKEEPER_DEBUG'] || ENV['ZKRB_DEBUG'])
7
+ ::Logger.new(STDERR)
8
+ else
9
+ ::Logger.new(TEST_LOG_PATH)
10
+ end
9
11
 
10
- appender = (ENV['ZOOKEEPER_DEBUG'] || ENV['ZKRB_DEBUG']) ? Logging.appenders.stderr : Logging.appenders.file(Zookeeper::TEST_LOG_PATH)
11
- appender.layout = layout
12
- appender.auto_flushing = 25
13
- appender.flush_period = 5
12
+ log.level = ::Logger::DEBUG
14
13
 
15
- %w[spec Zookeeper].each do |name|
16
- ::Logging.logger[name].tap do |log|
17
- log.appenders = [appender]
18
- log.level = :debug
14
+ Zookeeper::Logger.wrapped_logger = log
19
15
  end
20
16
  end
21
17
 
18
+ Zookeeper.setup_test_logger
19
+
22
20
  module SpecGlobalLogger
21
+ extend self
22
+
23
23
  def logger
24
- @spec_global_logger ||= ::Logging.logger['spec']
24
+ @spec_global_logger ||= Zookeeper::Logger::ForwardingLogger.for(Zookeeper::Logger.wrapped_logger, 'spec')
25
25
  end
26
26
 
27
27
  # sets the log level to FATAL for the duration of the block
28
28
  def mute_logger
29
- zk_log = Logging.logger['Zookeeper']
30
- orig_level, zk_log.level = zk_log.level, :off
29
+ zk_log = Zookeeper::Logger.wrapped_logger
30
+
31
+ orig_level, zk_log.level = zk_log.level, ::Logger::FATAL
31
32
  orig_zk_level, Zookeeper.debug_level = Zookeeper.debug_level, Zookeeper::Constants::ZOO_LOG_LEVEL_ERROR
32
33
  yield
33
34
  ensure
@@ -5,7 +5,7 @@ module RSpec
5
5
  module Formatters
6
6
  class ProgressFormatter
7
7
  def example_started(example)
8
- ::Logging.logger['spec'].write(yellow("\n=====<([ #{example.full_description} ])>=====\n"))
8
+ SpecGlobalLogger.logger << yellow("\n=====<([ #{example.full_description} ])>=====\n")
9
9
  super(example)
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zookeeper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 3
9
- - 0
10
- version: 1.3.0
8
+ - 4
9
+ - 1
10
+ version: 1.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phillip Pearson
@@ -20,24 +20,9 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2012-08-17 00:00:00 Z
24
- dependencies:
25
- - !ruby/object:Gem::Dependency
26
- name: logging
27
- prerelease: false
28
- requirement: &id001 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- hash: 15
34
- segments:
35
- - 1
36
- - 7
37
- - 2
38
- version: 1.7.2
39
- type: :runtime
40
- version_requirements: *id001
23
+ date: 2012-12-17 00:00:00 Z
24
+ dependencies: []
25
+
41
26
  description: |+
42
27
  A low-level multi-Ruby wrapper around the ZooKeeper API bindings. For a
43
28
  friendlier interface, see http://github.com/slyphon/zk. Currently supported:
@@ -101,6 +86,7 @@ files:
101
86
  - lib/zookeeper/forked.rb
102
87
  - lib/zookeeper/latch.rb
103
88
  - lib/zookeeper/logger.rb
89
+ - lib/zookeeper/logger/forwarding_logger.rb
104
90
  - lib/zookeeper/monitor.rb
105
91
  - lib/zookeeper/rake_tasks.rb
106
92
  - lib/zookeeper/request_registry.rb