diff options
author | Andrew Chen <a.chen@mongodb.com> | 2020-07-01 15:48:23 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-30 14:48:04 +0000 |
commit | 051bd6e51b33d7fd8a1265e166efffd20178a86d (patch) | |
tree | 6a2b92974c8e1cd148e0f085d0091ea0942e21f5 /src/mongo/tools | |
parent | 41fda13f7239308239ade7f143f9b5e2fef0e87b (diff) | |
download | mongo-051bd6e51b33d7fd8a1265e166efffd20178a86d.tar.gz |
SERVER-48978 Futurize handleRequest
Diffstat (limited to 'src/mongo/tools')
-rw-r--r-- | src/mongo/tools/bridge.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/mongo/tools/bridge.cpp b/src/mongo/tools/bridge.cpp index e377fae9be8..986114093ed 100644 --- a/src/mongo/tools/bridge.cpp +++ b/src/mongo/tools/bridge.cpp @@ -56,6 +56,7 @@ #include "mongo/transport/transport_layer_asio.h" #include "mongo/util/assert_util.h" #include "mongo/util/exit.h" +#include "mongo/util/future.h" #include "mongo/util/quick_exit.h" #include "mongo/util/signal_handlers.h" #include "mongo/util/str.h" @@ -248,10 +249,12 @@ class ServiceEntryPointBridge final : public ServiceEntryPointImpl { public: explicit ServiceEntryPointBridge(ServiceContext* svcCtx) : ServiceEntryPointImpl(svcCtx) {} - DbResponse handleRequest(OperationContext* opCtx, const Message& request) final; + Future<DbResponse> handleRequest(OperationContext* opCtx, + const Message& request) noexcept final; }; -DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const Message& request) { +Future<DbResponse> ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, + const Message& request) noexcept try { if (request.operation() == dbQuery) { DbMessage d(request); QueryMessage q(d); @@ -344,7 +347,8 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const if (!status->isOK()) { commandReply = StatusWith<BSONObj>(*status); } - return {replyBuilder->setCommandReply(std::move(commandReply)).done()}; + return Future<DbResponse>::makeReady( + {replyBuilder->setCommandReply(std::move(commandReply)).done()}); } @@ -361,7 +365,7 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const "remote"_attr = dest, "source"_attr = source->remote().toString()); source->end(); - return {Message()}; + return Future<DbResponse>::makeReady({Message()}); // Forward the message to 'dest' with probability '1 - hostSettings.loss'. case HostSettings::State::kDiscard: if (dest.nextCanonicalDouble() < hostSettings.loss) { @@ -381,7 +385,7 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const "operation"_attr = networkOpToString(request.operation()), "hostName"_attr = hostName); } - return {Message()}; + return Future<DbResponse>::makeReady({Message()}); } // Forward the message to 'dest' after waiting for 'hostSettings.delay' // milliseconds. @@ -429,7 +433,7 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const "remote"_attr = dest, "source"_attr = source->remote()); source->end(); - return {Message()}; + return Future<DbResponse>::makeReady({Message()}); } // Only support OP_MSG exhaust cursors. @@ -447,10 +451,13 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const // whether this should be run again to receive more responses from the exhaust stream. // We do not need to set 'nextInvocation' in the DbResponse because mongobridge // only receives responses but ignores the next request if it is in exhaust mode. - return {std::move(response), isExhaust}; + return Future<DbResponse>::makeReady({std::move(response), isExhaust}); } else { - return {Message()}; + return Future<DbResponse>::makeReady({Message()}); } +} catch (const DBException& e) { + LOGV2_ERROR(4879804, "Failed to handle request", "error"_attr = redact(e)); + return e.toStatus(); } int bridgeMain(int argc, char** argv) { |