From 35f4172754bec2cc62115f96af14366bf2b8ca1a Mon Sep 17 00:00:00 2001 From: Misha Tyulenev Date: Tue, 11 Dec 2018 11:23:39 -0500 Subject: SERVER-37929 reload ShardRegistry on config servers on rollback (cherry picked from commit fc1b17cfdeffa13b5326050893658e7ba4df57a1) --- src/mongo/db/SConscript | 2 ++ src/mongo/db/op_observer_impl.cpp | 15 +++++++++++++++ src/mongo/db/repl/rs_rollback.cpp | 15 +++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index d915f3d1a4f..1315ef36baa 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -764,6 +764,8 @@ env.Library( 'views/views_mongod', '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/db/catalog/uuid_catalog', + '$BUILD_DIR/mongo/s/coreshard', + "$BUILD_DIR/mongo/s/grid", ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/commands/mongod_fcv', diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp index 23e0f7427a4..7b106277c61 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -52,6 +52,8 @@ #include "mongo/db/server_options.h" #include "mongo/db/session_catalog.h" #include "mongo/db/views/durable_view_catalog.h" +#include "mongo/s/client/shard_registry.h" +#include "mongo/s/grid.h" #include "mongo/scripting/engine.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point_service.h" @@ -982,6 +984,19 @@ void OpObserverImpl::onReplicationRollback(OperationContext* opCtx, if (rbInfo.shardIdentityRolledBack) { fassertFailedNoTrace(50712); } + + // The code below will force the config server to update its shard registry. + // Otherwise it may have the stale data that has been just rolled back. + if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { + if (auto shardRegistry = Grid::get(opCtx)->shardRegistry()) { + auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx); + ON_BLOCK_EXIT([ argsCopy = readConcernArgs, &readConcernArgs ] { + readConcernArgs = std::move(argsCopy); + }); + readConcernArgs = repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern); + shardRegistry->reload(opCtx); + } + } } } // namespace mongo diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index f1a9c2d3493..65ba8fff86b 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -73,6 +73,8 @@ #include "mongo/db/repl/rslog.h" #include "mongo/db/s/shard_identity_rollback_notifier.h" #include "mongo/db/session_catalog.h" +#include "mongo/s/client/shard_registry.h" +#include "mongo/s/grid.h" #include "mongo/util/exit.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" @@ -1465,6 +1467,19 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, validator->resetKeyManagerCache(); } + // The code below will force the config server to update its shard registry. + // Otherwise it may have the stale data that has been just rolled back. + if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { + if (auto shardRegistry = Grid::get(opCtx)->shardRegistry()) { + auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx); + ON_BLOCK_EXIT([ argsCopy = readConcernArgs, &readConcernArgs ] { + readConcernArgs = std::move(argsCopy); + }); + readConcernArgs = repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern); + shardRegistry->reload(opCtx); + } + } + // Reload the lastAppliedOpTime and lastDurableOpTime value in the replcoord and the // lastAppliedHash value in bgsync to reflect our new last op. The rollback common point does // not necessarily represent a consistent database state. For example, on a secondary, we may -- cgit v1.2.1