/* delete this index. does NOT clean up the system catalog (system.indexes or system.namespaces) -- only NamespaceIndex. */ void IndexDetails::kill_idx() { string ns = indexNamespace(); // e.g. foo.coll.$ts_1 try { string pns = parentNS(); // note we need a copy, as parentNS() won't work after the drop() below // clean up parent namespace index cache NamespaceDetailsTransient::get_w( pns.c_str() ).deletedIndex(); string name = indexName(); /* important to catch exception here so we can finish cleanup below. */ try { dropNS(ns.c_str()); } catch(DBException& ) { log(2) << "IndexDetails::kill(): couldn't drop ns " << ns << endl; } head.setInvalid(); info.setInvalid(); // clean up in system.indexes. we do this last on purpose. int n = removeFromSysIndexes(pns.c_str(), name.c_str()); wassert( n == 1 ); } catch ( DBException &e ) { log() << "exception in kill_idx: " << e << ", ns: " << ns << endl; } }
void IndexDetails::kill_idx() { const string ns = indexNamespace(); const string parentns = parentNS(); close(); storage::db_remove(ns); // Removing this index's ns from the system.indexes/namespaces catalog. removeNamespaceFromCatalog(ns); if (nsToCollectionSubstring(parentns) != "system.indexes") { removeFromSysIndexes(parentns, indexName()); } }
bool dropIndexes(NamespaceDetails *d, const char *ns, const char *name, string &errmsg, BSONObjBuilder &anObjBuilder, bool mayDeleteIdIndex) { BackgroundOperation::assertNoBgOpInProgForNs(ns); /* there may be pointers pointing at keys in the btree(s). kill them. */ ClientCursor::invalidate(ns); // delete a specific index or all? if ( *name == '*' && name[1] == 0 ) { // this should be covered by assertNoBgOpInProgForNs above, but being paranoid verify( d->getCompletedIndexCount() == d->getTotalIndexCount() ); LOG(4) << " d->nIndexes was " << d->getCompletedIndexCount() << std::endl; anObjBuilder.appendNumber("nIndexesWas", d->getCompletedIndexCount() ); IndexDetails *idIndex = 0; for ( int i = 0; i < d->getCompletedIndexCount(); i++ ) { if ( !mayDeleteIdIndex && d->idx(i).isIdIndex() ) { idIndex = &d->idx(i); continue; } d->removeIndex( i ); i--; } if ( idIndex ) { verify( d->getCompletedIndexCount() == 1 ); } //verify( 0 == assureSysIndexesEmptied(ns, idIndex) );// TODO(erh) assureSysIndexesEmptied(ns, idIndex); anObjBuilder.append("msg", mayDeleteIdIndex ? "indexes dropped for collection" : "non-_id indexes dropped for collection"); } else { // delete just one index int x = d->findIndexByName(name); if ( x >= 0 ) { if ( !mayDeleteIdIndex && d->idx(x).isIdIndex() ) { errmsg = "may not delete _id index"; return false; } LOG(4) << " d->nIndexes was " << d->getCompletedIndexCount() << endl; anObjBuilder.appendNumber("nIndexesWas", d->getCompletedIndexCount() ); d->removeIndex( x ); } else { int n = removeFromSysIndexes(ns, name); // just in case an orphaned listing there - i.e. should have been repaired but wasn't if( n ) { log() << "info: removeFromSysIndexes cleaned up " << n << " entries" << endl; } log() << "dropIndexes: " << name << " not found" << endl; errmsg = "index not found"; return false; } } return true; }