lib/mongo/retryable.rb in mongo-2.10.2 vs lib/mongo/retryable.rb in mongo-2.10.3
- old
+ new
@@ -117,11 +117,16 @@
modern_read_with_retry(session, server_selector, &block)
elsif client.max_read_retries > 0
legacy_read_with_retry(session, server_selector, &block)
else
server = select_server(cluster, server_selector, session)
- yield server
+ begin
+ yield server
+ rescue Error::SocketError, Error::SocketTimeoutError, Error::OperationFailure => e
+ e.add_note('retries disabled')
+ raise e
+ end
end
end
# Execute a read operation with a single retry on network errors.
#
@@ -212,16 +217,18 @@
session.next_txn_num
end
begin
yield(server, txn_num, false)
rescue Error::SocketError, Error::SocketTimeoutError => e
+ e.add_note('modern retry')
e.add_note("attempt 1")
if session.in_transaction? && !ending_transaction
raise e
end
retry_write(e, session, txn_num, &block)
rescue Error::OperationFailure => e
+ e.add_note('modern retry')
e.add_note("attempt 1")
if e.unsupported_retryable_write?
raise_unsupported_error(e)
elsif (session.in_transaction? && !ending_transaction) || !e.write_retryable?
raise e
@@ -248,11 +255,16 @@
#
# @api private
def nro_write_with_retry(session, write_concern, &block)
if session && session.client.options[:retry_writes]
server = select_server(cluster, ServerSelector.primary, session)
- yield server
+ begin
+ yield server
+ rescue Error::SocketError, Error::SocketTimeoutError, Error::OperationFailure => e
+ e.add_note('retries disabled')
+ raise e
+ end
else
legacy_write_with_retry(nil, session, &block)
end
end
@@ -278,11 +290,12 @@
begin
attempt += 1
server ||= select_server(cluster, ServerSelector.primary, session)
yield server
rescue Error::OperationFailure => e
- e.add_note("attempt #{attempt + 1}")
+ e.add_note('legacy retry')
+ e.add_note("attempt #{attempt}")
server = nil
if attempt > client.max_write_retries
raise e
end
if e.write_retryable? && !(session && session.in_transaction?)
@@ -296,22 +309,23 @@
end
private
def modern_read_with_retry(session, server_selector, &block)
- attempt = 0
server = select_server(cluster, server_selector, session)
begin
yield server
rescue Error::SocketError, Error::SocketTimeoutError => e
- e.add_note("attempt #{attempt + 1}")
+ e.add_note('modern retry')
+ e.add_note("attempt 1")
if session.in_transaction?
raise e
end
retry_read(e, server_selector, session, &block)
rescue Error::OperationFailure => e
- e.add_note("attempt #{attempt + 1}")
+ e.add_note('modern retry')
+ e.add_note("attempt 1")
if session.in_transaction? || !e.write_retryable?
raise e
end
retry_read(e, server_selector, session, &block)
end
@@ -322,20 +336,22 @@
server = select_server(cluster, server_selector, session)
begin
attempt += 1
yield server
rescue Error::SocketError, Error::SocketTimeoutError => e
- e.add_note("attempt #{attempt + 1}")
+ e.add_note('legacy retry')
+ e.add_note("attempt #{attempt}")
if attempt > client.max_read_retries || (session && session.in_transaction?)
raise e
end
log_retry(e, message: 'Legacy read retry')
server = select_server(cluster, server_selector, session)
retry
rescue Error::OperationFailure => e
- e.add_note("attempt #{attempt + 1}")
- if cluster.sharded? && e.retryable? && !(session && session.in_transaction?)
+ e.add_note('legacy retry')
+ e.add_note("attempt #{attempt}")
+ if e.retryable? && !(session && session.in_transaction?)
if attempt > client.max_read_retries
raise e
end
log_retry(e, message: 'Legacy read retry')
sleep(client.read_retry_interval)
@@ -373,20 +389,23 @@
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
@@ -396,26 +415,32 @@
# server description and/or topology as necessary (specifically,
# a socket error or a not master error should have marked the respective
# server unknown). Here we just need to wait for server selection.
server = select_server(cluster, ServerSelector.primary, session)
unless server.retry_writes?
+ # Do not need to add "modern retry" here, it should already be on
+ # the first exception.
original_error.add_note('did not retry because server selected for retry does not supoprt retryable writes')
raise original_error
end
log_retry(original_error, message: 'Write retry')
yield(server, txn_num, 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')
if e.write_retryable?
e.add_note('attempt 2')
raise e
else
original_error.add_note("later retry failed: #{e.class}: #{e}")
raise original_error
end
rescue => e
+ # Do not need to add "modern retry" here, it should already be on
+ # the first exception.
original_error.add_note("later retry failed: #{e.class}: #{e}")
raise original_error
end
# This is a separate method to make it possible for the test suite to