Пример #1
0
    bool ConfigServer::init( vector<string> configHosts ){
        uassert( 10187 ,  "need configdbs" , configHosts.size() );

        string hn = getHostName();
        if ( hn.empty() ) {
            sleepsecs(5);
            dbexit( EXIT_BADOPTIONS );
        }
        
        set<string> hosts;
        for ( size_t i=0; i<configHosts.size(); i++ ){
            string host = configHosts[i];
            hosts.insert( getHost( host , false ) );
            configHosts[i] = getHost( host , true );
        }
        
        for ( set<string>::iterator i=hosts.begin(); i!=hosts.end(); i++ ){
            string host = *i;
            bool ok = false;
            for ( int x=10; x>0; x-- ){
                if ( ! hostbyname( host.c_str() ).empty() ){
                    ok = true;
                    break;
                }
                log() << "can't resolve DNS for [" << host << "]  sleeping and trying " << x << " more times" << endl;
                sleepsecs( 10 );
            }
            if ( ! ok )
                return false;
        }

        _config = configHosts;
        
        string fullString;
        joinStringDelim( configHosts, &fullString, ',' );
        _primary.setAddress( fullString , true );
        log(1) << " config string : " << fullString << endl;

        return true;
    }
Пример #2
0
    bool ConfigServer::init( vector<string> configHosts ){
        uassert( 10187 ,  "need configdbs" , configHosts.size() );

        string hn = getHostName();
        if ( hn.empty() ) {
            sleepsecs(5);
            dbexit( EXIT_BADOPTIONS );
        }
        ourHostname = hn;
        
        set<string> hosts;
        for ( size_t i=0; i<configHosts.size(); i++ ){
            string host = configHosts[i];
            hosts.insert( getHost( host , false ) );
            configHosts[i] = getHost( host , true );
        }

        for ( set<string>::iterator i=hosts.begin(); i!=hosts.end(); i++ ){
            string host = *i;
            bool ok = false;
            for ( int x=0; x<10; x++ ){
                if ( ! hostbyname( host.c_str() ).empty() ){
                    ok = true;
                    break;
                }
                log() << "can't resolve DNS for [" << host << "]  sleeping and trying " << (10-x) << " more times" << endl;
                sleepsecs( 10 );
            }
            if ( ! ok )
                return false;
        }
        
        uassert( 10188 ,  "can only hand 1 config db right now" , configHosts.size() == 1 );
        _primary = configHosts[0];
        
        return true;
    }
Пример #3
0
 void run() {
     ASSERT_EQUALS( "127.0.0.1", hostbyname( "localhost" ) );
     ASSERT_EQUALS( "127.0.0.1", hostbyname( "127.0.0.1" ) );
 }
Пример #4
0
Status storeMongosOptions(const moe::Environment& params) {
    Status ret = storeServerOptions(params);
    if (!ret.isOK()) {
        return ret;
    }

    if (params.count("net.port")) {
        int port = params["net.port"].as<int>();
        if (port <= 0 || port > 65535) {
            return Status(ErrorCodes::BadValue, "error: port number must be between 1 and 65535");
        }
    }

    if (params.count("noscripting") || params.count("security.javascriptEnabled")) {
        warning() << "The Javascript enabled/disabled options are not supported for mongos. "
                     "(\"noscripting\" and/or \"security.javascriptEnabled\" are set.)";
    }

    if (!params.count("sharding.configDB")) {
        return Status(ErrorCodes::BadValue, "error: no args for --configdb");
    }

    std::string configdbString = params["sharding.configDB"].as<std::string>();

    auto configdbConnectionString = ConnectionString::parse(configdbString);
    if (!configdbConnectionString.isOK()) {
        return configdbConnectionString.getStatus();
    }

    if (configdbConnectionString.getValue().type() != ConnectionString::SET) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "configdb supports only replica set connection string");
    }

    std::vector<HostAndPort> seedServers;
    bool resolvedSomeSeedSever = false;
    for (const auto& host : configdbConnectionString.getValue().getServers()) {
        seedServers.push_back(host);
        if (!seedServers.back().hasPort()) {
            seedServers.back() = HostAndPort{host.host(), ServerGlobalParams::ConfigServerPort};
        }
        if (!hostbyname(seedServers.back().host().c_str()).empty()) {
            resolvedSomeSeedSever = true;
        }
    }
    if (!resolvedSomeSeedSever) {
        if (!hostbyname(configdbConnectionString.getValue().getSetName().c_str()).empty()) {
            warning() << "The replica set name \""
                      << escape(configdbConnectionString.getValue().getSetName())
                      << "\" resolves as a host name, but none of the servers in the seed list do. "
                         "Did you reverse the replica set name and the seed list in "
                      << escape(configdbConnectionString.getValue().toString()) << "?";
        }
    }

    mongosGlobalParams.configdbs =
        ConnectionString{configdbConnectionString.getValue().type(),
                         seedServers,
                         configdbConnectionString.getValue().getSetName()};

    if (mongosGlobalParams.configdbs.getServers().size() < 3) {
        warning() << "Running a sharded cluster with fewer than 3 config servers should only be "
                     "done for testing purposes and is not recommended for production.";
    }

    return Status::OK();
}
Пример #5
0
bool ConfigServer::init( vector<string> configHosts , bool infer ) {
    string hn = getHostName();
    if ( hn.empty() ) {
        sleepsecs(5);
        exit(16);
    }
    ourHostname = hn;

    char buf[256];
    strcpy(buf, hn.c_str());

    if ( configHosts.empty() ) {
        char *p = strchr(buf, '-');
        if ( p )
            p = strchr(p+1, '-');
        if ( !p ) {
            log() << "can't parse server's hostname, expect <city>-<locname>-n<nodenum>, got: " << buf << endl;
            sleepsecs(5);
            exit(17);
        }
        p[1] = 0;
    }

    string left, right; // with :port#
    string hostLeft, hostRight;

    if ( configHosts.empty() ) {
        if ( ! infer ) {
            out() << "--configdb or --infer required\n";
            exit(7);
        }
        stringstream sl, sr;
        sl << buf << "grid-l";
        sr << buf << "grid-r";
        hostLeft = sl.str();
        hostRight = sr.str();
        sl << ":" << Port;
        sr << ":" << Port;
        left = sl.str();
        right = sr.str();
    }
    else {
        hostLeft = getHost( configHosts[0] , false );
        left = getHost( configHosts[0] , true );

        if ( configHosts.size() > 1 ) {
            hostRight = getHost( configHosts[1] , false );
            right = getHost( configHosts[1] , true );
        }
    }


    if ( !isdigit(left[0]) )
        /* this loop is not really necessary, we we print out if we can't connect
           but it gives much prettier error msg this way if the config is totally
           wrong so worthwhile.
           */
        while ( 1 ) {
            if ( hostbyname(hostLeft.c_str()).empty() ) {
                log() << "can't resolve DNS for " << hostLeft << ", sleeping and then trying again" << endl;
                sleepsecs(15);
                continue;
            }
            if ( !hostRight.empty() && hostbyname(hostRight.c_str()).empty() ) {
                log() << "can't resolve DNS for " << hostRight << ", sleeping and then trying again" << endl;
                sleepsecs(15);
                continue;
            }
            break;
        }

    Nullstream& l = log();
    l << "connecting to griddb ";

    if ( !hostRight.empty() ) {
        // connect in paired mode
        l << "L:" << left << " R:" << right << "...";
        l.flush();
        _primary = left + "," + right;
    }
    else {
        l << left << "...";
        l.flush();
        _primary = left;
    }

    return true;
}