summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorCheahuychou Mao <mao.cheahuychou@gmail.com>2020-10-06 15:43:35 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-10-07 02:20:30 +0000
commita427c0b06f5cb6a70762054118ccee8a5d90feef (patch)
treef0080c171bfd4fb18b7392696f9d59958bd6f59b /src/mongo
parenta6da4c6162dfb47adfc17c76d27b31d8ec7ae087 (diff)
downloadmongo-a427c0b06f5cb6a70762054118ccee8a5d90feef.tar.gz
SERVER-51392 Include recipientConnectionString in TenantMigrationCommitted error
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/base/error_codes.yml2
-rw-r--r--src/mongo/db/SConscript2
-rw-r--r--src/mongo/db/catalog/multi_index_block.cpp4
-rw-r--r--src/mongo/db/repl/SConscript5
-rw-r--r--src/mongo/db/repl/tenant_migration_access_blocker.cpp15
-rw-r--r--src/mongo/db/repl/tenant_migration_access_blocker.h7
-rw-r--r--src/mongo/db/repl/tenant_migration_committed_info.cpp63
-rw-r--r--src/mongo/db/repl/tenant_migration_committed_info.h63
-rw-r--r--src/mongo/db/repl/tenant_migration_conflict_info.cpp2
-rw-r--r--src/mongo/db/repl/tenant_migration_donor_service.cpp1
-rw-r--r--src/mongo/db/repl/tenant_migration_donor_util.cpp12
11 files changed, 156 insertions, 20 deletions
diff --git a/src/mongo/base/error_codes.yml b/src/mongo/base/error_codes.yml
index f93088fc35d..5b77c616dbe 100644
--- a/src/mongo/base/error_codes.yml
+++ b/src/mongo/base/error_codes.yml
@@ -382,7 +382,7 @@ error_codes:
- {code: 319,name: MovePrimaryInProgress}
- {code: 320, name: TenantMigrationConflict,extra: TenantMigrationConflictInfo}
- - {code: 321, name: TenantMigrationCommitted}
+ - {code: 321, name: TenantMigrationCommitted,extra: TenantMigrationCommittedInfo}
- {code: 322, name: APIVersionError, categories: [VersionedAPIError]}
- {code: 323, name: APIStrictError, categories: [VersionedAPIError]}
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 7e02e458cf8..387424a0b45 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -65,7 +65,7 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/index_names',
- '$BUILD_DIR/mongo/db/repl/tenant_migration_conflict_info',
+ '$BUILD_DIR/mongo/db/repl/tenant_migration_errors',
'$BUILD_DIR/mongo/db/write_concern_options',
'shutdown_in_progress_quiesce_info',
]
diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp
index e4628d75165..187d25f2cf0 100644
--- a/src/mongo/db/catalog/multi_index_block.cpp
+++ b/src/mongo/db/catalog/multi_index_block.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/query/collection_query_info.h"
#include "mongo/db/repl/repl_set_config.h"
#include "mongo/db/repl/replication_coordinator.h"
+#include "mongo/db/repl/tenant_migration_committed_info.h"
#include "mongo/db/repl/tenant_migration_conflict_info.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/storage/write_unit_of_work.h"
@@ -343,6 +344,9 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(
} catch (const TenantMigrationConflictException&) {
// Avoid converting TenantMigrationConflictException to Status.
throw;
+ } catch (const TenantMigrationCommittedException&) {
+ // Avoid converting TenantMigrationCommittedException to Status.
+ throw;
} catch (...) {
auto status = exceptionToStatus();
return {status.code(),
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index 83f414b05cf..fae4854aa9f 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -1244,8 +1244,9 @@ env.Library(
)
env.Library(
- target='tenant_migration_conflict_info',
+ target='tenant_migration_errors',
source= [
+ 'tenant_migration_committed_info.cpp',
'tenant_migration_conflict_info.cpp',
],
LIBDEPS=[
@@ -1329,7 +1330,7 @@ env.Library(
'local_oplog_info',
'optime',
'repl_coordinator_interface',
- 'tenant_migration_conflict_info',
+ 'tenant_migration_errors',
'tenant_migration_state_machine_idl'
],
)
diff --git a/src/mongo/db/repl/tenant_migration_access_blocker.cpp b/src/mongo/db/repl/tenant_migration_access_blocker.cpp
index 19a991c6c16..f2b21fa32c7 100644
--- a/src/mongo/db/repl/tenant_migration_access_blocker.cpp
+++ b/src/mongo/db/repl/tenant_migration_access_blocker.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/client.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/repl/tenant_migration_access_blocker.h"
+#include "mongo/db/repl/tenant_migration_committed_info.h"
#include "mongo/db/repl/tenant_migration_conflict_info.h"
#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
@@ -61,7 +62,7 @@ void TenantMigrationAccessBlocker::checkIfCanWriteOrThrow() {
uasserted(TenantMigrationConflictInfo(_dbPrefix),
"Write must block until this tenant migration commits or aborts");
case Access::kReject:
- uasserted(ErrorCodes::TenantMigrationCommitted,
+ uasserted(TenantMigrationCommittedInfo(_dbPrefix, _recipientConnString),
"Write must be re-routed to the new owner of this tenant");
default:
MONGO_UNREACHABLE;
@@ -83,8 +84,8 @@ void TenantMigrationAccessBlocker::checkIfCanWriteOrBlock(OperationContext* opCt
auto status = onCompletion().getNoThrow();
if (status.isOK()) {
invariant(_access == Access::kReject);
- uasserted(ErrorCodes::TenantMigrationCommitted,
- "Write must be re-routed to the new owner of this database");
+ uasserted(TenantMigrationCommittedInfo(_dbPrefix, _recipientConnString),
+ "Write must be re-routed to the new owner of this tenant");
}
uassertStatusOK(status);
}
@@ -105,16 +106,16 @@ void TenantMigrationAccessBlocker::checkIfCanDoClusterTimeReadOrBlock(
opCtx->waitForConditionOrInterrupt(
_transitionOutOfBlockingCV, ul, [&]() { return canRead() || _access == Access::kReject; });
- uassert(ErrorCodes::TenantMigrationCommitted,
- "Read must be re-routed to the new owner of this database",
+ uassert(TenantMigrationCommittedInfo(_dbPrefix, _recipientConnString),
+ "Read must be re-routed to the new owner of this tenant",
canRead());
}
void TenantMigrationAccessBlocker::checkIfLinearizableReadWasAllowedOrThrow(
OperationContext* opCtx) {
stdx::lock_guard<Latch> lg(_mutex);
- uassert(ErrorCodes::TenantMigrationCommitted,
- "Read must be re-routed to the new owner of this database",
+ uassert(TenantMigrationCommittedInfo(_dbPrefix, _recipientConnString),
+ "Read must be re-routed to the new owner of this tenant",
_access != Access::kReject);
}
diff --git a/src/mongo/db/repl/tenant_migration_access_blocker.h b/src/mongo/db/repl/tenant_migration_access_blocker.h
index 44f045f1dce..0b75cca09f2 100644
--- a/src/mongo/db/repl/tenant_migration_access_blocker.h
+++ b/src/mongo/db/repl/tenant_migration_access_blocker.h
@@ -116,10 +116,12 @@ class TenantMigrationAccessBlocker
public:
TenantMigrationAccessBlocker(ServiceContext* serviceContext,
std::shared_ptr<executor::TaskExecutor> executor,
- std::string dbPrefix)
+ std::string dbPrefix,
+ std::string recipientConnString)
: _serviceContext(serviceContext),
_executor(std::move(executor)),
- _dbPrefix(std::move(dbPrefix)) {}
+ _dbPrefix(std::move(dbPrefix)),
+ _recipientConnString(std::move(recipientConnString)) {}
//
// Called by all writes and reads against the database.
@@ -161,6 +163,7 @@ private:
ServiceContext* _serviceContext;
std::shared_ptr<executor::TaskExecutor> _executor;
std::string _dbPrefix;
+ std::string _recipientConnString;
// Protects the state below.
mutable Mutex _mutex = MONGO_MAKE_LATCH("TenantMigrationAccessBlocker::_mutex");
diff --git a/src/mongo/db/repl/tenant_migration_committed_info.cpp b/src/mongo/db/repl/tenant_migration_committed_info.cpp
new file mode 100644
index 00000000000..6c1c0abf1b1
--- /dev/null
+++ b/src/mongo/db/repl/tenant_migration_committed_info.cpp
@@ -0,0 +1,63 @@
+/**
+ * Copyright (C) 2020-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/db/repl/tenant_migration_committed_info.h"
+
+#include "mongo/base/init.h"
+
+namespace mongo {
+
+namespace {
+
+MONGO_INIT_REGISTER_ERROR_EXTRA_INFO(TenantMigrationCommittedInfo);
+
+constexpr StringData kDatabasePrefixFieldName = "databasePrefix"_sd;
+constexpr StringData kRecipientConnetionStringFieldName = "recipientConnectionString"_sd;
+
+} // namespace
+
+BSONObj TenantMigrationCommittedInfo::toBSON() const {
+ BSONObjBuilder bob;
+ serialize(&bob);
+ return bob.obj();
+}
+
+void TenantMigrationCommittedInfo::serialize(BSONObjBuilder* bob) const {
+ bob->append(kDatabasePrefixFieldName, _dbPrefix);
+ bob->append(kRecipientConnetionStringFieldName, _recipientConnString);
+}
+
+std::shared_ptr<const ErrorExtraInfo> TenantMigrationCommittedInfo::parse(const BSONObj& obj) {
+ return std::make_shared<TenantMigrationCommittedInfo>(
+ obj[kDatabasePrefixFieldName].String(), obj[kRecipientConnetionStringFieldName].String());
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/repl/tenant_migration_committed_info.h b/src/mongo/db/repl/tenant_migration_committed_info.h
new file mode 100644
index 00000000000..3acbfc5a514
--- /dev/null
+++ b/src/mongo/db/repl/tenant_migration_committed_info.h
@@ -0,0 +1,63 @@
+/**
+ * Copyright (C) 2020-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.
+ */
+
+#pragma once
+
+#include "mongo/base/error_extra_info.h"
+#include "mongo/bson/bsonobj.h"
+#include "mongo/bson/bsonobjbuilder.h"
+
+namespace mongo {
+
+class TenantMigrationCommittedInfo final : public ErrorExtraInfo {
+public:
+ static constexpr auto code = ErrorCodes::TenantMigrationCommitted;
+
+ TenantMigrationCommittedInfo(const std::string dbPrefix, const std::string recipientConnString)
+ : _dbPrefix(std::move(dbPrefix)), _recipientConnString(std::move(recipientConnString)){};
+
+ const auto& getDatabasePrefix() const {
+ return _dbPrefix;
+ }
+
+ const auto& getRecipientConnString() const {
+ return _recipientConnString;
+ }
+
+ BSONObj toBSON() const;
+ void serialize(BSONObjBuilder* bob) const override;
+ static std::shared_ptr<const ErrorExtraInfo> parse(const BSONObj&);
+
+private:
+ std::string _dbPrefix;
+ std::string _recipientConnString;
+};
+using TenantMigrationCommittedException = ExceptionFor<ErrorCodes::TenantMigrationCommitted>;
+
+} // namespace mongo
diff --git a/src/mongo/db/repl/tenant_migration_conflict_info.cpp b/src/mongo/db/repl/tenant_migration_conflict_info.cpp
index 5f6f3faab35..37f15314661 100644
--- a/src/mongo/db/repl/tenant_migration_conflict_info.cpp
+++ b/src/mongo/db/repl/tenant_migration_conflict_info.cpp
@@ -39,7 +39,7 @@ namespace {
MONGO_INIT_REGISTER_ERROR_EXTRA_INFO(TenantMigrationConflictInfo);
-constexpr StringData kDatabasePrefixFieldName = "dbPrefix"_sd;
+constexpr StringData kDatabasePrefixFieldName = "databasePrefix"_sd;
} // namespace
diff --git a/src/mongo/db/repl/tenant_migration_donor_service.cpp b/src/mongo/db/repl/tenant_migration_donor_service.cpp
index 883054a131d..c42f6c22f93 100644
--- a/src/mongo/db/repl/tenant_migration_donor_service.cpp
+++ b/src/mongo/db/repl/tenant_migration_donor_service.cpp
@@ -40,7 +40,6 @@
#include "mongo/db/persistent_task_store.h"
#include "mongo/db/repl/repl_server_parameters_gen.h"
#include "mongo/db/repl/tenant_migration_access_blocker.h"
-#include "mongo/db/repl/tenant_migration_conflict_info.h"
#include "mongo/db/repl/tenant_migration_donor_util.h"
#include "mongo/db/repl/tenant_migration_state_machine_gen.h"
#include "mongo/db/repl/wait_for_majority_service.h"
diff --git a/src/mongo/db/repl/tenant_migration_donor_util.cpp b/src/mongo/db/repl/tenant_migration_donor_util.cpp
index d252b85dbb2..318cc1075b1 100644
--- a/src/mongo/db/repl/tenant_migration_donor_util.cpp
+++ b/src/mongo/db/repl/tenant_migration_donor_util.cpp
@@ -71,7 +71,8 @@ void onTransitionToDataSync(OperationContext* opCtx,
auto mtab = std::make_shared<TenantMigrationAccessBlocker>(
opCtx->getServiceContext(),
getTenantMigrationDonorExecutor(),
- donorStateDoc.getDatabasePrefix().toString());
+ donorStateDoc.getDatabasePrefix().toString(),
+ donorStateDoc.getRecipientConnectionString().toString());
TenantMigrationAccessBlockerByPrefix::get(opCtx->getServiceContext())
.add(donorStateDoc.getDatabasePrefix(), mtab);
}
@@ -246,10 +247,11 @@ void recoverTenantMigrationAccessBlockers(OperationContext* opCtx) {
Query query;
store.forEach(opCtx, query, [&](const TenantMigrationDonorDocument& doc) {
- auto mtab =
- std::make_shared<TenantMigrationAccessBlocker>(opCtx->getServiceContext(),
- getTenantMigrationDonorExecutor(),
- doc.getDatabasePrefix().toString());
+ auto mtab = std::make_shared<TenantMigrationAccessBlocker>(
+ opCtx->getServiceContext(),
+ getTenantMigrationDonorExecutor(),
+ doc.getDatabasePrefix().toString(),
+ doc.getRecipientConnectionString().toString());
TenantMigrationAccessBlockerByPrefix::get(opCtx->getServiceContext())
.add(doc.getDatabasePrefix(), mtab);