moped 2.0.4 → 2.0.5

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: 31b65cfe80d130d0aaba89725d9ff1f8e5d5fe77
4
- data.tar.gz: 89175cb0f07a9b3f634d324b7871927e1869056f
3
+ metadata.gz: 7dba3a2f186d5c84ba26637291643efa327c261b
4
+ data.tar.gz: 54733a6e86b6552dc7e3bf7ea2225d4326833404
5
5
  SHA512:
6
- metadata.gz: 8eeaf0ba8133fee14caa778b7e79811d641852c981e9f1588b910e05c63229ad41c0e62929b676ebb344e062e47ea5bd0affc36bd9a6c969c9f44bc97e061b46
7
- data.tar.gz: 45d6b311a62e3a233acf851c2bd231a4f88e659169feae228950214f689d8116af1ddfbcae0b6febe582ad83df87f74071b00c581b5533d3e41c22d8f1a3f438
6
+ metadata.gz: 65a84b04bf7da4ca7866ca74653e3024b786333cd41a2f313d5c8a5493d7e2d49b238089e7627e771c04b828e496bbff202d1729cfcc0e109e552c3ec34079f2
7
+ data.tar.gz: e41dfe9ef081ba6bca54b9cf9c154d9f57788a84066644388f6ba28a8c51c883fa2da0e9a7a0dad03c57708e34f747887e9bb4b99563bf331a6fa448afe92ffe
@@ -1,5 +1,14 @@
1
1
  # Overview
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Resolved Issues
6
+
7
+ * \#351
8
+ Fixing retries with authentication. (Wandenberg Peixoto)
9
+
10
+ * Bump BSON dependency to 3.0.4
11
+
3
12
  ## 2.0.4
4
13
 
5
14
  ### Resolved Issues
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "moped/query"
3
+ require "moped/retryable"
3
4
 
4
5
  module Moped
5
6
 
@@ -8,6 +9,7 @@ module Moped
8
9
  # @since 1.0.0
9
10
  class Collection
10
11
  include Readable
12
+ include Retryable
11
13
 
12
14
  # @!attribute database
13
15
  # @return [ Database ] The database for the collection.
@@ -120,9 +122,11 @@ module Moped
120
122
  #
121
123
  # @since 1.0.0
122
124
  def insert(documents, flags = nil)
123
- docs = documents.is_a?(Array) ? documents : [ documents ]
124
- cluster.with_primary do |node|
125
- node.insert(database.name, name, docs, write_concern, flags: flags || [])
125
+ with_retry(cluster) do
126
+ docs = documents.is_a?(Array) ? documents : [ documents ]
127
+ cluster.with_primary do |node|
128
+ node.insert(database.name, name, docs, write_concern, flags: flags || [])
129
+ end
126
130
  end
127
131
  end
128
132
 
@@ -112,7 +112,7 @@ module Moped
112
112
  class PotentialReconfiguration < MongoError
113
113
 
114
114
  # Not master error codes.
115
- NOT_MASTER = [ 13435, 13436, 10009 ]
115
+ NOT_MASTER = [ 13435, 13436, 10009, 15986 ]
116
116
 
117
117
  # Error codes received around reconfiguration
118
118
  CONNECTION_ERRORS_RECONFIGURATION = [ 15988, 10276, 11600, 9001, 13639, 10009, 11002 ]
@@ -21,6 +21,7 @@ module Moped
21
21
  # people.find.count # => 1
22
22
  class Query
23
23
  include Enumerable
24
+ include Retryable
24
25
 
25
26
  # @attribute [r] collection The collection to execute the query on.
26
27
  # @attribute [r] operation The query operation.
@@ -321,14 +322,16 @@ module Moped
321
322
  #
322
323
  # @since 1.0.0
323
324
  def remove
324
- cluster.with_primary do |node|
325
- node.remove(
326
- operation.database,
327
- operation.collection,
328
- operation.basic_selector,
329
- write_concern,
330
- flags: [ :remove_first ]
331
- )
325
+ with_retry(cluster) do
326
+ cluster.with_primary do |node|
327
+ node.remove(
328
+ operation.database,
329
+ operation.collection,
330
+ operation.basic_selector,
331
+ write_concern,
332
+ flags: [ :remove_first ]
333
+ )
334
+ end
332
335
  end
333
336
  end
334
337
 
@@ -341,13 +344,15 @@ module Moped
341
344
  #
342
345
  # @since 1.0.0
343
346
  def remove_all
344
- cluster.with_primary do |node|
345
- node.remove(
346
- operation.database,
347
- operation.collection,
348
- operation.basic_selector,
349
- write_concern
350
- )
347
+ with_retry(cluster) do
348
+ cluster.with_primary do |node|
349
+ node.remove(
350
+ operation.database,
351
+ operation.collection,
352
+ operation.basic_selector,
353
+ write_concern
354
+ )
355
+ end
351
356
  end
352
357
  end
353
358
 
@@ -423,15 +428,17 @@ module Moped
423
428
  #
424
429
  # @since 1.0.0
425
430
  def update(change, flags = nil)
426
- cluster.with_primary do |node|
427
- node.update(
428
- operation.database,
429
- operation.collection,
430
- operation.selector["$query"] || operation.selector,
431
- change,
432
- write_concern,
433
- flags: flags
434
- )
431
+ with_retry(cluster) do
432
+ cluster.with_primary do |node|
433
+ node.update(
434
+ operation.database,
435
+ operation.collection,
436
+ operation.selector["$query"] || operation.selector,
437
+ change,
438
+ write_concern,
439
+ flags: flags
440
+ )
441
+ end
435
442
  end
436
443
  end
437
444
 
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require "moped/retryable"
2
3
  module Moped
3
4
  module ReadPreference
4
5
 
@@ -7,6 +8,7 @@ module Moped
7
8
  #
8
9
  # @since 2.0.0
9
10
  module Selectable
11
+ include Retryable
10
12
 
11
13
  # @!attribute tags
12
14
  # @return [ Array<Hash> ] The tag sets.
@@ -39,41 +41,6 @@ module Moped
39
41
  options[:flags] |= [ :slave_ok ]
40
42
  options
41
43
  end
42
-
43
- private
44
-
45
- # Execute the provided block on the cluster and retry if the execution
46
- # fails.
47
- #
48
- # @api private
49
- #
50
- # @example Execute with retry.
51
- # preference.with_retry(cluster) do
52
- # cluster.with_primary do |node|
53
- # node.refresh
54
- # end
55
- # end
56
- #
57
- # @param [ Cluster ] cluster The cluster.
58
- # @param [ Integer ] retries The number of times to retry.
59
- #
60
- # @return [ Object ] The result of the block.
61
- #
62
- # @since 2.0.0
63
- def with_retry(cluster, retries = cluster.max_retries, &block)
64
- begin
65
- block.call
66
- rescue Errors::ConnectionFailure => e
67
- if retries > 0
68
- Loggable.warn(" MOPED:", "Retrying connection attempt #{retries} more time(s).", "n/a")
69
- sleep(cluster.retry_interval)
70
- cluster.refresh
71
- with_retry(cluster, retries - 1, &block)
72
- else
73
- raise e
74
- end
75
- end
76
- end
77
44
  end
78
45
  end
79
46
  end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ module Moped
3
+ # Provides the shared behaviour for retry failed operations.
4
+ #
5
+ # @since 2.0.0
6
+ module Retryable
7
+
8
+ private
9
+
10
+ # Execute the provided block on the cluster and retry if the execution
11
+ # fails.
12
+ #
13
+ # @api private
14
+ #
15
+ # @example Execute with retry.
16
+ # preference.with_retry(cluster) do
17
+ # cluster.with_primary do |node|
18
+ # node.refresh
19
+ # end
20
+ # end
21
+ #
22
+ # @param [ Cluster ] cluster The cluster.
23
+ # @param [ Integer ] retries The number of times to retry.
24
+ #
25
+ # @return [ Object ] The result of the block.
26
+ #
27
+ # @since 2.0.0
28
+ def with_retry(cluster, retries = cluster.max_retries, &block)
29
+ begin
30
+ block.call
31
+ rescue Errors::ConnectionFailure, Errors::PotentialReconfiguration => e
32
+ raise e if e.is_a?(Errors::PotentialReconfiguration) &&
33
+ ! (e.message.include?("not master") || e.message.include?("Not primary"))
34
+
35
+ if retries > 0
36
+ Loggable.warn(" MOPED:", "Retrying connection attempt #{retries} more time(s).", "n/a")
37
+ sleep(cluster.retry_interval)
38
+ cluster.refresh
39
+ with_retry(cluster, retries - 1, &block)
40
+ else
41
+ raise e
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Moped
3
- VERSION = "2.0.4"
3
+ VERSION = "2.0.5"
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.4
4
+ version: 2.0.5
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-02-20 00:00:00.000000000 Z
12
+ date: 2015-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '2.2'
20
+ version: 3.0.4
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '2.2'
27
+ version: 3.0.4
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: connection_pool
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +114,7 @@ files:
114
114
  - lib/moped/read_preference/secondary_preferred.rb
115
115
  - lib/moped/read_preference/selectable.rb
116
116
  - lib/moped/readable.rb
117
+ - lib/moped/retryable.rb
117
118
  - lib/moped/session.rb
118
119
  - lib/moped/uri.rb
119
120
  - lib/moped/version.rb