summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2018-04-24 13:45:59 -0400
committerLouis Williams <louis.williams@mongodb.com>2018-04-25 14:46:00 -0400
commit2deac715b6345a8103acc1da6187f77e65843019 (patch)
tree59ea003be40f3e8b0a1ab923bc42c07a9384b3d6
parent210caef9918d3846d17252add50d955c80dec73f (diff)
downloadmongo-2deac715b6345a8103acc1da6187f77e65843019.tar.gz
SERVER-34639 Background indexes on primaries should advance the minimumVisibleSnapshot when they begin
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index 1e1cc649afe..e19773b34fd 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -409,11 +409,12 @@ Status IndexCatalogImpl::IndexBuildBlock::init() {
_indexName = descriptor->indexName();
_indexNamespace = descriptor->indexNamespace();
+ bool isBackgroundIndex = _spec["background"].trueValue();
bool isBackgroundSecondaryBuild = false;
if (auto replCoord = repl::ReplicationCoordinator::get(_opCtx)) {
isBackgroundSecondaryBuild =
replCoord->getReplicationMode() == repl::ReplicationCoordinator::Mode::modeReplSet &&
- replCoord->getMemberState().secondary() && _spec["background"].trueValue();
+ replCoord->getMemberState().secondary() && isBackgroundIndex;
}
// Setup on-disk structures.
@@ -422,12 +423,13 @@ Status IndexCatalogImpl::IndexBuildBlock::init() {
if (!status.isOK())
return status;
- if (isBackgroundSecondaryBuild) {
+ if (isBackgroundIndex) {
_opCtx->recoveryUnit()->onCommit([&] {
- auto commitTs = _opCtx->recoveryUnit()->getCommitTimestamp();
- if (!commitTs.isNull()) {
- _collection->setMinimumVisibleSnapshot(commitTs);
- }
+ // This will prevent the unfinished index from being visible on index iterators.
+ auto minVisible =
+ repl::ReplicationCoordinator::get(_opCtx)->getMinimumVisibleSnapshot(_opCtx);
+ _entry->setMinimumVisibleSnapshot(minVisible);
+ _collection->setMinimumVisibleSnapshot(minVisible);
});
}