summaryrefslogtreecommitdiff
path: root/src/mongo/db/index_builder.cpp
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2014-10-29 13:42:26 -0400
committerEric Milkie <milkie@10gen.com>2014-11-03 12:17:01 -0500
commitafce8c3ca626f8fddcd24c7c86de93fd081227cd (patch)
treea668f8de8d42d3c93a127cff6891f3de7d3a19c5 /src/mongo/db/index_builder.cpp
parentdf567c92f07eeb2c2dc92580121703274ac6fc88 (diff)
downloadmongo-afce8c3ca626f8fddcd24c7c86de93fd081227cd.tar.gz
SERVER-14860 Re-add support for interruptable background index builds on secondaries.
Diffstat (limited to 'src/mongo/db/index_builder.cpp')
-rw-r--r--src/mongo/db/index_builder.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp
index 915b468891b..64d13ca974d 100644
--- a/src/mongo/db/index_builder.cpp
+++ b/src/mongo/db/index_builder.cpp
@@ -76,21 +76,21 @@ namespace mongo {
Database* db = dbHolder().get(&txn, ns.db().toString());
- Status status = build(&txn, db, true);
+ Status status = _build(&txn, db, true);
if ( !status.isOK() ) {
- log() << "IndexBuilder could not build index: " << status.toString();
+ error() << "IndexBuilder could not build index: " << status.toString();
}
txn.getClient()->shutdown();
}
Status IndexBuilder::buildInForeground(OperationContext* txn, Database* db) const {
- return build(txn, db, false);
+ return _build(txn, db, false);
}
- Status IndexBuilder::build(OperationContext* txn,
- Database* db,
- bool allowBackgroundBuilding) const {
+ Status IndexBuilder::_build(OperationContext* txn,
+ Database* db,
+ bool allowBackgroundBuilding) const {
const string ns = _index["ns"].String();
Collection* c = db->getCollection( txn, ns );
@@ -104,18 +104,22 @@ namespace mongo {
// Show which index we're building in the curop display.
txn->getCurOp()->setQuery(_index);
-
MultiIndexBlock indexer(txn, c);
indexer.allowInterruption();
if (allowBackgroundBuilding)
indexer.allowBackgroundBuilding();
Status status = Status::OK();
+ IndexDescriptor* descriptor(NULL);
try {
status = indexer.init(_index);
if ( status.code() == ErrorCodes::IndexAlreadyExists )
return Status::OK();
+ if (allowBackgroundBuilding) {
+ descriptor = indexer.registerIndexBuild();
+ }
+
if (status.isOK())
status = indexer.insertAllDocumentsInCollection();
@@ -133,7 +137,10 @@ namespace mongo {
// leave it as-if kill -9 happened. This will be handled on restart.
indexer.abortWithoutCleanup();
}
-
+
+ if (allowBackgroundBuilding) {
+ indexer.unregisterIndexBuild(descriptor);
+ }
return status;
}