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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/moped/address.rb +19 -5
- data/lib/moped/connection/manager.rb +9 -2
- data/lib/moped/cursor.rb +7 -4
- data/lib/moped/errors.rb +4 -3
- data/lib/moped/failover.rb +2 -1
- data/lib/moped/failover/retry.rb +4 -2
- data/lib/moped/loggable.rb +4 -0
- data/lib/moped/node.rb +22 -7
- data/lib/moped/operation/read.rb +20 -3
- data/lib/moped/retryable.rb +1 -1
- data/lib/moped/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eda09d3428a61f892b3d983486b0bcacb4d22c1f
|
4
|
+
data.tar.gz: 0d496810ace691461b3443f1163102a76f85ec5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 951ba327262a778af25d190b5f80332c10bac5f8186194c399091bb924bcab9c625f4b317d3807390a2fc233f3c2f2a7cfb1f499045363743ec2e6a789581043
|
7
|
+
data.tar.gz: 8a5fcdd582261c79a7d1fd241d17ffd437bd4232e3a663e040c316fa8c2bc29e15c56399fa2e677e8971c1687cbbafd8743ba4fc6af6b1c97eb888ca1a4d6c56
|
data/CHANGELOG.md
CHANGED
data/lib/moped/address.rb
CHANGED
@@ -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
|
-
|
50
|
-
Timeout
|
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
|
-
|
62
|
-
|
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
|
-
|
54
|
-
|
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
|
|
data/lib/moped/cursor.rb
CHANGED
@@ -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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
data/lib/moped/errors.rb
CHANGED
@@ -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
|
-
|
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?
|
data/lib/moped/failover.rb
CHANGED
@@ -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.
|
data/lib/moped/failover/retry.rb
CHANGED
@@ -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
|
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)
|
data/lib/moped/loggable.rb
CHANGED
@@ -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.
|
data/lib/moped/node.rb
CHANGED
@@ -111,8 +111,19 @@ module Moped
|
|
111
111
|
#
|
112
112
|
# @since 2.0.0
|
113
113
|
def connection
|
114
|
-
|
115
|
-
|
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.
|
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
|
data/lib/moped/operation/read.rb
CHANGED
@@ -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
|
-
|
50
|
-
|
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
|
-
|
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
|
data/lib/moped/retryable.rb
CHANGED
@@ -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)
|
data/lib/moped/version.rb
CHANGED
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.
|
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-
|
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.
|
143
|
+
rubygems_version: 2.2.2
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: A MongoDB driver for Ruby.
|