Search in sources :

Example 1 with HostMessenger

use of org.voltcore.messaging.HostMessenger in project voltdb by VoltDB.

the class InvocationDispatcher method dispatchStopNode.

private ClientResponseImpl dispatchStopNode(StoredProcedureInvocation task) {
    Object[] params = task.getParams().toArray();
    if (params.length != 1 || params[0] == null) {
        return gracefulFailureResponse("@StopNode must provide hostId", task.clientHandle);
    }
    if (!(params[0] instanceof Integer)) {
        return gracefulFailureResponse("@StopNode must have one Integer parameter specified. Provided type was " + params[0].getClass().getName(), task.clientHandle);
    }
    int ihid = (Integer) params[0];
    final HostMessenger hostMessenger = VoltDB.instance().getHostMessenger();
    Set<Integer> liveHids = hostMessenger.getLiveHostIds();
    if (!liveHids.contains(ihid)) {
        return gracefulFailureResponse("Invalid Host Id or Host Id not member of cluster: " + ihid, task.clientHandle);
    }
    if (!m_cartographer.isClusterSafeIfNodeDies(liveHids, ihid)) {
        hostLog.info("Its unsafe to shutdown node with hostId: " + ihid + " Cannot stop the requested node. Stopping individual nodes is only allowed on a K-safe cluster." + " And all rejoin nodes should be completed." + " Use shutdown to stop the cluster.");
        return gracefulFailureResponse("Cannot stop the requested node. Stopping individual nodes is only allowed on a K-safe cluster." + " And all rejoin nodes should be completed." + " Use shutdown to stop the cluster.", task.clientHandle);
    }
    int hid = hostMessenger.getHostId();
    if (hid == ihid) {
        //Killing myself no pill needs to be sent
        VoltDB.instance().halt();
    } else {
        //Send poison pill with target to kill
        hostMessenger.sendPoisonPill("@StopNode", ihid, ForeignHost.CRASH_ME);
    }
    return new ClientResponseImpl(ClientResponse.SUCCESS, new VoltTable[0], "SUCCESS", task.clientHandle);
}
Also used : HostMessenger(org.voltcore.messaging.HostMessenger) JSONObject(org.json_voltpatches.JSONObject)

Example 2 with HostMessenger

use of org.voltcore.messaging.HostMessenger in project voltdb by VoltDB.

the class TestZK method recoverSite.

public void recoverSite(int site) throws Exception {
    HostMessenger.Config config = new HostMessenger.Config();
    config.internalPort += site;
    config.acceptor = criteria;
    int clientPort = m_ports.next();
    config.zkInterface = "127.0.0.1:" + clientPort;
    m_siteIdToZKPort.put(site, clientPort);
    config.networkThreads = 1;
    HostMessenger hm = new HostMessenger(config, null);
    hm.start();
    MeshProber.prober(hm).waitForDetermination();
    m_messengers.set(site, hm);
}
Also used : HostMessenger(org.voltcore.messaging.HostMessenger)

Example 3 with HostMessenger

use of org.voltcore.messaging.HostMessenger 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 HostMessenger

use of org.voltcore.messaging.HostMessenger in project voltdb by VoltDB.

the class ZKTestBase method setUpZK.

protected void setUpZK(int sites) throws Exception {
    m_siteIdToZKPort = new TreeMap<Integer, Integer>();
    m_clients = new ArrayList<ZooKeeper>();
    m_messengers = new ArrayList<HostMessenger>();
    String[] coordinators = IntStream.range(0, sites).mapToObj(i -> ":" + (i + Constants.DEFAULT_INTERNAL_PORT)).toArray(s -> new String[s]);
    for (int ii = 0; ii < sites; ii++) {
        HostMessenger.Config config = new HostMessenger.Config();
        config.internalPort += ii;
        config.acceptor = MeshProber.builder().coordinators(coordinators).startAction(StartAction.PROBE).hostCount(sites).build();
        int externalPort = m_ports.next();
        config.zkInterface = "127.0.0.1:" + externalPort;
        m_siteIdToZKPort.put(ii, externalPort);
        config.networkThreads = 1;
        HostMessenger hm = new HostMessenger(config, null);
        hm.start();
        m_messengers.add(hm);
    }
    for (HostMessenger hm : m_messengers) {
        MeshProber.prober(hm).waitForDetermination();
    }
}
Also used : IntStream(java.util.stream.IntStream) WatchedEvent(org.apache.zookeeper_voltpatches.WatchedEvent) MeshProber(org.voltdb.probe.MeshProber) Semaphore(java.util.concurrent.Semaphore) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Sets(com.google_voltpatches.common.collect.Sets) KeeperState(org.apache.zookeeper_voltpatches.Watcher.Event.KeeperState) ArrayList(java.util.ArrayList) Watcher(org.apache.zookeeper_voltpatches.Watcher) HostMessenger(org.voltcore.messaging.HostMessenger) HostAndPort(com.google_voltpatches.common.net.HostAndPort) TreeMap(java.util.TreeMap) Map(java.util.Map) Constants(org.voltcore.common.Constants) StartAction(org.voltdb.StartAction) PortGenerator(org.voltcore.utils.PortGenerator) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) HostMessenger(org.voltcore.messaging.HostMessenger)

Example 5 with HostMessenger

use of org.voltcore.messaging.HostMessenger in project voltdb by VoltDB.

the class ZKTestBase method tearDownZK.

protected void tearDownZK() throws Exception {
    for (ZooKeeper keeper : m_clients) {
        keeper.close();
    }
    m_clients.clear();
    for (HostMessenger hm : m_messengers) {
        if (hm != null) {
            hm.shutdown();
        }
    }
    m_messengers.clear();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) HostMessenger(org.voltcore.messaging.HostMessenger)

Aggregations

HostMessenger (org.voltcore.messaging.HostMessenger)11 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)6 HostAndPort (com.google_voltpatches.common.net.HostAndPort)3 JSONObject (org.json_voltpatches.JSONObject)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Matchers.anyLong (org.mockito.Matchers.anyLong)2 BinaryPayloadMessage (org.voltcore.messaging.BinaryPayloadMessage)2 VoltMessage (org.voltcore.messaging.VoltMessage)2 MeshProber (org.voltdb.probe.MeshProber)2 Supplier (com.google_voltpatches.common.base.Supplier)1 Sets (com.google_voltpatches.common.collect.Sets)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SocketException (java.net.SocketException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1