Search in sources :

Example 1 with ZKDatabase

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));
    }
}
Also used : IOException(java.io.IOException) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) After(org.junit.After)

Example 2 with ZKDatabase

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));
    }
}
Also used : IOException(java.io.IOException) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 3 with ZKDatabase

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());
    }
}
Also used : OSMXBean(org.apache.zookeeper.server.util.OSMXBean) Leader(org.apache.zookeeper.server.quorum.Leader) ServerStats(org.apache.zookeeper.server.ServerStats) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) LeaderZooKeeperServer(org.apache.zookeeper.server.quorum.LeaderZooKeeperServer)

Example 4 with ZKDatabase

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();
}
Also used : TestEndpoint(com.twitter.common.zookeeper.testing.angrybird.gen.TestEndpoint) Stat(org.apache.zookeeper.data.Stat) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ParseException(java.text.ParseException) ZKDatabase(org.apache.zookeeper.server.ZKDatabase)

Example 5 with ZKDatabase

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);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) QuorumMaj(org.apache.zookeeper.server.quorum.flexible.QuorumMaj) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZKDatabase(org.apache.zookeeper.server.ZKDatabase)

Aggregations

ZKDatabase (org.apache.zookeeper.server.ZKDatabase)38 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)17 File (java.io.File)13 IOException (java.io.IOException)9 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)9 Test (org.junit.jupiter.api.Test)9 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)8 Stat (org.apache.zookeeper.data.Stat)6 QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)5 ZooKeeper (org.apache.zookeeper.ZooKeeper)4 TxnHeader (org.apache.zookeeper.txn.TxnHeader)4 ServerStats (org.apache.zookeeper.server.ServerStats)3 Proposal (org.apache.zookeeper.server.quorum.Leader.Proposal)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 TestEndpoint (com.twitter.common.zookeeper.testing.angrybird.gen.TestEndpoint)2 InetSocketAddress (java.net.InetSocketAddress)2 SelectionKey (java.nio.channels.SelectionKey)2 SocketChannel (java.nio.channels.SocketChannel)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2