diff options
author | Spencer T Brody <spencer@mongodb.com> | 2015-09-17 19:25:09 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2015-09-18 13:35:14 -0400 |
commit | 455d5e0cc5aa9649b12b25f827efdf96b4a7c360 (patch) | |
tree | 092b4acd8bd88a482c9e1164042d988eb637b412 | |
parent | d6c1bb1838d434c9ff354467ba8f831ef379c954 (diff) | |
download | mongo-455d5e0cc5aa9649b12b25f827efdf96b4a7c360.tar.gz |
SERVER-19855 Update config server optime based on response metadata from running commands through DBClientInterface connections
-rw-r--r-- | src/mongo/s/client/sharding_connection_hook.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/mongo/s/client/sharding_connection_hook.cpp b/src/mongo/s/client/sharding_connection_hook.cpp index bfd6adc17f3..04ae7d72fb7 100644 --- a/src/mongo/s/client/sharding_connection_hook.cpp +++ b/src/mongo/s/client/sharding_connection_hook.cpp @@ -42,7 +42,9 @@ #include "mongo/db/client.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/rpc/metadata/audit_metadata.h" +#include "mongo/rpc/metadata/config_server_response_metadata.h" #include "mongo/s/client/scc_fast_query_handler.h" +#include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_last_error_info.h" #include "mongo/s/grid.h" #include "mongo/s/version_manager.h" @@ -52,6 +54,28 @@ namespace mongo { using std::string; +namespace { +Status _shardingReplyMetadataReader(const BSONObj& metadataObj, StringData hostString) { + saveGLEStats(metadataObj, hostString); + + auto shard = grid.shardRegistry()->getShardNoReload(hostString.toString()); + if (!shard) { + return Status::OK(); + } + // If this host is a known shard of ours, look for a config server optime in the response + // metadata to use to update our notion of the current config server optime. + auto responseStatus = rpc::ConfigServerResponseMetadata::readFromMetadata(metadataObj); + if (!responseStatus.isOK()) { + return responseStatus.getStatus(); + } + auto opTime = responseStatus.getValue().getOpTime(); + if (opTime.is_initialized()) { + grid.shardRegistry()->advanceConfigOpTime(opTime.get()); + } + return Status::OK(); +} +} // namespace + ShardingConnectionHook::ShardingConnectionHook(bool shardedConnections) : _shardedConnections(shardedConnections) {} @@ -72,11 +96,7 @@ void ShardingConnectionHook::onCreate(DBClientBase* conn) { // For every DBClient created by mongos, add a hook that will capture the response from // commands we pass along from the client, so that we can target the correct node when // subsequent getLastError calls are made by mongos. - conn->setReplyMetadataReader([](const BSONObj& metadataObj, StringData hostString) - -> Status { - saveGLEStats(metadataObj, hostString); - return Status::OK(); - }); + conn->setReplyMetadataReader(_shardingReplyMetadataReader); } // For every DBClient created by mongos, add a hook that will append impersonated users |