mongo_ha 2.0.1 → 2.5.0

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
- SHA1:
3
- metadata.gz: ae55c68a2fcb98cbbc45ce2c38b9704568b0a840
4
- data.tar.gz: 32f0cc03e5b4d8b4b5ffc971b3d6c095ee23ee00
2
+ SHA256:
3
+ metadata.gz: 81ceebba66286ee047edc336a2002178c3f4be2c020249b3fa1735329c88b72f
4
+ data.tar.gz: 9917438968b6fc4289bf496352a6ea4ac4f20fc05fe7a815b21f9365fd29f92d
5
5
  SHA512:
6
- metadata.gz: 924d0fed8af1570863e16f4708856719c1826e9efb959304b6c82baa0993c68101371595a8369db8e83628346a619a2670384cbf44b7c1489cacc24f1af1d07e
7
- data.tar.gz: 6faa9a2bc05a2d1fb703fb32335d43da13f10e79274b299bddd4ba2594ad5df8918ec9fcaa6aa70fbe5a485d3b1d330aec218e28040838802e9966ed7949f495
6
+ metadata.gz: 5d3cef755e934e7b3b9e61155fbd38273f0a754f0c83ba1f2b741fc8e34a386ed703ea5fbbef0390a3b2deff3dc7ac46f5ec6eb0a9c91aaa999003213093ea4b
7
+ data.tar.gz: 8bbb7915a3bfcea4513e1c7d04f92f8d9a15a4bd2b1f1065e2875c81a0cc5a0cf8bd9f37eb514d0c254af20a4c9cda9c3a18ec3f8c7290ba8c90a4679e027fba
data/README.md CHANGED
@@ -4,7 +4,16 @@ High availability for the mongo ruby driver. Automatic reconnects and recovery w
4
4
 
5
5
  ## Status
6
6
 
7
- Production Ready: Used every day in an enterprise environment across remote data centers.
7
+ Most of the features of this gem were accepted into the mongo-ruby-client gem. :tada:
8
+
9
+ There are still a few outstanding changes that are only available with this gem:
10
+ * Retry on writes due to a master change.
11
+ * Retry on writes due to loss of network connectivity.
12
+ * Retry on reads during an operation failure other than when in a cluster.
13
+
14
+ ## Note
15
+
16
+ It is recommended to use mongo_ha v2.5 along with the Mongo Ruby Client v2.5 to get the latest HA capabilities.
8
17
 
9
18
  ## Overview
10
19
 
@@ -22,19 +31,12 @@ In the event of a connection failure, only one thread will attempt to re-establi
22
31
  connectivity to the Mongo server(s). This is to prevent swamping the mongo
23
32
  servers with reconnect attempts.
24
33
 
25
- Supports Ruby Mongo driver V1 and V2
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
-
30
- `mongo_ha` transparently supports `MongoMapper` and `Mongoid` which use the mongo ruby driver.
31
-
32
34
  ## Installation
33
35
 
34
36
  Add to Gemfile:
35
37
 
36
38
  ```ruby
37
- gem 'mongo_ha'
39
+ gem 'mongo_ha', '~> 2.5'
38
40
  ```
39
41
 
40
42
  Or for standalone environments
data/lib/mongo_ha.rb CHANGED
@@ -1,3 +1,2 @@
1
1
  require 'mongo'
2
- require 'mongo_ha/operation_failure'
3
2
  require 'mongo_ha/retryable'
@@ -10,66 +10,34 @@ module Mongo
10
10
  yield
11
11
  rescue Error::SocketError, Error::SocketTimeoutError => e
12
12
  raise(e) if attempt > cluster.max_read_retries
13
- retry_reconnect(e)
13
+ log_retry(e)
14
+ cluster.scan!
14
15
  retry
15
16
  rescue Error::OperationFailure => e
16
- if cluster.sharded? && e.retryable?
17
- if attempt < cluster.max_read_retries
18
- # We don't scan the cluster in this case as Mongos always returns
19
- # ready after a ping no matter what the state behind it is.
20
- sleep(cluster.read_retry_interval)
21
- retry
22
- else
23
- raise e
24
- end
25
- else
26
- raise e
27
- end
17
+ raise(e) if !e.retryable? || (attempt > cluster.max_read_retries)
18
+ log_retry(e)
19
+ cluster.sharded? ? sleep(cluster.read_retry_interval) : cluster.scan!
20
+ retry
28
21
  end
29
22
  end
30
23
 
31
- def read_with_one_retry
32
- yield
33
- rescue Error::SocketError, Error::SocketTimeoutError => e
34
- retry_reconnect(e)
35
- yield
36
- end
37
-
38
- def write_with_retry
24
+ def write_with_retry(session, server_selector)
39
25
  attempt = 0
40
26
  begin
41
27
  attempt += 1
42
- yield
43
- rescue Error::SocketError => e
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)
28
+ yield(server_selector.call)
29
+ rescue Error::SocketError, Error::SocketTimeoutError => e
30
+ raise(e) if attempt > cluster.max_read_retries
31
+ log_retry(e)
32
+ cluster.scan!
54
33
  retry
55
34
  rescue Error::OperationFailure => e
56
- raise(e) if attempt >= cluster.max_read_retries
57
- if e.write_retryable?
58
- retry_reconnect(e)
59
- retry
60
- else
61
- raise(e)
62
- end
35
+ raise(e) if !e.write_retryable? || (attempt > cluster.max_read_retries)
36
+ log_retry(e)
37
+ cluster.scan!
38
+ retry
63
39
  end
64
40
  end
65
41
 
66
- private
67
-
68
- def retry_reconnect(e)
69
- Logger.logger.warn "Retry due to: #{e.class.name} #{e.message}"
70
- sleep(cluster.read_retry_interval)
71
- cluster.scan!
72
- end
73
-
74
42
  end
75
43
  end
@@ -1,3 +1,3 @@
1
1
  module MongoHA #:nodoc
2
- VERSION = '2.0.1'
2
+ VERSION = '2.5.0'
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.1
4
+ version: 2.5.0
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-12-02 00:00:00.000000000 Z
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: 2.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: 2.5.0
27
27
  description: Automatic reconnects and recovery when replica-set changes, or connections
28
28
  are lost, with transparent recovery
29
29
  email:
@@ -35,7 +35,6 @@ files:
35
35
  - LICENSE.txt
36
36
  - README.md
37
37
  - lib/mongo_ha.rb
38
- - lib/mongo_ha/operation_failure.rb
39
38
  - lib/mongo_ha/retryable.rb
40
39
  - lib/mongo_ha/version.rb
41
40
  homepage: https://github.com/reidmorrison/mongo_ha
@@ -58,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
57
  version: '0'
59
58
  requirements: []
60
59
  rubyforge_project:
61
- rubygems_version: 2.6.8
60
+ rubygems_version: 2.7.3
62
61
  signing_key:
63
62
  specification_version: 4
64
63
  summary: High availability for the mongo ruby driver
@@ -1,34 +0,0 @@
1
- require 'mongo/error/operation_failure'
2
-
3
- module Mongo
4
- class Error
5
- class OperationFailure
6
- WRITE_RETRY_MESSAGES = [
7
- 'no master',
8
- 'not master',
9
- 'could not contact primary',
10
- 'Not primary'
11
- ]
12
-
13
- remove_const :RETRY_MESSAGES
14
- RETRY_MESSAGES = WRITE_RETRY_MESSAGES + [
15
- 'transport error',
16
- 'socket exception',
17
- "can't connect",
18
- 'connect failed',
19
- 'error querying',
20
- 'could not get last error',
21
- 'connection attempt failed',
22
- 'interrupted at shutdown',
23
- 'unknown replica set',
24
- 'dbclient error communicating with server'
25
- ]
26
-
27
- def write_retryable?
28
- WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) }
29
- end
30
-
31
- end
32
- end
33
- end
34
-