use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class QuorumBase method startServers.
void startServers(boolean withObservers, boolean withOracle) throws Exception {
int tickTime = 2000;
int initLimit = 3;
int syncLimit = 3;
int connectToLearnerMasterLimit = 3;
Map<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;
}
if (!withOracle) {
LOG.info("creating QuorumPeer 1 port {}", portClient1);
s1 = new QuorumPeer(peers, s1dir, s1dir, portClient1, 3, 1, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
assertEquals(portClient1, s1.getClientPort());
LOG.info("creating QuorumPeer 2 port {}", portClient2);
s2 = new QuorumPeer(peers, s2dir, s2dir, portClient2, 3, 2, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
assertEquals(portClient2, s2.getClientPort());
LOG.info("creating QuorumPeer 3 port {}", portClient3);
s3 = new QuorumPeer(peers, s3dir, s3dir, portClient3, 3, 3, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
assertEquals(portClient3, s3.getClientPort());
LOG.info("creating QuorumPeer 4 port {}", portClient4);
s4 = new QuorumPeer(peers, s4dir, s4dir, portClient4, 3, 4, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
assertEquals(portClient4, s4.getClientPort());
LOG.info("creating QuorumPeer 5 port {}", portClient5);
s5 = new QuorumPeer(peers, s5dir, s5dir, portClient5, 3, 5, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
assertEquals(portClient5, s5.getClientPort());
} else {
createOraclePath();
LOG.info("creating QuorumPeer 1 port {}", portClient1);
s1 = new QuorumPeer(peers, s1dir, s1dir, portClient1, 3, 1, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit, oracleDir.getAbsolutePath() + oraclePath_0 + mastership);
assertEquals(portClient1, s1.getClientPort());
LOG.info("creating QuorumPeer 2 port {}", portClient2);
s2 = new QuorumPeer(peers, s2dir, s2dir, portClient2, 3, 2, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit, oracleDir.getAbsolutePath() + oraclePath_1 + mastership);
assertEquals(portClient2, s2.getClientPort());
LOG.info("creating QuorumPeer 3 port {}", portClient3);
s3 = new QuorumPeer(peers, s3dir, s3dir, portClient3, 3, 3, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit, oracleDir.getAbsolutePath() + oraclePath_2 + mastership);
assertEquals(portClient3, s3.getClientPort());
LOG.info("creating QuorumPeer 4 port {}", portClient4);
s4 = new QuorumPeer(peers, s4dir, s4dir, portClient4, 3, 4, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit, oracleDir.getAbsolutePath() + oraclePath_3 + mastership);
assertEquals(portClient4, s4.getClientPort());
LOG.info("creating QuorumPeer 5 port {}", portClient5);
s5 = new QuorumPeer(peers, s5dir, s5dir, portClient5, 3, 5, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit, oracleDir.getAbsolutePath() + oraclePath_4 + mastership);
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(",")) {
assertTrue(ClientBase.waitForServerUp(hp, CONNECTION_TIMEOUT), "waiting for server up");
LOG.info("{} is accepting client connections", hp);
}
// 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()]));
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project zookeeper by apache.
the class TruncateTest method testTruncate.
@Test
public void testTruncate() throws Exception {
// Prime the server that is going to come in late with 50 txns
String hostPort = "127.0.0.1:" + PortAssignment.unique();
int maxCnxns = 100;
ServerCnxnFactory factory = ClientBase.createNewServerInstance(null, hostPort, maxCnxns);
ClientBase.startServerInstance(dataDir1, factory, hostPort, 1);
ClientBase.shutdownServerInstance(factory, hostPort);
// standalone starts with 0 epoch while quorum starts with 1
File origfile = new File(new File(dataDir1, "version-2"), "snapshot.0");
File newfile = new File(new File(dataDir1, "version-2"), "snapshot.100000000");
origfile.renameTo(newfile);
factory = ClientBase.createNewServerInstance(null, hostPort, maxCnxns);
ClientBase.startServerInstance(dataDir1, factory, hostPort, 1);
ZooKeeper zk = ClientBase.createZKClient(hostPort, 15000);
for (int i = 0; i < 50; i++) {
zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
zk.close();
ZKDatabase zkDb;
{
ZooKeeperServer zs = factory.getZooKeeperServer();
zkDb = zs.getZKDatabase();
}
factory.shutdown();
try {
zkDb.close();
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
}
int tickTime = 2000;
int initLimit = 3;
int syncLimit = 3;
int connectToLearnerMasterLimit = 3;
int port1 = PortAssignment.unique();
int port2 = PortAssignment.unique();
int port3 = PortAssignment.unique();
// Start up two of the quorum and add 10 txns
Map<Long, QuorumServer> peers = new HashMap<Long, QuorumServer>();
peers.put(Long.valueOf(1), new QuorumServer(1, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", port1)));
peers.put(Long.valueOf(2), new QuorumServer(2, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", port2)));
peers.put(Long.valueOf(3), new QuorumServer(3, new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", PortAssignment.unique()), new InetSocketAddress("127.0.0.1", port3)));
QuorumPeer s2 = new QuorumPeer(peers, dataDir2, dataDir2, port2, 3, 2, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
s2.start();
QuorumPeer s3 = new QuorumPeer(peers, dataDir3, dataDir3, port3, 3, 3, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
s3.start();
zk = ClientBase.createZKClient("127.0.0.1:" + port2, 15000);
for (int i = 0; i < 10; i++) {
zk.create("/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
zk.close();
final ZooKeeper zk2 = ClientBase.createZKClient("127.0.0.1:" + port2, 15000);
zk2.getData("/9", false, new Stat());
try {
zk2.getData("/10", false, new Stat());
fail("Should have gotten an error");
} catch (KeeperException.NoNodeException e) {
// this is what we want
}
QuorumPeer s1 = new QuorumPeer(peers, dataDir1, dataDir1, port1, 3, 1, tickTime, initLimit, syncLimit, connectToLearnerMasterLimit);
s1.start();
ZooKeeper zk1 = ClientBase.createZKClient("127.0.0.1:" + port1, 15000);
zk1.getData("/9", false, new Stat());
try {
// /10 wont work because the session expiration
// will match the zxid for /10 and so we wont
// actually truncate the zxid for /10 creation
// due to an artifact of switching the xid of the standalone
// /11 is the last entry in the log for the xid
// as a result /12 is the first of the truncated znodes to check for
zk1.getData("/12", false, new Stat());
fail("Should have gotten an error");
} catch (KeeperException.NoNodeException e) {
// this is what we want
}
zk1.close();
QuorumBase.shutdown(s1);
QuorumBase.shutdown(s2);
QuorumBase.shutdown(s3);
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project coprhd-controller by CoprHD.
the class SpringQuorumPeerConfigTest method testInitWithCustomizedSeperator.
@Test
public void testInitWithCustomizedSeperator() throws Exception {
springQuorumPeerConfig.setProperties(properties);
springQuorumPeerConfig.init();
assertTrue(springQuorumPeerConfig.getServers().size() == 3);
QuorumServer server1 = springQuorumPeerConfig.getServers().get(new Long(1));
assertTrue(server1.addr.toString().equals("/192.168.1.1:2888"));
assertTrue(server1.electionAddr.toString().equals("/192.168.1.1:3888"));
assertTrue(server1.type == LearnerType.PARTICIPANT);
QuorumServer server2 = springQuorumPeerConfig.getServers().get(new Long(2));
assertTrue(server2.addr.toString().equals("hostname:2888"));
assertTrue(server2.electionAddr.toString().equals("hostname:3888"));
assertTrue(server2.type == LearnerType.PARTICIPANT);
QuorumServer server3 = springQuorumPeerConfig.getServers().get(new Long(3));
assertTrue(server3.addr.toString().equals("/fe80:0:0:0:81fe:4fd:95b1:8bbf:2888"));
assertTrue(server3.electionAddr.toString().equals("/fe80:0:0:0:81fe:4fd:95b1:8bbf:3888"));
assertTrue(server3.type == LearnerType.PARTICIPANT);
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project coprhd-controller by CoprHD.
the class SpringQuorumPeerConfig method createQuorumServer.
/**
* This logic is same as ZK 3.4.6 except splitting values with "," instead of ":"
*/
private void createQuorumServer(String key, String value) throws ConfigException {
int dot = key.indexOf('.');
long sid = Long.parseLong(key.substring(dot + 1));
String[] parts = value.split(",");
if ((parts.length != 2) && (parts.length != 3) && (parts.length != 4)) {
log.error(value + " does not have the form host,port or host,port,port " + " or host,port,port,type");
}
InetSocketAddress addr = new InetSocketAddress(parts[0], Integer.parseInt(parts[1]));
if (parts.length == 2) {
servers.put(Long.valueOf(sid), new QuorumServer(sid, addr));
} else if (parts.length == 3) {
InetSocketAddress electionAddr = new InetSocketAddress(parts[0], Integer.parseInt(parts[2]));
servers.put(Long.valueOf(sid), new QuorumServer(sid, addr, electionAddr));
} else if (parts.length == 4) {
InetSocketAddress electionAddr = new InetSocketAddress(parts[0], Integer.parseInt(parts[2]));
LearnerType type = LearnerType.PARTICIPANT;
if (parts[3].toLowerCase().equals("observer")) {
type = LearnerType.OBSERVER;
observers.put(Long.valueOf(sid), new QuorumServer(sid, addr, electionAddr, type));
} else if (parts[3].toLowerCase().equals("participant")) {
type = LearnerType.PARTICIPANT;
servers.put(Long.valueOf(sid), new QuorumServer(sid, addr, electionAddr, type));
} else {
throw new ConfigException("Unrecognised peertype: " + value);
}
}
}
Aggregations