You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -23,20 +23,21 @@ A random secondary will be chosen to be read from. In a typical multi-process Ru
23
23
24
24
### Connection Failures
25
25
26
-
Imagine that our master node goes offline. How will the driver respond?
26
+
Imagine that either the master node or one of the read nodes goes offline. How will the driver respond?
27
27
28
-
At first, the driver will try to send operations to what was the master node. These operations will fail, and the driver will raise a *ConnectionFailure* exception. It then becomes the client's responsibility to decide how to handle this.
28
+
If any read operation fails, the driver will raise a *ConnectionFailure* exception. It then becomes the client's responsibility to decide how to handle this.
29
29
30
30
If the client decides to retry, it's not guaranteed that another member of the replica set will have been promoted to master right away, so it's still possible that the driver will raise another *ConnectionFailure*. However, once a member has been promoted to master, typically within a few seconds, subsequent operations will succeed.
31
31
32
32
The driver will essentially cycle through all known seed addresses until a node identifies itself as master.
33
33
34
34
### Recovery
35
35
36
-
Driver users may wish to wrap their database calls with failure recovery code. Here's one possibility:
36
+
Driver users may wish to wrap their database calls with failure recovery code. Here's one possibility, which will attempt to connection
37
+
every half second and time out after thirty seconds.
37
38
38
39
# Ensure retry upon failure
39
-
def rescue_connection_failure(max_retries=5)
40
+
def rescue_connection_failure(max_retries=60)
40
41
success = false
41
42
retries = 0
42
43
while !success
@@ -46,7 +47,7 @@ Driver users may wish to wrap their database calls with failure recovery code. H
46
47
rescue Mongo::ConnectionFailure => ex
47
48
retries += 1
48
49
raise ex if retries >= max_retries
49
-
sleep(1)
50
+
sleep(0.5)
50
51
end
51
52
end
52
53
end
@@ -74,4 +75,3 @@ Make sure you have a replica set running on localhost before trying to run these
The first, `true`, simply indicates that we should request a response from the server to ensure that to errors have occurred. The second, `{:w => 2}`forces the server to wait until at least two servers have recorded the write. The third does the same but will time out if the replication can't be completed in 200 milliseconds. The fourth forces an fsync on each server being written to (note: this option is rarely necessary and will have a dramaticly negative effect on performance).
13
+
14
+
## Write concern inheritance
15
+
16
+
The Ruby driver allows you to set write concern on each of four levels: the connection, database, collection, and write operation.
17
+
Objects will inherit the default write concern from their parents. Thus, if you set a write concern of `{:w => 1}` when creating
18
+
a new connection, then all databases and collections created from that connection will inherit the same setting. See this code example:
0 commit comments