use of org.apache.zookeeper.server.ZKDatabase in project hadoop by apache.
the class TestZKClient method tearDown.
@After
public void tearDown() throws IOException, InterruptedException {
if (zks != null) {
ZKDatabase zkDb = zks.getZKDatabase();
factory.shutdown();
try {
zkDb.close();
} catch (IOException ie) {
}
final int PORT = Integer.parseInt(hostPort.split(":")[1]);
Assert.assertTrue("waiting for server down", waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT));
}
}
use of org.apache.zookeeper.server.ZKDatabase in project hadoop by apache.
the class ClientBaseWithFixes method shutdownServerInstance.
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) {
if (factory != null) {
ZKDatabase zkDb;
{
ZooKeeperServer zs = getServer(factory);
zkDb = zs.getZKDatabase();
}
factory.shutdown();
try {
zkDb.close();
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
}
final int PORT = getPort(hostPort);
Assert.assertTrue("waiting for server down", ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT));
}
}
use of org.apache.zookeeper.server.ZKDatabase in project zookeeper by apache.
the class MonitorCommand method commandRun.
@Override
public void commandRun() {
if (!isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
return;
}
ZKDatabase zkdb = zkServer.getZKDatabase();
ServerStats stats = zkServer.serverStats();
print("version", Version.getFullVersion());
print("avg_latency", stats.getAvgLatency());
print("max_latency", stats.getMaxLatency());
print("min_latency", stats.getMinLatency());
print("packets_received", stats.getPacketsReceived());
print("packets_sent", stats.getPacketsSent());
print("num_alive_connections", stats.getNumAliveClientConnections());
print("outstanding_requests", stats.getOutstandingRequests());
print("server_state", stats.getServerState());
print("znode_count", zkdb.getNodeCount());
print("watch_count", zkdb.getDataTree().getWatchCount());
print("ephemerals_count", zkdb.getDataTree().getEphemeralsCount());
print("approximate_data_size", zkdb.getDataTree().approximateDataSize());
OSMXBean osMbean = new OSMXBean();
if (osMbean != null && osMbean.getUnix() == true) {
print("open_file_descriptor_count", osMbean.getOpenFileDescriptorCount());
print("max_file_descriptor_count", osMbean.getMaxFileDescriptorCount());
}
if (stats.getServerState().equals("leader")) {
Leader leader = ((LeaderZooKeeperServer) zkServer).getLeader();
print("followers", leader.getLearners().size());
print("synced_followers", leader.getForwardingFollowers().size());
print("pending_syncs", leader.getNumPendingSyncs());
print("last_proposal_size", leader.getProposalStats().getLastProposalSize());
print("max_proposal_size", leader.getProposalStats().getMaxProposalSize());
print("min_proposal_size", leader.getProposalStats().getMinProposalSize());
}
}
use of org.apache.zookeeper.server.ZKDatabase in project commons by twitter.
the class AngryBirdZooKeeperServer method getSessionIdFromHostPair.
/**
* Returns the session whose corresponding znode encodes "host:port"
*
* @param host ip address of the endpoint
* @param port endpoint port
* @return session id of the corresponding zk session if a match is found.
*/
private Optional<Long> getSessionIdFromHostPair(String host, int port) {
// TODO(vinod): Instead of (host, port) args use the more generic byte[] as args
// so that comparison can be made on znodes that are ServerSet ephemerals
ZKDatabase zkDb = zooKeeperServer.getZKDatabase();
for (long sessionId : zkDb.getSessions()) {
for (String path : zkDb.getEphemerals(sessionId)) {
LOG.info("SessionId:" + sessionId + " Path:" + path);
try {
String data = new String(zkDb.getData(path, new Stat(), null));
LOG.info("Data in znode: " + data);
TestEndpoint endpoint = parseEndpoint(data);
LOG.info("Extracted endpoint " + endpoint);
if (endpoint.getHost().equals(host) && endpoint.getPort() == port) {
LOG.info(String.format("Matching session id %s found for endpoint %s:%s", sessionId, host, port));
return Optional.of(sessionId);
}
} catch (NoNodeException e) {
LOG.severe("Exception getting data for Path:" + path + " : " + e);
} catch (ParseException e) {
LOG.severe("Exception parsing data: " + e);
} catch (NumberFormatException e) {
LOG.severe("Exception in url format " + e);
}
}
}
return Optional.absent();
}
use of org.apache.zookeeper.server.ZKDatabase in project rest.li by linkedin.
the class ZKPeer method setQuorumPeer.
public void setQuorumPeer(int peersCount, Map<Long, QuorumServer> peersView, FileTxnSnapLog fts) throws IOException {
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(new InetSocketAddress("127.0.0.1", _clientPort), _maxClientCnxns);
_peer = QuorumPeer.testingQuorumPeer();
_peer.setClientPortAddress(new InetSocketAddress("127.0.0.1", _clientPort));
_peer.setTxnFactory(fts);
_peer.setQuorumPeers(peersView);
_peer.setElectionType(_electionAlg);
_peer.setMyid(_id);
_peer.setTickTime(_tickTime);
_peer.setMinSessionTimeout(_minSessionTimeout);
_peer.setMaxSessionTimeout(_maxSessionTimeout);
_peer.setInitLimit(_initLimit);
_peer.setSyncLimit(_syncLimit);
_peer.setQuorumVerifier(new QuorumMaj(peersCount));
_peer.setCnxnFactory(cnxnFactory);
_peer.setZKDatabase(new ZKDatabase(_peer.getTxnFactory()));
_peer.setLearnerType(LearnerType.PARTICIPANT);
}
Aggregations