lib/mongo/retryable.rb
def retry_read(original_error, server_selector, session, &block)
      begin
        server = select_server(cluster, server_selector, session)
      rescue => e
        original_error.add_note("later retry failed: #{e.class}: #{e}")
        raise original_error
      end

      log_retry(original_error, message: 'Read retry')

      begin
        yield server, true
      rescue Error::SocketError, Error::SocketTimeoutError => e
        e.add_note('modern retry')
        e.add_note("attempt 2")
        raise e
      rescue Error::OperationFailure => e
        e.add_note('modern retry')
        unless e.write_retryable?
          original_error.add_note("later retry failed: #{e.class}: #{e}")
          raise original_error
        end
        e.add_note("attempt 2")
        raise e
      rescue => e
        e.add_note('modern retry')
        original_error.add_note("later retry failed: #{e.class}: #{e}")
        raise original_error
      end
    end
# 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.
#
# @api private
#
# @example Execute a read returning a cursor.
#   cursor = read_with_retry_cursor(session, server_selector, view) do |server|
#     # return a Mongo::Operation::Result
#     ...
#   end
#
# @param [ Mongo::Session ] session The session that the operation is being
#   run on.
# @param [ Mongo::ServerSelector::Selectable ] server_selector Server
#   selector for the operation.
# @param [ CollectionView ] view The +CollectionView+ defining the query.
# @param [ Proc ] block The block to execute.
#
# @return [ Cursor ] The cursor for the result set.
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 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.
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 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 .
def retry_read(original_error, server_selector, session, &block)
      begin
        server = select_server(cluster, server_selector, session)
      rescue => e
        original_error.add_note("later retry failed: #{e.class}: #{e}")
        raise original_error
      end
      log_retry(original_error, message: 'Read retry')
      begin
        yield server, true
      rescue Error::SocketError, Error::SocketTimeoutError => e
        e.add_note('modern retry')
        e.add_note("attempt 2")
        raise e
      rescue Error::OperationFailure => e
        e.add_note('modern retry')
        unless e.write_retryable?
          original_error.add_note("later retry failed: #{e.class}: #{e}")
          raise original_error
        end
        e.add_note("attempt 2")
        raise e
      rescue => e
        e.add_note('modern retry')
        original_error.add_note("later retry failed: #{e.class}: #{e}")
        raise original_error
      end
    end
def retry_read ( original_error , server_selector , session , & block ) begin server = select_server ( cluster , server_selector , session ) rescue => e original_error . add_note ( "later retry failed: #{e.class}: #{e}" ) raise original_error end log_retry ( original_error , message : 'Read retry' ) begin yield server , true rescue Error :: SocketError , Error :: SocketTimeoutError => e e . add_note ( 'modern retry' ) e . add_note ( "attempt 2" ) raise e rescue Error :: OperationFailure => e e . add_note ( 'modern retry' ) unless e . write_retryable? original_error . add_note ( "later retry failed: #{e.class}: #{e}" ) raise original_error end e . add_note ( "attempt 2" ) raise e rescue => e e . add_note ( 'modern retry' ) original_error . add_note ( "later retry failed: #{e.class}: #{e}" ) raise original_error end end
Execute a read operation returning a cursor with retrying.
Execute a read operation returning a cursor with retrying .
The cursor for the result set.
The cursor for the result set .
 Cursor 
original_error
server_selector
session
block
block The block to execute.
block The block to execute .
api
None
example
Execute a read returning a cursor. cursor = read_with_retry_cursor(session, server_selector, view) do |server| # return a Mongo::Operation::Result ... end
Execute a read returning a cursor . cursor = read_with_retry_cursor ( session server_selector view ) do |server| # return a Mongo :: Operation :: Result ... end