Status dropIndexes(OperationContext* txn, const NamespaceString& ns, const BSONObj& idxDescriptor, BSONObjBuilder* result) { StringData dbName = ns.db(); MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { ScopedTransaction transaction(txn, MODE_IX); AutoGetDb autoDb(txn, dbName, MODE_X); bool userInitiatedWritesAndNotPrimary = txn->writesAreReplicated() && !repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(ns); if (userInitiatedWritesAndNotPrimary) { return Status(ErrorCodes::NotMaster, str::stream() << "Not primary while dropping indexes in " << ns.toString()); } WriteUnitOfWork wunit(txn); Status status = wrappedRun(txn, dbName, ns, autoDb.getDb(), idxDescriptor, result); if (!status.isOK()) { return status; } getGlobalServiceContext()->getOpObserver()->onDropIndex( txn, dbName.toString() + ".$cmd", idxDescriptor); wunit.commit(); } MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "dropIndexes", dbName); return Status::OK(); }
bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { const std::string ns = parseNsCollectionRequired(dbname, jsobj); MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { ScopedTransaction transaction(txn, MODE_IX); AutoGetDb autoDb(txn, dbname, MODE_X); if (!fromRepl && !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() << "Not primary while dropping indexes in " << ns)); } WriteUnitOfWork wunit(txn); bool ok = wrappedRun(txn, dbname, ns, autoDb.getDb(), jsobj, errmsg, result); if (!ok) { return false; } if (!fromRepl) { getGlobalEnvironment()->getOpObserver()->onDropIndex(txn, dbname + ".$cmd", jsobj); } wunit.commit(); } MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "dropIndexes", dbname); return true; }
bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& anObjBuilder, bool fromRepl) { Lock::DBWrite dbXLock(txn->lockState(), dbname); bool ok = wrappedRun(txn, dbname, jsobj, errmsg, anObjBuilder); if (ok && !fromRepl) repl::logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); return ok; }
virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { Lock::GlobalWrite globalWriteLock; DurTransaction txn; bool ok = wrappedRun(&txn, dbname, cmdObj, errmsg, result, fromRepl); if (ok && !fromRepl) logOp(&txn, "c",(dbname + ".$cmd").c_str(), cmdObj); return ok; }
bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& anObjBuilder, bool fromRepl) { Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); WriteUnitOfWork wunit(txn); bool ok = wrappedRun(txn, dbname, jsobj, errmsg, anObjBuilder); if (!ok) { return false; } if (!fromRepl) repl::logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); wunit.commit(); return true; }
Status dropIndexes(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& cmdObj, BSONObjBuilder* result) { return writeConflictRetry(opCtx, "dropIndexes", nss.db(), [opCtx, &nss, &cmdObj, result] { AutoGetCollection autoColl(opCtx, nss, MODE_IX, MODE_X); bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() && !repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, nss); if (userInitiatedWritesAndNotPrimary) { return Status(ErrorCodes::NotMaster, str::stream() << "Not primary while dropping indexes in " << nss); } if (!serverGlobalParams.quiet.load()) { LOG(0) << "CMD: dropIndexes " << nss << ": " << cmdObj[kIndexFieldName].toString(false); } // If db/collection does not exist, short circuit and return. Database* db = autoColl.getDb(); Collection* collection = autoColl.getCollection(); if (!collection) { if (db && ViewCatalog::get(db)->lookup(opCtx, nss.ns())) { return Status(ErrorCodes::CommandNotSupportedOnView, str::stream() << "Cannot drop indexes on view " << nss); } return Status(ErrorCodes::NamespaceNotFound, "ns not found"); } BackgroundOperation::assertNoBgOpInProgForNs(nss); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( collection->uuid().get()); WriteUnitOfWork wunit(opCtx); OldClientContext ctx(opCtx, nss.ns()); Status status = wrappedRun(opCtx, collection, cmdObj, result); if (!status.isOK()) { return status; } wunit.commit(); return Status::OK(); }); }