Class: Mongo::Retryable::ReadWorker Private
- Inherits:
-
BaseWorker
- Object
- BaseWorker
- Mongo::Retryable::ReadWorker
- Defined in:
- lib/mongo/retryable/read_worker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Implements the logic around retrying read operations.
Instance Attribute Summary
Attributes inherited from BaseWorker
Instance Method Summary collapse
-
#read_with_one_retry(options = nil) { ... } ⇒ Result
private
Execute a read operation with a single retry on network errors.
-
#read_with_retry(session = nil, server_selector = nil, context = nil, &block) ⇒ Result
private
Execute a read operation with retrying.
-
#read_with_retry_cursor(session, server_selector, view, context: nil, &block) ⇒ Cursor
private
Execute a read operation returning a cursor with retrying.
Methods inherited from BaseWorker
Constructor Details
This class inherits a constructor from Mongo::Retryable::BaseWorker
Instance Method Details
#read_with_one_retry(options = nil) { ... } ⇒ 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 on network errors.
This method is used by the driver for some of the internal housekeeping operations. Application-requested reads should use read_with_retry rather than this method.
153 154 155 156 157 158 159 160 161 |
# File 'lib/mongo/retryable/read_worker.rb', line 153 def read_with_one_retry( = nil) yield rescue *retryable_exceptions, Error::PoolError => e raise e unless e.write_retryable? = && [:retry_message] log_retry(e, message: ) yield end |
#read_with_retry(session = nil, server_selector = nil, context = nil, &block) ⇒ 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.
Execute a read operation with retrying.
This method performs server selection for the specified server selector and yields to the provided block, which should execute the initial query operation and return its result. The block will be passed the server selected for the operation. If the block raises an exception, and this exception corresponds to a read retryable error, and read retries are enabled for the client, this method will perform server selection again and yield to the block again (with potentially a different server). If the block returns successfully, the result of the block is returned.
If modern retry reads are on (which is the default), the initial read operation will be retried once. If legacy retry reads are on, the initial read operation will be retried zero or more times depending on the :max_read_retries client setting, the default for which is 1. To disable read retries, turn off modern read retries by setting retry_reads: false and set :max_read_retries to 0 on the client.
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/mongo/retryable/read_worker.rb', line 117 def read_with_retry(session = nil, server_selector = nil, context = nil, &block) if session.nil? && server_selector.nil? deprecated_legacy_read_with_retry(&block) elsif session&.retry_reads? modern_read_with_retry(session, server_selector, context, &block) elsif client.max_read_retries > 0 legacy_read_with_retry(session, server_selector, context, &block) else read_without_retry(session, server_selector, &block) end end |
#read_with_retry_cursor(session, server_selector, view, context: nil, &block) ⇒ Cursor
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.
Execute a read operation returning a cursor with retrying.
This method performs server selection for the specified server selector and yields to the provided block, which should execute the initial query operation and return its result. The block will be passed the server selected for the operation. If the block raises an exception, and this exception corresponds to a read retryable error, and read retries are enabled for the client, this method will perform server selection again and yield to the block again (with potentially a different server). If the block returns successfully, the result of the block (which should be a Mongo::Operation::Result) is used to construct a Mongo::Cursor object for the result set. The cursor is then returned.
If modern retry reads are on (which is the default), the initial read operation will be retried once. If legacy retry reads are on, the initial read operation will be retried zero or more times depending on the :max_read_retries client setting, the default for which is 1. To disable read retries, turn off modern read retries by setting retry_reads: false and set :max_read_retries to 0 on the client.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mongo/retryable/read_worker.rb', line 68 def read_with_retry_cursor(session, server_selector, view, context: nil, &block) read_with_retry(session, server_selector, context) do |server| result = yield server # RUBY-2367: This will be updated to allow the query cache to # cache cursors with multi-batch results. if QueryCache.enabled? && !view.collection.system_collection? CachingCursor.new(view, result, server, session: session, context: context) else Cursor.new(view, result, server, session: session, context: context) end end end |