summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Osta <luis.osta@mongodb.com>2020-07-08 15:35:29 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-07-08 17:23:36 +0000
commit0b1eab6caebf276b9d73ea7126b74efab813fc51 (patch)
tree8a3bec7c6effd4fb942be4dcb6ae77ddf98c16fc
parent90455329e6fbe4dc584205992dc3e71beb86fef1 (diff)
downloadmongo-0b1eab6caebf276b9d73ea7126b74efab813fc51.tar.gz
SERVER-49172 Create MigratingTenantAccessBlockerByPrefix class and expose it through serverStatus
-rw-r--r--src/mongo/db/repl/SConscript2
-rw-r--r--src/mongo/db/repl/migrating_tenant_access_blocker.cpp11
-rw-r--r--src/mongo/db/repl/migrating_tenant_access_blocker.h2
-rw-r--r--src/mongo/db/repl/migrating_tenant_access_blocker_by_prefix.cpp111
-rw-r--r--src/mongo/db/repl/migrating_tenant_access_blocker_by_prefix.h60
-rw-r--r--src/mongo/db/repl/migrating_tenant_access_blocker_server_status_section.cpp57
6 files changed, 243 insertions, 0 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index dae5cbb881a..2f89d244e6b 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -1167,6 +1167,8 @@ env.Library(
target='migrating_tenant_access_blocker',
source=[
'migrating_tenant_access_blocker.cpp',
+ 'migrating_tenant_access_blocker_by_prefix.cpp',
+ 'migrating_tenant_access_blocker_server_status_section.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/db/repl/migrating_tenant_access_blocker.cpp b/src/mongo/db/repl/migrating_tenant_access_blocker.cpp
index c451116f8c5..ca811e326e3 100644
--- a/src/mongo/db/repl/migrating_tenant_access_blocker.cpp
+++ b/src/mongo/db/repl/migrating_tenant_access_blocker.cpp
@@ -236,4 +236,15 @@ void MigratingTenantAccessBlocker::_waitForOpTimeToMajorityCommit(
}));
}
+void MigratingTenantAccessBlocker::appendInfoForServerStatus(BSONObjBuilder* builder) const {
+ builder->append("access", _access);
+ if (_blockTimestamp) {
+ builder->append("blockTimestamp", _blockTimestamp.get());
+ }
+
+ if (_commitOrAbortOpTime) {
+ builder->append("commitOrAbortOpTime", _commitOrAbortOpTime->toBSON());
+ }
+}
+
} // namespace mongo
diff --git a/src/mongo/db/repl/migrating_tenant_access_blocker.h b/src/mongo/db/repl/migrating_tenant_access_blocker.h
index 444f7d83593..69ba6975836 100644
--- a/src/mongo/db/repl/migrating_tenant_access_blocker.h
+++ b/src/mongo/db/repl/migrating_tenant_access_blocker.h
@@ -135,6 +135,8 @@ public:
void abort(repl::OpTime opTime);
void rollBackCommitOrAbort();
+ void appendInfoForServerStatus(BSONObjBuilder* builder) const;
+
private:
void _waitForOpTimeToMajorityCommit(repl::OpTime opTime, std::function<void()> callbackFn);
diff --git a/src/mongo/db/repl/migrating_tenant_access_blocker_by_prefix.cpp b/src/mongo/db/repl/migrating_tenant_access_blocker_by_prefix.cpp
new file mode 100644
index 00000000000..6c59e14975a
--- /dev/null
+++ b/src/mongo/db/repl/migrating_tenant_access_blocker_by_prefix.cpp
@@ -0,0 +1,111 @@
+/**
+ * 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.
+ */
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kReplication
+
+#include "mongo/db/repl/migrating_tenant_access_blocker_by_prefix.h"
+#include "mongo/db/repl/migrating_tenant_access_blocker.h"
+
+namespace mongo {
+
+const ServiceContext::Decoration<MigratingTenantAccessBlockerByPrefix>
+ MigratingTenantAccessBlockerByPrefix::get =
+ ServiceContext::declareDecoration<MigratingTenantAccessBlockerByPrefix>();
+
+/**
+ * Invariants that no entry for dbPrefix exists and then adds the entry for (dbPrefix, mtab)
+ */
+void MigratingTenantAccessBlockerByPrefix::add(StringData dbPrefix,
+ std::shared_ptr<MigratingTenantAccessBlocker> mtab) {
+ stdx::lock_guard<Latch> lg(_mutex);
+
+ auto blockerIterator = _migratingTenantAccessBlockers.find(dbPrefix);
+ invariant(blockerIterator != _migratingTenantAccessBlockers.end());
+
+ _migratingTenantAccessBlockers.emplace(dbPrefix, mtab);
+}
+
+
+/**
+ * Invariants that an entry for dbPrefix exists, and then removes the entry for (dbPrefix, mtab)
+ */
+void MigratingTenantAccessBlockerByPrefix::remove(StringData dbPrefix) {
+ stdx::lock_guard<Latch> lg(_mutex);
+
+ auto it = _migratingTenantAccessBlockers.find(dbPrefix);
+ invariant(it != _migratingTenantAccessBlockers.end());
+
+ _migratingTenantAccessBlockers.erase(it);
+}
+
+
+/**
+ * Iterates through each of the MigratingTenantAccessBlockers and
+ * returns the first MigratingTenantBlocker it finds whose dbPrefix is a prefix for dbName.
+ */
+std::shared_ptr<MigratingTenantAccessBlocker>
+MigratingTenantAccessBlockerByPrefix::getMigratingTenantBlocker(StringData dbName) {
+ stdx::lock_guard<Latch> lg(_mutex);
+
+ auto doesDBNameStartWithPrefix =
+ [dbName](
+ const std::pair<std::string, std::shared_ptr<MigratingTenantAccessBlocker>>& blocker) {
+ StringData dbPrefix = blocker.first;
+ return dbName.startsWith(dbPrefix);
+ };
+
+ auto blockerMatchedIterator = std::find_if(_migratingTenantAccessBlockers.begin(),
+ _migratingTenantAccessBlockers.end(),
+ doesDBNameStartWithPrefix);
+
+ if (blockerMatchedIterator == _migratingTenantAccessBlockers.end()) {
+ return nullptr;
+ } else {
+ return blockerMatchedIterator->second;
+ }
+}
+
+/**
+ * Iterates through each of the MigratingTenantAccessBlockers stored by the mapping
+ * and appends the server status of each blocker to the BSONObjBuilder.
+ */
+void MigratingTenantAccessBlockerByPrefix::appendInfoForServerStatus(BSONObjBuilder* builder) {
+
+ auto appendBlockerStatus =
+ [builder](
+ const std::pair<std::string, std::shared_ptr<MigratingTenantAccessBlocker>>& blocker) {
+ blocker.second->appendInfoForServerStatus(builder);
+ };
+
+ std::for_each(_migratingTenantAccessBlockers.begin(),
+ _migratingTenantAccessBlockers.end(),
+ appendBlockerStatus);
+}
+
+} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/repl/migrating_tenant_access_blocker_by_prefix.h b/src/mongo/db/repl/migrating_tenant_access_blocker_by_prefix.h
new file mode 100644
index 00000000000..5a9f687e962
--- /dev/null
+++ b/src/mongo/db/repl/migrating_tenant_access_blocker_by_prefix.h
@@ -0,0 +1,60 @@
+/**
+ * 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/string_data.h"
+#include "mongo/db/repl/migrating_tenant_access_blocker.h"
+#include "mongo/util/string_map.h"
+
+namespace mongo {
+
+class MigratingTenantAccessBlockerByPrefix {
+ MigratingTenantAccessBlockerByPrefix(const MigratingTenantAccessBlockerByPrefix&) = delete;
+ MigratingTenantAccessBlockerByPrefix& operator=(const MigratingTenantAccessBlockerByPrefix&) =
+ delete;
+
+public:
+ MigratingTenantAccessBlockerByPrefix() = default;
+ static const ServiceContext::Decoration<MigratingTenantAccessBlockerByPrefix> get;
+
+ void appendInfoForServerStatus(BSONObjBuilder* builder);
+ void add(StringData dbPrefix, std::shared_ptr<MigratingTenantAccessBlocker> mtab);
+ void remove(StringData dbPrefix);
+ std::shared_ptr<MigratingTenantAccessBlocker> getMigratingTenantBlocker(StringData dbName);
+
+private:
+ using MigratingTenantAccessBlockersMap =
+ StringMap<std::shared_ptr<MigratingTenantAccessBlocker>>;
+
+ Mutex _mutex = MONGO_MAKE_LATCH("MigratingTenantAccessBlockerByPrefix::_mutex");
+ MigratingTenantAccessBlockersMap _migratingTenantAccessBlockers;
+};
+
+} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/repl/migrating_tenant_access_blocker_server_status_section.cpp b/src/mongo/db/repl/migrating_tenant_access_blocker_server_status_section.cpp
new file mode 100644
index 00000000000..7c4ee857ba3
--- /dev/null
+++ b/src/mongo/db/repl/migrating_tenant_access_blocker_server_status_section.cpp
@@ -0,0 +1,57 @@
+/**
+ * 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/bson/bsonobjbuilder.h"
+#include "mongo/db/commands/server_status.h"
+#include "mongo/db/repl/migrating_tenant_access_blocker_by_prefix.h"
+
+namespace mongo {
+
+namespace {
+class MigratingTenantAccessBlockerServerStatus final : public ServerStatusSection {
+
+public:
+ MigratingTenantAccessBlockerServerStatus()
+ : ServerStatusSection("migratingTenantAccessBlocker") {}
+
+ bool includeByDefault() const override {
+ return true;
+ }
+ BSONObj generateSection(OperationContext* opCtx,
+ const BSONElement& configElement) const override {
+ BSONObjBuilder result;
+ MigratingTenantAccessBlockerByPrefix::get(opCtx->getServiceContext())
+ .appendInfoForServerStatus(&result);
+ return result.obj();
+ }
+} migratingTenantAccessBlockerServerStatus;
+} // namespace
+} // namespace mongo \ No newline at end of file