Exception: Mongo::Error::OperationFailure
- Inherits:
-
Mongo::Error
- Object
- StandardError
- Mongo::Error
- Mongo::Error::OperationFailure
- Extended by:
- Forwardable
- Includes:
- SdamErrorDetection
- Defined in:
- lib/mongo/error/operation_failure.rb
Overview
Raised when an operation fails for some reason.
Constant Summary collapse
- WRITE_RETRY_ERRORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Error codes and code names that should result in a failing write being retried.
[ {:code_name => 'InterruptedAtShutdown', :code => 11600}, {:code_name => 'InterruptedDueToStepDown', :code => 11602}, {:code_name => 'NotMaster', :code => 10107}, {:code_name => 'NotMasterNoSlaveOk', :code => 13435}, {:code_name => 'NotMasterOrSecondary', :code => 13436}, {:code_name => 'PrimarySteppedDown', :code => 189}, {:code_name => 'ShutdownInProgress', :code => 91}, {:code_name => 'HostNotFound', :code => 7}, {:code_name => 'HostUnreachable', :code => 6}, {:code_name => 'NetworkTimeout', :code => 89}, {:code_name => 'SocketException', :code => 9001}, {:code_name => 'ExceededTimeLimit', :code => 262} ].freeze
- WRITE_RETRY_MESSAGES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
These are magic error messages that could indicate a master change.
[ 'not master', 'node is recovering', ].freeze
- RETRY_MESSAGES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
These are magic error messages that could indicate a cluster reconfiguration behind a mongos.
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
- CHANGE_STREAM_NOT_RESUME_ERRORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Error codes and code names that should result in a failing getMore command on a change stream NOT being resumed.
[ {:code_name => 'CappedPositionLost', :code => 136}, {:code_name => 'CursorKilled', :code => 237}, {:code_name => 'Interrupted', :code => 11601}, ].freeze
- CHANGE_STREAM_RESUME_MESSAGES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Change stream can be resumed when these error messages are encountered.
WRITE_RETRY_MESSAGES
Constants included from SdamErrorDetection
SdamErrorDetection::NODE_RECOVERING_CODES, SdamErrorDetection::NODE_SHUTTING_DOWN_CODES, SdamErrorDetection::NOT_MASTER_CODES
Constants inherited from Mongo::Error
BAD_VALUE, CODE, CURSOR_NOT_FOUND, ERR, ERRMSG, ERROR, TRANSIENT_TRANSACTION_ERROR_LABEL, UNKNOWN_ERROR, UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL, WRITE_CONCERN_ERROR, WRITE_CONCERN_ERRORS, WRITE_ERRORS
Instance Attribute Summary collapse
-
#code ⇒ Integer
readonly
The error code parsed from the document.
-
#code_name ⇒ String
readonly
The error code name parsed from the document.
-
#write_concern_error_code ⇒ Integer | nil
readonly
The error code for the write concern error, if a write concern error is present and has a code.
-
#write_concern_error_code_name ⇒ String | nil
readonly
The code name for the write concern error, if a write concern error is present and has a code name.
Instance Method Summary collapse
-
#change_stream_resumable? ⇒ true, false
Can the change stream on which this error occurred be resumed, provided the operation that triggered this error was a getMore?.
-
#initialize(message = nil, result = nil, options = {}) ⇒ OperationFailure
constructor
Create the operation failure.
-
#max_time_ms_expired? ⇒ true | false
Whether the error is MaxTimeMSExpired.
- #retryable? ⇒ true, false deprecated Deprecated.
-
#unsupported_retryable_write? ⇒ true | false
Whether the error is caused by an attempted retryable write on a storage engine that does not support retryable writes.
-
#write_concern_error? ⇒ true | false
Whether the failure includes a write concern error.
-
#write_retryable? ⇒ true, false
Whether the error is a retryable error according to the modern retryable reads and retryable writes specifications.
-
#wtimeout? ⇒ true | false
Whether the error is a write concern timeout.
Methods included from SdamErrorDetection
#node_recovering?, #node_shutting_down?, #not_master?
Methods inherited from Mongo::Error
Methods included from Notable
Constructor Details
#initialize(message = nil, result = nil, options = {}) ⇒ OperationFailure
Create the operation failure.
227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/mongo/error/operation_failure.rb', line 227 def initialize( = nil, result = nil, = {}) super() @result = result @code = [:code] @code_name = [:code_name] @write_concern_error = !![:write_concern_error] @write_concern_error_code = [:write_concern_error_code] @write_concern_error_code_name = [:write_concern_error_code_name] @labels = [:labels] || [] @wtimeout = !![:wtimeout] end |
Instance Attribute Details
#code ⇒ Integer (readonly)
Returns The error code parsed from the document.
77 78 79 |
# File 'lib/mongo/error/operation_failure.rb', line 77 def code @code end |
#code_name ⇒ String (readonly)
Returns The error code name parsed from the document.
82 83 84 |
# File 'lib/mongo/error/operation_failure.rb', line 82 def code_name @code_name end |
#write_concern_error_code ⇒ Integer | nil (readonly)
Returns The error code for the write concern error, if a write concern error is present and has a code.
193 194 195 |
# File 'lib/mongo/error/operation_failure.rb', line 193 def write_concern_error_code @write_concern_error_code end |
#write_concern_error_code_name ⇒ String | nil (readonly)
Returns The code name for the write concern error, if a write concern error is present and has a code name.
200 201 202 |
# File 'lib/mongo/error/operation_failure.rb', line 200 def write_concern_error_code_name @write_concern_error_code_name end |
Instance Method Details
#change_stream_resumable? ⇒ true, false
Can the change stream on which this error occurred be resumed, provided the operation that triggered this error was a getMore?
145 146 147 148 149 150 151 152 153 |
# File 'lib/mongo/error/operation_failure.rb', line 145 def change_stream_resumable? if @result && @result.is_a?(Mongo::Operation::GetMore::Result) !change_stream_not_resumable_label? && ( || change_stream_resumable_code?) else false end end |
#max_time_ms_expired? ⇒ true | false
Whether the error is MaxTimeMSExpired.
253 254 255 |
# File 'lib/mongo/error/operation_failure.rb', line 253 def max_time_ms_expired? code == 50 # MaxTimeMSExpired end |
#retryable? ⇒ true, false
Whether the error is a retryable error according to the legacy read retry logic.
91 92 93 |
# File 'lib/mongo/error/operation_failure.rb', line 91 def retryable? write_retryable? || RETRY_MESSAGES.any?{ |m| .include?(m) } end |
#unsupported_retryable_write? ⇒ true | false
Whether the error is caused by an attempted retryable write on a storage engine that does not support retryable writes.
retryable write on a storage engine that does not support retryable writes.
264 265 266 267 |
# File 'lib/mongo/error/operation_failure.rb', line 264 def unsupported_retryable_write? # code 20 is IllegalOperation code == 20 && .start_with?("Transaction numbers") end |
#write_concern_error? ⇒ true | false
Returns Whether the failure includes a write concern error. A failure may have a top level error and a write concern error or either one of the two.
184 185 186 |
# File 'lib/mongo/error/operation_failure.rb', line 184 def write_concern_error? @write_concern_error end |
#write_retryable? ⇒ true, false
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.
104 105 106 107 |
# File 'lib/mongo/error/operation_failure.rb', line 104 def write_retryable? WRITE_RETRY_MESSAGES.any? { |m| .include?(m) } || write_retryable_code? end |
#wtimeout? ⇒ true | false
Whether the error is a write concern timeout.
244 245 246 |
# File 'lib/mongo/error/operation_failure.rb', line 244 def wtimeout? @wtimeout end |