summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2018-12-11 11:23:39 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-27 17:25:34 +0000
commit35f4172754bec2cc62115f96af14366bf2b8ca1a (patch)
tree27bdc9bd86f857b7246451b5b49b845411e1fcd6
parentbe0eb178a1c599497a307a5b114d112343fab9c1 (diff)
downloadmongo-35f4172754bec2cc62115f96af14366bf2b8ca1a.tar.gz
SERVER-37929 reload ShardRegistry on config servers on rollback
(cherry picked from commit fc1b17cfdeffa13b5326050893658e7ba4df57a1)
-rw-r--r--src/mongo/db/SConscript2
-rw-r--r--src/mongo/db/op_observer_impl.cpp15
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp15
3 files changed, 32 insertions, 0 deletions
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