Skip to content

Commit fb9e6ec

Browse files
committed
SERVER-34649 Return a bad status when the MovePrimarySourceManager receives a bad return from commitMovePrimary
1 parent 34333a9 commit fb9e6ec

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ selector:
8282
- jstests/sharding/parallel.js
8383
- jstests/sharding/migrateBig.js
8484
- jstests/sharding/sharding_rs1.js
85+
- jstests/sharding/move_primary_fails_without_database_version.js
8586
# Calls the config server primary directly (not through mongos)
8687
- jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js
8788
- jstests/sharding/min_optime_recovery_on_successful_move_chunk_commit.js

buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ selector:
3131
- jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js
3232
- jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js
3333
- jstests/sharding/move_primary_basic.js
34+
- jstests/sharding/move_primary_fails_without_database_version.js
3435
- jstests/sharding/movePrimary1.js
3536
- jstests/sharding/mongos_validate_writes.js
3637
- jstests/sharding/resume_change_stream_on_subset_of_shards.js

buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards_misc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ selector:
3939
- jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js
4040
- jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js
4141
- jstests/sharding/move_primary_basic.js
42+
- jstests/sharding/move_primary_fails_without_database_version.js
4243
- jstests/sharding/movePrimary1.js
4344
- jstests/sharding/mongos_validate_writes.js
4445
- jstests/sharding/resume_change_stream_on_subset_of_shards.js
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Tests that a movePrimary will fail if the database doesn't have a version in config.databases
2+
(function() {
3+
"use strict";
4+
5+
const dbName = "test";
6+
7+
const st = new ShardingTest({shards: 2});
8+
9+
assert.commandWorked(st.s.getDB("config").getCollection("databases").insert({
10+
_id: dbName,
11+
partitioned: false,
12+
primary: st.shard0.shardName
13+
}));
14+
15+
assert.commandFailedWithCode(st.s.adminCommand({movePrimary: dbName, to: st.shard1.shardName}),
16+
ErrorCodes.InternalError);
17+
18+
st.stop();
19+
})();

src/mongo/db/s/move_primary_source_manager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,19 @@ Status MovePrimarySourceManager::commitOnConfig(OperationContext* opCtx) {
266266
}
267267
}
268268

269+
// We would not be able to guarantee our next database refresh would pick up the write for
270+
// the movePrimary commit (if it happened), because we were unable to get the latest config
271+
// OpTime.
269272
fassert(50762,
270273
validateStatus.withContext(
271274
str::stream() << "Failed to commit movePrimary for database " << getNss().ns()
272275
<< " due to "
273276
<< redact(commitStatus)
274277
<< ". Updating the optime with a write before clearing the "
275278
<< "version also failed"));
279+
280+
// If we can validate but the commit still failed, return the status.
281+
return commitStatus;
276282
}
277283

278284
_state = kCommitted;

0 commit comments

Comments
 (0)