summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2023-04-03 11:54:53 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-03 12:40:55 +0000
commit3c65ae2fd3a341fdfb71b8ee043deb878bd41dc3 (patch)
tree1526b47af446b5395601cbb063790ee10f800a39
parent48ac8dc83ca2ed8be7437bab9fef6b74b795495d (diff)
downloadmongo-3c65ae2fd3a341fdfb71b8ee043deb878bd41dc3.tar.gz
SERVER-75520 Properly handle auto-merge responses
-rw-r--r--src/mongo/db/s/balancer/auto_merger_policy.cpp41
-rw-r--r--src/mongo/db/s/balancer/auto_merger_policy_test.cpp8
2 files changed, 23 insertions, 26 deletions
diff --git a/src/mongo/db/s/balancer/auto_merger_policy.cpp b/src/mongo/db/s/balancer/auto_merger_policy.cpp
index 07e53ae8df7..9bcf25a869a 100644
--- a/src/mongo/db/s/balancer/auto_merger_policy.cpp
+++ b/src/mongo/db/s/balancer/auto_merger_policy.cpp
@@ -152,33 +152,30 @@ void AutoMergerPolicy::applyActionResult(OperationContext* opCtx,
const auto& mergeAction = stdx::get<MergeAllChunksOnShardInfo>(action);
- try {
- const auto& swResponse = stdx::get<StatusWith<NumMergedChunks>>(response);
- // swResponse must be ok, otherwise it would not have been possible to parse it as a
- // StatusWith<NumMergedChunks>
- invariant(swResponse.isOK());
+ const auto& swResponse = stdx::get<StatusWith<NumMergedChunks>>(response);
+ if (swResponse.isOK()) {
auto numMergedChunks = swResponse.getValue();
if (numMergedChunks > 0) {
// Reschedule auto-merge for <shard, nss> until no merge has been performed
_rescheduledCollectionsToMergePerShard[mergeAction.shardId].push_back(mergeAction.nss);
}
- } catch (std::exception&) {
- // Parsing of StatusWith<NumMergedChunks> failed, meaning we need to parse a status
- const auto& status = stdx::get<Status>(response);
- if (status.code() == ErrorCodes::ConflictingOperationInProgress) {
- // Reschedule auto-merge for <shard, nss> because commit overlapped with other chunk ops
- _rescheduledCollectionsToMergePerShard[mergeAction.shardId].push_back(mergeAction.nss);
- } else {
- // Reset the history window to consider during next round because chunk merges may have
- // been potentially missed due to an unexpected error
- _maxHistoryTimeCurrentRound = _maxHistoryTimePreviousRound;
- LOGV2_DEBUG(7312600,
- 1,
- "Hit unexpected error while automerging chunks",
- "shard"_attr = mergeAction.shardId,
- "nss"_attr = mergeAction.nss,
- "error"_attr = redact(status));
- }
+ return;
+ }
+
+ const auto status = std::move(swResponse.getStatus());
+ if (status.code() == ErrorCodes::ConflictingOperationInProgress) {
+ // Reschedule auto-merge for <shard, nss> because commit overlapped with other chunk ops
+ _rescheduledCollectionsToMergePerShard[mergeAction.shardId].push_back(mergeAction.nss);
+ } else {
+ // Reset the history window to consider during next round because chunk merges may have
+ // been potentially missed due to an unexpected error
+ _maxHistoryTimeCurrentRound = _maxHistoryTimePreviousRound;
+ LOGV2_DEBUG(7312600,
+ 1,
+ "Hit unexpected error while automerging chunks",
+ "shard"_attr = mergeAction.shardId,
+ "nss"_attr = mergeAction.nss,
+ "error"_attr = redact(status));
}
}
diff --git a/src/mongo/db/s/balancer/auto_merger_policy_test.cpp b/src/mongo/db/s/balancer/auto_merger_policy_test.cpp
index a2b6e123f1c..090fb6e4567 100644
--- a/src/mongo/db/s/balancer/auto_merger_policy_test.cpp
+++ b/src/mongo/db/s/balancer/auto_merger_policy_test.cpp
@@ -419,10 +419,10 @@ TEST_F(AutoMergerPolicyTest, MergeActionRescheduledUponConflictingOperationInPro
auto action = stdx::get<MergeAllChunksOnShardInfo>(*optAction);
ASSERT_EQ(action.nss, nss);
ASSERT_EQ(action.shardId, _shard0);
- _automerger.applyActionResult(
- operationContext(),
- action,
- BalancerStreamActionResponse(Status{ErrorCodes::ConflictingOperationInProgress, "err"}));
+ _automerger.applyActionResult(operationContext(),
+ action,
+ BalancerStreamActionResponse(StatusWith<int>{
+ ErrorCodes::ConflictingOperationInProgress, "err"}));
// Discard merge scheduled for shard1
_automerger.getNextStreamingAction(operationContext());