mongo_ha 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/mongo_ha/retryable.rb +33 -20
- data/lib/mongo_ha/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae55c68a2fcb98cbbc45ce2c38b9704568b0a840
|
4
|
+
data.tar.gz: 32f0cc03e5b4d8b4b5ffc971b3d6c095ee23ee00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/mongo_ha/retryable.rb
CHANGED
@@ -3,20 +3,22 @@ require 'mongo/retryable'
|
|
3
3
|
module Mongo
|
4
4
|
module Retryable
|
5
5
|
|
6
|
-
def read_with_retry
|
6
|
+
def read_with_retry
|
7
|
+
attempt = 0
|
7
8
|
begin
|
8
|
-
|
9
|
+
attempt += 1
|
10
|
+
yield
|
9
11
|
rescue Error::SocketError, Error::SocketTimeoutError => e
|
10
|
-
|
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
|
-
|
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
|
30
|
-
|
31
|
+
def read_with_one_retry
|
32
|
+
yield
|
31
33
|
rescue Error::SocketError, Error::SocketTimeoutError => e
|
32
|
-
|
33
|
-
|
34
|
+
retry_reconnect(e)
|
35
|
+
yield
|
34
36
|
end
|
35
37
|
|
36
|
-
def write_with_retry
|
38
|
+
def write_with_retry
|
39
|
+
attempt = 0
|
37
40
|
begin
|
38
|
-
|
41
|
+
attempt += 1
|
42
|
+
yield
|
39
43
|
rescue Error::SocketError => e
|
40
|
-
|
41
|
-
#
|
42
|
-
|
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
|
-
|
58
|
+
retry_reconnect(e)
|
59
|
+
retry
|
46
60
|
else
|
47
|
-
raise
|
61
|
+
raise(e)
|
48
62
|
end
|
49
63
|
end
|
50
64
|
end
|
51
65
|
|
52
66
|
private
|
53
67
|
|
54
|
-
|
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
|
data/lib/mongo_ha/version.rb
CHANGED
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.
|
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
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|