mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-49249 initial sync skips single-phase index build if there is an index build already in progress
This commit is contained in:
parent
4739fb2322
commit
77554e9e4f
@ -67,19 +67,15 @@ try {
|
||||
// Resume initial sync. The createIndexes oplog entry will be applied.
|
||||
failPoint.off();
|
||||
|
||||
assert.soon(function() {
|
||||
return rawMongoProgramOutput().search(
|
||||
/Invariant failure.*indexSpecs.size\(\) > 1.*test.coll.*a_1.*multi_index_block\.cpp/) >=
|
||||
0;
|
||||
});
|
||||
// Wait for initial sync to finish.
|
||||
rst.awaitSecondaryNodes();
|
||||
} finally {
|
||||
IndexBuildTest.resumeIndexBuilds(secondary);
|
||||
IndexBuildTest.resumeIndexBuilds(primary);
|
||||
createIdx();
|
||||
}
|
||||
|
||||
IndexBuildTest.assertIndexes(primaryColl, 2, ['_id_', 'a_1']);
|
||||
|
||||
rst.stop(secondary, undefined, {allowedExitCode: MongoRunner.EXIT_ABORT});
|
||||
TestData.skipCheckDBHashes = true;
|
||||
rst.stopSet();
|
||||
})();
|
||||
|
@ -194,6 +194,30 @@ void createIndexForApplyOps(OperationContext* opCtx,
|
||||
opCtx->getWriteConcern());
|
||||
}
|
||||
|
||||
// Check for conflict with two-phase index builds during initial sync. It is possible that
|
||||
// this index may have been dropped and recreated after inserting documents into the collection.
|
||||
auto indexBuildsCoordinator = IndexBuildsCoordinator::get(opCtx);
|
||||
if (OplogApplication::Mode::kInitialSync == mode) {
|
||||
auto normalSpecs =
|
||||
indexBuildsCoordinator->normalizeIndexSpecs(opCtx, indexCollection, {indexSpec});
|
||||
invariant(1U == normalSpecs.size(),
|
||||
str::stream() << "Unexpected result from normalizeIndexSpecs - ns: " << indexNss
|
||||
<< "; uuid: " << indexCollection->uuid()
|
||||
<< "; original index spec: " << indexSpec
|
||||
<< "; normalized index specs: "
|
||||
<< BSON("normalSpecs" << normalSpecs));
|
||||
auto indexCatalog = indexCollection->getIndexCatalog();
|
||||
auto prepareSpecResult = indexCatalog->prepareSpecForCreate(opCtx, normalSpecs[0], {});
|
||||
if (ErrorCodes::IndexBuildAlreadyInProgress == prepareSpecResult) {
|
||||
LOGV2(4924900,
|
||||
"Index build: already in progress during initial sync",
|
||||
"ns"_attr = indexNss,
|
||||
"uuid"_attr = indexCollection->uuid(),
|
||||
"spec"_attr = indexSpec);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(SERVER-48593): Add invariant on shouldRelaxIndexConstraints(opCtx, indexNss) and
|
||||
// set constraints to kRelax.
|
||||
const auto constraints =
|
||||
@ -205,7 +229,6 @@ void createIndexForApplyOps(OperationContext* opCtx,
|
||||
// stop using ghost timestamps. Single phase builds are only used for empty collections, and
|
||||
// to rebuild indexes admin.system collections. See SERVER-47439.
|
||||
IndexBuildsCoordinator::updateCurOpOpDescription(opCtx, indexNss, {indexSpec});
|
||||
auto indexBuildsCoordinator = IndexBuildsCoordinator::get(opCtx);
|
||||
auto collUUID = indexCollection->uuid();
|
||||
auto fromMigrate = false;
|
||||
indexBuildsCoordinator->createIndex(opCtx, collUUID, indexSpec, constraints, fromMigrate);
|
||||
|
Loading…
Reference in New Issue
Block a user