summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAlex Taskov <alex.taskov@mongodb.com>2020-03-12 14:36:19 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-12 18:58:49 +0000
commit4e329f262b5c083068700930177d2eb003241273 (patch)
treeff47ec8bcd93dfa8f4834848e059037ee941d2d8 /src/mongo
parent682ef0452245f0964b9024d00eca0ee8bd1725a1 (diff)
downloadmongo-4e329f262b5c083068700930177d2eb003241273.tar.gz
SERVER-46440 Routing info should be reloaded before retry of creating session collection index on stale config error
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/sessions_collection_config_server.cpp55
-rw-r--r--src/mongo/db/sessions_collection_config_server.h4
3 files changed, 22 insertions, 38 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index f93d37a0f6f..4c62a46d924 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -1335,6 +1335,7 @@ env.Library(
],
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/s/sharding_router_api',
+ '$BUILD_DIR/mongo/db/pipeline/sharded_agg_helpers',
]
)
diff --git a/src/mongo/db/sessions_collection_config_server.cpp b/src/mongo/db/sessions_collection_config_server.cpp
index 5d5f0153c7b..0acc4cec7c2 100644
--- a/src/mongo/db/sessions_collection_config_server.cpp
+++ b/src/mongo/db/sessions_collection_config_server.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/logical_session_id.h"
#include "mongo/db/operation_context.h"
+#include "mongo/db/pipeline/sharded_agg_helpers.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/client/shard_registry.h"
@@ -79,41 +80,27 @@ void SessionsCollectionConfigServer::_shardCollectionIfNeeded(OperationContext*
void SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext* opCtx) {
const auto nss = NamespaceString::kLogicalSessionsNamespace;
- auto routingInfo =
- uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss));
- try {
- for (int tries = 0;; ++tries) {
- const bool canRetry = tries < kMaxNumStaleVersionRetries - 1;
- try {
- scatterGatherVersionedTargetByRoutingTable(
- opCtx,
- nss.db(),
- nss,
- routingInfo,
- SessionsCollection::generateCreateIndexesCmd(),
- ReadPreferenceSetting(ReadPreference::PrimaryOnly),
- Shard::RetryPolicy::kNoRetry,
- BSONObj() /* query */,
- BSONObj() /* collation */);
- return;
- } catch (const ExceptionForCat<ErrorCategory::StaleShardVersionError>& ex) {
- LOGV2(21980,
- "Attempt {tries} to generate TTL index for {nss} received StaleShardVersion "
- "error{causedBy_ex}",
- "tries"_attr = tries,
- "nss"_attr = nss,
- "causedBy_ex"_attr = causedBy(ex));
- if (canRetry) {
- continue;
- }
- throw;
- }
- }
- } catch (DBException& ex) {
- ex.addContext(str::stream() << "Failed to generate TTL index for " << nss);
- throw;
- }
+ sharded_agg_helpers::shardVersionRetry(
+ opCtx,
+ Grid::get(opCtx)->catalogCache(),
+ nss,
+ "SessionsCollectionConfigServer::_generateIndexesIfNeeded",
+ [&] {
+ auto routingInfo = uassertStatusOK(
+ Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss));
+
+ scatterGatherVersionedTargetByRoutingTable(
+ opCtx,
+ nss.db(),
+ nss,
+ routingInfo,
+ SessionsCollection::generateCreateIndexesCmd(),
+ ReadPreferenceSetting(ReadPreference::PrimaryOnly),
+ Shard::RetryPolicy::kNoRetry,
+ BSONObj() /* query */,
+ BSONObj() /* collation */);
+ });
}
void SessionsCollectionConfigServer::setupSessionsCollection(OperationContext* opCtx) {
diff --git a/src/mongo/db/sessions_collection_config_server.h b/src/mongo/db/sessions_collection_config_server.h
index 0c5bdbb596e..2deeac82549 100644
--- a/src/mongo/db/sessions_collection_config_server.h
+++ b/src/mongo/db/sessions_collection_config_server.h
@@ -29,12 +29,8 @@
#pragma once
-#include <memory>
-
-#include "mongo/db/logical_session_id.h"
#include "mongo/db/sessions_collection_sharded.h"
#include "mongo/platform/mutex.h"
-#include "mongo/util/time_support.h"
namespace mongo {