mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-558917 Wait until donors/recipients are aware that coordinator has persisted decision before expecting successful collMod, createIndexes, and dropIndexes in resharding_prohibited_commands.js
This commit is contained in:
parent
4e0eecad3a
commit
8179692b36
@ -34,8 +34,20 @@ let ns = sourceCollection.getFullName();
|
||||
|
||||
const topology = DiscoverTopology.findConnectedNodes(mongos);
|
||||
const configPrimary = new Mongo(topology.configsvr.primary);
|
||||
let pauseCoordinatorBeforeRemovingStateDoc =
|
||||
configureFailPoint(configPrimary, "reshardingPauseCoordinatorBeforeRemovingStateDoc");
|
||||
const donor0 = new Mongo(topology.shards[donorShardNames[0]].primary);
|
||||
const donor1 = new Mongo(topology.shards[donorShardNames[1]].primary);
|
||||
|
||||
// TODO SERVER-58950: Remove all calls to isMixedVersionCluster() in this test
|
||||
let pauseCoordinatorBeforeRemovingStateDoc;
|
||||
let pauseBeforeRemoveDonor0Doc;
|
||||
let pauseBeforeRemoveDonor1Doc;
|
||||
if (!reshardingTest.isMixedVersionCluster()) {
|
||||
pauseCoordinatorBeforeRemovingStateDoc =
|
||||
configureFailPoint(configPrimary, "reshardingPauseCoordinatorBeforeRemovingStateDoc");
|
||||
|
||||
pauseBeforeRemoveDonor0Doc = configureFailPoint(donor0, "removeDonorDocFailpoint");
|
||||
pauseBeforeRemoveDonor1Doc = configureFailPoint(donor1, "removeDonorDocFailpoint");
|
||||
}
|
||||
|
||||
let awaitAbort;
|
||||
reshardingTest.withReshardingInBackground(
|
||||
@ -45,10 +57,9 @@ reshardingTest.withReshardingInBackground(
|
||||
},
|
||||
(tempNs) => {
|
||||
const topology = DiscoverTopology.findConnectedNodes(mongos);
|
||||
const donor = new Mongo(topology.shards[donorShardNames[1]].primary);
|
||||
assert.soon(() => {
|
||||
let res =
|
||||
donor.getCollection("config.localReshardingOperations.donor").find().toArray();
|
||||
donor0.getCollection("config.localReshardingOperations.donor").find().toArray();
|
||||
return res.length == 1;
|
||||
}, "timed out waiting for resharding initialization on donor shard");
|
||||
|
||||
@ -60,29 +71,42 @@ reshardingTest.withReshardingInBackground(
|
||||
{
|
||||
expectedErrorCode: ErrorCodes.ReshardCollectionAborted,
|
||||
postDecisionPersistedFn: () => {
|
||||
// Once the coordinator has persisted an abort decision, collMod, createIndexes, and
|
||||
// dropIndexes should be able to succeed
|
||||
assert.soon(() => {
|
||||
const res = mongos.getCollection("config.collections").findOne({_id: ns});
|
||||
let state = res.reshardingFields.state;
|
||||
return state === "aborting";
|
||||
}, () => `timed out waiting for the coordinator to persist decision: ${tojson(res)}`);
|
||||
if (!reshardingTest.isMixedVersionCluster()) {
|
||||
// Once the coordinator has persisted an abort decision, collMod, createIndexes, and
|
||||
// dropIndexes should be able to succeed. Wait until both donors have heard that the
|
||||
// coordinator has made the decision.
|
||||
assert.soon(() => {
|
||||
const res0 =
|
||||
donor0.getCollection("config.cache.collections").findOne({_id: ns});
|
||||
const res1 =
|
||||
donor1.getCollection("config.cache.collections").findOne({_id: ns});
|
||||
return res0.reshardingFields.state === "aborting" &&
|
||||
res1.reshardingFields.state === "aborting";
|
||||
}, () => `timed out waiting for the coordinator to persist decision`);
|
||||
|
||||
const db = mongos.getDB("reshardingDb");
|
||||
assert.commandWorked(db.runCommand({collMod: 'coll'}));
|
||||
assert.commandWorked(db.runCommand(
|
||||
{createIndexes: 'coll', indexes: [{name: "idx1", key: {newKey: 1, oldKey: 1}}]}));
|
||||
assert.commandWorked(
|
||||
db.runCommand({dropIndexes: 'coll', index: {newKey: 1, oldKey: 1}}));
|
||||
const db = mongos.getDB("reshardingDb");
|
||||
assert.commandWorked(db.runCommand({collMod: 'coll'}));
|
||||
assert.commandWorked(db.runCommand({
|
||||
createIndexes: 'coll',
|
||||
indexes: [{name: "idx1", key: {newKey: 1, oldKey: 1}}]
|
||||
}));
|
||||
assert.commandWorked(
|
||||
db.runCommand({dropIndexes: 'coll', index: {newKey: 1, oldKey: 1}}));
|
||||
|
||||
pauseCoordinatorBeforeRemovingStateDoc.off();
|
||||
awaitAbort();
|
||||
pauseBeforeRemoveDonor0Doc.off();
|
||||
pauseBeforeRemoveDonor1Doc.off();
|
||||
pauseCoordinatorBeforeRemovingStateDoc.off();
|
||||
awaitAbort();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pauseCoordinatorBeforeRemovingStateDoc =
|
||||
configureFailPoint(configPrimary, "reshardingPauseCoordinatorBeforeRemovingStateDoc");
|
||||
if (!reshardingTest.isMixedVersionCluster()) {
|
||||
pauseCoordinatorBeforeRemovingStateDoc =
|
||||
configureFailPoint(configPrimary, "reshardingPauseCoordinatorBeforeRemovingStateDoc");
|
||||
}
|
||||
|
||||
let pauseBeforeRemoveRecipientDoc;
|
||||
reshardingTest.withReshardingInBackground(
|
||||
{
|
||||
newShardKeyPattern: {newKey: 1},
|
||||
@ -133,38 +157,56 @@ reshardingTest.withReshardingInBackground(
|
||||
ErrorCodes.ReshardCollectionInProgress);
|
||||
|
||||
mongos.getCollection(newNs).drop();
|
||||
|
||||
if (!reshardingTest.isMixedVersionCluster()) {
|
||||
const recipient = new Mongo(topology.shards[recipientShardNames[0]].primary);
|
||||
pauseBeforeRemoveRecipientDoc =
|
||||
configureFailPoint(recipient, "removeRecipientDocFailpoint");
|
||||
}
|
||||
},
|
||||
{
|
||||
postDecisionPersistedFn: () => {
|
||||
// Once the coordinator has persisted a commit decision, collMod, createIndexes, and
|
||||
// dropIndexes should be able to succeed
|
||||
assert.soon(() => {
|
||||
const res = mongos.getCollection("config.collections").findOne({_id: ns});
|
||||
let state = res.reshardingFields.state;
|
||||
return state === "committing";
|
||||
}, () => `timed out waiting for the coordinator to persist decision: ${tojson(res)}`);
|
||||
if (!reshardingTest.isMixedVersionCluster()) {
|
||||
// Once the coordinator has persisted a commit decision, collMod, createIndexes, and
|
||||
// dropIndexes should be able to succeed. Wait until the recipient is aware that the
|
||||
// coordinator has persisted the decision.
|
||||
const recipient = new Mongo(topology.shards[recipientShardNames[0]].primary);
|
||||
assert.soon(
|
||||
() => {
|
||||
const res =
|
||||
recipient.getCollection("config.cache.collections").findOne({_id: ns});
|
||||
return res.reshardingFields.state === "committing";
|
||||
},
|
||||
() => `timed out waiting for the coordinator to persist decision: ${
|
||||
tojson(res)}`);
|
||||
|
||||
const db = mongos.getDB("reshardingDb");
|
||||
assert.commandWorked(db.runCommand({collMod: 'coll'}));
|
||||
const db = mongos.getDB("reshardingDb");
|
||||
assert.commandWorked(db.runCommand({collMod: 'coll'}));
|
||||
|
||||
// Create two indexes - one (idx1) that we will drop right away to ensure that
|
||||
// dropIndexes succeeds, and the other (idx2) we will check still exists after the
|
||||
// collection has been renamed.
|
||||
assert.commandWorked(db.runCommand(
|
||||
{createIndexes: 'coll', indexes: [{name: "idx1", key: {newKey: 1, oldKey: 1}}]}));
|
||||
assert.commandWorked(db.runCommand(
|
||||
{createIndexes: 'coll', indexes: [{name: "idx2", key: {newKey: 1, x: 1}}]}));
|
||||
// Create two indexes - one (idx1) that we will drop right away to ensure that
|
||||
// dropIndexes succeeds, and the other (idx2) we will check still exists after the
|
||||
// collection has been renamed.
|
||||
assert.commandWorked(db.runCommand({
|
||||
createIndexes: 'coll',
|
||||
indexes: [{name: "idx1", key: {newKey: 1, oldKey: 1}}]
|
||||
}));
|
||||
assert.commandWorked(db.runCommand(
|
||||
{createIndexes: 'coll', indexes: [{name: "idx2", key: {newKey: 1, x: 1}}]}));
|
||||
|
||||
assert.commandWorked(
|
||||
db.runCommand({dropIndexes: 'coll', index: {newKey: 1, oldKey: 1}}));
|
||||
assert.commandWorked(
|
||||
db.runCommand({dropIndexes: 'coll', index: {newKey: 1, oldKey: 1}}));
|
||||
|
||||
pauseCoordinatorBeforeRemovingStateDoc.off();
|
||||
pauseBeforeRemoveRecipientDoc.off();
|
||||
pauseCoordinatorBeforeRemovingStateDoc.off();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Assert that 'idx2' still exists after we've renamed the collection and resharding is finished.
|
||||
let indexes = mongos.getDB("reshardingDb").runCommand({listIndexes: 'coll'});
|
||||
assert(indexes.cursor.firstBatch.some((index) => index.name === 'idx2'));
|
||||
if (!reshardingTest.isMixedVersionCluster()) {
|
||||
let indexes = mongos.getDB("reshardingDb").runCommand({listIndexes: 'coll'});
|
||||
assert(indexes.cursor.firstBatch.some((index) => index.name === 'idx2'));
|
||||
}
|
||||
|
||||
reshardingTest.teardown();
|
||||
})();
|
||||
|
@ -97,9 +97,8 @@ boost::optional<ShardKeyPattern> CollectionMetadata::getReshardingKeyIfShouldFor
|
||||
void CollectionMetadata::throwIfReshardingInProgress(NamespaceString const& nss) const {
|
||||
if (isSharded()) {
|
||||
const auto& reshardingFields = getReshardingFields();
|
||||
if (reshardingFields &&
|
||||
!(reshardingFields->getState() == CoordinatorStateEnum::kCommitting ||
|
||||
reshardingFields->getState() == CoordinatorStateEnum::kAborting)) {
|
||||
// Throw if the coordinator is not in states "aborting", "committing", or "done".
|
||||
if (reshardingFields && reshardingFields->getState() < CoordinatorStateEnum::kAborting) {
|
||||
LOGV2(5277122, "reshardCollection in progress", "namespace"_attr = nss.toString());
|
||||
|
||||
uasserted(ErrorCodes::ReshardCollectionInProgress,
|
||||
|
Loading…
Reference in New Issue
Block a user