summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@10gen.com>2017-03-09 10:34:52 -0500
committerDianna Hohensee <dianna.hohensee@10gen.com>2017-03-10 15:26:20 -0500
commit56810e6acb3a0425284189d852eaefb391e5f800 (patch)
tree5c98ec4b9a928fddd9b5932f6754ce4c8b742c80
parent76b8e0443d4b1e0a0533d04768c7c0339bc2ad0d (diff)
downloadmongo-56810e6acb3a0425284189d852eaefb391e5f800.tar.gz
SERVER-27632 replace 'shardVersion' field in splitChunk with an 'epoch' field
-rw-r--r--src/mongo/db/s/split_chunk_command.cpp43
-rw-r--r--src/mongo/s/shard_util.cpp3
2 files changed, 29 insertions, 17 deletions
diff --git a/src/mongo/db/s/split_chunk_command.cpp b/src/mongo/db/s/split_chunk_command.cpp
index 703143cfd67..7140556d5ec 100644
--- a/src/mongo/db/s/split_chunk_command.cpp
+++ b/src/mongo/db/s/split_chunk_command.cpp
@@ -266,22 +266,32 @@ public:
return false;
}
- const auto& oss = OperationShardingState::get(opCtx);
- uassert(ErrorCodes::InvalidOptions, "collection version is missing", oss.hasShardVersion());
+ OID expectedCollectionEpoch;
+ if (cmdObj.hasField("epoch")) {
+ auto epochStatus = bsonExtractOIDField(cmdObj, "epoch", &expectedCollectionEpoch);
+ uassert(
+ ErrorCodes::InvalidOptions, "unable to parse collection epoch", epochStatus.isOK());
+ } else {
+ // Backwards compatibility with v3.4 mongos, which will send 'shardVersion' and not
+ // 'epoch'.
+ const auto& oss = OperationShardingState::get(opCtx);
+ uassert(
+ ErrorCodes::InvalidOptions, "collection version is missing", oss.hasShardVersion());
+ expectedCollectionEpoch = oss.getShardVersion(nss).epoch();
+ }
// Even though the splitChunk command transmits a value in the operation's shardVersion
// field, this value does not actually contain the shard version, but the global collection
// version.
- ChunkVersion expectedCollectionVersion = oss.getShardVersion(nss);
- if (expectedCollectionVersion.epoch() != shardVersion.epoch()) {
+ if (expectedCollectionEpoch != shardVersion.epoch()) {
std::string msg = str::stream() << "splitChunk cannot split chunk "
<< "[" << redact(min) << "," << redact(max) << "), "
- << "collection may have been dropped. "
+ << "collection '" << nss.ns()
+ << "' may have been dropped. "
<< "current epoch: " << shardVersion.epoch()
- << ", cmd epoch: " << expectedCollectionVersion.epoch();
+ << ", cmd epoch: " << expectedCollectionEpoch;
warning() << msg;
- throw SendStaleConfigException(
- nss.toString(), msg, expectedCollectionVersion, shardVersion);
+ return appendCommandStatus(result, {ErrorCodes::StaleEpoch, msg});
}
ScopedCollectionMetadata collMetadata;
@@ -306,8 +316,9 @@ public:
uassertStatusOK(collMetadata->checkChunkIsValid(chunkToMove));
}
- auto request = SplitChunkRequest(
- nss, shardName, expectedCollectionVersion.epoch(), chunkRange, splitKeys);
+ // Commit the split to the config server.
+ auto request =
+ SplitChunkRequest(nss, shardName, expectedCollectionEpoch, chunkRange, splitKeys);
auto configCmdObj =
request.toConfigCommandBSON(ShardingCatalogClient::kMajorityWriteConcern.toBSON());
@@ -350,15 +361,15 @@ public:
if (commandStatus == ErrorCodes::StaleEpoch) {
std::string msg = str::stream() << "splitChunk cannot split chunk "
<< "[" << redact(min) << "," << redact(max) << "), "
- << "collection may have been dropped. "
+ << "collection '" << nss.ns()
+ << "' may have been dropped. "
<< "current epoch: " << collVersion.epoch()
- << ", cmd epoch: " << expectedCollectionVersion.epoch();
+ << ", cmd epoch: " << expectedCollectionEpoch;
warning() << msg;
- throw SendStaleConfigException(
- nss.toString(), msg, expectedCollectionVersion, collVersion);
-
- return appendCommandStatus(result, commandStatus);
+ return appendCommandStatus(
+ result,
+ {commandStatus.code(), str::stream() << msg << redact(causedBy(commandStatus))});
}
//
diff --git a/src/mongo/s/shard_util.cpp b/src/mongo/s/shard_util.cpp
index 8adf605d4a3..b440a6c6491 100644
--- a/src/mongo/s/shard_util.cpp
+++ b/src/mongo/s/shard_util.cpp
@@ -167,7 +167,8 @@ StatusWith<boost::optional<ChunkRange>> splitChunkAtMultiplePoints(
cmd.append("splitChunk", nss.ns());
cmd.append("from", shardId.toString());
cmd.append("keyPattern", shardKeyPattern.toBSON());
- collectionVersion.appendForCommands(&cmd);
+ cmd.append("epoch", collectionVersion.epoch());
+ collectionVersion.appendForCommands(&cmd); // backwards compatibility with v3.4
chunkRange.append(&cmd);
cmd.append("splitKeys", splitPoints);