From 2e1f172bc139adce256ada5675f0197bb2949ddc Mon Sep 17 00:00:00 2001 From: jannaerin Date: Wed, 31 Jan 2018 17:41:29 -0500 Subject: SERVER-31979 Include chunk migration stats in `moveChunk.commit` changelog entries --- ...harding_last_stable_mongos_and_mixed_shards.yml | 1 + .../sharding/movechunk_commit_changelog_stats.js | 40 ++++++++++++++++++++++ src/mongo/db/s/migration_chunk_cloner_source.h | 2 +- .../db/s/migration_chunk_cloner_source_legacy.cpp | 5 +-- .../db/s/migration_chunk_cloner_source_legacy.h | 2 +- src/mongo/db/s/migration_source_manager.cpp | 12 +++++-- src/mongo/db/s/migration_source_manager.h | 3 ++ 7 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 jstests/sharding/movechunk_commit_changelog_stats.js diff --git a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml index 896c4d0548a..a2a39365987 100644 --- a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml +++ b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml @@ -26,6 +26,7 @@ selector: - jstests/sharding/basic_drop_coll.js - jstests/sharding/commands_that_write_accept_wc_configRS.js - jstests/sharding/clone_metadata_only.js + - jstests/sharding/movechunk_commit_changelog_stats.js # Enable when 3.6 becomes last-stable. - jstests/sharding/coll_epoch_test1.js - jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js diff --git a/jstests/sharding/movechunk_commit_changelog_stats.js b/jstests/sharding/movechunk_commit_changelog_stats.js new file mode 100644 index 00000000000..cff5ae2a445 --- /dev/null +++ b/jstests/sharding/movechunk_commit_changelog_stats.js @@ -0,0 +1,40 @@ +// +// Tests that the changelog entry for moveChunk.commit contains stats on the migration. +// + +(function() { + 'use strict'; + + var st = new ShardingTest({mongos: 1, shards: 2}); + var kDbName = 'db'; + + var mongos = st.s0; + var shard0 = st.shard0.shardName; + var shard1 = st.shard1.shardName; + + assert.commandWorked(mongos.adminCommand({enableSharding: kDbName})); + st.ensurePrimaryShard(kDbName, shard0); + + function assertCountsInChangelog() { + let changeLog = st.s.getDB('config').changelog.find({what: 'moveChunk.commit'}).toArray(); + assert.gt(changeLog.length, 0); + for (let i = 0; i < changeLog.length; i++) { + assert(changeLog[i].details.hasOwnProperty('counts')); + } + } + + var ns = kDbName + '.fooHashed'; + assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: {_id: 'hashed'}})); + + var aChunk = mongos.getDB('config').chunks.findOne({_id: RegExp(ns), shard: shard0}); + assert(aChunk); + + // Assert counts field exists in the changelog entry for moveChunk.commit + assert.commandWorked( + mongos.adminCommand({moveChunk: ns, bounds: [aChunk.min, aChunk.max], to: shard1})); + assertCountsInChangelog(); + + mongos.getDB(kDbName).fooHashed.drop(); + + st.stop(); +})(); \ No newline at end of file diff --git a/src/mongo/db/s/migration_chunk_cloner_source.h b/src/mongo/db/s/migration_chunk_cloner_source.h index ff3d31132fa..65b2a6d23f6 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source.h +++ b/src/mongo/db/s/migration_chunk_cloner_source.h @@ -95,7 +95,7 @@ public: * * NOTE: Must be called without any locks. */ - virtual Status commitClone(OperationContext* opCtx) = 0; + virtual StatusWith commitClone(OperationContext* opCtx) = 0; /** * Tells the recipient to abort the clone and cleanup any unused data. This method's diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp index 95914f9c4b0..78cf1102ef4 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp @@ -332,7 +332,7 @@ Status MigrationChunkClonerSourceLegacy::awaitUntilCriticalSectionIsAppropriate( return {ErrorCodes::ExceededTimeLimit, "Timed out waiting for the cloner to catch up"}; } -Status MigrationChunkClonerSourceLegacy::commitClone(OperationContext* opCtx) { +StatusWith MigrationChunkClonerSourceLegacy::commitClone(OperationContext* opCtx) { invariant(_state == kCloning); invariant(!opCtx->lockState()->isLocked()); @@ -346,7 +346,8 @@ Status MigrationChunkClonerSourceLegacy::commitClone(OperationContext* opCtx) { "destination shard finished committing but there are still some session " "metadata that needs to be transferred"}; } - return Status::OK(); + + return responseStatus; } cancelClone(opCtx); diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.h b/src/mongo/db/s/migration_chunk_cloner_source_legacy.h index 28981b21c15..17979a5c2ef 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.h +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.h @@ -68,7 +68,7 @@ public: Status awaitUntilCriticalSectionIsAppropriate(OperationContext* opCtx, Milliseconds maxTimeToWait) override; - Status commitClone(OperationContext* opCtx) override; + StatusWith commitClone(OperationContext* opCtx) override; void cancelClone(OperationContext* opCtx) override; diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index fb1ebee0293..558e32f667a 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -358,7 +358,7 @@ Status MigrationSourceManager::commitChunkOnRecipient(OperationContext* opCtx) { auto scopedGuard = MakeGuard([&] { cleanupOnError(opCtx); }); // Tell the recipient shard to fetch the latest changes. - Status commitCloneStatus = _cloneDriver->commitClone(opCtx); + auto commitCloneStatus = _cloneDriver->commitClone(opCtx); if (MONGO_FAIL_POINT(failMigrationCommit) && commitCloneStatus.isOK()) { commitCloneStatus = {ErrorCodes::InternalError, @@ -366,7 +366,11 @@ Status MigrationSourceManager::commitChunkOnRecipient(OperationContext* opCtx) { } if (!commitCloneStatus.isOK()) { - return commitCloneStatus.withContext("commit clone failed"); + return commitCloneStatus.getStatus().withContext("commit clone failed"); + } + + if (commitCloneStatus.getValue()["counts"].type() == BSONType::Object) { + _recipientCloneCounts = commitCloneStatus.getValue()["counts"].Obj().getOwned(); } _state = kCloneCompleted; @@ -571,7 +575,9 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig(OperationContext* opC BSON("min" << _args.getMinKey() << "max" << _args.getMaxKey() << "from" << _args.getFromShardId() << "to" - << _args.getToShardId()), + << _args.getToShardId() + << "counts" + << _recipientCloneCounts), ShardingCatalogClient::kMajorityWriteConcern) .ignore(); diff --git a/src/mongo/db/s/migration_source_manager.h b/src/mongo/db/s/migration_source_manager.h index 050fd8e43bf..cb24599e519 100644 --- a/src/mongo/db/s/migration_source_manager.h +++ b/src/mongo/db/s/migration_source_manager.h @@ -250,6 +250,9 @@ private: // The transition from false to true is protected by the collection X-lock, which happens just // before the config server metadata commit is scheduled. bool _readsShouldWaitOnCritSec{false}; + + // The statistics about a chunk migration to be included in moveChunk.commit + BSONObj _recipientCloneCounts; }; } // namespace mongo -- cgit v1.2.1