mongo_ha 2.0.0 → 2.0.1

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: c07613ccc0db614856311ea723d0bb980bd53113
4
- data.tar.gz: f449fd924fd37daac5bfd82d3d13950422d895d9
3
+ metadata.gz: ae55c68a2fcb98cbbc45ce2c38b9704568b0a840
4
+ data.tar.gz: 32f0cc03e5b4d8b4b5ffc971b3d6c095ee23ee00
5
5
  SHA512:
6
- metadata.gz: 4e65723c5ba6bb1ac48c2095c353ee6ca048d49016e92db7329f8820a568b95a63949151f0831a3a3379f477b9673d1c9f999749f2e4d623e56a5a3f2651abbe
7
- data.tar.gz: 83e9ccb94dc81194df0c87b8558def4f5d17efff66297071c43ab3ed4b48c52d019a4175921b87418fcd44e42d9543b282c765d3e88bcbb8e91c8b1e5b192e8a
6
+ metadata.gz: 924d0fed8af1570863e16f4708856719c1826e9efb959304b6c82baa0993c68101371595a8369db8e83628346a619a2670384cbf44b7c1489cacc24f1af1d07e
7
+ data.tar.gz: 6faa9a2bc05a2d1fb703fb32335d43da13f10e79274b299bddd4ba2594ad5df8918ec9fcaa6aa70fbe5a485d3b1d330aec218e28040838802e9966ed7949f495
data/README.md CHANGED
@@ -24,6 +24,9 @@ servers with reconnect attempts.
24
24
 
25
25
  Supports Ruby Mongo driver V1 and V2
26
26
 
27
+ NOTE: The Ruby Mongo driver V2.4.0 does not work yet, since it sometimes fails to refresh its view of the
28
+ replicaset after `cluster.scan!` is called. Use V2.3 for now.
29
+
27
30
  `mongo_ha` transparently supports `MongoMapper` and `Mongoid` which use the mongo ruby driver.
28
31
 
29
32
  ## Installation
@@ -3,20 +3,22 @@ require 'mongo/retryable'
3
3
  module Mongo
4
4
  module Retryable
5
5
 
6
- def read_with_retry(attempt = 0, &block)
6
+ def read_with_retry
7
+ attempt = 0
7
8
  begin
8
- block.call
9
+ attempt += 1
10
+ yield
9
11
  rescue Error::SocketError, Error::SocketTimeoutError => e
10
- retry_operation(e, &block)
12
+ raise(e) if attempt > cluster.max_read_retries
13
+ retry_reconnect(e)
14
+ retry
11
15
  rescue Error::OperationFailure => e
12
- # TODO: Non sharded, retryable due to Replicaset primary change
13
-
14
16
  if cluster.sharded? && e.retryable?
15
17
  if attempt < cluster.max_read_retries
16
18
  # We don't scan the cluster in this case as Mongos always returns
17
19
  # ready after a ping no matter what the state behind it is.
18
20
  sleep(cluster.read_retry_interval)
19
- read_with_retry(attempt + 1, &block)
21
+ retry
20
22
  else
21
23
  raise e
22
24
  end
@@ -26,36 +28,47 @@ module Mongo
26
28
  end
27
29
  end
28
30
 
29
- def read_with_one_retry(&block)
30
- block.call
31
+ def read_with_one_retry
32
+ yield
31
33
  rescue Error::SocketError, Error::SocketTimeoutError => e
32
- Logger.logger.warn "Single retry due to: #{e.class.name} #{e.message}"
33
- block.call
34
+ retry_reconnect(e)
35
+ yield
34
36
  end
35
37
 
36
- def write_with_retry(&block)
38
+ def write_with_retry
39
+ attempt = 0
37
40
  begin
38
- block.call
41
+ attempt += 1
42
+ yield
39
43
  rescue Error::SocketError => e
40
- # During a master move in a replica-set the master closes existing client connections.
41
- # Note: Small possibility the write occurs twice.
42
- retry_operation(e, &block)
44
+ raise(e) if attempt >= cluster.max_read_retries
45
+ # During a replicaset master change the primary immediately closes all existing client connections.
46
+ #
47
+ # Note:
48
+ # Small possibility the write occurs twice.
49
+ # Usually this is acceptable since most applications would just retry the write anyway.
50
+ # The ideal way is to check if the write succeeded, or just use a primary key to
51
+ # prevent multiple writes etc.
52
+ # In production we have not seen duplicates using this retry mechanism.
53
+ retry_reconnect(e)
54
+ retry
43
55
  rescue Error::OperationFailure => e
56
+ raise(e) if attempt >= cluster.max_read_retries
44
57
  if e.write_retryable?
45
- retry_operation(e, &block)
58
+ retry_reconnect(e)
59
+ retry
46
60
  else
47
- raise e
61
+ raise(e)
48
62
  end
49
63
  end
50
64
  end
51
65
 
52
66
  private
53
67
 
54
- # Log a warning on retry to prevent appearance of "hanging" during a failover.
55
- def retry_operation(e, &block)
68
+ def retry_reconnect(e)
56
69
  Logger.logger.warn "Retry due to: #{e.class.name} #{e.message}"
70
+ sleep(cluster.read_retry_interval)
57
71
  cluster.scan!
58
- block.call
59
72
  end
60
73
 
61
74
  end
@@ -1,3 +1,3 @@
1
1
  module MongoHA #:nodoc
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_ha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-30 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo