flydata 0.5.3 → 0.5.4

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: 550d6891d0b0315d762ded08f079e915888c9b52
4
- data.tar.gz: 477cbc3a4977c15b17b9dd3a7ecedfa3fe35595d
3
+ metadata.gz: d35ee35146966b2d980eb979c3d36c23ce0c5d36
4
+ data.tar.gz: 9789cbe06d27163a5afc8cfaf9c44a2bf9de495a
5
5
  SHA512:
6
- metadata.gz: d9eaccb595b37a199a92244e2e27d6b8c8cf79740a8dd69a9add01cce9a68bcd1f94428c2749fdf28d35784d03ff5c0f02c13ccd6d71b324d8b129d93a9f46c5
7
- data.tar.gz: bcfa91ee81945016d24f1f686cb329f7c940ab5c36db7baad3886de2fbd34f12d5be6eae80811fccc74aa0f4a2dd31477be98f96045717e486a399d33c86e8e4
6
+ metadata.gz: 4a7fc6bf22d826f3f7444b0ca85724576f517ded96ed56023a1497b2bc2e2e6e6cc1d561a899d01be0d55b7e1de7cba78aec158e7a78a125b588cd07b7e04479
7
+ data.tar.gz: f2390bf2dd00890e0cb7e2948d5a7930a2266d3d87aecabe0119e20bb7c97ebe3d3cacf6a6f82348495a9374bd3652ce8fa248d17dda19178128ad68b4bf4dc4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: flydata 0.5.3 ruby lib
5
+ # stub: flydata 0.5.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "flydata"
9
- s.version = "0.5.3"
9
+ s.version = "0.5.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Koichi Fujikawa", "Masashi Miyazaki", "Matthew Luu", "Mak Inada", "Sriram NS"]
14
- s.date = "2015-09-03"
14
+ s.date = "2015-09-08"
15
15
  s.description = "FlyData Agent"
16
16
  s.email = "sysadmin@flydata.com"
17
17
  s.executables = ["fdmysqldump", "flydata", "serverinfo"]
@@ -161,12 +161,30 @@ EOS
161
161
 
162
162
  def create_table_locker
163
163
  Fiber.new do
164
- client = FlydataMysqlClient.new(@db_opts)
165
- # Lock tables
166
- client.query "FLUSH LOCAL TABLES;"
164
+ # short timeout to avoid blocking other queries
165
+ client = FlydataMysqlClient.new({reconnect: true, read_timeout:9}.merge(@db_opts))
166
+
167
167
  q = flush_tables_with_read_lock_query(client)
168
168
  $log.debug "FLUSH TABLES query: #{q}"
169
- client.query q
169
+ thread_id = nil
170
+ begin
171
+ thread_id = client.thread_id
172
+ client.query(q, retry_count: -1, retry_interval: 1,
173
+ ) do |retry_count, e|
174
+ # Query failure callback
175
+ $log.info "Unable to complete FLUSH TABLES WITH READ LOCK. Retrying(#{retry_count}).. error:#{e.to_s}"
176
+ if retry_count >= 360 # should take an hour to get here
177
+ raise "Failed to complete FLUSH TABLES WITH READ LOCK after #{retry_count} attemps"
178
+ end
179
+ client.query "KILL QUERY #{thread_id}"
180
+ thread_id = client.thread_id
181
+ end
182
+ thread_id = nil
183
+ ensure
184
+ if thread_id
185
+ client.query "KILL QUERY #{thread_id}"
186
+ end
187
+ end
170
188
  $log.debug "lock acquired"
171
189
  begin
172
190
  Fiber.yield # Lock is acquired. Wait until it can be unlocked.
@@ -223,28 +241,28 @@ EOS
223
241
  end
224
242
  end
225
243
 
226
- # Custom mysql client that sets config params (eg:-read_timeout) uniformly for all
227
- # mysql access. Also, gives access to the last query that was executed using the client
228
- # which can be helpful when handling exceptions
244
+ # Custom mysql client that gives access to the last query that was
245
+ # executed using the client which can be helpful when handling exceptions
229
246
  class FlydataMysqlClient < Mysql2::Client
230
247
 
231
248
  attr_accessor :last_query
232
249
 
233
- def initialize(db_opts)
234
- #TODO : Pass timeout in as a setting from the data entry
235
- super(db_opts.merge(read_timeout: 3600))
236
- end
237
-
238
250
  def query(sql, options = {})
239
251
  @last_query = sql
252
+ max_retry = options[:retry_count] || 0
253
+ retry_interval = options[:retry_interval] || 3
254
+ count = 0
255
+ result = nil
240
256
  begin
241
- super(sql, options)
242
- rescue Mysql2::Error => e
243
- if /^Timeout waiting for a response/ === e.to_s
244
- raise "The below query timed out when running. Please check long running processes and locks in your database.\n#{last_query}"
245
- end
246
- raise e
257
+ result = super(sql, options)
258
+ rescue => e
259
+ count += 1
260
+ raise e if max_retry != -1 && count > max_retry
261
+ yield(count, e) if block_given?
262
+ sleep retry_interval
263
+ retry
247
264
  end
265
+ result
248
266
  end
249
267
  end
250
268
 
@@ -40,8 +40,10 @@ module Flydata
40
40
  allow(m).to receive(:query).with(/TABLES/)
41
41
  allow(m).to receive(:query).with("SHOW VARIABLES LIKE 'version'").
42
42
  and_return([{'Value' => '5.1.40-0ubuntu0.12.04.1-log'}])
43
+ allow(m).to receive(:query).with("FLUSH TABLES WITH READ LOCK;", {retry_count:-1, retry_interval:1})
43
44
  allow(m).to receive(:query).with("SHOW MASTER STATUS;").
44
45
  and_return([{'File' => 'mysql-bin.000451', 'Position' => 89872}])
46
+ allow(m).to receive(:thread_id).and_return(1191)
45
47
  allow(m).to receive(:close)
46
48
  m
47
49
  end
@@ -98,11 +100,11 @@ module Flydata
98
100
  raise Mysql2::Error.new("Timeout waiting for a response from the last query. (waited 600 seconds)")
99
101
  end
100
102
  end
101
- it 'raises appropriate error when query times out' do
103
+ it 'raises a timeout error as is' do
102
104
  described_class.instance_eval { include DummyMysqlClient }
103
105
  sql = "FLUSH LOCAL TABLES"
104
106
  test_client = described_class.new(db_opts)
105
- expect{test_client.query(sql)}.to raise_error(RuntimeError, /query timed out when running/)
107
+ expect{test_client.query(sql)}.to raise_error(Mysql2::Error, "Timeout waiting for a response from the last query. (waited 600 seconds)")
106
108
  expect(test_client.last_query).to eq(sql)
107
109
  end
108
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flydata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Fujikawa
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-09-03 00:00:00.000000000 Z
15
+ date: 2015-09-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rest-client