Search in sources :

Example 61 with ZooKeeperServer

use of org.apache.zookeeper.server.ZooKeeperServer in project fabric8 by jboss-fuse.

the class ZookeeperServerTestSupport method startZooKeeper.

protected NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
    ServerConfig cfg = new ServerConfig();
    cfg.parse(new String[] { Integer.toString(port), "target/zk/data-" + String.format("%15d", new Date().getTime()) });
    ZooKeeperServer zkServer = new ZooKeeperServer();
    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
    zkServer.setTxnLogFactory(ftxn);
    zkServer.setTickTime(cfg.getTickTime());
    zkServer.setMinSessionTimeout(cfg.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout());
    NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
    cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
    cnxnFactory.startup(zkServer);
    return cnxnFactory;
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) Date(java.util.Date) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Example 62 with ZooKeeperServer

use of org.apache.zookeeper.server.ZooKeeperServer in project fabric8 by jboss-fuse.

the class GitDataStoreImplTestSupport method startZooKeeper.

private NIOServerCnxnFactory startZooKeeper(int port, String directory) throws Exception {
    ServerConfig cfg = new ServerConfig();
    cfg.parse(new String[] { Integer.toString(port), directory });
    ZooKeeperServer zkServer = new ZooKeeperServer();
    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
    zkServer.setTxnLogFactory(ftxn);
    zkServer.setTickTime(cfg.getTickTime());
    zkServer.setMinSessionTimeout(cfg.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout());
    NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
    cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
    cnxnFactory.startup(zkServer);
    return cnxnFactory;
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Example 63 with ZooKeeperServer

use of org.apache.zookeeper.server.ZooKeeperServer in project strimzi by strimzi.

the class EmbeddedZooKeeper method restart.

public void restart() throws IOException, InterruptedException {
    if (zk != null) {
        zk.shutdown(false);
    }
    // Reuse the existing port
    InetSocketAddress addr = factory.getLocalAddress();
    factory.shutdown();
    zk = new ZooKeeperServer(dir, dir, 1000);
    start(addr);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 64 with ZooKeeperServer

use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.

the class FuzzySnapshotRelatedTest method testMultiOpDigestConsistentDuringSnapshot.

@Test
public void testMultiOpDigestConsistentDuringSnapshot() throws Exception {
    ServerMetrics.getMetrics().resetAll();
    LOG.info("Create some txns");
    final String path = "/testMultiOpDigestConsistentDuringSnapshot";
    createEmptyNode(zk[followerA], path, CreateMode.PERSISTENT);
    CustomDataTree dt = (CustomDataTree) mt[followerA].main.quorumPeer.getZkDb().getDataTree();
    final CountDownLatch setDataLatch = new CountDownLatch(1);
    final CountDownLatch continueSetDataLatch = new CountDownLatch(1);
    final ZooKeeper followerZk = zk[followerA];
    dt.setDigestSerializeListener(new DigestSerializeListener() {

        @Override
        public void process() {
            LOG.info("Trigger a multi op in async");
            followerZk.multi(Arrays.asList(Op.create("/multi0", "/multi0".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.setData(path, "new data".getBytes(), -1)), new MultiCallback() {

                @Override
                public void processResult(int rc, String path, Object ctx, List<OpResult> opResults) {
                }
            }, null);
            LOG.info("Wait for the signal to continue");
            try {
                setDataLatch.await(3, TimeUnit.SECONDS);
            } catch (Exception e) {
                LOG.error("Error while waiting for set data txn, {}", e);
            }
        }

        @Override
        public void finished() {
            LOG.info("Finished writing digest out, continue");
            continueSetDataLatch.countDown();
        }
    });
    dt.setDataListener(new SetDataTxnListener() {

        @Override
        public void process() {
            setDataLatch.countDown();
            try {
                continueSetDataLatch.await(3, TimeUnit.SECONDS);
            } catch (Exception e) {
                LOG.error("Error while waiting for continue signal, {}", e);
            }
        }
    });
    LOG.info("Trigger a snapshot");
    ZooKeeperServer zkServer = mt[followerA].main.quorumPeer.getActiveServer();
    zkServer.takeSnapshot(true);
    checkNoMismatchReported();
    LOG.info("Restart the server to load the snapshot again");
    mt[followerA].shutdown();
    QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTING);
    mt[followerA].start();
    QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTED);
    LOG.info("Make sure there is nothing caught in the digest mismatch");
    checkNoMismatchReported();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) MultiCallback(org.apache.zookeeper.AsyncCallback.MultiCallback) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) SaslException(javax.security.sasl.SaslException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Example 65 with ZooKeeperServer

use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.

the class FuzzySnapshotRelatedTest method testMultiOpConsistency.

@Test
public void testMultiOpConsistency() throws Exception {
    LOG.info("Create a parent node");
    final String path = "/testMultiOpConsistency";
    createEmptyNode(zk[followerA], path, CreateMode.PERSISTENT);
    LOG.info("Hook to catch the 2nd sub create node txn in multi-op");
    CustomDataTree dt = (CustomDataTree) mt[followerA].main.quorumPeer.getZkDb().getDataTree();
    final ZooKeeperServer zkServer = mt[followerA].main.quorumPeer.getActiveServer();
    String node1 = path + "/1";
    String node2 = path + "/2";
    dt.addNodeCreateListener(node2, new NodeCreateListener() {

        @Override
        public void process(String path) {
            LOG.info("Take a snapshot");
            zkServer.takeSnapshot(true);
        }
    });
    LOG.info("Issue a multi op to create 2 nodes");
    zk[followerA].multi(Arrays.asList(Op.create(node1, node1.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create(node2, node2.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)));
    LOG.info("Restart the server");
    mt[followerA].shutdown();
    QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTING);
    mt[followerA].start();
    QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTED);
    LOG.info("Make sure the node consistent with leader");
    assertEquals(new String(zk[leaderId].getData(node2, null, null)), new String(zk[followerA].getData(node2, null, null)));
}
Also used : ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Aggregations

ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)96 File (java.io.File)39 Test (org.junit.jupiter.api.Test)33 ZooKeeper (org.apache.zookeeper.ZooKeeper)31 InetSocketAddress (java.net.InetSocketAddress)28 IOException (java.io.IOException)27 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)26 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)25 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)10 Stat (org.apache.zookeeper.data.Stat)9 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)8 ArrayList (java.util.ArrayList)6 ServerConfig (org.apache.zookeeper.server.ServerConfig)6 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)4 KeeperException (org.apache.zookeeper.KeeperException)4 Test (org.junit.Test)4 Field (java.lang.reflect.Field)3 ACL (org.apache.zookeeper.data.ACL)3 Proposal (org.apache.zookeeper.server.quorum.Leader.Proposal)3