diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/s/metadata_loader.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_state.cpp | 4 |
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 |