Module: Mongo::Retryable
- Included in:
- BulkWrite, Cluster::CursorReaper, Collection, Collection::View, Collection::View::Aggregation, Collection::View::MapReduce, Cursor, Server::Connection, Server::Monitor::Connection
- Defined in:
- lib/mongo/retryable.rb
Overview
Defines basic behaviour around retrying operations.
Instance Method Summary collapse
-
#read_with_one_retry ⇒ Result
private
Execute a read operation with a single retry.
-
#read_with_retry ⇒ Result
private
Execute a read operation with a retry.
-
#write_with_retry ⇒ Result
private
Execute a write operation with a retry.
Instance Method Details
#read_with_one_retry ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This only retries read operations on socket errors.
Execute a read operation with a single retry.
77 78 79 80 81 |
# File 'lib/mongo/retryable.rb', line 77 def read_with_one_retry yield rescue Error::SocketError, Error::SocketTimeoutError yield end |
#read_with_retry ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This only retries read operations on socket errors.
Execute a read operation with a retry.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mongo/retryable.rb', line 39 def read_with_retry attempt = 0 begin attempt += 1 yield rescue Error::SocketError, Error::SocketTimeoutError => e raise(e) if attempt > cluster.max_read_retries log_retry(e) cluster.scan! retry rescue Error::OperationFailure => e if cluster.sharded? && e.retryable? raise(e) if attempt > cluster.max_read_retries log_retry(e) sleep(cluster.read_retry_interval) retry else raise e end end end |
#write_with_retry ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This only retries operations on not master failures, since it is the only case we can be sure a partial write did not already occur.
Execute a write operation with a retry.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/mongo/retryable.rb', line 100 def write_with_retry attempt = 0 begin attempt += 1 yield rescue Error::OperationFailure => e raise(e) if attempt > Cluster::MAX_WRITE_RETRIES if e.write_retryable? log_retry(e) cluster.scan! retry else raise(e) end end end |