diff options
author | Patrick Freed <patrick.freed@mongodb.com> | 2023-02-24 23:13:55 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-25 07:07:43 +0000 |
commit | 71f90697444a61f9023c205d8df945d26dd033b7 (patch) | |
tree | e5c16197bb3b887f452729fe577a238a43e4200f | |
parent | 5b01b68c504ca9eab8d594188d9eb85edab35f74 (diff) | |
download | mongo-71f90697444a61f9023c205d8df945d26dd033b7.tar.gz |
SERVER-74006 Introduce abstraction for accessing the cluster-wide maxWireVersion
-rw-r--r-- | src/mongo/transport/SConscript | 10 | ||||
-rw-r--r-- | src/mongo/transport/grpc/SConscript | 15 | ||||
-rw-r--r-- | src/mongo/transport/grpc/wire_version_provider.cpp | 40 | ||||
-rw-r--r-- | src/mongo/transport/grpc/wire_version_provider.h | 59 |
4 files changed, 124 insertions, 0 deletions
diff --git a/src/mongo/transport/SConscript b/src/mongo/transport/SConscript index 6903da79f4d..84680f2813a 100644 --- a/src/mongo/transport/SConscript +++ b/src/mongo/transport/SConscript @@ -4,6 +4,15 @@ Import('env') env = env.Clone() +env.SConscript( + dirs=[ + 'grpc', + ], + exports=[ + 'env', + ], +) + env.Library( target='transport_layer_common', source=[ @@ -59,6 +68,7 @@ tlEnv.Library( 'transport_layer_manager.cpp', ], LIBDEPS=[ + 'grpc/grpc_transport_layer' if env.TargetOSIs('linux') else [], 'transport_layer', ], LIBDEPS_PRIVATE=[ diff --git a/src/mongo/transport/grpc/SConscript b/src/mongo/transport/grpc/SConscript new file mode 100644 index 00000000000..d093c777ed9 --- /dev/null +++ b/src/mongo/transport/grpc/SConscript @@ -0,0 +1,15 @@ +# -*- mode: python -*- + +Import('env') + +env = env.Clone() + +env.Library( + target='grpc_transport_layer', + source=[ + 'wire_version_provider.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/db/wire_version', + ], +) diff --git a/src/mongo/transport/grpc/wire_version_provider.cpp b/src/mongo/transport/grpc/wire_version_provider.cpp new file mode 100644 index 00000000000..c3084c13742 --- /dev/null +++ b/src/mongo/transport/grpc/wire_version_provider.cpp @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2023-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/transport/grpc/wire_version_provider.h" + +#include "mongo/db/wire_version.h" + +namespace mongo::transport::grpc { + +int WireVersionProvider::getClusterMaxWireVersion() const { + return WireSpec::instance().get()->incomingExternalClient.maxWireVersion; +} + +} // namespace mongo::transport::grpc diff --git a/src/mongo/transport/grpc/wire_version_provider.h b/src/mongo/transport/grpc/wire_version_provider.h new file mode 100644 index 00000000000..a391948bbf5 --- /dev/null +++ b/src/mongo/transport/grpc/wire_version_provider.h @@ -0,0 +1,59 @@ +/** + * Copyright (C) 2023-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/wire_version.h" + +namespace mongo::transport::grpc { + +class WireVersionProvider { +public: + WireVersionProvider() = default; + WireVersionProvider(const WireVersionProvider&) = delete; + WireVersionProvider& operator=(const WireVersionProvider&) = delete; + + /** + * Gets this server's understanding of the minimum maxWireVersion value for all servers in the + * cluster. This is used to gossip the wire version gRPC clients should use when constructing + * commands, as per the MongoDB gRPC Protocol. + * + * If this server is a mongos, "all servers in the cluster" refers to all the mongoses in the + * sharded cluster. If this server is a mongod, "all servers in the cluster" refers to that + * mongod alone, since gRPC clients only support direct connections to mongods and do not + * support communicating with entire replica sets. + * + * Currently, this method just returns this server's maxWireVersion, since the current version + * is the only server version that supports gRPC. In the future, the provider will be augmented + * to account for the other servers in the cluster. + */ + int getClusterMaxWireVersion() const; +}; + +} // namespace mongo::transport::grpc |