diff options
author | Justin Seyster <justin.seyster@mongodb.com> | 2019-04-23 15:44:56 -0400 |
---|---|---|
committer | Justin Seyster <justin.seyster@mongodb.com> | 2019-04-25 17:56:55 -0400 |
commit | 0e9564888a31af6b49afb7a6106301bc16ae6956 (patch) | |
tree | f84473ba48a1ba050b05a7747443a0fce4182150 /src | |
parent | 4b7ecadd7d1661f7d347d9bf990709b26cb539c4 (diff) | |
download | mongo-0e9564888a31af6b49afb7a6106301bc16ae6956.tar.gz |
SERVER-40446 Add "NonResumableChangeStreamError" error label
Give the "NonRetryableChangeStreamError" error class a more
appropriate name and propagate it to an "errorLabel" in the command
response.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/base/error_codes.err | 2 | ||||
-rw-r--r-- | src/mongo/db/handle_request_response.cpp | 29 |
2 files changed, 17 insertions, 14 deletions
diff --git a/src/mongo/base/error_codes.err b/src/mongo/base/error_codes.err index fe682f8eb62..837d4090b37 100644 --- a/src/mongo/base/error_codes.err +++ b/src/mongo/base/error_codes.err @@ -357,4 +357,4 @@ error_class("SnapshotError", ["SnapshotTooOld", "SnapshotUnavailable", "StaleChu error_class("VoteAbortError", ["NoSuchTransaction", "TransactionTooOld"]) -error_class("NonRetryableChangeStreamError", ["ChangeStreamFatalError", "ChangeStreamHistoryLost"]) +error_class("NonResumableChangeStreamError", ["ChangeStreamFatalError", "ChangeStreamHistoryLost"]) diff --git a/src/mongo/db/handle_request_response.cpp b/src/mongo/db/handle_request_response.cpp index 062075b82db..6628c60e8bc 100644 --- a/src/mongo/db/handle_request_response.cpp +++ b/src/mongo/db/handle_request_response.cpp @@ -36,23 +36,26 @@ BSONObj getErrorLabels(const OperationSessionInfoFromClient& sessionOptions, const std::string& commandName, ErrorCodes::Error code, bool hasWriteConcernError) { + BSONArrayBuilder labelArray; - // By specifying "autocommit", the user indicates they want to run a transaction. - // It is always false when set. - if (!sessionOptions.getAutocommit()) { - return {}; + // Note that we only apply the TransientTxnError label if the "autocommit" field is present in + // the session options. When present, "autocommit" will always be false, so we don't check its + // value. + if (sessionOptions.getAutocommit() && + isTransientTransactionError(code, + hasWriteConcernError, + commandName == "commitTransaction" || + commandName == "coordinateCommitTransaction")) { + // An error code for which isTransientTransactionError() is true indicates a transaction + // failure with no persistent side effects. + labelArray << txn::TransientTxnErrorFieldName; } - // The errors that indicate the transaction fails without any persistent side-effect. - bool isTransient = isTransientTransactionError( - code, - hasWriteConcernError, - commandName == "commitTransaction" || commandName == "coordinateCommitTransaction"); - - if (isTransient) { - return BSON("errorLabels" << BSON_ARRAY(txn::TransientTxnErrorFieldName)); + if (ErrorCodes::isNonResumableChangeStreamError(code)) { + labelArray << "NonResumableChangeStreamError"; } - return {}; + + return (labelArray.arrSize() > 0) ? BSON("errorLabels" << labelArray.arr()) : BSONObj(); } } // namespace mongo |