summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2016-11-11 16:32:18 -0500
committerEsha Maharishi <esha.maharishi@mongodb.com>2016-11-14 10:31:42 -0500
commit508aae2223da2390b7b22c9d04d7707af7e131a8 (patch)
tree7a478411dd83f9e5612316c4f5268de6bfcdea4d
parent493b1f4bb89d721e630bcd99b1aac2808c8a5161 (diff)
downloadmongo-508aae2223da2390b7b22c9d04d7707af7e131a8.tar.gz
SERVER-27004 move check for pending RangeDeleter deletes to after registering the receive chunk
-rw-r--r--src/mongo/base/error_codes.err1
-rw-r--r--src/mongo/db/s/migration_destination_manager_legacy_commands.cpp27
2 files changed, 15 insertions, 13 deletions
diff --git a/src/mongo/base/error_codes.err b/src/mongo/base/error_codes.err
index 3eb5740d743..46e051afc9c 100644
--- a/src/mongo/base/error_codes.err
+++ b/src/mongo/base/error_codes.err
@@ -197,6 +197,7 @@ error_code("ViewPipelineMaxSizeExceeded", 195)
error_code("InvalidIndexSpecificationOption", 197)
error_code("OBSOLETE_ReceivedOpReplyMessage", 198)
error_code("ReplicaSetMonitorRemoved", 199)
+error_code("ChunkRangeCleanupPending", 200)
# Non-sequential error codes (for compatibility only)
error_code("SocketException", 9001)
diff --git a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp
index 781029b7405..a20db670259 100644
--- a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp
+++ b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp
@@ -93,19 +93,6 @@ public:
BSONObjBuilder& result) {
ShardingState* const shardingState = ShardingState::get(txn);
- // Pending deletes (for migrations) are serialized by the distributed collection lock,
- // we are sure we registered a delete for a range *before* we can migrate-in a
- // subrange.
- const size_t numDeletes = getDeleter()->getTotalDeletes();
- if (numDeletes > 0) {
- errmsg = str::stream() << "can't accept new chunks because "
- << " there are still " << numDeletes
- << " deletes from previous migration";
-
- warning() << errmsg;
- return false;
- }
-
const ShardId toShard(cmdObj["toShardName"].String());
const ShardId fromShard(cmdObj["fromShardName"].String());
@@ -163,9 +150,23 @@ public:
const MigrationSessionId migrationSessionId(
uassertStatusOK(MigrationSessionId::extractFromBSON(cmdObj)));
+ // Ensure this shard is not currently receiving or donating any chunks.
auto scopedRegisterReceiveChunk(
uassertStatusOK(shardingState->registerReceiveChunk(nss, chunkRange, fromShard)));
+ // Even if this shard is not currently donating any chunks, it may still have pending
+ // deletes from a previous migration, particularly if there are still open cursors on the
+ // range pending deletion.
+ const size_t numDeletes = getDeleter()->getTotalDeletes();
+ if (numDeletes > 0) {
+ errmsg = str::stream() << "can't accept new chunks because "
+ << " there are still " << numDeletes
+ << " deletes from previous migration";
+
+ warning() << errmsg;
+ return appendCommandStatus(result, {ErrorCodes::ChunkRangeCleanupPending, errmsg});
+ }
+
uassertStatusOK(shardingState->migrationDestinationManager()->start(
nss,
std::move(scopedRegisterReceiveChunk),