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);
}
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);
}
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();
}
}
}
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();
}
}
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();
}
Aggregations