Search in sources :

Example 36 with QuorumPeer

use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.

the class ObserverLETest method testLEWithObserver.

/**
     * See ZOOKEEPER-1294. Confirms that an observer will not support the quorum
     * of a leader by forming a 5-node, 2-observer ensemble (so quorum size is 2).
     * When all but the leader and one observer are shut down, the leader should
     * enter the 'looking' state, not stay in the 'leading' state.
     */
@Test
public void testLEWithObserver() throws Exception {
    QuorumPeer leader = null;
    for (QuorumPeer server : Arrays.asList(qb.s1, qb.s2, qb.s3)) {
        if (server.getServerState().equals(QuorumStats.Provider.FOLLOWING_STATE)) {
            server.shutdown();
            assertTrue("Waiting for server down", ClientBase.waitForServerDown("127.0.0.1:" + server.getClientPort(), ClientBase.CONNECTION_TIMEOUT));
        } else {
            assertNull("More than one leader found", leader);
            leader = server;
        }
    }
    assertTrue("Leader is not in Looking state", ClientBase.waitForServerState(leader, ClientBase.CONNECTION_TIMEOUT, QuorumStats.Provider.LOOKING_STATE));
}
Also used : QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer) Test(org.junit.Test)

Example 37 with QuorumPeer

use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.

the class QuorumBase method getPeersMatching.

public String getPeersMatching(ServerState state) {
    StringBuilder hosts = new StringBuilder();
    for (QuorumPeer p : getPeerList()) {
        if (p.getPeerState() == state) {
            hosts.append(String.format("%s:%d,", LOCALADDR, p.getClientAddress().getPort()));
        }
    }
    LOG.info("getPeersMatching ports are {}", hosts);
    return hosts.toString();
}
Also used : QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer)

Example 38 with QuorumPeer

use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.

the class QuorumBase method startServers.

void startServers(boolean withObservers) throws Exception {
    int tickTime = 2000;
    int initLimit = 3;
    int syncLimit = 3;
    HashMap<Long, QuorumServer> peers = new HashMap<Long, QuorumServer>();
    peers.put(Long.valueOf(1), new QuorumServer(1, new InetSocketAddress(LOCALADDR, port1), new InetSocketAddress(LOCALADDR, portLE1), new InetSocketAddress(LOCALADDR, portClient1), LearnerType.PARTICIPANT));
    peers.put(Long.valueOf(2), new QuorumServer(2, new InetSocketAddress(LOCALADDR, port2), new InetSocketAddress(LOCALADDR, portLE2), new InetSocketAddress(LOCALADDR, portClient2), LearnerType.PARTICIPANT));
    peers.put(Long.valueOf(3), new QuorumServer(3, new InetSocketAddress(LOCALADDR, port3), new InetSocketAddress(LOCALADDR, portLE3), new InetSocketAddress(LOCALADDR, portClient3), LearnerType.PARTICIPANT));
    peers.put(Long.valueOf(4), new QuorumServer(4, new InetSocketAddress(LOCALADDR, port4), new InetSocketAddress(LOCALADDR, portLE4), new InetSocketAddress(LOCALADDR, portClient4), LearnerType.PARTICIPANT));
    peers.put(Long.valueOf(5), new QuorumServer(5, new InetSocketAddress(LOCALADDR, port5), new InetSocketAddress(LOCALADDR, portLE5), new InetSocketAddress(LOCALADDR, portClient5), LearnerType.PARTICIPANT));
    if (withObservers) {
        peers.get(Long.valueOf(4)).type = LearnerType.OBSERVER;
        peers.get(Long.valueOf(5)).type = LearnerType.OBSERVER;
    }
    LOG.info("creating QuorumPeer 1 port " + portClient1);
    s1 = new QuorumPeer(peers, s1dir, s1dir, portClient1, 3, 1, tickTime, initLimit, syncLimit);
    Assert.assertEquals(portClient1, s1.getClientPort());
    LOG.info("creating QuorumPeer 2 port " + portClient2);
    s2 = new QuorumPeer(peers, s2dir, s2dir, portClient2, 3, 2, tickTime, initLimit, syncLimit);
    Assert.assertEquals(portClient2, s2.getClientPort());
    LOG.info("creating QuorumPeer 3 port " + portClient3);
    s3 = new QuorumPeer(peers, s3dir, s3dir, portClient3, 3, 3, tickTime, initLimit, syncLimit);
    Assert.assertEquals(portClient3, s3.getClientPort());
    LOG.info("creating QuorumPeer 4 port " + portClient4);
    s4 = new QuorumPeer(peers, s4dir, s4dir, portClient4, 3, 4, tickTime, initLimit, syncLimit);
    Assert.assertEquals(portClient4, s4.getClientPort());
    LOG.info("creating QuorumPeer 5 port " + portClient5);
    s5 = new QuorumPeer(peers, s5dir, s5dir, portClient5, 3, 5, tickTime, initLimit, syncLimit);
    Assert.assertEquals(portClient5, s5.getClientPort());
    if (withObservers) {
        s4.setLearnerType(LearnerType.OBSERVER);
        s5.setLearnerType(LearnerType.OBSERVER);
    }
    LOG.info("QuorumPeer 1 voting view: " + s1.getVotingView());
    LOG.info("QuorumPeer 2 voting view: " + s2.getVotingView());
    LOG.info("QuorumPeer 3 voting view: " + s3.getVotingView());
    LOG.info("QuorumPeer 4 voting view: " + s4.getVotingView());
    LOG.info("QuorumPeer 5 voting view: " + s5.getVotingView());
    s1.enableLocalSessions(localSessionsEnabled);
    s2.enableLocalSessions(localSessionsEnabled);
    s3.enableLocalSessions(localSessionsEnabled);
    s4.enableLocalSessions(localSessionsEnabled);
    s5.enableLocalSessions(localSessionsEnabled);
    s1.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled);
    s2.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled);
    s3.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled);
    s4.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled);
    s5.enableLocalSessionsUpgrading(localSessionsUpgradingEnabled);
    LOG.info("start QuorumPeer 1");
    s1.start();
    LOG.info("start QuorumPeer 2");
    s2.start();
    LOG.info("start QuorumPeer 3");
    s3.start();
    LOG.info("start QuorumPeer 4");
    s4.start();
    LOG.info("start QuorumPeer 5");
    s5.start();
    LOG.info("started QuorumPeer 5");
    LOG.info("Checking ports " + hostPort);
    for (String hp : hostPort.split(",")) {
        Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(hp, CONNECTION_TIMEOUT));
        LOG.info(hp + " is accepting client connections");
    }
    // interesting to see what's there...
    JMXEnv.dump();
    // make sure we have these 5 servers listed
    Set<String> ensureNames = new LinkedHashSet<String>();
    for (int i = 1; i <= 5; i++) {
        ensureNames.add("InMemoryDataTree");
    }
    for (int i = 1; i <= 5; i++) {
        ensureNames.add("name0=ReplicatedServer_id" + i + ",name1=replica." + i + ",name2=");
    }
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            ensureNames.add("name0=ReplicatedServer_id" + i + ",name1=replica." + j);
        }
    }
    for (int i = 1; i <= 5; i++) {
        ensureNames.add("name0=ReplicatedServer_id" + i);
    }
    JMXEnv.ensureAll(ensureNames.toArray(new String[ensureNames.size()]));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) InetSocketAddress(java.net.InetSocketAddress) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer)

Example 39 with QuorumPeer

use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.

the class QuorumBase method setupServer.

public void setupServer(int i) throws IOException {
    int tickTime = 2000;
    int initLimit = 3;
    int syncLimit = 3;
    if (peers == null) {
        peers = new HashMap<Long, QuorumServer>();
        peers.put(Long.valueOf(1), new QuorumServer(1, new InetSocketAddress(LOCALADDR, port1), new InetSocketAddress(LOCALADDR, portLE1), new InetSocketAddress(LOCALADDR, portClient1), LearnerType.PARTICIPANT));
        peers.put(Long.valueOf(2), new QuorumServer(2, new InetSocketAddress(LOCALADDR, port2), new InetSocketAddress(LOCALADDR, portLE2), new InetSocketAddress(LOCALADDR, portClient2), LearnerType.PARTICIPANT));
        peers.put(Long.valueOf(3), new QuorumServer(3, new InetSocketAddress(LOCALADDR, port3), new InetSocketAddress(LOCALADDR, portLE3), new InetSocketAddress(LOCALADDR, portClient3), LearnerType.PARTICIPANT));
        peers.put(Long.valueOf(4), new QuorumServer(4, new InetSocketAddress(LOCALADDR, port4), new InetSocketAddress(LOCALADDR, portLE4), new InetSocketAddress(LOCALADDR, portClient4), LearnerType.PARTICIPANT));
        peers.put(Long.valueOf(5), new QuorumServer(5, new InetSocketAddress(LOCALADDR, port5), new InetSocketAddress(LOCALADDR, portLE5), new InetSocketAddress(LOCALADDR, portClient5), LearnerType.PARTICIPANT));
    }
    switch(i) {
        case 1:
            LOG.info("creating QuorumPeer 1 port " + portClient1);
            s1 = new QuorumPeer(peers, s1dir, s1dir, portClient1, 3, 1, tickTime, initLimit, syncLimit);
            Assert.assertEquals(portClient1, s1.getClientPort());
            break;
        case 2:
            LOG.info("creating QuorumPeer 2 port " + portClient2);
            s2 = new QuorumPeer(peers, s2dir, s2dir, portClient2, 3, 2, tickTime, initLimit, syncLimit);
            Assert.assertEquals(portClient2, s2.getClientPort());
            break;
        case 3:
            LOG.info("creating QuorumPeer 3 port " + portClient3);
            s3 = new QuorumPeer(peers, s3dir, s3dir, portClient3, 3, 3, tickTime, initLimit, syncLimit);
            Assert.assertEquals(portClient3, s3.getClientPort());
            break;
        case 4:
            LOG.info("creating QuorumPeer 4 port " + portClient4);
            s4 = new QuorumPeer(peers, s4dir, s4dir, portClient4, 3, 4, tickTime, initLimit, syncLimit);
            Assert.assertEquals(portClient4, s4.getClientPort());
            break;
        case 5:
            LOG.info("creating QuorumPeer 5 port " + portClient5);
            s5 = new QuorumPeer(peers, s5dir, s5dir, portClient5, 3, 5, tickTime, initLimit, syncLimit);
            Assert.assertEquals(portClient5, s5.getClientPort());
    }
}
Also used : QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) InetSocketAddress(java.net.InetSocketAddress) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer)

Aggregations

QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)39 Test (org.junit.Test)24 InetSocketAddress (java.net.InetSocketAddress)19 QuorumServer (org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer)19 QuorumCnxManager (org.apache.zookeeper.server.quorum.QuorumCnxManager)8 ZooKeeper (org.apache.zookeeper.ZooKeeper)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 ByteBuffer (java.nio.ByteBuffer)5 File (java.io.File)4 HashMap (java.util.HashMap)4 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)4 Stat (org.apache.zookeeper.data.Stat)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Socket (java.net.Socket)2 SocketChannel (java.nio.channels.SocketChannel)2 LinkedHashSet (java.util.LinkedHashSet)2 BinaryOutputArchive (org.apache.jute.BinaryOutputArchive)2 KeeperException (org.apache.zookeeper.KeeperException)2 ZooKeeperAdmin (org.apache.zookeeper.admin.ZooKeeperAdmin)2