void PubSubSendSocket::initSharding(const std::string configServers) { if (!pubsubEnabled) return; vector<string> configdbs; splitStringDelim(configServers, &configdbs, ','); // find config db we are using for pubsub HostAndPort maxConfigHP; maxConfigHP.setPort(0); for (vector<string>::iterator it = configdbs.begin(); it != configdbs.end(); it++) { HostAndPort configHP = HostAndPort(*it); if (configHP.port() > maxConfigHP.port()) maxConfigHP = configHP; } HostAndPort configPullEndpoint = HostAndPort(maxConfigHP.host(), maxConfigHP.port() + 1234); try { dbEventSocket = new zmq::socket_t(zmqContext, ZMQ_PUSH); dbEventSocket->connect(("tcp://" + configPullEndpoint.toString()).c_str()); } catch (zmq::error_t& e) { log() << "PubSub could not connect to config server. Turning off db events..." << causedBy(e); publishDataEvents = false; } }
/** * Save a BSON obj representing the host system's details */ void ProcessInfo::SystemInfo::collectSystemInfo() { struct utsname unameData; if (uname(&unameData) == -1) { log() << "Unable to collect detailed system information: " << strerror(errno) << endl; } char buf_64[32]; char buf_native[32]; if (sysinfo(SI_ARCHITECTURE_64, buf_64, sizeof(buf_64)) != -1 && sysinfo(SI_ARCHITECTURE_NATIVE, buf_native, sizeof(buf_native)) != -1) { addrSize = mongoutils::str::equals(buf_64, buf_native) ? 64 : 32; } else { log() << "Unable to determine system architecture: " << strerror(errno) << endl; } osType = unameData.sysname; osName = mongoutils::str::ltrim(readLineFromFile("/etc/release")); osVersion = unameData.version; pageSize = static_cast<unsigned long long>(sysconf(_SC_PAGESIZE)); memSize = pageSize * static_cast<unsigned long long>(sysconf(_SC_PHYS_PAGES)); numCores = static_cast<unsigned>(sysconf(_SC_NPROCESSORS_CONF)); cpuArch = unameData.machine; hasNuma = checkNumaEnabled(); // We prefer FSync over msync, when: // 1. Pre-Oracle Solaris 11.2 releases // 2. Illumos kernel releases (which is all non Oracle Solaris releases) preferMsyncOverFSync = false; if (mongoutils::str::startsWith(osName, "Oracle Solaris")) { std::vector<std::string> versionComponents; splitStringDelim(osVersion, &versionComponents, '.'); if (versionComponents.size() > 1) { unsigned majorInt, minorInt; Status majorStatus = parseNumberFromString<unsigned>(versionComponents[0], &majorInt); Status minorStatus = parseNumberFromString<unsigned>(versionComponents[1], &minorInt); if (!majorStatus.isOK() || !minorStatus.isOK()) { warning() << "Could not parse OS version numbers from uname: " << osVersion; } else if ((majorInt == 11 && minorInt >= 2) || majorInt > 11) { preferMsyncOverFSync = true; } } else { warning() << "Could not parse OS version string from uname: " << osVersion; } } BSONObjBuilder bExtra; bExtra.append("kernelVersion", unameData.release); bExtra.append("pageSize", static_cast<long long>(pageSize)); bExtra.append("numPages", static_cast<int>(sysconf(_SC_PHYS_PAGES))); bExtra.append("maxOpenFiles", static_cast<int>(sysconf(_SC_OPEN_MAX))); _extraStats = bExtra.obj(); }
boost::filesystem::path ProgramRunner::findProgram(const string& prog) { boost::filesystem::path p = prog; #ifdef _WIN32 // The system programs either come versioned in the form of <utility>-<major.minor> // (e.g., mongorestore-2.4) or just <utility>. For windows, the appropriate extension // needs to be appended. // if (p.extension() != ".exe") { p = prog + ".exe"; } #endif // The file could exist if it is specified as a full path. if (p.is_absolute() && boost::filesystem::exists(p)) { return p; } // Check if the binary exists in the current working directory boost::filesystem::path t = boost::filesystem::current_path() / p; if (boost::filesystem::exists(t)) { return t; } #ifndef _WIN32 // On POSIX, we need to manually resolve the $PATH variable, to try and find the binary in the // filesystem. const char* cpath = getenv("PATH"); if (!cpath) { // PATH was unset, so path search is implementation defined return t; } std::string path(cpath); std::vector<std::string> pathEntries; // PATH entries are separated by colons. Per POSIX 2013, there is no way to escape a colon in // an entry. splitStringDelim(path, &pathEntries, ':'); for (const std::string& pathEntry : pathEntries) { boost::filesystem::path potentialBinary = boost::filesystem::path(pathEntry) / p; if (boost::filesystem::exists(potentialBinary) && boost::filesystem::is_regular_file(potentialBinary) && access(potentialBinary.c_str(), X_OK) == 0) { return potentialBinary; } } #endif return p; }
Status ActionSet::parseActionSetFromString(const std::string& actionsString, ActionSet* result) { std::vector<std::string> actionsList; splitStringDelim(actionsString, &actionsList, ','); std::vector<std::string> unrecognizedActions; Status status = parseActionSetFromStringVector(actionsList, result, &unrecognizedActions); invariantOK(status); if (unrecognizedActions.empty()) { return Status::OK(); } std::string unrecognizedActionsString; joinStringDelim(unrecognizedActions, &unrecognizedActionsString, ','); return Status( ErrorCodes::FailedToParse, str::stream() << "Unrecognized action privilege strings: " << unrecognizedActionsString); }
Status ActionSet::parseActionSetFromString(const std::string& actionsString, ActionSet* result) { std::vector<std::string> actionsList; splitStringDelim(actionsString, &actionsList, ','); ActionSet actions; for (size_t i = 0; i < actionsList.size(); i++) { ActionType action; Status status = ActionType::parseActionFromString(actionsList[i], &action); if (status != Status::OK()) { ActionSet empty; *result = empty; return status; } actions.addAction(action); } *result = actions; return Status::OK(); }
Status ExportedServerParameter< vector<string> >::setFromString( const string& str ) { vector<string> v; splitStringDelim( str, &v, ',' ); return set( v ); }
Status storeMongosOptions(const moe::Environment& params, const std::vector<std::string>& args) { Status ret = storeServerOptions(params, args); if (!ret.isOK()) { return ret; } if ( params.count( "chunkSize" ) ) { int csize = params["chunkSize"].as<int>(); // validate chunksize before proceeding if ( csize == 0 ) { return Status(ErrorCodes::BadValue, "error: need a non-zero chunksize"); } if ( !Chunk::setMaxChunkSizeSizeMB( csize ) ) { return Status(ErrorCodes::BadValue, "MaxChunkSize invalid"); } } if (params.count( "port" ) ) { int port = params["port"].as<int>(); if ( port <= 0 || port > 65535 ) { return Status(ErrorCodes::BadValue, "error: port number must be between 1 and 65535"); } } if ( params.count( "localThreshold" ) ) { serverGlobalParams.defaultLocalThresholdMillis = params["localThreshold"].as<int>(); } if ( params.count( "ipv6" ) ) { enableIPv6(); } if ( params.count( "jsonp" ) ) { serverGlobalParams.jsonp = true; } if (params.count("noscripting")) { // This option currently has no effect for mongos } if (params.count("httpinterface")) { if (params.count("nohttpinterface")) { return Status(ErrorCodes::BadValue, "can't have both --httpinterface and --nohttpinterface"); } serverGlobalParams.isHttpInterfaceEnabled = true; } if (params.count("noAutoSplit")) { warning() << "running with auto-splitting disabled" << endl; Chunk::ShouldAutoSplit = false; } if ( ! params.count( "configdb" ) ) { return Status(ErrorCodes::BadValue, "error: no args for --configdb"); } splitStringDelim(params["configdb"].as<std::string>(), &mongosGlobalParams.configdbs, ','); if (mongosGlobalParams.configdbs.size() != 1 && mongosGlobalParams.configdbs.size() != 3) { return Status(ErrorCodes::BadValue, "need either 1 or 3 configdbs"); } if (mongosGlobalParams.configdbs.size() == 1) { warning() << "running with 1 config server should be done only for testing purposes " << "and is not recommended for production" << endl; } mongosGlobalParams.upgrade = params.count("upgrade"); return Status::OK(); }
Status ActionSet::parseActionSetFromString(const std::string& actionsString, ActionSet* result) { std::vector<std::string> actionsList; splitStringDelim(actionsString, &actionsList, ','); return parseActionSetFromStringVector(actionsList, result); }
Status storeMongosOptions(const moe::Environment& params, const std::vector<std::string>& args) { Status ret = storeServerOptions(params, args); if (!ret.isOK()) { std::cerr << "Error storing command line: " << ret.toString() << std::endl; ::_exit(EXIT_BADOPTIONS); } if ( params.count( "chunkSize" ) ) { int csize = params["chunkSize"].as<int>(); // validate chunksize before proceeding if ( csize == 0 ) { std::cerr << "error: need a non-zero chunksize" << std::endl; ::_exit(EXIT_BADOPTIONS); } if ( !Chunk::setMaxChunkSizeSizeMB( csize ) ) { std::cerr << "MaxChunkSize invalid" << std::endl; ::_exit(EXIT_BADOPTIONS); } } if (params.count( "port" ) ) { int port = params["port"].as<int>(); if ( port <= 0 || port > 65535 ) { out() << "error: port number must be between 1 and 65535" << endl; ::_exit(EXIT_FAILURE); } } if ( params.count( "localThreshold" ) ) { serverGlobalParams.defaultLocalThresholdMillis = params["localThreshold"].as<int>(); } if ( params.count( "ipv6" ) ) { enableIPv6(); } if ( params.count( "jsonp" ) ) { serverGlobalParams.jsonp = true; } if ( params.count( "test" ) ) { ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity( ::mongo::logger::LogSeverity::Debug(5)); StartupTest::runTests(); ::_exit(EXIT_SUCCESS); } if (params.count("noscripting")) { // This option currently has no effect for mongos } if (params.count("httpinterface")) { if (params.count("nohttpinterface")) { std::cerr << "can't have both --httpinterface and --nohttpinterface" << std::endl; ::_exit(EXIT_BADOPTIONS); } serverGlobalParams.isHttpInterfaceEnabled = true; } if (params.count("noAutoSplit")) { warning() << "running with auto-splitting disabled" << endl; Chunk::ShouldAutoSplit = false; } if ( ! params.count( "configdb" ) ) { std::cerr << "error: no args for --configdb" << std::endl; ::_exit(EXIT_BADOPTIONS); } splitStringDelim(params["configdb"].as<std::string>(), &mongosGlobalParams.configdbs, ','); if (mongosGlobalParams.configdbs.size() != 1 && mongosGlobalParams.configdbs.size() != 3) { std::cerr << "need either 1 or 3 configdbs" << std::endl; ::_exit(EXIT_BADOPTIONS); } if (mongosGlobalParams.configdbs.size() == 1) { warning() << "running with 1 config server should be done only for testing purposes " << "and is not recommended for production" << endl; } mongosGlobalParams.upgrade = params.count("upgrade"); return Status::OK(); }
bool ConfigServer::init( string s ) { vector<string> configdbs; splitStringDelim( s, &configdbs, ',' ); return init( configdbs ); }