lib/mongo/retryable.rb in mongo-2.1.0 vs lib/mongo/retryable.rb in mongo-2.1.1

- old
+ new

@@ -24,30 +24,46 @@ # @since 2.1.0 NOT_MASTER = 'not master'.freeze # Execute a read operation with a retry. # + # @api private + # # @example Execute the read. # read_with_retry do # ... # end # # @note This only retries read operations on socket errors. # + # @param [ Integer ] attempt The retry attempt count - for internal use. # @param [ Proc ] block The block to execute. # # @return [ Result ] The result of the operation. # # @since 2.1.0 - def read_with_retry(&block) + def read_with_retry(attempt = 0, &block) begin block.call rescue Error::SocketError, Error::SocketTimeoutError retry_operation(&block) + rescue Error::OperationFailure => e + if cluster.sharded? && e.retryable? + if attempt < cluster.max_read_retries + # We don't scan the cluster in this case as Mongos always returns + # ready after a ping no matter what the state behind it is. + sleep(cluster.read_retry_interval) + read_with_retry(attempt - 1, &block) + end + else + raise e + end end end # Execute a write operation with a retry. + # + # @api private # # @example Execute the write. # write_with_retry do # ... # end