Search in sources :

Example 56 with ZooKeeperServer

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

the class RestoreCommittedLogTest method testRestoreCommittedLog.

/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testRestoreCommittedLog() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    try {
        for (int i = 0; i < 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.shutdown();
    Assert.assertTrue("waiting for server to shutdown", ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // start server again
    zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    zks.startdata();
    List<Proposal> committedLog = zks.getZKDatabase().getCommittedLog();
    int logsize = committedLog.size();
    LOG.info("committedLog size = {}", logsize);
    Assert.assertTrue("log size != 0", (logsize != 0));
    zks.shutdown();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Proposal(org.apache.zookeeper.server.quorum.Leader.Proposal) Test(org.junit.Test)

Example 57 with ZooKeeperServer

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

the class ZooKeeperStateServer method startStandalone.

private void startStandalone() throws IOException {
    logger.info("Starting Embedded ZooKeeper Server");
    final ServerConfig config = new ServerConfig();
    config.readFrom(quorumPeerConfig);
    try {
        transactionLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir()));
        embeddedZkServer = new ZooKeeperServer();
        embeddedZkServer.setTxnLogFactory(transactionLog);
        embeddedZkServer.setTickTime(config.getTickTime());
        embeddedZkServer.setMinSessionTimeout(config.getMinSessionTimeout());
        embeddedZkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
        connectionFactory = ServerCnxnFactory.createFactory();
        connectionFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
        connectionFactory.startup(embeddedZkServer);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        logger.warn("Embedded ZooKeeper Server interrupted", e);
    } catch (final IOException ioe) {
        throw new IOException("Failed to start embedded ZooKeeper Server", ioe);
    } catch (final Exception e) {
        throw new RuntimeException("Failed to start embedded ZooKeeper Server", e);
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) IOException(java.io.IOException) File(java.io.File) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IOException(java.io.IOException)

Example 58 with ZooKeeperServer

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

the class EmbeddedZookeeper method before.

@Override
public void before() throws IOException {
    this.snapshotDir = constructTempDir(perTest("zk-snapshot"));
    this.logDir = constructTempDir(perTest("zk-log"));
    try {
        zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime);
        cnxnFactory = new NIOServerCnxnFactory();
        cnxnFactory.configure(new InetSocketAddress("localhost", port), 1024);
        cnxnFactory.startup(zooKeeperServer);
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) IOException(java.io.IOException) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 59 with ZooKeeperServer

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

the class ZooKeeperServerShimImpl method initialize.

@Override
public void initialize(File snapDir, File logDir, int zkPort, int maxCC) throws IOException {
    zks = new ZooKeeperServer(snapDir, logDir, ZooKeeperServer.DEFAULT_TICK_TIME);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(zkPort), maxCC);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 60 with ZooKeeperServer

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

the class EmbeddedZookeeper method startup.

public void startup() throws IOException {
    if (this.port == -1) {
        this.port = TestUtils.getAvailablePort();
    }
    this.factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
    this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot");
    this.logDir = TestUtils.constructTempDir("embeeded-zk/log");
    try {
        factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime));
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

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