summaryrefslogtreecommitdiff
path: root/src/mongo/db/index_builder.cpp
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2018-11-27 14:51:48 -0500
committerLouis Williams <louis.williams@mongodb.com>2018-12-04 13:29:55 -0500
commitcf8fbf54354a805f0bdb5bc4282c8081f4802971 (patch)
tree8d223edb18036a98b73eae8f3827dc912e833bac /src/mongo/db/index_builder.cpp
parentfdf55fe183a07114428c69f091c94800ed9f3dac (diff)
downloadmongo-cf8fbf54354a805f0bdb5bc4282c8081f4802971.tar.gz
SERVER-37911 createIndex via applyOps should notify opObserver in the WUOW of index commit
Diffstat (limited to 'src/mongo/db/index_builder.cpp')
-rw-r--r--src/mongo/db/index_builder.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp
index c8e38cab94d..3335b0a421d 100644
--- a/src/mongo/db/index_builder.cpp
+++ b/src/mongo/db/index_builder.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/curop.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/logical_clock.h"
+#include "mongo/db/op_observer.h"
#include "mongo/db/repl/timestamp_block.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -110,10 +111,14 @@ void _setBgIndexStarting() {
}
} // namespace
-IndexBuilder::IndexBuilder(const BSONObj& index, bool relaxConstraints, Timestamp initIndexTs)
+IndexBuilder::IndexBuilder(const BSONObj& index,
+ IndexConstraints indexConstraints,
+ ReplicatedWrites replicatedWrites,
+ Timestamp initIndexTs)
: BackgroundJob(true /* self-delete */),
_index(index.getOwned()),
- _relaxConstraints(relaxConstraints),
+ _indexConstraints(indexConstraints),
+ _replicatedWrites(replicatedWrites),
_initIndexTs(initIndexTs),
_name(str::stream() << "repl index builder " << _indexBuildCount.addAndFetch(1)) {}
@@ -130,6 +135,12 @@ void IndexBuilder::run() {
auto opCtx = cc().makeOperationContext();
ShouldNotConflictWithSecondaryBatchApplicationBlock shouldNotConflictBlock(opCtx->lockState());
+ // If the calling thread is not replicating writes, neither should this thread.
+ boost::optional<repl::UnreplicatedWritesBlock> unreplicatedWrites;
+ if (_replicatedWrites == ReplicatedWrites::kUnreplicated) {
+ unreplicatedWrites.emplace(opCtx.get());
+ }
+
AuthorizationSession::get(opCtx->getClient())->grantInternalAuthorization();
{
@@ -238,7 +249,8 @@ Status IndexBuilder::_build(OperationContext* opCtx,
}
if (status == ErrorCodes::IndexAlreadyExists ||
- (status == ErrorCodes::IndexOptionsConflict && _relaxConstraints)) {
+ (status == ErrorCodes::IndexOptionsConflict &&
+ _indexConstraints == IndexConstraints::kRelax)) {
LOG(1) << "Ignoring indexing error: " << redact(status);
if (allowBackgroundBuilding) {
// Must set this in case anyone is waiting for this build.
@@ -295,9 +307,12 @@ Status IndexBuilder::_build(OperationContext* opCtx,
return _failIndexBuild(opCtx, indexer, dbLock, status, allowBackgroundBuilding);
}
- status = writeConflictRetry(opCtx, "Commit index build", ns.ns(), [this, opCtx, &indexer, &ns] {
+ status = writeConflictRetry(opCtx, "Commit index build", ns.ns(), [opCtx, coll, &indexer, &ns] {
WriteUnitOfWork wunit(opCtx);
- auto status = indexer.commit();
+ auto status = indexer.commit([opCtx, coll, &ns](const BSONObj& indexSpec) {
+ opCtx->getServiceContext()->getOpObserver()->onCreateIndex(
+ opCtx, ns, *(coll->uuid()), indexSpec, false);
+ });
if (!status.isOK()) {
return status;
}