hbase-jruby 0.4.5-java → 0.4.6-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 317e3299f449c9c5f847ae8118c631d22ff91872
4
- data.tar.gz: 092879ce25e3448c5a777310782c7fffab0ba586
3
+ metadata.gz: 35894372ec9c361c225d9dc621f09769f66c1815
4
+ data.tar.gz: 4e86e949fd9d8200bf4c790c58988b43dc621db5
5
5
  SHA512:
6
- metadata.gz: 3454275b00e7636a6d1bedf6b4172ad75f74da839f7bbdb91ac8882604c2e128cef248289abbb276629ed78d4da17834d59844c8fe949cf24bd5d180d3e42433
7
- data.tar.gz: 1bb37e732100751e1861605af88f0cf0e1aef988a396a95478bc10af5966c8223bcc9f03bf31529c44846b6cc7b47aa64d2796e5852964e40528ac0a851bba43
6
+ metadata.gz: d58ba2c67f70d04177b7c36d85739bbbcf54c58f41f74e3fa62a270b02bfc38bd0bf3aaf42c27fc756f004ff2cd7a38f66d2471e5c6babe62b859d7b94182df3
7
+ data.tar.gz: f61b4bece92dd25907524849d638633c9df30d4fede814b8d0373a937cd410e8e0f967f846d57c3fe28043b2322908a82186affe1649768b6a0c64460bf550d2
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 0.4.6
5
+ -----
6
+ - [#29 Fix possible HTable leaks](https://github.com/junegunn/hbase-jruby/issues/29)
7
+ - [#30 Make `HBase.log4j=` callable before dependencies are met](https://github.com/junegunn/hbase-jruby/issues/30)
8
+
4
9
  0.4.5
5
10
  -----
6
11
  - Fixed HBase 0.96 compatibily issues and tested on HBase 0.96 and 0.98
@@ -114,6 +114,9 @@ class HBase
114
114
  require(jar)
115
115
  }
116
116
 
117
+ # Apply pending log4j configuration
118
+ HBase.log4j = @@log4j if @@log4j
119
+
117
120
  # Try importing Java classes again
118
121
  not_found = HBase.import_java_classes!
119
122
  if verbose && !not_found.empty?
@@ -13,29 +13,34 @@ class HBase
13
13
  # @overload HBase.log4j=(filename)
14
14
  # Configure Log4j logging with the given file
15
15
  # @param [String] filename Path to log4j.properties or log4j.xml file
16
- # @return [nil]
16
+ # @return [String]
17
17
  # @overload HBase.log4j=(hash)
18
18
  # Configure Log4j logging with the given Hash
19
19
  # @param [Hash] hash Log4j properties in Ruby Hash
20
- # @return [nil]
20
+ # @return [Hash]
21
21
  # @overload HBase.log4j=(props)
22
22
  # Configure Log4j logging with the given Properties
23
23
  # @param [java.util.Properties] props Properties object
24
- # @return [nil]
24
+ # @return [java.util.Properties]
25
25
  def self.log4j= arg
26
- if arg.is_a?(Hash)
27
- props = java.util.Properties.new
28
- arg.each do |k, v|
29
- props.setProperty k.to_s, v.to_s
30
- end
31
- org.apache.log4j.PropertyConfigurator.configure props
32
- else
33
- case File.extname(arg).downcase
34
- when '.xml'
35
- org.apache.log4j.xml.DOMConfigurator.configure arg
26
+ org.apache.log4j.PropertyConfigurator rescue nil
27
+ if defined?(org.apache.log4j.PropertyConfigurator)
28
+ if arg.is_a?(Hash)
29
+ props = java.util.Properties.new
30
+ arg.each do |k, v|
31
+ props.setProperty k.to_s, v.to_s
32
+ end
33
+ org.apache.log4j.PropertyConfigurator.configure props
36
34
  else
37
- org.apache.log4j.PropertyConfigurator.configure arg
35
+ case File.extname(arg).downcase
36
+ when '.xml'
37
+ org.apache.log4j.xml.DOMConfigurator.configure arg
38
+ else
39
+ org.apache.log4j.PropertyConfigurator.configure arg
40
+ end
38
41
  end
42
+ else
43
+ @@log4j = arg
39
44
  end
40
45
  end
41
46
 
@@ -173,9 +178,21 @@ class HBase
173
178
 
174
179
  private
175
180
  def register_thread t
181
+ # (NOTE) The cleanup routine can be inefficient when the number of
182
+ # concurrent threads becomes large. However, since it is not likely that
183
+ # there will be more than a few hundred threads in a typical JRuby process
184
+ # and the code is executed only once per thread, let's simply assume that
185
+ # it's okay.
176
186
  @mutex.synchronize do
177
187
  check_closed
178
188
  @threads << t
189
+ alives, deads = @threads.partition { |e| e.alive? }
190
+ @threads = Set.new(alives)
191
+ deads.each do |dead|
192
+ (dead[:hbase_jruby].delete(self) || {}).each do |_, htable|
193
+ htable.close rescue nil
194
+ end
195
+ end
179
196
  end
180
197
  end
181
198
 
@@ -29,10 +29,16 @@ class Table
29
29
  local_htables[@name] ||= @hbase.send :get_htable, @name
30
30
  end
31
31
 
32
- # @deprecated
32
+ # Return HTable instance back to the table pool.
33
+ # Generally this is not required unless you use unlimited number of threads
33
34
  # @return [nil]
34
35
  def close
35
- nil
36
+ check_closed
37
+
38
+ (t = Thread.current[:hbase_jruby]) &&
39
+ (t = t[@hbase]) &&
40
+ (t = t.delete @name) &&
41
+ t.close
36
42
  end
37
43
 
38
44
  # Returns whether if the connection is closed
@@ -1,5 +1,5 @@
1
1
  class HBase
2
2
  module JRuby
3
- VERSION = '0.4.5'
3
+ VERSION = '0.4.6'
4
4
  end
5
5
  end
data/lib/hbase-jruby.rb CHANGED
@@ -2,6 +2,10 @@ unless RUBY_PLATFORM =~ /java/
2
2
  raise LoadError, 'Only supports JRuby'
3
3
  end
4
4
 
5
+ class HBase
6
+ @@log4j = nil
7
+ end
8
+
5
9
  require 'hbase-jruby/version'
6
10
  require 'hbase-jruby/dependency'
7
11
  require 'hbase-jruby/util'
@@ -21,4 +25,3 @@ require 'hbase-jruby/table/checked_operation'
21
25
  require 'hbase-jruby/row'
22
26
  require 'hbase-jruby/hbase'
23
27
 
24
- HBase.import_java_classes!
data/test/test_hbase.rb CHANGED
@@ -89,10 +89,11 @@ class TestHBase < TestHBaseJRubyBase
89
89
  threads = 4.times.map { |i|
90
90
  Thread.new {
91
91
  ht = hbase2[TABLE].htable
92
+ sleep
92
93
  }
93
94
  }
94
95
  threads.each do |t|
95
- t.join
96
+ t.kill
96
97
  assert t[:hbase_jruby][hbase2][TABLE]
97
98
  end
98
99
 
data/test/test_table.rb CHANGED
@@ -23,16 +23,56 @@ class TestTable < TestHBaseJRubyBase
23
23
  # Multi-threaded
24
24
  htables = []
25
25
  table = @hbase.table(TABLE)
26
+ nthr = num_managed_threads
26
27
  4.times do
27
28
  Thread.new {
28
29
  htables << table.htable
30
+ assert_equal nthr + 1, num_managed_threads
29
31
  }.join
30
32
  end
31
33
  assert_equal 4, htables.uniq.length
34
+ # XXX Implementation detail
35
+ assert_equal nthr + 1, num_managed_threads
32
36
 
33
37
  assert_equal @hbase.table(TABLE).htable, @hbase[TABLE].htable
34
38
  end
35
39
 
40
+ def test_table_close
41
+ htables = Set.new
42
+ htables << @hbase[TABLE].htable
43
+ htables << @hbase[TABLE].htable
44
+ assert_equal 1, htables.length
45
+
46
+ @hbase[TABLE].close
47
+ htables << @hbase[TABLE].htable
48
+ htables << @hbase[TABLE].htable
49
+ assert_equal 2, htables.length
50
+ end
51
+
52
+ def num_managed_threads
53
+ @hbase.instance_variable_get(:@threads).length
54
+ end
55
+
56
+ # FIXME
57
+ # - Implementation detail
58
+ # - Naive assertion
59
+ # - Race condition
60
+ def test_autoclose_htables
61
+ nthr = num_managed_threads
62
+ threads = 50.times.map { |i|
63
+ Thread.new {
64
+ @hbase[TABLE].htable
65
+ sleep 0.5
66
+ }
67
+ }
68
+ sleep 1
69
+ assert num_managed_threads > nthr
70
+
71
+ nthr = num_managed_threads
72
+ Thread.new { @hbase[TABLE].htable }.join
73
+ assert num_managed_threads < nthr
74
+ end
75
+
36
76
  def test_put_then_get
37
77
  row1 = next_rowkey.to_s
38
78
  row2 = next_rowkey.to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hbase-jruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: java
6
6
  authors:
7
7
  - Junegunn Choi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-24 00:00:00.000000000 Z
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.2.0
105
+ rubygems_version: 2.2.1
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: A JRuby binding for HBase