diff options
author | Misha Tyulenev <misha@mongodb.com> | 2017-07-31 17:10:07 -0400 |
---|---|---|
committer | Misha Tyulenev <misha@mongodb.com> | 2017-07-31 17:10:19 -0400 |
commit | c9638cd6bcb85f6f5371ca92226d37aecf3d045b (patch) | |
tree | 8ae3b3d4cd79805ca10742c3b4a16852856355a8 /src/mongo/s/server.cpp | |
parent | e3bdbd02624f5dce42aada11b84f28ff14f578da (diff) | |
download | mongo-c9638cd6bcb85f6f5371ca92226d37aecf3d045b.tar.gz |
SERVER-30249 wait for the signing keys to be available in mongos at startup
Diffstat (limited to 'src/mongo/s/server.cpp')
-rw-r--r-- | src/mongo/s/server.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index f388d1bf493..760e313c5d0 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -126,6 +126,45 @@ namespace { boost::optional<ShardingUptimeReporter> shardingUptimeReporter; +static constexpr auto kRetryInterval = Seconds{1}; + +Status waitForSigningKeys(OperationContext* opCtx) { + while (true) { + // this should be true when shard registry is up + invariant(grid.shardRegistry()->isUp()); + auto configCS = grid.shardRegistry()->getConfigServerConnectionString(); + auto rsm = ReplicaSetMonitor::get(configCS.getSetName()); + // mongod will set minWireVersion == maxWireVersion for isMaster requests from + // internalClient. + if (rsm && (rsm->getMaxWireVersion() < WireVersion::SUPPORTS_OP_MSG || + rsm->getMaxWireVersion() != rsm->getMinWireVersion())) { + log() << "Not waiting for signing keys, not supported by the config shard " + << configCS.getSetName(); + return Status::OK(); + } + auto stopStatus = opCtx->checkForInterruptNoAssert(); + if (!stopStatus.isOK()) { + return stopStatus; + } + + try { + if (LogicalTimeValidator::get(opCtx)->shouldGossipLogicalTime()) { + return Status::OK(); + } + log() << "Waiting for signing keys, sleeping for " << kRetryInterval + << " and trying again."; + sleepFor(kRetryInterval); + continue; + } catch (const DBException& ex) { + Status status = ex.toStatus(); + warning() << "Error waiting for signing keys, sleeping for " << kRetryInterval + << " and trying again " << causedBy(status); + sleepFor(kRetryInterval); + continue; + } + } +} + } // namespace #if defined(_WIN32) @@ -240,6 +279,11 @@ static Status initializeSharding(OperationContext* opCtx) { return status; } + status = waitForSigningKeys(opCtx); + if (!status.isOK()) { + return status; + } + return Status::OK(); } |