diff options
| author | Simon Gratzer <simon.gratzer@mongodb.com> | 2021-05-11 16:51:47 +0200 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-01 14:40:56 +0000 |
| commit | c58adbce4f628f0da863bd779ada0512e5b242ec (patch) | |
| tree | 029481487cbb315fd35de4eafeb62ae4c885df6c /src/mongo/db/s/split_chunk.cpp | |
| parent | eb43e20229bdb20abdcaca1d89b965a22ac44584 (diff) | |
| download | mongo-v4.2.12.tar.gz | |
SERVER-48653 Return updated ShardVersion in _configsvrCommitChunkSplit to avoid blind metadata refresh (BACKPORT-9049)v4.2.12
Diffstat (limited to 'src/mongo/db/s/split_chunk.cpp')
| -rw-r--r-- | src/mongo/db/s/split_chunk.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/mongo/db/s/split_chunk.cpp b/src/mongo/db/s/split_chunk.cpp index 9e98c376ede..71bd707ae03 100644 --- a/src/mongo/db/s/split_chunk.cpp +++ b/src/mongo/db/s/split_chunk.cpp @@ -188,9 +188,22 @@ StatusWith<boost::optional<ChunkRange>> splitChunk(OperationContext* opCtx, return cmdResponseStatus.getStatus(); } + // old versions might not have the shardVersion field + const Shard::CommandResponse& cmdResponse = cmdResponseStatus.getValue(); + if (cmdResponse.response[ChunkVersion::kShardVersionField]) { + const auto cv = uassertStatusOK( + ChunkVersion::parseWithField(cmdResponse.response, ChunkVersion::kShardVersionField)); + uassertStatusOK(onShardVersionMismatchNoExcept( + opCtx, nss, std::move(cv), true /* forceRefreshFromThisThread */)); + } else { + // Refresh metadata to pick up new chunk definitions (regardless of the results returned + // from running _configsvrCommitChunkMerge). + forceShardFilteringMetadataRefresh(opCtx, nss, true /* forceRefreshFromThisThread */); + } + // Check commandStatus and writeConcernStatus - auto commandStatus = cmdResponseStatus.getValue().commandStatus; - auto writeConcernStatus = cmdResponseStatus.getValue().writeConcernStatus; + auto commandStatus = cmdResponse.commandStatus; + auto writeConcernStatus = cmdResponse.writeConcernStatus; // Send stale epoch if epoch of request did not match epoch of collection if (commandStatus == ErrorCodes::StaleEpoch) { @@ -198,14 +211,12 @@ StatusWith<boost::optional<ChunkRange>> splitChunk(OperationContext* opCtx, } // - // If _configsvrCommitChunkSplit returned an error, refresh and look at the metadata to + // If _configsvrCommitChunkSplit returned an error, look at the metadata to // determine if the split actually did happen. This can happen if there's a network error // getting the response from the first call to _configsvrCommitChunkSplit, but it actually // succeeds, thus the automatic retry fails with a precondition violation, for example. // if (!commandStatus.isOK() || !writeConcernStatus.isOK()) { - forceShardFilteringMetadataRefresh(opCtx, nss); - if (checkMetadataForSuccessfulSplitChunk( opCtx, nss, expectedCollectionEpoch, chunkRange, splitKeys)) { // Split was committed. @@ -249,7 +260,6 @@ StatusWith<boost::optional<ChunkRange>> splitChunk(OperationContext* opCtx, checkIfSingleDoc(opCtx, collection, idx, &frontChunk)) { return boost::optional<ChunkRange>(ChunkRange(frontChunk.getMin(), frontChunk.getMax())); } - return boost::optional<ChunkRange>(boost::none); } |
