summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Marks <gabriel.marks@mongodb.com>2022-02-11 17:03:04 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-11 17:52:08 +0000
commit7ebe8364c1234261a500870df642d245fc8b6f5f (patch)
treeb6e5e81e235db69adddc918c8d251c46f277ecc4
parent8ac145331880626e64bc4339763208140ade6609 (diff)
downloadmongo-7ebe8364c1234261a500870df642d245fc8b6f5f.tar.gz
SERVER-63176 Create RPC serialization hook for WriteBlockBypass
-rw-r--r--src/mongo/db/SConscript10
-rw-r--r--src/mongo/db/write_block_bypass_propagation_egress_hook.cpp57
-rw-r--r--src/mongo/db/write_block_bypass_propagation_egress_hook.h54
-rw-r--r--src/mongo/rpc/metadata.cpp12
4 files changed, 133 insertions, 0 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 0a7df2c5649..219b665762c 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -1972,6 +1972,16 @@ env.Library(
)
env.Library(
+ target='write_block_bypass_propagation_egress_hook',
+ source=[
+ 'write_block_bypass_propagation_egress_hook.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/rpc/metadata',
+ ],
+)
+
+env.Library(
target='vector_clock_test_fixture',
source=[
'vector_clock_test_fixture.cpp',
diff --git a/src/mongo/db/write_block_bypass_propagation_egress_hook.cpp b/src/mongo/db/write_block_bypass_propagation_egress_hook.cpp
new file mode 100644
index 00000000000..8293e6189a7
--- /dev/null
+++ b/src/mongo/db/write_block_bypass_propagation_egress_hook.cpp
@@ -0,0 +1,57 @@
+/**
+ * Copyright (C) 2022-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/write_block_bypass_propagation_egress_hook.h"
+
+namespace mongo {
+namespace rpc {
+
+Status WriteBlockBypassPropagationEgressHook::writeRequestMetadata(OperationContext* opCtx,
+ BSONObjBuilder* metadataBob) {
+ if (!opCtx) {
+ return Status::OK();
+ }
+
+ bool mayBypassWriteBlocking = false;
+ // TODO SERVER-63177: Change above to something like:
+ // mayBypassWriteBlocking = WriteBlockBypass::get(opCtx)->getActive();
+ metadataBob->append(kMayBypassWriteBlockingFieldName, mayBypassWriteBlocking);
+ return Status::OK();
+}
+
+Status WriteBlockBypassPropagationEgressHook::readReplyMetadata(OperationContext* opCtx,
+ StringData replySource,
+ const BSONObj& metadataObj) {
+ return Status::OK();
+}
+
+} // namespace rpc
+} // namespace mongo
diff --git a/src/mongo/db/write_block_bypass_propagation_egress_hook.h b/src/mongo/db/write_block_bypass_propagation_egress_hook.h
new file mode 100644
index 00000000000..51c00a5bc7d
--- /dev/null
+++ b/src/mongo/db/write_block_bypass_propagation_egress_hook.h
@@ -0,0 +1,54 @@
+/**
+ * Copyright (C) 2022-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/db/service_context.h"
+#include "mongo/rpc/metadata/metadata_hook.h"
+
+namespace mongo {
+namespace rpc {
+
+constexpr static auto kMayBypassWriteBlockingFieldName = "mayBypassWriteBlocking"_sd;
+
+/**
+ * Hook for attaching whether user can bypass write blocking.
+ */
+class WriteBlockBypassPropagationEgressHook : public rpc::EgressMetadataHook {
+public:
+ virtual ~WriteBlockBypassPropagationEgressHook() = default;
+
+ Status readReplyMetadata(OperationContext* opCtx,
+ StringData replySource,
+ const BSONObj& metadataObj) final;
+ Status writeRequestMetadata(OperationContext* opCtx, BSONObjBuilder* metadataBob) final;
+};
+
+} // namespace rpc
+} // namespace mongo
diff --git a/src/mongo/rpc/metadata.cpp b/src/mongo/rpc/metadata.cpp
index 666e0584583..ab4b3809bd3 100644
--- a/src/mongo/rpc/metadata.cpp
+++ b/src/mongo/rpc/metadata.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/logical_time_validator.h"
#include "mongo/db/multitenancy.h"
#include "mongo/db/vector_clock.h"
+#include "mongo/db/write_block_bypass_propagation_egress_hook.h"
#include "mongo/rpc/metadata/client_metadata.h"
#include "mongo/rpc/metadata/impersonated_user_metadata.h"
#include "mongo/rpc/metadata/tracking_metadata.h"
@@ -59,6 +60,7 @@ void readRequestMetadata(OperationContext* opCtx, const OpMsg& opMsg, bool cmdRe
BSONElement helloClientElem;
BSONElement impersonationElem;
BSONElement clientOperationKeyElem;
+ BSONElement mayBypassWriteBlockingElem;
for (const auto& metadataElem : opMsg.body) {
auto fieldName = metadataElem.fieldNameStringData();
@@ -72,6 +74,8 @@ void readRequestMetadata(OperationContext* opCtx, const OpMsg& opMsg, bool cmdRe
impersonationElem = metadataElem;
} else if (fieldName == "clientOperationKey"_sd) {
clientOperationKeyElem = metadataElem;
+ } else if (fieldName == kMayBypassWriteBlockingFieldName) {
+ mayBypassWriteBlockingElem = metadataElem;
}
}
@@ -107,6 +111,14 @@ void readRequestMetadata(OperationContext* opCtx, const OpMsg& opMsg, bool cmdRe
uassertStatusOK(TrackingMetadata::readFromMetadata(trackingElem));
VectorClock::get(opCtx)->gossipIn(opCtx, opMsg.body, !cmdRequiresAuth);
+
+ if (mayBypassWriteBlockingElem) {
+ uassert(6317600,
+ "mayBypassWriteBlockingElem was not false",
+ !mayBypassWriteBlockingElem.Bool());
+ // TODO SERVER-63177: Change above to something like:
+ // WriteBlockBypass::get(opCtx)->setActive(mayBypassWriteBlockingElem.Bool());
+ }
}
namespace {