summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/split_chunk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/split_chunk.cpp')
-rw-r--r--src/mongo/db/s/split_chunk.cpp22
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);
}