summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie Anderson <jamie.anderson@mongodb.com>2021-04-30 15:05:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-04 15:05:06 +0000
commit8ed8f5bbd665b5601c08e08094b01ade51cc4576 (patch)
tree58d8c6a4fde8727484df11bbd1cd682d3c552f94
parent8fdd8568c58310cbb1d4e177d95ec63955f6c1aa (diff)
downloadmongo-8ed8f5bbd665b5601c08e08094b01ade51cc4576.tar.gz
SERVER-55600: Indicate to resharding metrics system if a resharding operation has been cancelled
-rw-r--r--jstests/sharding/resharding_abort_command.js21
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.cpp3
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics_test.cpp21
3 files changed, 44 insertions, 1 deletions
diff --git a/jstests/sharding/resharding_abort_command.js b/jstests/sharding/resharding_abort_command.js
index f4045840d03..a5d7d609fd9 100644
--- a/jstests/sharding/resharding_abort_command.js
+++ b/jstests/sharding/resharding_abort_command.js
@@ -177,6 +177,11 @@ const runAbortWithFailpoint = (failpointName, failpointNodeType, abortLocation,
const topology = DiscoverTopology.findConnectedNodes(mongos);
const configsvr = new Mongo(topology.configsvr.nodes[0]);
+ let reshardingMetrics = configsvr.getDB('admin').serverStatus({}).shardingStatistics.resharding;
+ const reshardingOperationsInitialCount = reshardingMetrics.countReshardingOperations;
+ const reshardingSuccessesInitialCount = reshardingMetrics.countReshardingSuccessful;
+ const reshardingCanceledInitialCount = reshardingMetrics.countReshardingCanceled;
+
let expectedAbortErrorCodes = ErrorCodes.OK;
let expectedReshardingErrorCode = ErrorCodes.ReshardCollectionAborted;
@@ -275,6 +280,22 @@ const runAbortWithFailpoint = (failpointName, failpointNodeType, abortLocation,
}
}
});
+
+ reshardingMetrics = configsvr.getDB('admin').serverStatus({}).shardingStatistics.resharding;
+ const reshardingOperationsFinalCount = reshardingMetrics.countReshardingOperations;
+ const reshardingSuccessesFinalCount = reshardingMetrics.countReshardingSuccessful;
+ const reshardingCanceledFinalCount = reshardingMetrics.countReshardingCanceled;
+
+ assert(reshardingOperationsFinalCount == reshardingOperationsInitialCount + 1);
+
+ if (expectedReshardingErrorCode == ErrorCodes.OK) {
+ assert.eq(reshardingSuccessesFinalCount, reshardingSuccessesInitialCount + 1);
+ assert.eq(reshardingCanceledInitialCount, reshardingCanceledFinalCount);
+ } else if (expectedAbortErrorCodes == ErrorCodes.OK) {
+ assert.eq(reshardingCanceledFinalCount, reshardingCanceledInitialCount + 1);
+ assert.eq(reshardingSuccessesInitialCount, reshardingSuccessesFinalCount);
+ }
+
reshardingTest.teardown();
abortThread.join();
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
index b9546aabbaa..256617eff89 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
@@ -967,9 +967,10 @@ ExecutorFuture<void> waitForMinimumOperationDuration(
void markCompleted(const Status& status) {
auto metrics = ReshardingMetrics::get(cc().getServiceContext());
- // TODO SERVER-52770 to process the cancellation of resharding operations.
if (status.isOK())
metrics->onCompletion(ReshardingOperationStatusEnum::kSuccess);
+ else if (status == ErrorCodes::ReshardCollectionAborted)
+ metrics->onCompletion(ReshardingOperationStatusEnum::kCanceled);
else
metrics->onCompletion(ReshardingOperationStatusEnum::kFailure);
}
diff --git a/src/mongo/db/s/resharding/resharding_metrics_test.cpp b/src/mongo/db/s/resharding/resharding_metrics_test.cpp
index dead907849d..1e7322aef1b 100644
--- a/src/mongo/db/s/resharding/resharding_metrics_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_metrics_test.cpp
@@ -236,6 +236,27 @@ TEST_F(ReshardingMetricsTest, CumulativeOpMetricsAreRetainedAfterCompletion) {
kTag, kDocumentsToCopy, "Cumulative metrics are reset", OpReportType::CumulativeReport);
}
+TEST_F(ReshardingMetricsTest, CumulativeOpMetricsAreRetainedAfterCancellation) {
+ auto constexpr kTag = "documentsCopied";
+ getMetrics()->onStart();
+ const auto kDocumentsToCopy = 2;
+ const auto kBytesToCopy = 200;
+ getMetrics()->setRecipientState(RecipientStateEnum::kCloning);
+ getMetrics()->onDocumentsCopied(kDocumentsToCopy, kBytesToCopy);
+ advanceTime();
+ getMetrics()->onCompletion(ReshardingOperationStatusEnum::kCanceled);
+ advanceTime();
+
+ checkMetrics(kTag,
+ kDocumentsToCopy,
+ "Cumulative metrics are not retained",
+ OpReportType::CumulativeReport);
+
+ getMetrics()->onStart();
+ checkMetrics(
+ kTag, kDocumentsToCopy, "Cumulative metrics are reset", OpReportType::CumulativeReport);
+}
+
TEST_F(ReshardingMetricsTest, CurrentOpMetricsAreResetAfterCompletion) {
auto constexpr kTag = "documentsCopied";
getMetrics()->onStart();