summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2015-09-15 14:55:37 -0400
committerMathias Stearn <mathias@10gen.com>2015-09-17 18:21:20 -0400
commit25f24f1e4db441398c3c1592605b45dfb758a631 (patch)
tree3fd74bb5e4b6565402023dfdbe100fbc2bba06d6
parent06d14e5e510d69a902489c66524e186d39608ff3 (diff)
downloadmongo-25f24f1e4db441398c3c1592605b45dfb758a631.tar.gz
SERVER-20213 ReIndex must make majority reads wait for complete visibility
-rw-r--r--jstests/noPassthrough/read_majority.js14
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp9
2 files changed, 20 insertions, 3 deletions
diff --git a/jstests/noPassthrough/read_majority.js b/jstests/noPassthrough/read_majority.js
index 14d3ae38226..64f287590aa 100644
--- a/jstests/noPassthrough/read_majority.js
+++ b/jstests/noPassthrough/read_majority.js
@@ -117,6 +117,14 @@ assertNoReadMajoritySnapshotAvailable();
assert.commandWorked(db.adminCommand({"setCommittedSnapshot": snapshot6}));
assert.eq(getReadMajorityCursor().itcount(), 10);
+// Reindex bumps the min snapshot.
+t.reIndex();
+assertNoReadMajoritySnapshotAvailable();
+var snapshot7 = assert.commandWorked(db.adminCommand("makeSnapshot")).name;
+assertNoReadMajoritySnapshotAvailable();
+assert.commandWorked(db.adminCommand({"setCommittedSnapshot": snapshot7}));
+assert.eq(getReadMajorityCursor().itcount(), 10);
+
// Dropping the collection is visible in the committed snapshot, even though it hasn't been marked
// committed yet. This is allowed by the current specification even though it violates strict
// read-committed semantics since we don't guarantee them on metadata operations.
@@ -125,11 +133,11 @@ assert.eq(getReadMajorityCursor().itcount(), 0);
// Creating a new collection with the same name hides the collection until that operation is in the
// committed view.
-t.insert({_id:0, version: 7});
+t.insert({_id:0, version: 8});
assertNoReadMajoritySnapshotAvailable();
-var snapshot7 = assert.commandWorked(db.adminCommand("makeSnapshot")).name;
+var snapshot8 = assert.commandWorked(db.adminCommand("makeSnapshot")).name;
assertNoReadMajoritySnapshotAvailable();
-assert.commandWorked(db.adminCommand({"setCommittedSnapshot": snapshot7}));
+assert.commandWorked(db.adminCommand({"setCommittedSnapshot": snapshot8}));
assert.eq(getReadMajorityCursor().itcount(), 1);
MongoRunner.stopMongod(testServer);
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index d0e6ac633a5..96757af0834 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -191,6 +191,15 @@ public:
wunit.commit();
}
+ // Do not allow majority reads from this collection until all original indexes are visible.
+ // This was also done when dropAllIndexes() committed, but we need to ensure that no one
+ // tries to read in the intermediate state where all indexes are newer than the current
+ // snapshot so are unable to be used.
+ auto replCoord = repl::ReplicationCoordinator::get(txn);
+ auto snapshotName = replCoord->reserveSnapshotName(txn);
+ replCoord->forceSnapshotCreation(); // Ensures a newer snapshot gets created even if idle.
+ collection->setMinimumVisibleSnapshot(snapshotName);
+
result.append("nIndexes", (int)all.size());
result.append("indexes", all);