summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-03-27 17:05:31 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-27 21:18:42 +0000
commita22ca630d0f533af0a260018690699473d51f2ee (patch)
tree2c781a79347956b19b7afdc35cfcb4d1d559ffd6
parentd47240d22e29ae0751fcd2ccb0e088ac3375cd99 (diff)
downloadmongo-a22ca630d0f533af0a260018690699473d51f2ee.tar.gz
Revert "SERVER-39423 Secondaries already possessing an index replicated via startIndexBuild oplog entry should vote for commit immediately"
This reverts commit 4870cb1a9dbefc1007a8d35f0be25d385e9f95f8.
-rw-r--r--jstests/noPassthrough/rolling_index_builds_secondaries_vote_immediately.js103
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp38
-rw-r--r--src/mongo/db/index_builds_coordinator_mongod.cpp27
-rw-r--r--src/mongo/db/repl_index_build_state.h3
4 files changed, 0 insertions, 171 deletions
diff --git a/jstests/noPassthrough/rolling_index_builds_secondaries_vote_immediately.js b/jstests/noPassthrough/rolling_index_builds_secondaries_vote_immediately.js
deleted file mode 100644
index 1b3f0769931..00000000000
--- a/jstests/noPassthrough/rolling_index_builds_secondaries_vote_immediately.js
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * Tests that secondaries already containing an index build started by the primary node vote for
- * committing the index immediately. This will be the case if the secondary indexes were built using
- * the rolling index builds method.
- *
- * @tags: [
- * requires_persistence,
- * requires_replication,
- * ]
- */
-
-(function() {
-'use strict';
-
-const replTest = new ReplSetTest({
- nodes: [
- {},
- {
- // Disallow elections on secondary.
- rsConfig: {
- priority: 0,
- votes: 0,
- }
- },
- {
- // Disallow elections on secondary.
- rsConfig: {
- priority: 0,
- votes: 0,
- }
- },
- ]
-});
-
-const nodes = replTest.startSet();
-replTest.initiate();
-
-const dbName = 'test';
-const collName = 't';
-
-let primary = replTest.getPrimary();
-let primaryDB = primary.getDB(dbName);
-let coll = primaryDB.getCollection(collName);
-
-// Populate the collection to avoid empty collection index build optimization.
-assert.commandWorked(coll.insert({x: 1, y: 1}));
-
-// Make sure the documents make it to the secondaries.
-replTest.awaitReplication();
-
-const secondaries = replTest.getSecondaries();
-const standalonePort = allocatePort();
-jsTestLog('Standalone server will listen on port: ' + standalonePort);
-
-function buildIndexOnNodeAsStandalone(node) {
- jsTestLog('A. Restarting as standalone: ' + node.host);
- replTest.stop(node, /*signal=*/null, /*opts=*/null, {forRestart: true, waitpid: true});
- const standalone = MongoRunner.runMongod({
- restart: true,
- dbpath: node.dbpath,
- port: standalonePort,
- setParameter: {
- disableLogicalSessionCacheRefresh: true,
- ttlMonitorEnabled: false,
- },
- });
- if (jsTestOptions().keyFile) {
- assert(jsTest.authenticate(standalone),
- 'Failed authentication during restart: ' + standalone.host);
- }
-
- jsTestLog('B. Building index on standalone: ' + standalone.host);
- const standaloneDB = standalone.getDB(dbName);
- const standaloneColl = standaloneDB.getCollection(collName);
- assert.commandWorked(standaloneColl.createIndex({x: 1}, {name: 'rolling_index_x_1'}));
-
- jsTestLog('C. Restarting as replica set node: ' + node.host);
- MongoRunner.stopMongod(standalone);
- replTest.restart(node);
- replTest.awaitReplication();
-
- let mongo = new Mongo(node.host);
- mongo.setSlaveOk(true);
- let indexes = mongo.getDB(dbName).getCollection(collName).getIndexes();
- assert.eq(2, indexes.length);
-}
-
-buildIndexOnNodeAsStandalone(secondaries[0]);
-
-jsTestLog('D. Repeat the procedure for the remaining secondary: ' + secondaries[1].host);
-buildIndexOnNodeAsStandalone(secondaries[1]);
-
-replTest.awaitNodesAgreeOnPrimary(
- replTest.kDefaultTimeoutMS, replTest.nodes, replTest.getNodeId(primary));
-
-jsTestLog('E. Build index on the primary: ' + primary.host);
-assert.commandWorked(coll.createIndex({x: 1}, {name: 'rolling_index_x_1'}, 3));
-
-// Ensure we can create an index after doing a rolling index build.
-assert.commandWorked(coll.createIndex({y: 1}, {name: 'post_rolling_index_y_1'}, 3));
-
-replTest.stopSet();
-}());
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index 3fc04b8aff5..f2b3b75b9dc 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -1476,44 +1476,6 @@ IndexBuildsCoordinator::_filterSpecsAndRegisterBuild(
return SharedSemiFuture(indexCatalogStats);
}
- // If all the requested index(es) have already been built on this secondary node due to rolling
- // index builds, we'll be able to vote for committing the index build once an index builder
- // thread gets created.
- auto replCoord = repl::ReplicationCoordinator::get(opCtx);
- if (replCoord->isReplEnabled() && !replCoord->getMemberState().primary()) {
- const IndexCatalog* indexCatalog = collection->getIndexCatalog();
- const bool includeUnfinishedIndexes = true;
-
- bool indexesAlreadyBuilt =
- std::all_of(filteredSpecs.begin(), filteredSpecs.end(), [&](const BSONObj& spec) {
- std::string name = spec.getStringField(IndexDescriptor::kIndexNameFieldName);
- return indexCatalog->findIndexByName(opCtx, name, includeUnfinishedIndexes);
- });
-
- if (indexesAlreadyBuilt) {
- // Register the index build on the secondary. This is needed when the secondary
- // processes the 'commitIndexBuild' oplog entry otherwise it will be forced to rebuild
- // the existing index(es).
- auto replIndexBuildState = std::make_shared<ReplIndexBuildState>(buildUUID,
- collectionUUID,
- dbName.toString(),
- filteredSpecs,
- protocol,
- commitQuorum);
-
- replIndexBuildState->stats.numIndexesBefore = getNumIndexesTotal(opCtx, collection);
- replIndexBuildState->stats.numIndexesAfter = getNumIndexesTotal(opCtx, collection);
- replIndexBuildState->alreadyHasIndexesBuilt = true;
-
- status = _registerIndexBuild(lk, replIndexBuildState);
- if (!status.isOK()) {
- return status;
- }
-
- return boost::none;
- }
- }
-
// Bypass the thread pool if we are building indexes on an empty collection.
if (shouldBuildIndexesOnEmptyCollectionSinglePhased(opCtx, collection, protocol)) {
ReplIndexBuildState::IndexCatalogStats indexCatalogStats;
diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp
index 04260b0e4e2..2eda872cbea 100644
--- a/src/mongo/db/index_builds_coordinator_mongod.cpp
+++ b/src/mongo/db/index_builds_coordinator_mongod.cpp
@@ -220,33 +220,6 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx,
sleepmillis(100);
}
- auto replCoord = repl::ReplicationCoordinator::get(opCtx.get());
- auto replState = invariant(_getIndexBuild(buildUUID));
- if (replCoord->isReplEnabled() && !replCoord->getMemberState().primary() &&
- replState->alreadyHasIndexesBuilt) {
- LOGV2(3942301,
- "Node already has the requested index(es) finished, will vote for committing the "
- "index build",
- "collectionUUID"_attr = replState->collectionUUID,
- "buildUUID"_attr = replState->buildUUID,
- "indexNames"_attr = replState->indexNames,
- "indexSpecs"_attr = replState->indexSpecs);
-
- // Signal that the index build started successfully.
- startPromise.setWith([] {});
-
- _signalPrimaryForCommitReadiness(opCtx.get(), replState);
- _waitForNextIndexBuildAction(opCtx.get(), replState);
-
- {
- stdx::unique_lock<Latch> lk(_mutex);
- _unregisterIndexBuild(lk, replState);
- }
-
- replState->sharedPromise.emplaceValue((replState->stats));
- return;
- }
-
// Index builds should never take the PBWM lock, even on a primary. This allows the
// index build to continue running after the node steps down to a secondary.
ShouldNotConflictWithSecondaryBatchApplicationBlock shouldNotConflictBlock(
diff --git a/src/mongo/db/repl_index_build_state.h b/src/mongo/db/repl_index_build_state.h
index 11c712bf6de..7dd90768bf2 100644
--- a/src/mongo/db/repl_index_build_state.h
+++ b/src/mongo/db/repl_index_build_state.h
@@ -262,9 +262,6 @@ struct ReplIndexBuildState {
// Protects the state below.
mutable Mutex mutex = MONGO_MAKE_LATCH("ReplIndexBuildState::mutex");
- // Whether all the requested index(es) are already built on this node.
- bool alreadyHasIndexesBuilt = false;
-
// Secondaries do not set this information, so it is only set on primaries or on
// transition to primary.
boost::optional<CommitQuorumOptions> commitQuorum;