mongolly 0.2.13 → 0.2.14

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: b713755ba462faa167a5f77618970f336b5f84d1
4
- data.tar.gz: 65ab23831ee92c2a296a6d1b898dd5f1c2e764ba
3
+ metadata.gz: 4e4150dd42a9bbef396ff00c1975801aa7b3f04a
4
+ data.tar.gz: 7f45feff004cdb1899b9a23928c245dc5c14e73a
5
5
  SHA512:
6
- metadata.gz: e472e1c767ad5563c50ed14be637c03fcc1c852ca3a5b11a0c976da568a4157562daba5d773717fb26bee2581be2a5fe72ac7a4df30fe25117c2f2af9eda664b
7
- data.tar.gz: 3c4623600ee2eaca0a772d02687b8702cb9f08fb40bca9e0164637ff407dcd153442068ca7746a07c394223b517d119b7a7a68914dc37840f649408152ec6ab0
6
+ metadata.gz: 3d5fe8937291b7b98be798fa2af5bb8dd62a829e8d373725b23ae56957b1de1bfae80c3b9bdafa60747532d01f50ca73ec2300ef76727999958995b21bc0ae08
7
+ data.tar.gz: d14155a3d15822d3e2b3de279645a82ceb2b7b159081eb08776e36e5f8b2fae491196932db30f653a5bd63884f37a23ba4cb18710218d02748c33343bfce9dcf
@@ -3,8 +3,16 @@ require "logger"
3
3
  require "net/ssh"
4
4
  require "retries"
5
5
 
6
+ class LockFailException < StandardError
7
+ end
8
+
9
+ class UnlockFailException < StandardError
10
+ end
11
+
6
12
  class Mongo::MongoClient
7
13
  MAX_DISABLE_BALANCER_WAIT = 60 * 8 # 8 Minutes
14
+ MAX_UNLOCK_RETRIES = 3
15
+ UNLOCK_SLEEP = 10 # 10 Seconds
8
16
  REPLICA_SNAPSHOT_THRESHOLD = 60 * 5 # 5 Minutes
9
17
  REPLICA_SNAPSHOT_PREFER_HIDDEN = true
10
18
  DEFAULT_MONGO_PORT = 27017 # rubocop: disable Style/NumericLiterals
@@ -99,14 +107,18 @@ class Mongo::MongoClient
99
107
  def with_database_locked
100
108
  @mongolly_logger.debug "Locking database..."
101
109
  disable_profiling
102
- lock! unless @mongolly_dry_run || locked?
110
+ # {"info"=>"now locked against writes, use db.fsyncUnlock() to unlock", "seeAlso"=>"http://dochub.mongodb.org/core/fsynccommand", "ok"=>1.0}
111
+ unless @mongolly_dry_run || locked?
112
+ response = lock!
113
+ @mongolly_logger.debug "Lock response: #{response['info']}"
114
+ raise LockFailException, response["info"] if response["ok"] != 1.0
115
+ end
103
116
  @mongolly_logger.debug "With database locked..."
104
117
  yield
105
118
  rescue => ex
106
119
  @mongolly_logger.error "Error with database locked: #{ex}"
107
120
  ensure
108
- @mongolly_logger.debug "Unlocking database..."
109
- unlock! if !@mongolly_dry_run && locked?
121
+ strong_unlock!
110
122
  enable_profiling
111
123
  end
112
124
 
@@ -184,13 +196,24 @@ class Mongo::MongoClient
184
196
  ssh.loop
185
197
  end
186
198
 
187
- if exit_code != 0
188
- raise "Unable to exec #{command} on #{host}, #{output}"
189
- end
199
+ raise "Unable to exec #{command} on #{host}, #{output}" if exit_code != 0
190
200
  end
191
201
 
192
202
  private
193
203
 
204
+ def strong_unlock!
205
+ @mongolly_logger.debug "Unlocking database..."
206
+ return if @mongolly_dry_run || !locked?
207
+ retries ||= 0
208
+ # {"info"=>"unlock completed", "ok"=>1.0}
209
+ response = unlock!
210
+ raise UnlockFailException, response["info"] if response["ok"] != 1.0 || locked?
211
+ rescue UnlockFailException => ex
212
+ @mongolly_logger.warn "Failed to unlock, #{ex}, sleeping #{UNLOCK_SLEEP} on attempt #{retries} of #{MAX_UNLOCK_RETRIES}"
213
+ sleep UNLOCK_SLEEP
214
+ retry if (retries += 1) <= MAX_UNLOCK_RETRIES
215
+ end
216
+
194
217
  def backup_instance(address, options)
195
218
  host, port = address.split(":")
196
219
  port ||= DEFAULT_MONGO_PORT
@@ -1,3 +1,3 @@
1
1
  module Mongolly
2
- VERSION = "0.2.13".freeze
2
+ VERSION = "0.2.14".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongolly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Saffitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-17 00:00:00.000000000 Z
11
+ date: 2017-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor