summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@10gen.com>2016-05-25 17:00:18 -0400
committerDianna Hohensee <dianna.hohensee@10gen.com>2016-06-01 09:44:40 -0400
commitb02759c687efcde72a0343532ae4c1b896d1db64 (patch)
tree3c5f787458991e4a6258a42f1fcf7e4292c29721 /src/mongo/db/s
parenta5864a5d54e667af548b4ce7b5b652ebcce84ef4 (diff)
downloadmongo-b02759c687efcde72a0343532ae4c1b896d1db64.tar.gz
SERVER-22659 Changing ShardingState::refreshMetadataNow to correctly handle updating from a nonzero shardVersion to a remote shardVersion of 0000|0.
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/metadata_loader.cpp12
-rw-r--r--src/mongo/db/s/sharding_state.cpp4
2 files changed, 14 insertions, 2 deletions
diff --git a/src/mongo/db/s/metadata_loader.cpp b/src/mongo/db/s/metadata_loader.cpp
index 9a0823fb0b3..e4d41dad429 100644
--- a/src/mongo/db/s/metadata_loader.cpp
+++ b/src/mongo/db/s/metadata_loader.cpp
@@ -146,7 +146,9 @@ Status MetadataLoader::initChunks(OperationContext* txn,
// Check to see if we should use the old version or not.
if (oldMetadata) {
- // If our epochs are compatible, it's useful to use the old metadata for diffs
+ // If our epochs are compatible, it's useful to use the old metadata for diffs: this leads
+ // to a performance gain because not all the chunks must be reloaded, just the ones this
+ // shard has not seen -- they will have higher versions than present in oldMetadata.
if (oldMetadata->getCollVersion().hasEqualEpoch(epoch)) {
fullReload = false;
invariant(oldMetadata->isValid());
@@ -199,6 +201,14 @@ Status MetadataLoader::initChunks(OperationContext* txn,
LOG(2) << "loaded " << diffsApplied << " chunks into new metadata for " << ns
<< " with version " << metadata->_collVersion;
+ // If the last chunk was moved off of this shard, the shardVersion should be reset to
+ // zero (if we did not conduct a full reload and oldMetadata was present,
+ // versionMap[shard] was previously set to the oldMetadata's shardVersion for
+ // performance gains).
+ if (!fullReload && metadata->_chunksMap.size() == 0) {
+ versionMap[shard] = ChunkVersion(0, 0, epoch);
+ }
+
metadata->_shardVersion = versionMap[shard];
metadata->fillRanges();
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index 1a66f122329..46609016cfa 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -778,7 +778,9 @@ Status ShardingState::_refreshMetadata(OperationContext* txn,
choice = chooseNewestVersion(beforeCollVersion, afterCollVersion, remoteCollVersion);
if (choice == VersionChoice::Remote) {
- dassert(!remoteCollVersion.epoch().isSet() || remoteShardVersion >= beforeShardVersion);
+ dassert(
+ !remoteCollVersion.epoch().isSet() || remoteShardVersion >= beforeShardVersion ||
+ (remoteShardVersion.minorVersion() == 0 && remoteShardVersion.majorVersion() == 0));
if (!afterCollVersion.epoch().isSet()) {
// First metadata load