use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.
the class ReconfigTest method testJMXBeanAfterRemoveAddOne.
/**
* Tests verifies the jmx attributes of local and remote peer bean - remove
* one quorum peer and again adding it back
*/
@Test
public void testJMXBeanAfterRemoveAddOne() throws Exception {
// create 3 servers
qu = new QuorumUtil(1);
qu.disableJMXTest = true;
qu.startAll();
ZooKeeper[] zkArr = createHandles(qu);
ZooKeeperAdmin[] zkAdminArr = createAdminHandles(qu);
List<String> leavingServers = new ArrayList<String>();
List<String> joiningServers = new ArrayList<String>();
// assert remotePeerBean.1 of ReplicatedServer_2
int leavingIndex = 1;
int replica2 = 2;
QuorumPeer peer2 = qu.getPeer(replica2).peer;
QuorumServer leavingQS2 = peer2.getView().get(new Long(leavingIndex));
String remotePeerBean2 = CommonNames.DOMAIN + ":name0=ReplicatedServer_id" + replica2 + ",name1=replica." + leavingIndex;
assertRemotePeerMXBeanAttributes(leavingQS2, remotePeerBean2);
// assert remotePeerBean.1 of ReplicatedServer_3
int replica3 = 3;
QuorumPeer peer3 = qu.getPeer(replica3).peer;
QuorumServer leavingQS3 = peer3.getView().get(new Long(leavingIndex));
String remotePeerBean3 = CommonNames.DOMAIN + ":name0=ReplicatedServer_id" + replica3 + ",name1=replica." + leavingIndex;
assertRemotePeerMXBeanAttributes(leavingQS3, remotePeerBean3);
ZooKeeper zk = zkArr[leavingIndex];
ZooKeeperAdmin zkAdmin = zkAdminArr[leavingIndex];
leavingServers.add(Integer.toString(leavingIndex));
// remember this server so we can add it back later
joiningServers.add("server." + leavingIndex + "=127.0.0.1:" + qu.getPeer(leavingIndex).peer.getQuorumAddress().getPort() + ":" + qu.getPeer(leavingIndex).peer.getElectionAddress().getPort() + ":participant;127.0.0.1:" + qu.getPeer(leavingIndex).peer.getClientPort());
// Remove ReplicatedServer_1 from the ensemble
reconfig(zkAdmin, null, leavingServers, null, -1);
// localPeerBean.1 of ReplicatedServer_1
QuorumPeer removedPeer = qu.getPeer(leavingIndex).peer;
String localPeerBean = CommonNames.DOMAIN + ":name0=ReplicatedServer_id" + leavingIndex + ",name1=replica." + leavingIndex;
assertLocalPeerMXBeanAttributes(removedPeer, localPeerBean, false);
// remotePeerBean.1 shouldn't exists in ReplicatedServer_2
JMXEnv.ensureNone(remotePeerBean2);
// remotePeerBean.1 shouldn't exists in ReplicatedServer_3
JMXEnv.ensureNone(remotePeerBean3);
// Add ReplicatedServer_1 back to the ensemble
reconfig(zkAdmin, joiningServers, null, null, -1);
// localPeerBean.1 of ReplicatedServer_1
assertLocalPeerMXBeanAttributes(removedPeer, localPeerBean, true);
// assert remotePeerBean.1 of ReplicatedServer_2
leavingQS2 = peer2.getView().get(new Long(leavingIndex));
assertRemotePeerMXBeanAttributes(leavingQS2, remotePeerBean2);
// assert remotePeerBean.1 of ReplicatedServer_3
leavingQS3 = peer3.getView().get(new Long(leavingIndex));
assertRemotePeerMXBeanAttributes(leavingQS3, remotePeerBean3);
closeAllHandles(zkArr, zkAdminArr);
}
use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.
the class ReconfigTest method testJMXBeanAfterRoleChange.
/**
* Tests verifies the jmx attributes of local and remote peer bean - change
* participant to observer role
*/
@Test
public void testJMXBeanAfterRoleChange() throws Exception {
// create 3 servers
qu = new QuorumUtil(1);
qu.disableJMXTest = true;
qu.startAll();
ZooKeeper[] zkArr = createHandles(qu);
ZooKeeperAdmin[] zkAdminArr = createAdminHandles(qu);
// changing a server's role / port is done by "adding" it with the same
// id but different role / port
List<String> joiningServers = new ArrayList<String>();
// assert remotePeerBean.1 of ReplicatedServer_2
int changingIndex = 1;
int replica2 = 2;
QuorumPeer peer2 = qu.getPeer(replica2).peer;
QuorumServer changingQS2 = peer2.getView().get(new Long(changingIndex));
String remotePeerBean2 = CommonNames.DOMAIN + ":name0=ReplicatedServer_id" + replica2 + ",name1=replica." + changingIndex;
assertRemotePeerMXBeanAttributes(changingQS2, remotePeerBean2);
// assert remotePeerBean.1 of ReplicatedServer_3
int replica3 = 3;
QuorumPeer peer3 = qu.getPeer(replica3).peer;
QuorumServer changingQS3 = peer3.getView().get(new Long(changingIndex));
String remotePeerBean3 = CommonNames.DOMAIN + ":name0=ReplicatedServer_id" + replica3 + ",name1=replica." + changingIndex;
assertRemotePeerMXBeanAttributes(changingQS3, remotePeerBean3);
String newRole = "observer";
ZooKeeper zk = zkArr[changingIndex];
ZooKeeperAdmin zkAdmin = zkAdminArr[changingIndex];
// exactly as it is now, except for role change
joiningServers.add("server." + changingIndex + "=127.0.0.1:" + qu.getPeer(changingIndex).peer.getQuorumAddress().getPort() + ":" + qu.getPeer(changingIndex).peer.getElectionAddress().getPort() + ":" + newRole + ";127.0.0.1:" + qu.getPeer(changingIndex).peer.getClientPort());
reconfig(zkAdmin, joiningServers, null, null, -1);
testNormalOperation(zkArr[changingIndex], zk);
Assert.assertTrue(qu.getPeer(changingIndex).peer.observer != null && qu.getPeer(changingIndex).peer.follower == null && qu.getPeer(changingIndex).peer.leader == null);
Assert.assertTrue(qu.getPeer(changingIndex).peer.getPeerState() == ServerState.OBSERVING);
QuorumPeer qp = qu.getPeer(changingIndex).peer;
String localPeerBeanName = CommonNames.DOMAIN + ":name0=ReplicatedServer_id" + changingIndex + ",name1=replica." + changingIndex;
// localPeerBean.1 of ReplicatedServer_1
assertLocalPeerMXBeanAttributes(qp, localPeerBeanName, true);
// assert remotePeerBean.1 of ReplicatedServer_2
changingQS2 = peer2.getView().get(new Long(changingIndex));
assertRemotePeerMXBeanAttributes(changingQS2, remotePeerBean2);
// assert remotePeerBean.1 of ReplicatedServer_3
changingQS3 = peer3.getView().get(new Long(changingIndex));
assertRemotePeerMXBeanAttributes(changingQS3, remotePeerBean3);
closeAllHandles(zkArr, zkAdminArr);
}
use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.
the class ZkDatabaseCorruptionTest method testCorruption.
@Test
public void testCorruption() throws Exception {
ClientBase.waitForServerUp(qb.hostPort, 10000);
ClientBase.waitForServerUp(qb.hostPort, 10000);
ZooKeeper zk = ClientBase.createZKClient(qb.hostPort, 10000);
SyncRequestProcessor.setSnapCount(100);
for (int i = 0; i < 2000; i++) {
zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, new NoopStringCallback(), null);
}
zk.close();
long leaderSid = 1;
QuorumPeer leader = null;
// find out who is the leader and kill it
for (QuorumPeer quorumPeer : Arrays.asList(qb.s1, qb.s2, qb.s3, qb.s4, qb.s5)) {
if (quorumPeer.getPeerState() == ServerState.LEADING) {
leader = quorumPeer;
break;
}
++leaderSid;
}
Assert.assertNotNull("Cannot find the leader.", leader);
leader.shutdown();
// now corrupt the leader's database
FileTxnSnapLog snapLog = leader.getTxnFactory();
File snapDir = snapLog.getSnapDir();
// corrupt all the snapshot in the snapshot directory
corruptAllSnapshots(snapDir);
qb.shutdownServers();
qb.setupServers();
if (leaderSid != 1)
qb.s1.start();
else
leader = qb.s1;
if (leaderSid != 2)
qb.s2.start();
else
leader = qb.s2;
if (leaderSid != 3)
qb.s3.start();
else
leader = qb.s3;
if (leaderSid != 4)
qb.s4.start();
else
leader = qb.s4;
if (leaderSid != 5)
qb.s5.start();
else
leader = qb.s5;
try {
leader.start();
Assert.assertTrue(false);
} catch (RuntimeException re) {
LOG.info("Got an error: expected", re);
}
// wait for servers to be up
String[] list = qb.hostPort.split(",");
for (int i = 0; i < 5; i++) {
if (leaderSid != (i + 1)) {
String hp = list[i];
Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(hp, CONNECTION_TIMEOUT));
LOG.info("{} is accepting client connections", hp);
} else {
LOG.info("Skipping the leader");
}
}
zk = qb.createClient();
SyncRequestProcessor.setSnapCount(100);
for (int i = 2000; i < 4000; i++) {
zk.create("/0-" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, new NoopStringCallback(), null);
}
zk.close();
if (leaderSid != 1)
QuorumBase.shutdown(qb.s1);
if (leaderSid != 2)
QuorumBase.shutdown(qb.s2);
if (leaderSid != 3)
QuorumBase.shutdown(qb.s3);
if (leaderSid != 4)
QuorumBase.shutdown(qb.s4);
if (leaderSid != 5)
QuorumBase.shutdown(qb.s5);
}
use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.
the class FLETest method testJoin.
/*
* For ZOOKEEPER-975 verify that a peer joining an established cluster
* does not go in LEADING state.
*/
@Test
public void testJoin() throws Exception {
int sid;
QuorumPeer peer;
int waitTime = 10 * 1000;
ArrayList<QuorumPeer> peerList = new ArrayList<QuorumPeer>();
for (sid = 0; sid < 3; sid++) {
port[sid] = PortAssignment.unique();
peers.put(Long.valueOf(sid), new QuorumServer(sid, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", port[sid])));
tmpdir[sid] = ClientBase.createTmpDir();
}
// start 2 peers and verify if they form the cluster
for (sid = 0; sid < 2; sid++) {
peer = new QuorumPeer(peers, tmpdir[sid], tmpdir[sid], port[sid], 3, sid, 2000, 2, 2);
LOG.info("Starting peer " + peer.getId());
peer.start();
peerList.add(sid, peer);
}
peer = peerList.get(0);
VerifyState v1 = new VerifyState(peerList.get(0));
v1.start();
v1.join(waitTime);
Assert.assertFalse("Unable to form cluster in " + waitTime + " ms", !v1.isSuccess());
// Start 3rd peer and check if it goes in LEADING state
peer = new QuorumPeer(peers, tmpdir[sid], tmpdir[sid], port[sid], 3, sid, 2000, 2, 2);
LOG.info("Starting peer " + peer.getId());
peer.start();
peerList.add(sid, peer);
v1 = new VerifyState(peer);
v1.start();
v1.join(waitTime);
if (v1.isAlive()) {
Assert.fail("Peer " + peer.getId() + " failed to join the cluster " + "within " + waitTime + " ms");
} else if (!v1.isSuccess()) {
Assert.fail("Incorrect LEADING state for peer " + peer.getId());
}
// cleanup
for (int id = 0; id < 3; id++) {
peer = peerList.get(id);
if (peer != null) {
peer.shutdown();
}
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeer in project zookeeper by apache.
the class FLENewEpochTest method testLENewEpoch.
@Test
public void testLENewEpoch() throws Exception {
LOG.info("TestLE: " + getTestName() + ", " + count);
for (int i = 0; i < count; i++) {
peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = PortAssignment.unique();
}
for (int i = 1; i < count; i++) {
QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i, 1000, 2, 2);
peer.startLeaderElection();
LEThread thread = new LEThread(peer, i);
thread.start();
threads.add(thread);
}
if (!start0.tryAcquire(4000, java.util.concurrent.TimeUnit.MILLISECONDS))
Assert.fail("First leader election failed");
QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 1000, 2, 2);
peer.startLeaderElection();
LEThread thread = new LEThread(peer, 0);
thread.start();
threads.add(thread);
LOG.info("Started threads " + getTestName());
for (int i = 0; i < threads.size(); i++) {
threads.get(i).join(10000);
if (threads.get(i).isAlive()) {
Assert.fail("Threads didn't join");
}
}
}
Aggregations