bool RestAdminAccess::haveAdminUsers() const { Client::Transaction txn(DB_TXN_READ_ONLY | DB_TXN_SNAPSHOT); openAdminDb(); readlocktry rl(/*"admin.system.users", */10000); uassert( 16173 , "couldn't get read lock to get admin auth credentials" , rl.got() ); Client::Context cx( "admin.system.users", dbpath, false ); BSONObj o; NamespaceDetails *d = nsdetails( "admin.system.users" ); bool ok = d != NULL && d->findOne(BSONObj(), o); txn.commit(); return ok; }
bool gtidExistsInOplog(GTID gtid) { Client::ReadContext ctx(rsoplog); // TODO: Should this be using rsOplogDetails, verifying non-null? NamespaceDetails *d = nsdetails(rsoplog); BSONObjBuilder q; BSONObj result; addGTIDToBSON("_id", gtid, q); const bool found = d != NULL && d->findOne( q.done(), result ); return found; }
BSONObj RestAdminAccess::getAdminUser( const string& username ) const { Client::Transaction txn(DB_TXN_READ_ONLY | DB_TXN_SNAPSHOT); openAdminDb(); Client::GodScope gs; readlocktry rl(/*"admin.system.users", */10000); uassert( 16174 , "couldn't get read lock to check admin user" , rl.got() ); Client::Context cx( "admin.system.users" ); BSONObj user; NamespaceDetails *d = nsdetails( "admin.system.users" ); if ( d != NULL && d->findOne( BSON( "user" << username ) , user ) ) { txn.commit(); return user.copy(); } return BSONObj(); }
// find all oplog entries for a given OID in the oplog.refs collection and apply them // TODO this should be a range query on oplog.refs where _id.oid == oid and applyOps to // each entry found. The locking of the query interleaved with the locking in the applyOps // did not work, so it a sequence of point queries. // TODO verify that the query plan is a indexed lookup. // TODO verify that the query plan does not fetch too many docs and then only process one of them. void applyRefOp(BSONObj entry) { OID oid = entry["ref"].OID(); LOG(3) << "apply ref " << entry << " oid " << oid << endl; long long seq = 0; // note that 0 is smaller than any of the seq numbers while (1) { BSONObj entry; { Client::ReadContext ctx(rsOplogRefs); // TODO: Should this be using rsOplogRefsDetails, verifying non-null? NamespaceDetails *d = nsdetails(rsOplogRefs); if (d == NULL || !d->findOne(BSON("_id" << BSON("$gt" << BSON("oid" << oid << "seq" << seq))), entry, true)) { break; } } BSONElement e = entry.getFieldDotted("_id.seq"); seq = e.Long(); BSONElement eOID = entry.getFieldDotted("_id.oid"); if (oid != eOID.OID()) { break; } LOG(3) << "apply " << entry << " seq=" << seq << endl; applyOps(entry["ops"].Array()); } }