diff options
author | Spencer T Brody <spencer@mongodb.com> | 2015-09-22 11:20:42 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2015-09-24 13:36:59 -0400 |
commit | 3a7b1a9800f75706f35a290a8dee198bb29e3366 (patch) | |
tree | 7e54e245f21f9201cd9215972ec67609130e53cf | |
parent | 362aac3937e3ff39ee995919a529297488537191 (diff) | |
download | mongo-3a7b1a9800f75706f35a290a8dee198bb29e3366.tar.gz |
SERVER-19855 Include config server optime even on command failure responses from mongod
-rw-r--r-- | src/mongo/db/commands.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/commands.h | 3 | ||||
-rw-r--r-- | src/mongo/db/dbcommands.cpp | 10 |
3 files changed, 19 insertions, 9 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index e785a4c3d23..256e3fd2ead 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -410,15 +410,15 @@ namespace { void _generateErrorResponse(OperationContext* txn, rpc::ReplyBuilderInterface* replyBuilder, - const DBException& exception) { + const DBException& exception, + const BSONObj& metadata) { Command::registerError(txn, exception); // We could have thrown an exception after setting fields in the builder, // so we need to reset it to a clean state just to be sure. replyBuilder->reset(); - // No metadata is needed for an error reply. - replyBuilder->setMetadata(rpc::makeEmptyMetadata()); + replyBuilder->setMetadata(metadata); // We need to include some extra information for SendStaleConfig. if (exception.getCode() == ErrorCodes::SendStaleConfig) { @@ -439,14 +439,15 @@ void Command::generateErrorResponse(OperationContext* txn, rpc::ReplyBuilderInterface* replyBuilder, const DBException& exception, const rpc::RequestInterface& request, - Command* command) { + Command* command, + const BSONObj& metadata) { LOG(1) << "assertion while executing command '" << request.getCommandName() << "' " << "on database '" << request.getDatabase() << "' " << "with arguments '" << command->getRedactedCopyForLogging(request.getCommandArgs()) << "' " << "and metadata '" << request.getMetadata() << "': " << exception.toString(); - _generateErrorResponse(txn, replyBuilder, exception); + _generateErrorResponse(txn, replyBuilder, exception, metadata); } void Command::generateErrorResponse(OperationContext* txn, @@ -456,14 +457,14 @@ void Command::generateErrorResponse(OperationContext* txn, LOG(1) << "assertion while executing command '" << request.getCommandName() << "' " << "on database '" << request.getDatabase() << "': " << exception.toString(); - _generateErrorResponse(txn, replyBuilder, exception); + _generateErrorResponse(txn, replyBuilder, exception, rpc::makeEmptyMetadata()); } void Command::generateErrorResponse(OperationContext* txn, rpc::ReplyBuilderInterface* replyBuilder, const DBException& exception) { LOG(1) << "assertion while executing command: " << exception.toString(); - _generateErrorResponse(txn, replyBuilder, exception); + _generateErrorResponse(txn, replyBuilder, exception, rpc::makeEmptyMetadata()); } void runCommands(OperationContext* txn, diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index e71c4bbd0d4..8993f9e657a 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -386,7 +386,8 @@ public: rpc::ReplyBuilderInterface* replyBuilder, const DBException& exception, const rpc::RequestInterface& request, - Command* command); + Command* command, + const BSONObj& metadata); /** * Generates a command error response. This overload of generateErrorResponse is intended diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 500d3bd92e3..452670ddf23 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -1309,7 +1309,15 @@ void Command::execCommand(OperationContext* txn, command->_commandsFailed.increment(); } } catch (const DBException& exception) { - Command::generateErrorResponse(txn, replyBuilder, exception, request, command); + BSONObj metadata = rpc::makeEmptyMetadata(); + if (ShardingState::get(txn)->enabled()) { + auto opTime = grid.shardRegistry()->getConfigOpTime(); + BSONObjBuilder metadataBob; + rpc::ConfigServerMetadata(opTime).writeToMetadata(&metadataBob); + metadata = metadataBob.obj(); + } + + Command::generateErrorResponse(txn, replyBuilder, exception, request, command, metadata); } } |