hivemeta 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/CHANGELOG +4 -0
  2. data/lib/hivemeta/connection.rb +25 -10
  3. metadata +3 -3
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ * 2011-05-29 - fsf
2
+ - new: added retry logic to the db connection to account for mysql servers
3
+ with a relatively low max_connections setting
4
+
1
5
  * 2011-05-21 - fsf
2
6
  - new: added table.process* opts hash
3
7
  - new: added :ignore_field_count, :field_count_warning, and :file opts
@@ -15,22 +15,35 @@ module HiveMeta
15
15
  @dbi_string = dbi_string
16
16
  @db_user = db_user
17
17
  @db_pass = db_pass
18
-
19
- begin
20
- @dbh = DBI.connect(dbi_string, db_user, db_pass)
21
- rescue DBI::DatabaseError => e
22
- STDERR.puts "cannot connect to metastore %s:\n error (%s) %s" %
23
- [dbi_string, e.err, e.errstr]
24
- raise
25
- end
26
18
  end
27
19
 
28
20
  def query(sql, *args)
29
- results = nil
21
+ dbh = results = nil
22
+
23
+ # make a few attempts in the event that mysql has not been
24
+ # configured with enough connections to handle many mappers
25
+ max_attempts = 3
26
+ 1.upto(max_attempts) do |attempt|
27
+ begin
28
+ dbh = DBI.connect(@dbi_string, @db_user, @db_pass)
29
+ break
30
+ rescue DBI::DatabaseError => e
31
+ if attempt < max_attempts
32
+ attempt += 1
33
+ s = rand + 0.50
34
+ STDERR.puts "retrying hivemeta connection after %f seconds" % s
35
+ sleep s
36
+ else
37
+ STDERR.puts "cannot connect to metastore %s:\n error (%s) %s" %
38
+ [@dbi_string, e.err, e.errstr]
39
+ raise
40
+ end
41
+ end
42
+ end
30
43
 
31
44
  #puts "sql: #{sql}"
32
45
  #puts "args: #{args}"
33
- sth = @dbh.prepare(sql)
46
+ sth = dbh.prepare(sql)
34
47
  sth.execute(*args)
35
48
  if block_given?
36
49
  sth.fetch {|row| yield row}
@@ -40,6 +53,8 @@ module HiveMeta
40
53
  end
41
54
  sth.finish
42
55
 
56
+ dbh.disconnect
57
+
43
58
  results # returns nil if a block is given
44
59
  end
45
60
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Frank Fejes
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-21 00:00:00 -05:00
17
+ date: 2011-05-29 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20