I am just trying to start a zookeeper ensemble (Leader - follower) with java implementation using the Curator frame work or zookeeper .
Initially i have checked with binary mode and it was working fine with example configs shown below.
zoo.cfg
tickTime=2000
dataDir=/var/lib/zookeeper/
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
and myid files created accordingly and the zookeeper ensemble created as i expected (Leader - Followers created).
Connections: 4
Outstanding: 0
Zxid: 0x30000052a
Mode: leader
Node count: 158
Proposal sizes last/min/max: 146/36/1471
When i tried to achieve the same using org.apache.zookeeper.server.quorum.QuorumPeerConfig configs with Classes,
org.apache.zookeeper.server.ZooKeeperServerMain
ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
final ServerConfig configuration = new ServerConfig();
configuration.readFrom(peerConfig);
new Thread(() -> {
try {
zkServer.runFromConfig(configuration);
Thread.sleep(2000);
} catch (Exception e) {
logger.error("ZooKeeper Failed", e);
}
}).start();
org.apache.curator.test.TestingServer
InstanceSpec spec = new InstanceSpec(zkDataDir, clientPort, electionPort, -1, true, serverId, tickTime, maxClientCnxns, customProperties);
zkServer = new TestingServer(spec, true);
Both starts zookeeper in stand alone mode and it seems both the implementations not care about the configuration server.1=..... server.2=.... server.3=..... .
What i am missing here? how to start a zookeeper using java in leader follower mode?
Note: I am newbie with zookeeper related stuffs and docs still confusing me. Please guide me for the same.. Thanks... :)
Curator TestingServer can be treated as regular ZooKeeper server. As such, leader-follower can be tested with it, using Curator LeaderLatch for example.
Leader-follower unit test example
Leader-follower implementation example
Note: I am the author of this project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.