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 --- src/mongo/db/s/migration_chunk_cloner_source.h | 2 +- src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp | 5 +++-- src/mongo/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 +++ 5 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src') 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