123456789_123456789_123456789_123456789_123456789_

Module: Mongo::Error::ReadWriteRetryable

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/mongo/error/read_write_retryable.rb

Overview

Note:

Although methods of this module are part of the public API, the fact that these methods are defined on this module and not on the classes which include this module is not part of the public API.

A module encapsulating functionality to indicate whether errors are retryable.

Since:

  • 2.0.0

Constant Summary

  • RETRY_MESSAGES = Internal use only

    These are magic error messages that could indicate a cluster reconfiguration behind a mongos.

    Since:

    • 2.0.0

    # File 'lib/mongo/error/read_write_retryable.rb', line 62
    WRITE_RETRY_MESSAGES + [
      'transport error',
      'socket exception',
      "can't connect",
      'connect failed',
      'error querying',
      'could not get last error',
      'connection attempt failed',
      'interrupted at shutdown',
      'unknown replica set',
      'dbclient error communicating with server'
    ].freeze
  • WRITE_RETRY_ERRORS = Internal use only

    ::Mongo::Error codes and code names that should result in a failing write being retried.

    Since:

    • 2.0.0

    # File 'lib/mongo/error/read_write_retryable.rb', line 35
    [
      {:code_name => 'HostUnreachable', :code => 6},
      {:code_name => 'HostNotFound', :code => 7},
      {:code_name => 'NetworkTimeout', :code => 89},
      {:code_name => 'ShutdownInProgress', :code => 91},
      {:code_name => 'PrimarySteppedDown', :code => 189},
      {:code_name => 'ExceededTimeLimit', :code => 262},
      {:code_name => 'SocketException', :code => 9001},
      {:code_name => 'NotMaster', :code => 10107},
      {:code_name => 'InterruptedAtShutdown', :code => 11600},
      {:code_name => 'InterruptedDueToReplStateChange', :code => 11602},
      {:code_name => 'NotPrimaryNoSecondaryOk', :code => 13435},
      {:code_name => 'NotMasterOrSecondary', :code => 13436},
    ].freeze
  • WRITE_RETRY_MESSAGES = Internal use only

    These are magic error messages that could indicate a master change.

    Since:

    • 2.0.0

    # File 'lib/mongo/error/read_write_retryable.rb', line 53
    [
      'not master',
      'node is recovering',
    ].freeze

Instance Attribute Summary

Instance Attribute Details

#retryable?true, false (readonly)

Deprecated.

Whether the error is a retryable error according to the legacy read retry logic.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/error/read_write_retryable.rb', line 81

def retryable?
  write_retryable? ||
  code.nil? && RETRY_MESSAGES.any?{ |m| message.include?(m) }
end

#write_retryable?true, false (readonly)

Whether the error is a retryable error according to the modern retryable reads and retryable writes specifications.

This method is also used by the legacy retryable write logic to determine whether an error is a retryable one.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/error/read_write_retryable.rb', line 93

def write_retryable?
  write_retryable_code? ||
  code.nil? && WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) }
end

#write_retryable_code?Boolean (readonly, private)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/error/read_write_retryable.rb', line 98

private def write_retryable_code?
  if code
    WRITE_RETRY_ERRORS.any? { |e| e[:code] == code }
  else
    # return false rather than nil
    false
  end
end