bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { bool all = *cmdObj.firstElement().valuestrsafe() == '*'; int before = result.len(); // TODO: convert to ServerParameters -- SERVER-10515 if (isJournalingEnabled() && (all || cmdObj.hasElement("journalCommitInterval")) && !isMongos()) { result.append("journalCommitInterval", getJournalCommitInterval()); } if( all || cmdObj.hasElement( "traceExceptions" ) ) { result.append("traceExceptions", DBException::traceExceptions); } if( all || cmdObj.hasElement( "replMonitorMaxFailedChecks" ) ) { result.append("replMonitorMaxFailedChecks", ReplicaSetMonitor::getMaxFailedChecks()); } const ServerParameter::Map& m = ServerParameterSet::getGlobal()->getMap(); for ( ServerParameter::Map::const_iterator i = m.begin(); i != m.end(); ++i ) { if ( all || cmdObj.hasElement( i->first.c_str() ) ) { i->second->append( result, i->second->name() ); } } if ( before == result.len() ) { errmsg = "no option found to get"; return false; } return true; }
int run() { if (isMongos()) { toolError() << "mongotop only works on instances of mongod." << std::endl; return EXIT_FAILURE; } NamespaceStats prev = getData(); while ( true ) { sleepsecs(mongoTopGlobalParams.sleep); NamespaceStats now; try { now = getData(); } catch ( std::exception& e ) { toolError() << "can't get data: " << e.what() << std::endl; continue; } if ( now.size() == 0 ) return -2; try { printDiff( prev , now ); } catch ( AssertionException& e ) { toolError() << "\nerror: " << e.what() << std::endl; } prev = now; } return 0; }
bool VersionManager::isVersionableCB(DBClientBase* conn) { // We do not version shard connections when issued from mongod if (!isMongos()) { return false; } return conn->type() == ConnectionString::MASTER || conn->type() == ConnectionString::SET; }
ShardConnection::ShardConnection(OperationContext* opCtx, const ConnectionString& connectionString, const std::string& ns, std::shared_ptr<ChunkManager> manager) : _cs(connectionString), _ns(ns), _manager(manager) { invariant(_cs.isValid()); // This code should never run under a cross-shard transaction invariant(!TransactionRouter::get(opCtx)); // Make sure we specified a manager for the correct namespace if (_ns.size() && _manager) { invariant(_manager->getns().ns() == _ns); } auto csString = _cs.toString(); _conn = ClientConnections::threadInstance()->get(csString, _ns); if (isMongos()) { // In mongos, we record this connection as having been used for useful work to provide // useful information in getLastError. ClusterLastErrorInfo::get(opCtx->getClient())->addShardHost(csString); } }
Status ClientMetadata::parseClientMetadataDocument(const BSONObj& doc) { uint32_t maxLength = kMaxMongoDMetadataDocumentByteLength; if (isMongos()) { maxLength = kMaxMongoSMetadataDocumentByteLength; } if (static_cast<uint32_t>(doc.objsize()) > maxLength) { return Status(ErrorCodes::ClientMetadataDocumentTooLarge, str::stream() << "The client metadata document must be less then or equal to " << maxLength << "bytes"); } // Get a copy so that we can take a stable reference to the app name inside BSONObj docOwned = doc.getOwned(); StringData appName; bool foundDriver = false; bool foundOperatingSystem = false; BSONObjIterator i(docOwned); while (i.more()) { BSONElement e = i.next(); StringData name = e.fieldNameStringData(); if (name == kApplication) { // Application is an optional sub-document, but we require it to be a document if // specified. if (!e.isABSONObj()) { return Status(ErrorCodes::TypeMismatch, str::stream() << "The '" << kApplication << "' field is required to be a BSON document in the " "client metadata document"); } auto swAppName = parseApplicationDocument(e.Obj()); if (!swAppName.getStatus().isOK()) { return swAppName.getStatus(); } appName = swAppName.getValue(); } else if (name == kDriver) { if (!e.isABSONObj()) { return Status(ErrorCodes::TypeMismatch, str::stream() << "The '" << kDriver << "' field is required to be a " "BSON document in the client " "metadata document"); } Status s = validateDriverDocument(e.Obj()); if (!s.isOK()) { return s; } foundDriver = true; } else if (name == kOperatingSystem) { if (!e.isABSONObj()) { return Status(ErrorCodes::TypeMismatch, str::stream() << "The '" << kOperatingSystem << "' field is required to be a BSON document in the " "client metadata document"); } Status s = validateOperatingSystemDocument(e.Obj()); if (!s.isOK()) { return s; } foundOperatingSystem = true; } // Ignore other fields as extra fields are allowed. } // Driver is a required sub document. if (!foundDriver) { return Status(ErrorCodes::ClientMetadataMissingField, str::stream() << "Missing required sub-document '" << kDriver << "' in the client metadata document"); } // OS is a required sub document. if (!foundOperatingSystem) { return Status(ErrorCodes::ClientMetadataMissingField, str::stream() << "Missing required sub-document '" << kOperatingSystem << "' in the client metadata document"); } _document = std::move(docOwned); _appName = std::move(appName); return Status::OK(); }
bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { int s = 0; bool found = false; // TODO: convert to ServerParameters -- SERVER-10515 if( cmdObj.hasElement("journalCommitInterval") ) { if (isMongos()) { errmsg = "cannot set journalCommitInterval on a mongos"; return false; } if(!isJournalingEnabled()) { errmsg = "journaling is off"; return false; } int x = (int) cmdObj["journalCommitInterval"].Number(); verify( x > 1 && x < 500 ); setJournalCommitInterval(x); log() << "setParameter journalCommitInterval=" << x << endl; s++; } if( cmdObj.hasElement( "traceExceptions" ) ) { if( s == 0 ) result.append( "was", DBException::traceExceptions ); DBException::traceExceptions = cmdObj["traceExceptions"].Bool(); s++; } if( cmdObj.hasElement( "replMonitorMaxFailedChecks" ) ) { if( s == 0 ) result.append( "was", ReplicaSetMonitor::getMaxFailedChecks() ); ReplicaSetMonitor::setMaxFailedChecks( cmdObj["replMonitorMaxFailedChecks"].numberInt() ); s++; } const ServerParameter::Map& m = ServerParameterSet::getGlobal()->getMap(); BSONObjIterator i( cmdObj ); i.next(); // skip past command name while ( i.more() ) { BSONElement e = i.next(); ServerParameter::Map::const_iterator j = m.find( e.fieldName() ); if ( j == m.end() ) continue; if ( ! j->second->allowedToChangeAtRuntime() ) { errmsg = str::stream() << "not allowed to change [" << e.fieldName() << "] at runtime"; return false; } if ( s == 0 ) j->second->append( result, "was" ); Status status = j->second->set( e ); if ( status.isOK() ) { s++; continue; } errmsg = status.reason(); result.append( "code", status.code() ); return false; } if( s == 0 && !found ) { errmsg = "no option found to set, use help:true to see options "; return false; } return true; }