本文整理汇总了C++中indexcatalog::IndexIterator类的典型用法代码示例。如果您正苦于以下问题:C++ IndexIterator类的具体用法?C++ IndexIterator怎么用?C++ IndexIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IndexIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run() {
OperationContextImpl txn;
Client::WriteContext ctx(&txn, _ns);
int numFinishedIndexesStart = _catalog->numIndexesReady(&txn);
Helpers::ensureIndex(&txn, _coll, BSON("x" << 1), false, "_x_0");
Helpers::ensureIndex(&txn, _coll, BSON("y" << 1), false, "_y_0");
ASSERT_TRUE(_catalog->numIndexesReady(&txn) == numFinishedIndexesStart+2);
IndexCatalog::IndexIterator ii = _catalog->getIndexIterator(&txn,false);
int indexesIterated = 0;
bool foundIndex = false;
while (ii.more()) {
IndexDescriptor* indexDesc = ii.next();
indexesIterated++;
BSONObjIterator boit(indexDesc->infoObj());
while (boit.more() && !foundIndex) {
BSONElement e = boit.next();
if (str::equals(e.fieldName(), "name") &&
str::equals(e.valuestrsafe(), "_y_0")) {
foundIndex = true;
break;
}
}
}
ctx.commit();
ASSERT_TRUE(indexesIterated == _catalog->numIndexesReady(&txn));
ASSERT_TRUE(foundIndex);
}
示例2: getIndexSizeForCollection
long long Database::getIndexSizeForCollection(OperationContext* opCtx,
Collection* coll,
BSONObjBuilder* details,
int scale ) {
if ( !coll )
return 0;
IndexCatalog::IndexIterator ii =
coll->getIndexCatalog()->getIndexIterator( true /*includeUnfinishedIndexes*/ );
long long totalSize = 0;
while ( ii.more() ) {
IndexDescriptor* d = ii.next();
string indNS = d->indexNamespace();
// XXX creating a Collection for an index which isn't a Collection
Collection* indColl = getCollection( opCtx, indNS );
if ( ! indColl ) {
log() << "error: have index descriptor [" << indNS
<< "] but no entry in the index collection." << endl;
continue;
}
totalSize += indColl->dataSize();
if ( details ) {
long long const indexSize = indColl->dataSize() / scale;
details->appendNumber( d->indexName() , indexSize );
}
}
return totalSize;
}
示例3: touch
Status Collection::touch(OperationContext* txn,
bool touchData,
bool touchIndexes,
BSONObjBuilder* output) const {
if (touchData) {
BSONObjBuilder b;
Status status = _recordStore->touch(txn, &b);
if (!status.isOK())
return status;
output->append("data", b.obj());
}
if (touchIndexes) {
Timer t;
IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator(txn, false);
while (ii.more()) {
const IndexDescriptor* desc = ii.next();
const IndexAccessMethod* iam = _indexCatalog.getIndex(desc);
Status status = iam->touch(txn);
if (!status.isOK())
return status;
}
output->append("indexes",
BSON("num" << _indexCatalog.numIndexesTotal(txn) << "millis" << t.millis()));
}
return Status::OK();
}
示例4: renameCollection
Status Database::renameCollection( OperationContext* txn,
const StringData& fromNS,
const StringData& toNS,
bool stayTemp ) {
audit::logRenameCollection( currentClient.get(), fromNS, toNS );
{ // remove anything cached
Collection* coll = getCollection( txn, fromNS );
if ( !coll )
return Status( ErrorCodes::NamespaceNotFound, "collection not found to rename" );
IndexCatalog::IndexIterator ii = coll->getIndexCatalog()->getIndexIterator( true );
while ( ii.more() ) {
IndexDescriptor* desc = ii.next();
_clearCollectionCache( desc->indexNamespace() );
}
{
scoped_lock lk( _collectionLock );
_clearCollectionCache_inlock( fromNS );
_clearCollectionCache_inlock( toNS );
}
Top::global.collectionDropped( fromNS.toString() );
}
return _dbEntry->renameCollection( txn, fromNS, toNS, stayTemp );
}
示例5: truncate
/**
* order will be:
* 1) store index specs
* 2) drop indexes
* 3) truncate record store
* 4) re-write indexes
*/
Status Collection::truncate(OperationContext* txn) {
dassert(txn->lockState()->isCollectionLockedForMode(ns().toString(), MODE_X));
BackgroundOperation::assertNoBgOpInProgForNs(ns());
invariant(_indexCatalog.numIndexesInProgress(txn) == 0);
// 1) store index specs
vector<BSONObj> indexSpecs;
{
IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator(txn, false);
while (ii.more()) {
const IndexDescriptor* idx = ii.next();
indexSpecs.push_back(idx->infoObj().getOwned());
}
}
// 2) drop indexes
Status status = _indexCatalog.dropAllIndexes(txn, true);
if (!status.isOK())
return status;
_cursorManager.invalidateAll(false, "collection truncated");
// 3) truncate record store
status = _recordStore->truncate(txn);
if (!status.isOK())
return status;
// 4) re-create indexes
for (size_t i = 0; i < indexSpecs.size(); i++) {
status = _indexCatalog.createIndexOnEmptyCollection(txn, indexSpecs[i]);
if (!status.isOK())
return status;
}
return Status::OK();
}
示例6: updatePlanCacheIndexEntries
void CollectionInfoCache::updatePlanCacheIndexEntries(OperationContext* opCtx) {
std::vector<IndexEntry> indexEntries;
// TODO We shouldn't need to include unfinished indexes, but we must here because the index
// catalog may be in an inconsistent state. SERVER-18346.
const bool includeUnfinishedIndexes = true;
IndexCatalog::IndexIterator ii =
_collection->getIndexCatalog()->getIndexIterator(opCtx, includeUnfinishedIndexes);
while (ii.more()) {
const IndexDescriptor* desc = ii.next();
const IndexCatalogEntry* ice = ii.catalogEntry(desc);
indexEntries.emplace_back(desc->keyPattern(),
desc->getAccessMethodName(),
desc->isMultikey(opCtx),
ice->getMultikeyPaths(opCtx),
desc->isSparse(),
desc->unique(),
desc->indexName(),
ice->getFilterExpression(),
desc->infoObj(),
ice->getCollator());
}
_planCache->notifyOfIndexEntries(indexEntries);
}
示例7: renameCollection
Status Database::renameCollection(OperationContext* txn,
StringData fromNS,
StringData toNS,
bool stayTemp) {
audit::logRenameCollection(&cc(), fromNS, toNS);
invariant(txn->lockState()->isDbLockedForMode(name(), MODE_X));
BackgroundOperation::assertNoBgOpInProgForNs(fromNS);
BackgroundOperation::assertNoBgOpInProgForNs(toNS);
{ // remove anything cached
Collection* coll = getCollection(fromNS);
if (!coll)
return Status(ErrorCodes::NamespaceNotFound, "collection not found to rename");
string clearCacheReason = str::stream() << "renamed collection '" << fromNS << "' to '"
<< toNS << "'";
IndexCatalog::IndexIterator ii = coll->getIndexCatalog()->getIndexIterator(txn, true);
while (ii.more()) {
IndexDescriptor* desc = ii.next();
_clearCollectionCache(txn, desc->indexNamespace(), clearCacheReason);
}
_clearCollectionCache(txn, fromNS, clearCacheReason);
_clearCollectionCache(txn, toNS, clearCacheReason);
Top::get(txn->getClient()->getServiceContext()).collectionDropped(fromNS.toString());
}
txn->recoveryUnit()->registerChange(new AddCollectionChange(txn, this, toNS));
Status s = _dbEntry->renameCollection(txn, fromNS, toNS, stayTemp);
_collections[toNS] = _getOrCreateCollectionInstance(txn, toNS);
return s;
}
示例8: truncate
/**
* order will be:
* 1) store index specs
* 2) drop indexes
* 3) truncate record store
* 4) re-write indexes
*/
Status Collection::truncate(OperationContext* txn) {
massert( 17445, "index build in progress", _indexCatalog.numIndexesInProgress( txn ) == 0 );
// 1) store index specs
vector<BSONObj> indexSpecs;
{
IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator( txn, false );
while ( ii.more() ) {
const IndexDescriptor* idx = ii.next();
indexSpecs.push_back( idx->infoObj().getOwned() );
}
}
// 2) drop indexes
Status status = _indexCatalog.dropAllIndexes(txn, true);
if ( !status.isOK() )
return status;
_cursorCache.invalidateAll( false );
_infoCache.reset();
// 3) truncate record store
status = _recordStore->truncate(txn);
if ( !status.isOK() )
return status;
// 4) re-create indexes
for ( size_t i = 0; i < indexSpecs.size(); i++ ) {
status = _indexCatalog.createIndexOnEmptyCollection(txn, indexSpecs[i]);
if ( !status.isOK() )
return status;
}
return Status::OK();
}
示例9: renameCollection
Status Database::renameCollection( OperationContext* txn,
StringData fromNS,
StringData toNS,
bool stayTemp ) {
audit::logRenameCollection( currentClient.get(), fromNS, toNS );
invariant(txn->lockState()->isDbLockedForMode(name(), MODE_X));
{ // remove anything cached
Collection* coll = getCollection( fromNS );
if ( !coll )
return Status( ErrorCodes::NamespaceNotFound, "collection not found to rename" );
IndexCatalog::IndexIterator ii = coll->getIndexCatalog()->getIndexIterator( txn, true );
while ( ii.more() ) {
IndexDescriptor* desc = ii.next();
_clearCollectionCache( txn, desc->indexNamespace() );
}
_clearCollectionCache( txn, fromNS );
_clearCollectionCache( txn, toNS );
Top::global.collectionDropped( fromNS.toString() );
}
txn->recoveryUnit()->registerChange( new AddCollectionChange(this, toNS) );
Status s = _dbEntry->renameCollection( txn, fromNS, toNS, stayTemp );
_collections[toNS] = _getOrCreateCollectionInstance(txn, toNS);
return s;
}
示例10: prefetchIndexPages
// page in pages needed for all index lookups on a given object
void prefetchIndexPages(Collection* collection,
const repl::ReplSetImpl::IndexPrefetchConfig& prefetchConfig,
const BSONObj& obj) {
DiskLoc unusedDl; // unused
BSONObjSet unusedKeys;
// do we want prefetchConfig to be (1) as-is, (2) for update ops only, or (3) configured per op type?
// One might want PREFETCH_NONE for updates, but it's more rare that it is a bad idea for inserts.
// #3 (per op), a big issue would be "too many knobs".
switch (prefetchConfig) {
case repl::ReplSetImpl::PREFETCH_NONE:
return;
case repl::ReplSetImpl::PREFETCH_ID_ONLY:
{
TimerHolder timer( &prefetchIndexStats);
// on the update op case, the call to prefetchRecordPages will touch the _id index.
// thus perhaps this option isn't very useful?
try {
IndexDescriptor* desc = collection->getIndexCatalog()->findIdIndex();
if ( !desc )
return;
IndexAccessMethod* iam = collection->getIndexCatalog()->getIndex( desc );
verify( iam );
iam->touch(obj);
}
catch (const DBException& e) {
LOG(2) << "ignoring exception in prefetchIndexPages(): " << e.what() << endl;
}
break;
}
case repl::ReplSetImpl::PREFETCH_ALL:
{
// indexCount includes all indexes, including ones
// in the process of being built
IndexCatalog::IndexIterator ii = collection->getIndexCatalog()->getIndexIterator( true );
while ( ii.more() ) {
TimerHolder timer( &prefetchIndexStats);
// This will page in all index pages for the given object.
try {
IndexDescriptor* desc = ii.next();
IndexAccessMethod* iam = collection->getIndexCatalog()->getIndex( desc );
verify( iam );
iam->touch(obj);
}
catch (const DBException& e) {
LOG(2) << "ignoring exception in prefetchIndexPages(): " << e.what() << endl;
}
unusedKeys.clear();
}
break;
}
default:
fassertFailed(16427);
}
}
示例11: validate
Status Collection::validate( OperationContext* txn,
bool full, bool scanData,
ValidateResults* results, BSONObjBuilder* output ){
MyValidateAdaptor adaptor;
Status status = _recordStore->validate( txn, full, scanData, &adaptor, results, output );
if ( !status.isOK() )
return status;
{ // indexes
output->append("nIndexes", _indexCatalog.numIndexesReady( txn ) );
int idxn = 0;
try {
// Only applicable when 'full' validation is requested.
boost::scoped_ptr<BSONObjBuilder> indexDetails(full ? new BSONObjBuilder() : NULL);
BSONObjBuilder indexes; // not using subObjStart to be exception safe
IndexCatalog::IndexIterator i = _indexCatalog.getIndexIterator(txn, false);
while( i.more() ) {
const IndexDescriptor* descriptor = i.next();
log(LogComponent::kIndex) << "validating index " << descriptor->indexNamespace() << endl;
IndexAccessMethod* iam = _indexCatalog.getIndex( descriptor );
invariant( iam );
boost::scoped_ptr<BSONObjBuilder> bob(
indexDetails.get() ? new BSONObjBuilder(
indexDetails->subobjStart(descriptor->indexNamespace())) :
NULL);
int64_t keys;
iam->validate(txn, full, &keys, bob.get());
indexes.appendNumber(descriptor->indexNamespace(),
static_cast<long long>(keys));
idxn++;
}
output->append("keysPerIndex", indexes.done());
if (indexDetails.get()) {
output->append("indexDetails", indexDetails->done());
}
}
catch ( DBException& exc ) {
string err = str::stream() <<
"exception during index validate idxn "<<
BSONObjBuilder::numStr(idxn) <<
": " << exc.toString();
results->errors.push_back( err );
results->valid = false;
}
}
return Status::OK();
}
示例12: init
void CollectionInfoCache::init(OperationContext* opCtx) {
// Requires exclusive collection lock.
invariant(opCtx->lockState()->isCollectionLockedForMode(_collection->ns().ns(), MODE_X));
const bool includeUnfinishedIndexes = false;
IndexCatalog::IndexIterator ii =
_collection->getIndexCatalog()->getIndexIterator(opCtx, includeUnfinishedIndexes);
while (ii.more()) {
const IndexDescriptor* desc = ii.next();
_indexUsageTracker.registerIndex(desc->indexName(), desc->keyPattern());
}
rebuildIndexData(opCtx);
}
示例13: computeIndexKeys
void CollectionInfoCache::computeIndexKeys() {
DEV Lock::assertWriteLocked( _collection->ns().ns() );
_indexedPaths.clear();
IndexCatalog::IndexIterator i = _collection->getIndexCatalog()->getIndexIterator(true);
while (i.more()) {
IndexDescriptor* descriptor = i.next();
if (descriptor->getAccessMethodName() != IndexNames::TEXT) {
BSONObj key = descriptor->keyPattern();
BSONObjIterator j(key);
while (j.more()) {
BSONElement e = j.next();
_indexedPaths.addPath(e.fieldName());
}
}
else {
fts::FTSSpec ftsSpec(descriptor->infoObj());
if (ftsSpec.wildcard()) {
_indexedPaths.allPathsIndexed();
}
else {
for (size_t i = 0; i < ftsSpec.numExtraBefore(); ++i) {
_indexedPaths.addPath(ftsSpec.extraBefore(i));
}
for (fts::Weights::const_iterator it = ftsSpec.weights().begin();
it != ftsSpec.weights().end();
++it) {
_indexedPaths.addPath(it->first);
}
for (size_t i = 0; i < ftsSpec.numExtraAfter(); ++i) {
_indexedPaths.addPath(ftsSpec.extraAfter(i));
}
// Any update to a path containing "language" as a component could change the
// language of a subdocument. Add the override field as a path component.
_indexedPaths.addPathComponent(ftsSpec.languageOverrideField());
}
}
}
_keysComputed = true;
}
示例14: getIndexSize
uint64_t Collection::getIndexSize(OperationContext* opCtx, BSONObjBuilder* details, int scale) {
IndexCatalog* idxCatalog = getIndexCatalog();
IndexCatalog::IndexIterator ii = idxCatalog->getIndexIterator(opCtx, true);
uint64_t totalSize = 0;
while (ii.more()) {
IndexDescriptor* d = ii.next();
IndexAccessMethod* iam = idxCatalog->getIndex(d);
long long ds = iam->getSpaceUsedBytes(opCtx);
totalSize += ds;
if (details) {
details->appendNumber(d->indexName(), ds / scale);
}
}
return totalSize;
}
示例15: validate
Status Collection::validate( bool full, bool scanData,
ValidateResults* results, BSONObjBuilder* output ){
MyValidateAdaptor adaptor;
Status status = _recordStore->validate( full, scanData, &adaptor, results, output );
if ( !status.isOK() )
return status;
{ // indexes
output->append("nIndexes", _indexCatalog.numIndexesReady() );
int idxn = 0;
try {
BSONObjBuilder indexes; // not using subObjStart to be exception safe
IndexCatalog::IndexIterator i = _indexCatalog.getIndexIterator(false);
while( i.more() ) {
const IndexDescriptor* descriptor = i.next();
log() << "validating index " << descriptor->indexNamespace() << endl;
IndexAccessMethod* iam = _indexCatalog.getIndex( descriptor );
invariant( iam );
int64_t keys;
iam->validate(&keys);
indexes.appendNumber(descriptor->indexNamespace(),
static_cast<long long>(keys));
idxn++;
}
output->append("keysPerIndex", indexes.done());
}
catch ( DBException& exc ) {
string err = str::stream() <<
"exception during index validate idxn "<<
BSONObjBuilder::numStr(idxn) <<
": " << exc.toString();
results->errors.push_back( err );
results->valid = false;
}
}
return Status::OK();
}