1 2 /** 3 * Copyright (C) 2018-present MongoDB, Inc. 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the Server Side Public License, version 1, 7 * as published by MongoDB, Inc. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * Server Side Public License for more details. 13 * 14 * You should have received a copy of the Server Side Public License 15 * along with this program. If not, see 16 * <http://www.mongodb.com/licensing/server-side-public-license>. 17 * 18 * As a special exception, the copyright holders give permission to link the 19 * code of portions of this program with the OpenSSL library under certain 20 * conditions as described in each individual source file and distribute 21 * linked combinations including the program with the OpenSSL library. You 22 * must comply with the Server Side Public License in all respects for 23 * all of the code used other than as permitted herein. If you modify file(s) 24 * with this exception, you may extend this exception to your version of the 25 * file(s), but you are not obligated to do so. If you do not wish to do so, 26 * delete this exception statement from your version. If you delete this 27 * exception statement from all source files in the program, then also delete 28 * it in the license file. 29 */ 30 31 #pragma once 32 33 #include <iosfwd> 34 #include <string> 35 36 #include "mongo/db/jsobj.h" 37 #include "mongo/rpc/metadata.h" 38 #include "mongo/util/net/hostandport.h" 39 #include "mongo/util/time_support.h" 40 41 namespace mongo { 42 namespace executor { 43 44 /** 45 * Type of object describing a command to execute against a remote MongoDB node. 46 */ 47 struct RemoteCommandRequest { 48 // Indicates that there is no timeout for the request to complete 49 static constexpr Milliseconds kNoTimeout{-1}; 50 51 // Indicates that there is no expiration time by when the request needs to complete 52 static constexpr Date_t kNoExpirationDate{Date_t::max()}; 53 54 // Type to represent the internal id of this request 55 typedef uint64_t RequestId; 56 57 RemoteCommandRequest(); 58 59 RemoteCommandRequest(RequestId requestId, 60 const HostAndPort& theTarget, 61 const std::string& theDbName, 62 const BSONObj& theCmdObj, 63 const BSONObj& metadataObj, 64 OperationContext* opCtx, 65 Milliseconds timeoutMillis); 66 67 RemoteCommandRequest(const HostAndPort& theTarget, 68 const std::string& theDbName, 69 const BSONObj& theCmdObj, 70 const BSONObj& metadataObj, 71 OperationContext* opCtx, 72 Milliseconds timeoutMillis = kNoTimeout); 73 74 RemoteCommandRequest(const HostAndPort& theTarget, 75 const std::string& theDbName, 76 const BSONObj& theCmdObj, 77 OperationContext* opCtx, 78 Milliseconds timeoutMillis = kNoTimeout) RemoteCommandRequestRemoteCommandRequest79 : RemoteCommandRequest( 80 theTarget, theDbName, theCmdObj, rpc::makeEmptyMetadata(), opCtx, timeoutMillis) {} 81 82 std::string toString() const; 83 84 bool operator==(const RemoteCommandRequest& rhs) const; 85 bool operator!=(const RemoteCommandRequest& rhs) const; 86 87 // Internal id of this request. Not interpreted and used for tracing purposes only. 88 RequestId id; 89 90 HostAndPort target; 91 std::string dbname; 92 BSONObj metadata{rpc::makeEmptyMetadata()}; 93 BSONObj cmdObj; 94 95 // OperationContext is added to each request to allow OP_Command metadata attachment access to 96 // the Client object. The OperationContext is only accessed on the thread that calls 97 // NetworkInterface::startCommand. It is not safe to access from a thread that does not own the 98 // OperationContext in the general case. OperationContext should be non-null on 99 // NetworkInterfaces that do user work (i.e. reads, and writes) so that audit and client 100 // metadata is propagated. It is allowed to be null if used on NetworkInterfaces without 101 // metadata attachment (i.e., replication). 102 OperationContext* opCtx{nullptr}; 103 104 Milliseconds timeout = kNoTimeout; 105 106 // Deadline by when the request must be completed 107 Date_t expirationDate = kNoExpirationDate; 108 }; 109 110 std::ostream& operator<<(std::ostream& os, const RemoteCommandRequest& response); 111 112 } // namespace executor 113 } // namespace mongo 114