Search in sources :

Example 1 with HostAndPort

use of com.google_voltpatches.common.net.HostAndPort in project voltdb by VoltDB.

the class AsyncBenchmark method main.

/**
     * Main routine creates a benchmark instance and kicks off the run method.
     *
     * @param args Command line arguments.
     * @throws Exception if anything goes wrong.
     * @see {@link VoterConfig}
     */
public static void main(String[] args) throws Exception {
    VoltLogger log = new VoltLogger("Benchmark.main");
    // 5 minutes in milliseconds
    final long WAIT_FOR_A_WHILE = 100 * 1000;
    // create a configuration from the arguments
    Config config = new Config();
    config.parse(AsyncBenchmark.class.getName(), args);
    System.out.print(HORIZONTAL_RULE);
    log.info(" Command Line Configuration");
    log.info(HORIZONTAL_RULE);
    log.info(config.getConfigDumpString());
    if (config.latencyreport) {
        log.info("NOTICE: Not implemented in this benchmark client.\n");
    }
    // connect to one or more servers, loop until success
    dbconnect(config.servers);
    log.info("Setting up DDL");
    checkDB = new DataUtils(queue, dqueue, client, config.partitioned);
    checkDB.ddlSetup(config.partitioned);
    connect(config.sockservers);
    CountDownLatch cdl = new CountDownLatch(haplist.size());
    for (HostAndPort hap : haplist.keySet()) {
        AsyncBenchmark benchmark = new AsyncBenchmark(config);
        BenchmarkRunner runner = new BenchmarkRunner(benchmark, cdl, hap);
        runner.start();
    }
    schedulePeriodicStats();
    if (!config.perftest) {
        // start checking the table that's being populated by the socket injester(s)
        while (queue.size() == 0) {
            try {
                // one second.
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
        }
        log.info("Starting CheckData methods. Queue size: " + queue.size());
        checkDB.processQueue();
    }
    log.info("-- waiting for socket writers.");
    // this hangs occasionally, so adding a timeout with a margin
    cdl.await(config.duration + config.warmup + 1, TimeUnit.SECONDS);
    // close socket connections...
    for (HostAndPort hap : haplist.keySet()) {
        OutputStream writer = haplist.get(hap);
        writer.flush();
        writer.close();
    }
    // print the summary results
    printResults();
    if (!config.perftest) {
        log.info("...starting timed check looping... " + queue.size());
        final long queueEndTime = System.currentTimeMillis() + WAIT_FOR_A_WHILE;
        log.info("Continue checking for " + (queueEndTime - System.currentTimeMillis()) / 1000 + " seconds.");
        while (queueEndTime > System.currentTimeMillis()) {
            checkDB.processQueue();
        }
    }
    // final exit criteria -- queue of outstanding importer requests goes to zero
    // but with checking for no-progress so we don't get stuck forever.
    long outstandingRequests = UtilQueries.getImportOutstandingRequests(client);
    long prev_outstandingRequests = outstandingRequests;
    // kinda arbitrary but if outstanding requests is not changing for this interval...
    int waitloops = 10;
    while (outstandingRequests != 0 && waitloops > 0) {
        log.info("Importer outstanding requests is " + outstandingRequests + ". Waiting for zero.");
        outstandingRequests = UtilQueries.getImportOutstandingRequests(client);
        if (prev_outstandingRequests == outstandingRequests) {
            log.info("Outstanding requests unchanged since last interval.");
            waitloops--;
        }
        prev_outstandingRequests = outstandingRequests;
        Thread.sleep(config.displayinterval * 1000);
    }
    client.drain();
    client.close();
    if (!config.perftest) {
        log.info("Queued tuples remaining: " + queue.size());
        log.info("Rows checked against database: " + rowsChecked.get());
        log.info("Mismatch rows (value imported <> value in DB): " + rowsMismatch.get());
    }
    log.info("Total rows added by Socket Injester: " + (warmupCount.get() + runCount.get()));
    log.info("Socket write count: " + socketWrites.get());
    log.info("Socket write exception count: " + socketWriteExceptions.get());
    System.exit(0);
}
Also used : HostAndPort(com.google_voltpatches.common.net.HostAndPort) CLIConfig(org.voltdb.CLIConfig) VoltLogger(org.voltcore.logging.VoltLogger) OutputStream(java.io.OutputStream) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with HostAndPort

use of com.google_voltpatches.common.net.HostAndPort in project voltdb by VoltDB.

the class MeshProber method isValidCoordinatorSpec.

public static boolean isValidCoordinatorSpec(String specifier) {
    if (specifier == null) {
        return false;
    }
    if (specifier.isEmpty()) {
        return true;
    }
    final HostAndPort parsedHost = HostAndPort.fromString(specifier).withDefaultPort(Constants.DEFAULT_INTERNAL_PORT);
    final String host = parsedHost.getHostText();
    if (host.isEmpty()) {
        return true;
    }
    // Try to interpret the specifier as an IP address.  Note we build
    // the address rather than using the .is* methods because we want to
    // use InetAddresses.toUriString to convert the result to a string in
    // canonical form.
    InetAddress addr = null;
    try {
        addr = InetAddresses.forString(host);
    } catch (IllegalArgumentException e) {
    // It is not an IPv4 or IPv6 literal
    }
    if (addr != null) {
        return true;
    }
    // It is not any kind of IP address; must be a domain name or invalid.
    return InternetDomainName.isValid(host);
}
Also used : HostAndPort(com.google_voltpatches.common.net.HostAndPort) InetAddress(java.net.InetAddress)

Example 3 with HostAndPort

use of com.google_voltpatches.common.net.HostAndPort in project voltdb by VoltDB.

the class ZKTestBase method setUpZK.

protected void setUpZK(MeshProber criteria, boolean waitForDetermination) throws Exception {
    m_siteIdToZKPort = new TreeMap<Integer, Integer>();
    m_clients = new ArrayList<ZooKeeper>();
    m_messengers = new ArrayList<HostMessenger>();
    int i = 0;
    for (String coord : criteria.getCoordinators()) {
        HostAndPort hp = HostAndPort.fromString(coord).withDefaultPort(Constants.DEFAULT_INTERNAL_PORT);
        HostMessenger.Config config = new HostMessenger.Config();
        config.acceptor = criteria;
        assert config.internalPort + i == hp.getPort() : "coordinator port mismatches internal port";
        config.internalPort = hp.getPort();
        int externalPort = m_ports.next();
        config.zkInterface = "127.0.0.1:" + externalPort;
        m_siteIdToZKPort.put(i, externalPort);
        config.networkThreads = 1;
        HostMessenger hm = new HostMessenger(config, null);
        hm.start();
        m_messengers.add(hm);
        ++i;
    }
    for (; i < criteria.getHostCount(); ++i) {
        HostMessenger.Config config = new HostMessenger.Config();
        config.acceptor = criteria;
        config.internalPort += i;
        int externalPort = m_ports.next();
        config.zkInterface = "127.0.0.1:" + externalPort;
        m_siteIdToZKPort.put(i, externalPort);
        config.networkThreads = 1;
        HostMessenger hm = new HostMessenger(config, null);
        hm.start();
        m_messengers.add(hm);
    }
    if (waitForDetermination) {
        for (HostMessenger hm : m_messengers) {
            MeshProber.prober(hm).waitForDetermination();
        }
    }
}
Also used : HostAndPort(com.google_voltpatches.common.net.HostAndPort) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) HostMessenger(org.voltcore.messaging.HostMessenger)

Example 4 with HostAndPort

use of com.google_voltpatches.common.net.HostAndPort in project voltdb by VoltDB.

the class RegressionSuite method getClientChannel.

public SocketChannel getClientChannel(final boolean noTearDown) throws IOException {
    final List<String> listeners = m_config.getListenerAddresses();
    final Random r = new Random();
    final String listener = listeners.get(r.nextInt(listeners.size()));
    byte[] hashedPassword = ConnectionUtil.getHashedPassword(m_password);
    HostAndPort hNp = HostAndPort.fromString(listener);
    int port = Constants.DEFAULT_PORT;
    if (hNp.hasPort()) {
        port = hNp.getPort();
    }
    SSLEngine sslEngine = null;
    boolean sslEnabled = Boolean.valueOf(System.getenv("ENABLE_SSL") == null ? Boolean.toString(Boolean.getBoolean("ENABLE_SSL")) : System.getenv("ENABLE_SSL"));
    if (sslEnabled) {
        SSLContext sslContext = SSLConfiguration.createSslContext(new SSLConfiguration.SslConfig());
        sslEngine = sslContext.createSSLEngine("client", port);
        sslEngine.setUseClientMode(true);
    }
    final SocketChannel channel = (SocketChannel) ConnectionUtil.getAuthenticatedConnection(hNp.getHostText(), m_username, hashedPassword, port, null, ClientAuthScheme.getByUnencodedLength(hashedPassword.length), sslEngine)[0];
    channel.configureBlocking(true);
    if (!noTearDown) {
        synchronized (m_clientChannels) {
            m_clientChannels.add(channel);
        }
    }
    return channel;
}
Also used : HostAndPort(com.google_voltpatches.common.net.HostAndPort) SocketChannel(java.nio.channels.SocketChannel) SSLConfiguration(org.voltcore.utils.ssl.SSLConfiguration) Random(java.util.Random) SSLEngine(javax.net.ssl.SSLEngine) SSLContext(javax.net.ssl.SSLContext)

Example 5 with HostAndPort

use of com.google_voltpatches.common.net.HostAndPort in project voltdb by VoltDB.

the class RealVoltDB method buildClusterMesh.

/**
     * Start the voltcore HostMessenger. This joins the node
     * to the existing cluster. In the non rejoin case, this
     * function will return when the mesh is complete. If
     * rejoining, it will return when the node and agreement
     * site are synched to the existing cluster.
     */
MeshProber.Determination buildClusterMesh(ReadDeploymentResults readDepl) {
    final boolean bareAtStartup = m_config.m_forceVoltdbCreate || pathsWithRecoverableArtifacts(readDepl.deployment).isEmpty();
    setBare(bareAtStartup);
    final Supplier<Integer> hostCountSupplier = new Supplier<Integer>() {

        @Override
        public Integer get() {
            return m_clusterSettings.get().hostcount();
        }
    };
    ClusterType clusterType = readDepl.deployment.getCluster();
    MeshProber criteria = MeshProber.builder().coordinators(m_config.m_coordinators).versionChecker(m_versionChecker).enterprise(m_config.m_isEnterprise).startAction(m_config.m_startAction).bare(bareAtStartup).configHash(CatalogUtil.makeDeploymentHashForConfig(readDepl.deploymentBytes)).hostCountSupplier(hostCountSupplier).kfactor(clusterType.getKfactor()).paused(m_config.m_isPaused).nodeStateSupplier(m_statusTracker.getNodeStateSupplier()).addAllowed(m_config.m_enableAdd).safeMode(m_config.m_safeMode).terminusNonce(getTerminusNonce()).missingHostCount(m_config.m_missingHostCount).build();
    HostAndPort hostAndPort = criteria.getLeader();
    String hostname = hostAndPort.getHostText();
    int port = hostAndPort.getPort();
    org.voltcore.messaging.HostMessenger.Config hmconfig;
    hmconfig = new org.voltcore.messaging.HostMessenger.Config(hostname, port);
    if (m_config.m_placementGroup != null) {
        hmconfig.group = m_config.m_placementGroup;
    }
    hmconfig.internalPort = m_config.m_internalPort;
    hmconfig.internalInterface = m_config.m_internalInterface;
    hmconfig.zkInterface = m_config.m_zkInterface;
    hmconfig.deadHostTimeout = m_config.m_deadHostTimeoutMS;
    hmconfig.factory = new VoltDbMessageFactory();
    hmconfig.coreBindIds = m_config.m_networkCoreBindings;
    hmconfig.acceptor = criteria;
    hmconfig.localSitesCount = m_config.m_sitesperhost;
    m_messenger = new org.voltcore.messaging.HostMessenger(hmconfig, this);
    hostLog.info(String.format("Beginning inter-node communication on port %d.", m_config.m_internalPort));
    try {
        m_messenger.start();
    } catch (Exception e) {
        VoltDB.crashLocalVoltDB(e.getMessage(), true, e);
    }
    VoltZK.createPersistentZKNodes(m_messenger.getZK());
    // Use the host messenger's hostId.
    m_myHostId = m_messenger.getHostId();
    hostLog.info(String.format("Host id of this node is: %d", m_myHostId));
    consoleLog.info(String.format("Host id of this node is: %d", m_myHostId));
    MeshProber.Determination determination = criteria.waitForDetermination();
    // paused is determined in the mesh formation exchanged
    if (determination.paused) {
        m_messenger.pause();
    } else {
        m_messenger.unpause();
    }
    // leader and we're rejoining, this is clearly bad.
    if (m_myHostId == 0 && determination.startAction.doesJoin()) {
        VoltDB.crashLocalVoltDB("Unable to rejoin a node to itself.  " + "Please check your command line and start action and try again.", false, null);
    }
    // load or store settings form/to zookeeper
    if (determination.startAction.doesJoin()) {
        m_clusterSettings.load(m_messenger.getZK());
        m_clusterSettings.get().store();
    } else if (m_myHostId == 0) {
        m_clusterSettings.store(m_messenger.getZK());
    }
    m_clusterCreateTime = m_messenger.getInstanceId().getTimestamp();
    return determination;
}
Also used : VoltDbMessageFactory(org.voltdb.messaging.VoltDbMessageFactory) ClusterType(org.voltdb.compiler.deploymentfile.ClusterType) MeshProber(org.voltdb.probe.MeshProber) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException) HostAndPort(com.google_voltpatches.common.net.HostAndPort) HostMessenger(org.voltcore.messaging.HostMessenger) HostMessenger(org.voltcore.messaging.HostMessenger) Supplier(com.google_voltpatches.common.base.Supplier)

Aggregations

HostAndPort (com.google_voltpatches.common.net.HostAndPort)7 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Random (java.util.Random)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JSONException (org.json_voltpatches.JSONException)2 VoltLogger (org.voltcore.logging.VoltLogger)2 HostMessenger (org.voltcore.messaging.HostMessenger)2 Supplier (com.google_voltpatches.common.base.Supplier)1 EOFException (java.io.EOFException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketException (java.net.SocketException)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 ClosedSelectorException (java.nio.channels.ClosedSelectorException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 ExecutionException (java.util.concurrent.ExecutionException)1 SSLContext (javax.net.ssl.SSLContext)1