diff options
author | Esha Maharishi <esha.maharishi@mongodb.com> | 2018-06-01 00:29:20 -0400 |
---|---|---|
committer | Esha Maharishi <esha.maharishi@mongodb.com> | 2018-06-01 13:19:34 -0400 |
commit | 1f3c873569959e5e0c547bad9030a5ba2b3eb0dc (patch) | |
tree | e57abc769859b465774bbf5afdbac7c0a66044eb /src/mongo/s | |
parent | 19d78063c72bf448c0e49fad41ba6aa88a34ddb1 (diff) | |
download | mongo-1f3c873569959e5e0c547bad9030a5ba2b3eb0dc.tar.gz |
SERVER-34338 Find explain in legacy query path on mongos does not retry on StaleShardVersion
(cherry picked from commit 3e31679dfa6d85ebe48855582304c8cb7a635b0d)
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/commands/strategy.cpp | 91 |
1 files changed, 68 insertions, 23 deletions
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 80873b48382..89d5affdb1d 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -362,7 +362,7 @@ void runCommand(OperationContext* opCtx, try { execCommandClient(opCtx, invocation.get(), request, &crb); return; - } catch (ExceptionForCat<ErrorCategory::NeedRetargettingError>& ex) { + } catch (const ExceptionForCat<ErrorCategory::NeedRetargettingError>& ex) { const auto staleNs = [&] { if (auto staleInfo = ex.extraInfo<StaleConfigInfo>()) { return NamespaceString(staleInfo->getns()); @@ -383,32 +383,34 @@ void runCommand(OperationContext* opCtx, throw; } - if (!canRetry) - throw; - - LOG(2) << "Retrying command " << redact(request.body) << causedBy(ex); - + // Send setShardVersion on this thread's versioned connections to shards (to support + // commands that use the legacy (ShardConnection) versioning protocol). if (!MONGO_FAIL_POINT(doNotRefreshShardsOnRetargettingError)) { ShardConnection::checkMyConnectionVersions(opCtx, staleNs.ns()); } + // Mark collection entry in cache as stale. if (staleNs.isValid()) { Grid::get(opCtx)->catalogCache()->invalidateShardedCollection(staleNs); } - - continue; - } catch (const ExceptionFor<ErrorCodes::StaleDbVersion>& e) { - Grid::get(opCtx)->catalogCache()->onStaleDatabaseVersion(e->getDb(), - e->getVersionReceived()); - if (!canRetry) - throw; - continue; - } catch (const ExceptionForCat<ErrorCategory::SnapshotError>& ex) { - LOG(2) << "Retrying command " << redact(request.body) << causedBy(ex); - if (!canRetry) - throw; + if (canRetry) { + continue; + } + throw; + } catch (const ExceptionFor<ErrorCodes::StaleDbVersion>& ex) { + // Mark database entry in cache as stale. + Grid::get(opCtx)->catalogCache()->onStaleDatabaseVersion(ex->getDb(), + ex->getVersionReceived()); + if (canRetry) { + continue; + } + throw; + } catch (const ExceptionForCat<ErrorCategory::SnapshotError>&) { // Simple retry on any type of snapshot error. - continue; + if (canRetry) { + continue; + } + throw; } MONGO_UNREACHABLE; } @@ -766,12 +768,55 @@ void Strategy::explainFind(OperationContext* opCtx, qr.getCollation()); millisElapsed = timer.millis(); break; - } catch (const ExceptionFor<ErrorCodes::StaleDbVersion>& e) { - Grid::get(opCtx)->catalogCache()->onStaleDatabaseVersion(e->getDb(), - e->getVersionReceived()); - if (!canRetry) { + } catch (const ExceptionForCat<ErrorCategory::NeedRetargettingError>& ex) { + const auto staleNs = [&] { + if (auto staleInfo = ex.extraInfo<StaleConfigInfo>()) { + return NamespaceString(staleInfo->getns()); + } else if (auto implicitCreateInfo = + ex.extraInfo<CannotImplicitlyCreateCollectionInfo>()) { + return NamespaceString(implicitCreateInfo->getNss()); + } else { + throw; + } + }(); + + if (staleNs.isEmpty()) { + // This should be impossible but older versions tried incorrectly to handle + // it here. + log() << "Received a stale config error with an empty namespace while " + "executing " + << redact(explainCmd) << " : " << redact(ex); throw; } + + // Send setShardVersion on this thread's versioned connections to shards (to support + // commands that use the legacy (ShardConnection) versioning protocol). + if (!MONGO_FAIL_POINT(doNotRefreshShardsOnRetargettingError)) { + ShardConnection::checkMyConnectionVersions(opCtx, staleNs.ns()); + } + + // Mark collection entry in cache as stale. + if (staleNs.isValid()) { + Grid::get(opCtx)->catalogCache()->invalidateShardedCollection(staleNs); + } + if (canRetry) { + continue; + } + throw; + } catch (const ExceptionFor<ErrorCodes::StaleDbVersion>& ex) { + // Mark database entry in cache as stale. + Grid::get(opCtx)->catalogCache()->onStaleDatabaseVersion(ex->getDb(), + ex->getVersionReceived()); + if (canRetry) { + continue; + } + throw; + } catch (const ExceptionForCat<ErrorCategory::SnapshotError>&) { + // Simple retry on any type of snapshot error. + if (canRetry) { + continue; + } + throw; } } |