diff options
author | Jamie Heppenstall <jamie.heppenstall@mongodb.com> | 2020-05-12 15:51:19 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-29 18:21:52 +0000 |
commit | 495ea4a50219e08ac7a4e1bcd58dc4935f5f0173 (patch) | |
tree | 7407a1eb1795bf8e1454051d7f8d8c47299eea40 | |
parent | b336188806b945ae3e68d0c5cdfbd09aa164e9b6 (diff) | |
download | mongo-495ea4a50219e08ac7a4e1bcd58dc4935f5f0173.tar.gz |
SERVER-45570 Add a ProgressMeter to the index build startup recovery code path
(cherry picked from commit c6f6dc29665d8609f040c66c7107c270b813bc95)
-rw-r--r-- | src/mongo/db/catalog/index_builds_manager.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp index 7ad6d6b1c70..c4d1df22359 100644 --- a/src/mongo/db/catalog/index_builds_manager.cpp +++ b/src/mongo/db/catalog/index_builds_manager.cpp @@ -42,6 +42,7 @@ #include "mongo/db/storage/write_unit_of_work.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" +#include "mongo/util/progress_meter.h" #include "mongo/util/str.h" namespace mongo { @@ -147,6 +148,14 @@ StatusWith<std::pair<long long, long long>> IndexBuildsManager::startBuildingInd long long numRecords = 0; long long dataSize = 0; + const char* curopMessage = "Index Build: scanning collection"; + ProgressMeterHolder progressMeter; + { + stdx::unique_lock<Client> lk(*opCtx->getClient()); + progressMeter.set( + CurOp::get(opCtx)->setProgress_inlock(curopMessage, coll->numRecords(opCtx))); + } + auto cursor = rs->getCursor(opCtx); auto record = cursor->next(); while (record) { @@ -174,6 +183,9 @@ StatusWith<std::pair<long long, long long>> IndexBuildsManager::startBuildingInd warning() << "Invalid BSON detected at " << id << ": " << redact(validStatus) << ". Deleting."; rs->deleteRecord(opCtx, id); + // Must reduce the progress meter's expected total after deleting an invalid + // document from the collection. + progressMeter->setTotalWhileRunning(coll->numRecords(opCtx)); } else { numRecords++; dataSize += data.size(); @@ -181,6 +193,7 @@ StatusWith<std::pair<long long, long long>> IndexBuildsManager::startBuildingInd if (!insertStatus.isOK()) { return insertStatus; } + progressMeter.hit(); } record = cursor->next(); } @@ -204,6 +217,8 @@ StatusWith<std::pair<long long, long long>> IndexBuildsManager::startBuildingInd } } + progressMeter.finished(); + Status status = builder->dumpInsertsFromBulk(opCtx); if (!status.isOK()) { return status; |