moped 2.0.6 → 2.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c45c765e5368decfb1b558ccd8574a658697ecf2
4
- data.tar.gz: 5d4344b505bc2e1a2c9d418c5b84d321ab426d00
3
+ metadata.gz: eda09d3428a61f892b3d983486b0bcacb4d22c1f
4
+ data.tar.gz: 0d496810ace691461b3443f1163102a76f85ec5b
5
5
  SHA512:
6
- metadata.gz: 1a7780f10e4036d42b942bfa5dc9f4073b6d55b2984fa342e451a82887f7c2012e3fc40f6a900a617ca77b55f00e9854df2b02e23220e1b3ba0cba6e13deb590
7
- data.tar.gz: 1da0fac786faea2334f9bb5d1937e37440e5b8bd257025fc194764a383edc959ef3ee198e4ac2539c355289d67c736a5f60d610331200fbcd8b27153a698a578
6
+ metadata.gz: 951ba327262a778af25d190b5f80332c10bac5f8186194c399091bb924bcab9c625f4b317d3807390a2fc233f3c2f2a7cfb1f499045363743ec2e6a789581043
7
+ data.tar.gz: 8a5fcdd582261c79a7d1fd241d17ffd437bd4232e3a663e040c316fa8c2bc29e15c56399fa2e677e8971c1687cbbafd8743ba4fc6af6b1c97eb888ca1a4d6c56
@@ -1,5 +1,9 @@
1
1
  # Overview
2
2
 
3
+ ## 2.0.7
4
+
5
+ * Improved Moped Failover (John Hyman)
6
+
3
7
  ## 2.0.6
4
8
 
5
9
  * Relaxing BSON dependency to allow for 3.1.0 upgrade.
@@ -45,9 +45,13 @@ module Moped
45
45
  #
46
46
  # @since 2.0.0
47
47
  def resolve(node)
48
+ return @resolved if @resolved
49
+ start = Time.now
50
+ retries = 0
48
51
  begin
49
- return @resolved if @resolved
50
- Timeout::timeout(@timeout) do
52
+ # This timeout should be very large since Timeout::timeout plays very badly with multithreaded code
53
+ # TODO: Remove this Timeout entirely
54
+ Timeout::timeout(@timeout * 10) do
51
55
  Resolv.each_address(host) do |ip|
52
56
  if ip =~ Resolv::IPv4::Regex
53
57
  @ip ||= ip
@@ -57,9 +61,19 @@ module Moped
57
61
  raise Resolv::ResolvError unless @ip
58
62
  end
59
63
  @resolved = "#{ip}:#{port}"
60
- rescue Timeout::Error, Resolv::ResolvError, SocketError
61
- Loggable.warn(" MOPED:", "Could not resolve IP for: #{original}", "n/a")
62
- node.down! and false
64
+ rescue Timeout::Error, Resolv::ResolvError, SocketError => e
65
+ msg = [" MOPED:", "Could not resolve IP for: #{original}, delta is #{Time.now - start}, error class is #{e.inspect}, retries is #{retries}. Node is #{node.inspect}", "n/a"]
66
+ if retries == 0
67
+ Loggable.info(*msg)
68
+ else
69
+ Loggable.warn(*msg)
70
+ end
71
+ if retries < 2
72
+ retries += 1
73
+ retry
74
+ else
75
+ node.down! and false
76
+ end
63
77
  end
64
78
  end
65
79
  end
@@ -48,10 +48,17 @@ module Moped
48
48
  #
49
49
  # @since 2.0.3
50
50
  def shutdown(node)
51
+ pool = nil
51
52
  MUTEX.synchronize do
52
53
  pool = pools.delete(node.address.resolved)
53
- pool.shutdown{ |conn| conn.disconnect } if pool
54
- nil
54
+ end
55
+ pool.shutdown{ |conn| conn.disconnect } if pool
56
+ nil
57
+ end
58
+
59
+ def delete_pool(node)
60
+ MUTEX.synchronize do
61
+ pools.delete(node.address.resolved)
55
62
  end
56
63
  end
57
64
 
@@ -6,6 +6,7 @@ module Moped
6
6
  class Cursor
7
7
  include Readable
8
8
  include Enumerable
9
+ include Retryable
9
10
 
10
11
  # @attribute [r] get_more_op The get more message.
11
12
  # @attribute [r] kill_cursor_op The kill cursor message.
@@ -43,10 +44,12 @@ module Moped
43
44
  #
44
45
  # @since 1.0.0
45
46
  def get_more
46
- reply = @node.get_more @database, @collection, @cursor_id, request_limit
47
- @limit -= reply.count if limited?
48
- @cursor_id = reply.cursor_id
49
- reply.documents
47
+ with_retry(session.cluster) do
48
+ reply = @node.get_more @database, @collection, @cursor_id, request_limit
49
+ @limit -= reply.count if limited?
50
+ @cursor_id = reply.cursor_id
51
+ reply.documents
52
+ end
50
53
  end
51
54
 
52
55
  # Determine the request limit for the query
@@ -112,10 +112,10 @@ module Moped
112
112
  class PotentialReconfiguration < MongoError
113
113
 
114
114
  # Not master error codes.
115
- NOT_MASTER = [ 13435, 13436, 10009, 15986 ]
115
+ NOT_MASTER = [ 13435, 13436, 10009, 15986, 83 ]
116
116
 
117
117
  # Error codes received around reconfiguration
118
- CONNECTION_ERRORS_RECONFIGURATION = [ 15988, 10276, 11600, 9001, 13639, 10009, 11002 ]
118
+ CONNECTION_ERRORS_RECONFIGURATION = [ 15988, 10276, 11600, 9001, 13639, 10009, 11002, 7 ]
119
119
 
120
120
  # Replica set reconfigurations can be either in the form of an operation
121
121
  # error with code 13435, or with an error message stating the server is
@@ -126,7 +126,8 @@ module Moped
126
126
  end
127
127
 
128
128
  def connection_failure?
129
- CONNECTION_ERRORS_RECONFIGURATION.include?(details["code"])
129
+ err = details["err"] || details["errmsg"] || details["$err"] || ""
130
+ CONNECTION_ERRORS_RECONFIGURATION.include?(details["code"]) || err.include?("could not get last error") || err.include?("connection attempt failed")
130
131
  end
131
132
 
132
133
  # Is the error due to a namespace not being found?
@@ -21,7 +21,8 @@ module Moped
21
21
  Errors::ConnectionFailure => Retry,
22
22
  Errors::CursorNotFound => Ignore,
23
23
  Errors::OperationFailure => Reconfigure,
24
- Errors::QueryFailure => Reconfigure
24
+ Errors::QueryFailure => Reconfigure,
25
+ Errors::PoolTimeout => Retry
25
26
  }.freeze
26
27
 
27
28
  # Get the appropriate failover handler given the provided exception.
@@ -9,7 +9,7 @@ module Moped
9
9
  module Retry
10
10
  extend self
11
11
 
12
- # Executes the failover strategy. In the case of retyr, we disconnect and
12
+ # Executes the failover strategy. In the case of retry, we disconnect and
13
13
  # reconnect, then try the operation one more time.
14
14
  #
15
15
  # @example Execute the retry strategy.
@@ -24,11 +24,13 @@ module Moped
24
24
  #
25
25
  # @since 2.0.0
26
26
  def execute(exception, node)
27
- node.disconnect
27
+ node.disconnect unless exception.is_a?(Errors::PoolTimeout)
28
28
  begin
29
29
  node.connection do |conn|
30
30
  yield(conn) if block_given?
31
31
  end
32
+ rescue Errors::PoolTimeout => e
33
+ raise Errors::ConnectionFailure.new e
32
34
  rescue Exception => e
33
35
  node.down!
34
36
  raise(e)
@@ -42,6 +42,10 @@ module Moped
42
42
  Moped.logger.debug([ prefix, payload, "runtime: #{runtime}" ].join(' '))
43
43
  end
44
44
 
45
+ def self.info(prefix, payload, runtime)
46
+ Moped.logger.info([ prefix, payload, "runtime: #{runtime}" ].join(' '))
47
+ end
48
+
45
49
  # Log the payload to warn.
46
50
  #
47
51
  # @example Log to warn.
@@ -111,8 +111,19 @@ module Moped
111
111
  #
112
112
  # @since 2.0.0
113
113
  def connection
114
- pool.with do |conn|
115
- yield(conn)
114
+ connection_acquired = false
115
+ begin
116
+ pool.with do |conn|
117
+ connection_acquired = true
118
+ yield(conn)
119
+ end
120
+ rescue Timeout::Error, ConnectionPool::PoolShuttingDownError => e
121
+ if e.kind_of?(ConnectionPool::PoolShuttingDownError)
122
+ @pool = nil
123
+ Connection::Manager.delete_pool(self)
124
+ raise Errors::PoolTimeout.new(e)
125
+ end
126
+ raise connection_acquired ? e : Errors::PoolTimeout.new(e)
116
127
  end
117
128
  end
118
129
 
@@ -182,6 +193,10 @@ module Moped
182
193
  yield(conn)
183
194
  end
184
195
  rescue Exception => e
196
+ if e.kind_of?(ConnectionPool::PoolShuttingDownError)
197
+ @pool = nil
198
+ Connection::Manager.delete_pool(self)
199
+ end
185
200
  Failover.get(e).execute(e, self, &block)
186
201
  ensure
187
202
  end_execution(:connection)
@@ -198,7 +213,7 @@ module Moped
198
213
  #
199
214
  # @return [ nil ] nil.
200
215
  #
201
- # @since 1.0.0
216
+ # @since 1.0.0s
202
217
  def ensure_primary
203
218
  execute(:ensure_primary) do
204
219
  yield(self)
@@ -585,14 +600,14 @@ module Moped
585
600
  def flush(ops = queue)
586
601
  operations, callbacks = ops.transpose
587
602
  logging(operations) do
588
- replies = nil
589
603
  ensure_connected do |conn|
590
604
  conn.write(operations)
591
605
  replies = conn.receive_replies(operations)
606
+
607
+ replies.zip(callbacks).map do |reply, callback|
608
+ callback ? callback[reply] : reply
609
+ end.last
592
610
  end
593
- replies.zip(callbacks).map do |reply, callback|
594
- callback ? callback[reply] : reply
595
- end.last
596
611
  end
597
612
  ensure
598
613
  ops.clear
@@ -46,10 +46,27 @@ module Moped
46
46
  # @since 2.0.0
47
47
  def execute(node)
48
48
  node.process(operation) do |reply|
49
- if operation.failure?(reply)
50
- raise operation.failure_exception(reply)
49
+ # Avoid LocalJumpError
50
+ ret = nil
51
+ if reply.unauthorized? && node.credentials.key?(@database)
52
+ node.connection do |conn|
53
+ username, password = node.credentials[@database]
54
+ if username && password
55
+ conn.login(operation.database, username, password)
56
+ ret = execute(node)
57
+ end
58
+ end
51
59
  end
52
- operation.results(reply)
60
+
61
+ if ret.nil?
62
+ if operation.failure?(reply)
63
+ raise operation.failure_exception(reply)
64
+ end
65
+
66
+ ret = operation.results(reply)
67
+ end
68
+
69
+ ret
53
70
  end
54
71
  end
55
72
  end
@@ -33,7 +33,7 @@ module Moped
33
33
  ! (e.message.include?("not master") || e.message.include?("Not primary"))
34
34
 
35
35
  if retries > 0
36
- Loggable.warn(" MOPED:", "Retrying connection attempt #{retries} more time(s).", "n/a")
36
+ Loggable.warn(" MOPED:", "Retrying connection attempt #{retries} more time(s), nodes is #{cluster.nodes.inspect}, seeds are #{cluster.seeds.inspect}, cluster is #{cluster.inspect}. Error backtrace is #{e.backtrace}.", "n/a")
37
37
  sleep(cluster.retry_interval)
38
38
  cluster.refresh
39
39
  with_retry(cluster, retries - 1, &block)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Moped
3
- VERSION = "2.0.6"
3
+ VERSION = "2.0.7"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moped
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-11 00:00:00.000000000 Z
12
+ date: 2015-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  requirements: []
142
142
  rubyforge_project:
143
- rubygems_version: 2.4.6
143
+ rubygems_version: 2.2.2
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: A MongoDB driver for Ruby.