本文整理汇总了C++中ProgressMeterHolder::setTotalWhileRunning方法的典型用法代码示例。如果您正苦于以下问题:C++ ProgressMeterHolder::setTotalWhileRunning方法的具体用法?C++ ProgressMeterHolder::setTotalWhileRunning怎么用?C++ ProgressMeterHolder::setTotalWhileRunning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProgressMeterHolder
的用法示例。
在下文中一共展示了ProgressMeterHolder::setTotalWhileRunning方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drainWritesIntoIndex
//.........这里部分代码省略.........
auto cursor = _sideWritesTable->rs()->getCursor(opCtx);
bool atEof = false;
while (!atEof) {
opCtx->checkForInterrupt();
// Stashed records should be inserted into a batch first.
if (stashed) {
invariant(batch.empty());
batch.push_back(std::move(stashed.get()));
stashed.reset();
}
auto record = cursor->next();
if (record) {
RecordId currentRecordId = record->id;
BSONObj docOut = record->data.toBson().getOwned();
// If the total batch size in bytes would be too large, stash this document and let the
// current batch insert.
int objSize = docOut.objsize();
if (batchSizeBytes + objSize > kBatchMaxBytes) {
invariant(!stashed);
// Stash this document to be inserted in the next batch.
stashed.emplace(currentRecordId, std::move(docOut));
} else {
batchSizeBytes += objSize;
batch.emplace_back(currentRecordId, std::move(docOut));
// Continue if there is more room in the batch.
if (batch.size() < kBatchMaxSize) {
continue;
}
}
} else {
atEof = true;
if (batch.empty())
break;
}
invariant(!batch.empty());
cursor->save();
// If we are here, either we have reached the end of the table or the batch is full, so
// insert everything in one WriteUnitOfWork, and delete each inserted document from the side
// writes table.
auto status = writeConflictRetry(opCtx, "index build drain", _indexCatalogEntry->ns(), [&] {
WriteUnitOfWork wuow(opCtx);
for (auto& operation : batch) {
auto status =
_applyWrite(opCtx, operation.second, options, &totalInserted, &totalDeleted);
if (!status.isOK()) {
return status;
}
// Delete the document from the table as soon as it has been inserted into the
// index. This ensures that no key is ever inserted twice and no keys are skipped.
_sideWritesTable->rs()->deleteRecord(opCtx, operation.first);
}
// For rollback to work correctly, these writes need to be timestamped. The actual time
// is not important, as long as it not older than the most recent visible side write.
IndexTimestampHelper::setGhostCommitTimestampForWrite(
opCtx, NamespaceString(_indexCatalogEntry->ns()));
wuow.commit();
return Status::OK();
});
if (!status.isOK()) {
return status;
}
progress->hit(batch.size());
// Lock yielding will only happen if we are holding intent locks.
_tryYield(opCtx);
cursor->restore();
// Account for more writes coming in during a batch.
progress->setTotalWhileRunning(_sideWritesCounter.loadRelaxed() - appliedAtStart);
_numApplied += batch.size();
batch.clear();
batchSizeBytes = 0;
}
progress->finished();
int logLevel = (_numApplied - appliedAtStart > 0) ? 0 : 1;
LOG(logLevel) << "index build: drain applied " << (_numApplied - appliedAtStart)
<< " side writes (inserted: " << totalInserted << ", deleted: " << totalDeleted
<< ") for '" << _indexCatalogEntry->descriptor()->indexName() << "' in "
<< timer.millis() << " ms";
return Status::OK();
}