summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands/batch_downconvert.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/commands/batch_downconvert.cpp')
-rw-r--r--src/mongo/s/commands/batch_downconvert.cpp165
1 files changed, 0 insertions, 165 deletions
diff --git a/src/mongo/s/commands/batch_downconvert.cpp b/src/mongo/s/commands/batch_downconvert.cpp
deleted file mode 100644
index 4f4328fe4c6..00000000000
--- a/src/mongo/s/commands/batch_downconvert.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/s/commands/batch_downconvert.h"
-
-#include "mongo/bson/bsonmisc.h"
-#include "mongo/db/storage/duplicate_key_error_info.h"
-
-namespace mongo {
-
-Status extractGLEErrors(const BSONObj& gleResponse, GLEErrors* errors) {
- // DRAGONS
- // Parsing GLE responses is incredibly finicky.
- // The order of testing here is extremely important.
-
- ///////////////////////////////////////////////////////////////////////
- // IMPORTANT!
- // Also update extractGLEErrors in batch_api.js for any changes made here.
-
- const bool isOK = gleResponse["ok"].trueValue();
- const std::string err = gleResponse["err"].str();
- const std::string errMsg = gleResponse["errmsg"].str();
- const std::string wNote = gleResponse["wnote"].str();
- const std::string jNote = gleResponse["jnote"].str();
- const int code = gleResponse["code"].numberInt();
- const bool timeout = gleResponse["wtimeout"].trueValue();
-
- if (err == "norepl" || err == "noreplset") {
- // Know this is legacy gle and the repl not enforced - write concern error in 2.4
- errors->wcError.reset(new WriteConcernErrorDetail);
- std::string msg;
- if (!errMsg.empty()) {
- msg = errMsg;
- } else if (!wNote.empty()) {
- msg = wNote;
- } else {
- msg = err;
- }
- errors->wcError->setStatus({ErrorCodes::WriteConcernFailed, msg});
- } else if (timeout) {
- // Know there was no write error
- errors->wcError.reset(new WriteConcernErrorDetail);
- std::string msg;
- if (!errMsg.empty()) {
- msg = errMsg;
- } else {
- msg = err;
- }
- errors->wcError->setStatus({ErrorCodes::WriteConcernFailed, msg});
- errors->wcError->setErrInfo(BSON("wtimeout" << true));
- } else if (code == 10990 /* no longer primary */
- || code == 16805 /* replicatedToNum no longer primary */
- || code == 14830 /* gle wmode changed / invalid */
- // 2.6 Error codes
- || code == ErrorCodes::NotWritablePrimary ||
- code == ErrorCodes::UnknownReplWriteConcern ||
- code == ErrorCodes::WriteConcernFailed || code == ErrorCodes::PrimarySteppedDown) {
- // Write concern errors that get returned as regular errors (result may not be ok: 1.0)
- errors->wcError.reset(new WriteConcernErrorDetail());
- errors->wcError->setStatus({ErrorCodes::Error(code), errMsg});
- } else if (!isOK) {
- //
- // !!! SOME GLE ERROR OCCURRED, UNKNOWN WRITE RESULT !!!
- //
-
- return Status(ErrorCodes::Error(code ? code : ErrorCodes::UnknownError), errMsg);
- } else if (!err.empty()) {
- // Write error
- errors->writeError.reset(new WriteErrorDetail);
- int writeErrorCode = code == 0 ? ErrorCodes::UnknownError : code;
- errors->writeError->setStatus({ErrorCodes::Error(writeErrorCode), err});
- } else if (!jNote.empty()) {
- // Know this is legacy gle and the journaling not enforced - write concern error in 2.4
- errors->wcError.reset(new WriteConcernErrorDetail);
- errors->wcError->setStatus({ErrorCodes::WriteConcernFailed, jNote});
- }
-
- return Status::OK();
-}
-
-/**
- * Suppress the "err" and "code" field if they are coming from a previous write error and
- * are not related to write concern. Also removes any write stats information (e.g. "n")
- *
- * Also, In some cases, 2.4 GLE w/ wOpTime can give us duplicate "err" and "code" fields b/c of
- * reporting a previous error. The later field is what we want - dedup and use later field.
- *
- * Returns the stripped GLE response.
- */
-BSONObj stripNonWCInfo(const BSONObj& gleResponse) {
- BSONObjIterator it(gleResponse);
- BSONObjBuilder builder;
-
- BSONElement codeField; // eoo
- BSONElement errField; // eoo
-
- while (it.more()) {
- BSONElement el = it.next();
- StringData fieldName(el.fieldName());
- if (fieldName.compare("err") == 0) {
- errField = el;
- } else if (fieldName.compare("code") == 0) {
- codeField = el;
- } else if (fieldName.compare("n") == 0 || fieldName.compare("nModified") == 0 ||
- fieldName.compare("upserted") == 0 ||
- fieldName.compare("updatedExisting") == 0) {
- // Suppress field
- } else {
- builder.append(el);
- }
- }
-
- if (!codeField.eoo()) {
- if (!gleResponse["ok"].trueValue()) {
- // The last code will be from the write concern
- builder.append(codeField);
- } else {
- // The code is from a non-wc error on this connection - suppress it
- }
- }
-
- if (!errField.eoo()) {
- std::string err = errField.str();
- if (err == "norepl" || err == "noreplset" || err == "timeout") {
- // Append err if it's from a write concern issue
- builder.append(errField);
- } else {
- // Suppress non-write concern err as null, but we need to report null err if ok
- if (gleResponse["ok"].trueValue())
- builder.appendNull(errField.fieldName());
- }
- }
-
- return builder.obj();
-}
-
-} // namespace mongo