public String getConnectString(QuorumPeer peer) { return "127.0.0.1:" + peer.getClientPort(); }
public static ZooKeeper[] createHandles(QuorumUtil qu) throws IOException { // create an extra handle, so we can index the handles from 1 to qu.ALL // using the server id. ZooKeeper[] zkArr = new ZooKeeper[qu.ALL + 1]; zkArr[0] = null; // not used. for (int i = 1; i <= qu.ALL; i++) { // server ids are 1, 2 and 3 zkArr[i] = new ZooKeeper("127.0.0.1:" + qu.getPeer(i).peer.getClientPort(), ClientBase.CONNECTION_TIMEOUT, new Watcher() { public void process(WatchedEvent event) { }}); } return zkArr; }
public static ZooKeeperAdmin[] createAdminHandles(QuorumUtil qu) throws IOException { // create an extra handle, so we can index the handles from 1 to qu.ALL // using the server id. ZooKeeperAdmin[] zkAdminArr = new ZooKeeperAdmin[qu.ALL + 1]; zkAdminArr[0] = null; // not used. for (int i = 1; i <= qu.ALL; i++) { // server ids are 1, 2 and 3 zkAdminArr[i] = new ZooKeeperAdmin("127.0.0.1:" + qu.getPeer(i).peer.getClientPort(), ClientBase.CONNECTION_TIMEOUT, new Watcher() { public void process(WatchedEvent event) { }}); zkAdminArr[i].addAuthInfo("digest", "super:test".getBytes()); } return zkAdminArr; }
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());
public void start(int id) throws IOException { PeerStruct ps = getPeer(id); LOG.info("Creating QuorumPeer " + ps.id + "; public port " + ps.clientPort); ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, electionAlg, ps.id, tickTime, initLimit, syncLimit); if (localSessionEnabled) { ps.peer.enableLocalSessions(true); } Assert.assertEquals(ps.clientPort, ps.peer.getClientPort()); ps.peer.start(); }
ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, electionAlg, ps.id, tickTime, initLimit, syncLimit); Assert.assertEquals(ps.clientPort, ps.peer.getClientPort());
+ qu.getPeer(i).peer.getQuorumAddress().getPort() + ":" + qu.getPeer(i).peer.getElectionAddress().getPort() + ";" + "127.0.0.1:" + qu.getPeer(i).peer.getClientPort());
"127.0.0.1:" + qu.getPeer((index == 1)?2:1).peer.getClientPort(), ClientBase.CONNECTION_TIMEOUT, watcher); watcher.waitForConnected(CONNECTION_TIMEOUT);
/** * 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)); }
public void startThenShutdown(int id) throws IOException { PeerStruct ps = getPeer(id); LOG.info("Creating QuorumPeer " + ps.id + "; public port " + ps.clientPort); ps.peer = new QuorumPeer(peersView, ps.dataDir, ps.dataDir, ps.clientPort, electionAlg, ps.id, tickTime, initLimit, syncLimit); if (localSessionEnabled) { ps.peer.enableLocalSessions(true); } Assert.assertEquals(ps.clientPort, ps.peer.getClientPort()); ps.peer.start(); Assert.assertTrue("Waiting for server up", ClientBase.waitForServerUp("127.0.0.1:" + getPeer(id).clientPort, ClientBase.CONNECTION_TIMEOUT)); shutdown(id); }
private void instantiateZKAdmin() throws InterruptedException { String cnxString; ClientBase.CountdownWatcher watcher = new ClientBase.CountdownWatcher(); try { cnxString = "127.0.0.1:" + qu.getPeer(1).peer.getClientPort(); zkAdmin = new ZooKeeperAdmin(cnxString, ClientBase.CONNECTION_TIMEOUT, watcher); } catch (IOException e) { Assert.fail("Fail to create ZooKeeperAdmin handle."); return; } try { watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT); } catch (InterruptedException | TimeoutException e) { Assert.fail("ZooKeeper admin client can not connect to " + cnxString); } }
+ qu.getPeer(leavingIndex).peer.getElectionAddress().getPort() + ":participant;127.0.0.1:" + qu.getPeer(leavingIndex).peer.getClientPort());
/** * See ZOOKEEPER-790 for details * */ @Test public void testFollowersStartAfterLeader() throws Exception { qu = new QuorumUtil(1); CountdownWatcher watcher = new CountdownWatcher(); qu.startQuorum(); int index = 1; while(qu.getPeer(index).peer.leader == null) index++; // break the quorum qu.shutdown(index); // try to reestablish the quorum qu.start(index); // Connect the client after services are restarted (otherwise we would get // SessionExpiredException as the previous local session was not persisted). ZooKeeper zk = new ZooKeeper( "127.0.0.1:" + qu.getPeer((index == 1)?2:1).peer.getClientPort(), ClientBase.CONNECTION_TIMEOUT, watcher); try{ watcher.waitForConnected(CONNECTION_TIMEOUT); } catch(TimeoutException e) { Assert.fail("client could not connect to reestablished quorum: giving up after 30+ seconds."); } zk.close(); }
"localhost:" + qu.getPeer(index).peer.getClientPort()); zk1.create("/foo", "foo".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); "localhost:" + qu.getPeer(index).peer.getClientPort());
private void resetZKAdmin() throws InterruptedException { String cnxString; ClientBase.CountdownWatcher watcher = new ClientBase.CountdownWatcher(); try { cnxString = "127.0.0.1:" + qu.getPeer(1).peer.getClientPort(); if (zkAdmin != null) { zkAdmin.close(); } zkAdmin = new ZooKeeperAdmin(cnxString, ClientBase.CONNECTION_TIMEOUT, watcher); } catch (IOException e) { Assert.fail("Fail to create ZooKeeperAdmin handle."); return; } try { watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT); } catch (InterruptedException | TimeoutException e) { Assert.fail("ZooKeeper admin client can not connect to " + cnxString); } }
+ qu.getPeer(leavingIndex).peer.getElectionAddress() .getPort() + ":participant;localhost:" + qu.getPeer(leavingIndex).peer.getClientPort());
Assert.assertTrue("Servers didn't come up", ClientBase.waitForServerUp(qb.hostPort, 10000)); qb.s5.start(); String hostPort = "127.0.0.1:" + qb.s5.getClientPort(); Assert.assertFalse("Servers came up, but shouldn't have since it's ahead of leader", ClientBase.waitForServerUp(hostPort, 10000));
/** * Verify that the server is sending the proper zxid. See ZOOKEEPER-1412. */ @Test public void testFollowerSendsLastZxid() throws Exception { QuorumUtil qu = new QuorumUtil(1); qu.startAll(); int index = 1; while(qu.getPeer(index).peer.follower == null) { index++; } LOG.info("Connecting to follower: {}", index); TestableZooKeeper zk = createTestableClient("localhost:" + qu.getPeer(index).peer.getClientPort()); assertEquals(0L, zk.testableLastZxid()); zk.exists("/", false); long lzxid = zk.testableLastZxid(); assertTrue("lzxid:" + lzxid + " > 0", lzxid > 0); zk.close(); qu.shutdownAll(); }
+ ":" + PortAssignment.unique() + ":" + ((i == 4 || i == 5) ? "observer" : "participant") + ";localhost:" + qu.getPeer(i).peer.getClientPort(); newServers.add(server);
.waitForServerUp("127.0.0.1:" + leader.getClientPort(), CONNECTION_TIMEOUT)); assertTrue( "Leader failed to transition to new state. Current state is "