/* 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; } }
// Open the dictionary. Creates it if necessary. bool IndexDetails::open(const bool may_create) { const string dname = indexNamespace(); if (may_create) { addNewNamespaceToCatalog(dname); } TOKULOG(1) << "Opening IndexDetails " << dname << endl; try { _db.reset(new storage::Dictionary(dname, _info, *_descriptor, may_create, _info["background"].trueValue())); return true; } catch (storage::Dictionary::NeedsCreate) { if (cc().upgradingSystemUsers() && isSystemUsersCollection(parentNS()) && keyPattern() == oldSystemUsersKeyPattern) { // We're upgrading the system.users collection, and we are missing the old index. // That's ok, we'll signal the caller about this by returning a NULL pointer from // IndexDetails::make. See #673 return false; } // Unlike for NamespaceIndex, this dictionary must exist on disk if we think it should // exist. This error only gets thrown if may_create is false, which happens when we're // trying to open a collection for which we have serialized info. Therefore, this is a // fatal non-user error. msgasserted(16988, mongoutils::str::stream() << "dictionary " << dname << " should exist, but we got ENOENT"); } }
// Open the dictionary. Creates it if necessary. bool IndexDetailsBase::open(const bool may_create, const bool use_memcmp_magic) { const string dname = indexNamespace(); TOKULOG(1) << "Opening IndexDetails " << dname << endl; try { // We use the memcmp magic API only for single-key, ascending _id indexes, // because the _id field is always unique (and therefore we can simply // compare the OID fields if they exist and that will be sufficient) if (use_memcmp_magic) { verify(_unique); } _db.reset(new storage::Dictionary(dname, _info, *_descriptor, may_create, _info["background"].trueValue(), use_memcmp_magic)); return true; } catch (storage::Dictionary::NeedsCreate) { if (cc().upgradingSystemUsers() && isSystemUsersCollection(parentNS()) && keyPattern() == oldSystemUsersKeyPattern) { // We're upgrading the system.users collection, and we are missing the old index. // That's ok, we'll signal the caller about this by returning a NULL pointer from // IndexDetailsBase::make. See #673 return false; } // This dictionary must exist on disk if we think it should exist. // This error only gets thrown if may_create is false, which happens when we're // trying to open a collection for which we have serialized info. // Therefore, this is a fatal non-user error. msgasserted(16988, mongoutils::str::stream() << "dictionary " << dname << " should exist, but we got ENOENT"); } }
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()); } }