/* 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; } }
Status Database::dropCollection( const StringData& fullns ) { LOG(1) << "dropCollection: " << fullns << endl; CollectionTemp* collection = getCollectionTemp( fullns ); if ( !collection ) { // collection doesn't exist return Status::OK(); } _initForWrites(); BackgroundOperation::assertNoBgOpInProgForNs( fullns ); if ( collection->_details->getTotalIndexCount() > 0 ) { try { string errmsg; BSONObjBuilder result; if ( !dropIndexes( collection->_details, fullns, "*", errmsg, result, true) ) { warning() << "could not drop collection: " << fullns << " because of " << errmsg << endl; return Status( ErrorCodes::InternalError, errmsg ); } } catch( DBException& e ) { stringstream ss; ss << "drop: dropIndexes for collection failed - consider trying repair "; ss << " cause: " << e.what(); warning() << ss.str() << endl; return Status( ErrorCodes::InternalError, ss.str() ); } verify( collection->_details->getTotalIndexCount() == 0 ); } LOG(1) << "\t dropIndexes done" << endl; ClientCursor::invalidate( fullns ); Top::global.collectionDropped( fullns ); NamespaceDetailsTransient::eraseCollection( fullns.toString() ); dropNS( fullns.toString() ); scoped_lock lk( _collectionLock ); _collections.erase( fullns.toString() ); return Status::OK(); }
virtual ~Base() { if ( !nsd() ) return; string n( ns() ); dropNS( n ); }