Refine search
ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTimeToUse); server.setMinSessionTimeout(configuration.getInt( "hbase.zookeeper.property.minSessionTimeout", -1)); server.setMaxSessionTimeout(configuration.getInt( "hbase.zookeeper.property.maxSessionTimeout", -1)); NIOServerCnxnFactory standaloneServerFactory; while (true) { try { standaloneServerFactory = new NIOServerCnxnFactory(); standaloneServerFactory.configure( new InetSocketAddress(currentClientPort), configuration.getInt(HConstants.ZOOKEEPER_MAX_CLIENT_CNXNS, HConstants.DEFAULT_ZOOKEEPER_MAX_CLIENT_CNXNS)); standaloneServerFactory.startup(server);
@Test public void testFileDescriptorLeak() throws Exception { OSMXBean osMbean = new OSMXBean(); if (osMbean.getUnix() != true) { LOG.info("Unable to run test on non-unix system"); return; } long startFdCount = osMbean.getOpenFileDescriptorCount(); LOG.info("Start fdcount is: " + startFdCount); for (int i = 0; i < 50; ++i) { NIOServerCnxnFactory factory = new NIOServerCnxnFactory(); factory.configure( new InetSocketAddress( "127.0.0.1", PortAssignment.unique()), 10); factory.start(); Thread.sleep(100); factory.shutdown(); } long endFdCount = osMbean.getOpenFileDescriptorCount(); LOG.info("End fdcount is: " + endFdCount); // On my box, if selector.close() is not called fd diff is > 700. Assert.assertTrue("Possible fd leakage", ((endFdCount - startFdCount) < 50)); } }
public void shutdown() { try { // close listen socket and signal selector threads to stop stop(); // wait for selector and worker threads to shutdown join(); // close all open connections closeAll(); if (login != null) { login.shutdown(); } } catch (InterruptedException e) { LOG.warn("Ignoring interrupted exception during shutdown", e); } catch (Exception e) { LOG.warn("Ignoring unexpected exception during shutdown", e); } if (zkServer != null) { zkServer.shutdown(); } }
_factory = new NIOServerCnxnFactory(); } catch (IOException e) { _port = 0; _factory.configure(new InetSocketAddress(_port), maxClientCnxns); LOG.debug("Zookeeper server successfully binded at port " + _port); break;
public ServerCnxnFactory mkInprocessZookeeper(String localdir, int port) throws IOException, InterruptedException { LOG.info("Starting inprocess zookeeper at port " + port + " and dir " + localdir); File localfile = new File(localdir); ZooKeeperServer zk = new ZooKeeperServer(localfile, localfile, 2000); ServerCnxnFactory factory =NIOServerCnxnFactory.createFactory( new InetSocketAddress(port),60); factory.startup(zk); return factory; }
private String startZk() throws IOException, InterruptedException, URISyntaxException { String zkValue = properties.getProperty("zookeeper.connect"); LOG.info("Starting zookeeper at {}", zkValue); URL zkAddress = getURL(zkValue); File snapshotDir = constructDir("zk/txn"); File logDir = constructDir("zk/snap"); factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress(zkAddress.getHost(), zkAddress.getPort()), 1024); factory.startup(new ZooKeeperServer(snapshotDir, logDir, 500)); String ret = factory.getLocalAddress().getAddress().toString(); LOG.info("Embedded zookeeper for Kafka started at {}", ret); return ret; }
public static void startZookeeper(final int clusterId) { try { int numConnections = 100; int tickTime = 2000; File dir = new File(baseDir, zkdir[clusterId]); zkServer[clusterId] = new TestZookeeperServer(dir, dir, tickTime); zkFactory[clusterId] = new NIOServerCnxnFactory(); zkFactory[clusterId].configure(new InetSocketAddress(TEST_ZOOKEEPER_PORT[clusterId]), numConnections); zkFactory[clusterId].startup(zkServer[clusterId]); // start the zookeeper server. Thread.sleep(2000); //kserver.startup(); } catch (Exception ex) { logger.error(ex.getLocalizedMessage()); } }
public EmbeddedZookeeper(int port, Path baseDir) throws Exception { this.port = port; zookeeperBaseDir = baseDir; zkServer = new ZooKeeperServer(); File dataDir = zookeeperBaseDir.resolve("log").toFile(); File snapDir = zookeeperBaseDir.resolve("data").toFile(); FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, snapDir); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(1000); connectionFactory = new NIOServerCnxnFactory() { @Override protected void configureSaslLogin() throws IOException { // do nothing } }; connectionFactory.configure(new InetSocketAddress("localhost", port), 0); }
public EmbeddedZookeeper(int port) throws IOException { this.port = port; zkDataDir = Files.createTempDir(); zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(zkDataDir, zkDataDir); zkServer.setTxnLogFactory(ftxn); cnxnFactory = NIOServerCnxnFactory.createFactory(new InetSocketAddress(port), 0); }
public void run() throws Exception { File dir = new File(dataDirectory, "zookeeper").getAbsoluteFile(); NIOServerCnxnFactory factory = new NIOServerCnxnFactory(); ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTime); factory.setZooKeeperServer(server); factory.setMaxClientCnxnsPerHost(numConnections); factory.configure(new InetSocketAddress(clientPort), numConnections); factory.startup(server); }
public EmbeddedZookeeper() { try { snapshotDir = KafkaTestUtils.newTempDir(); logDir = KafkaTestUtils.newTempDir(); tickTime = 500; zk = new ZooKeeperServer(snapshotDir, logDir, tickTime); registerShutdownHandler(zk); cnxnFactory = new NIOServerCnxnFactory(); InetAddress localHost = InetAddress.getLocalHost(); hostAddress = localHost.getHostAddress(); InetSocketAddress bindAddress = new InetSocketAddress(localHost, port); cnxnFactory.configure(bindAddress, 0); cnxnFactory.startup(zk); port = zk.getClientPort(); } catch (Exception e) { throw new IllegalStateException(e); } //sanity check if (zk.getClientPort() != port) { throw new IllegalStateException(); } }
int clientPort = 2199; // not standard int numConnections = 5000; int tickTime = 2000; String dataDirectory = System.getProperty("java.io.tmpdir"); File dir = new File(dataDirectory, "zookeeper").getAbsoluteFile(); ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTime); ServerCnxnFactory factory = new NIOServerCnxnFactory(); factory.configure(new InetSocketAddress(clientPort), numConnections); factory.startup(server); // start the server. // ...shutdown some time later factory.shutdown();
/** * This method is coming from <code>ZooKeeperServerMain</code> but tweaked to not block and to * have access to <code>_zkServer</code> and <code>_cnxnFactory</code>. */ private void runFromConfig(ServerConfig config) throws IOException { log.info("Starting server"); try { _zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())); _zkServer.setTxnLogFactory(ftxn); _zkServer.setTickTime(config.getTickTime()); _zkServer.setMinSessionTimeout(config.getMinSessionTimeout()); _zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout()); _cnxnFactory = new NIOServerCnxnFactory(); _cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); _cnxnFactory.startup(_zkServer); } catch(InterruptedException e) { // warn, but generally this is ok log.warn("Server interrupted", e); } }
public ZooKeeperServerFactory(QuorumPeerConfig config) throws IOException, InterruptedException { LOGGER.info("Creating zookeeper server with: {}", config); ServerConfig serverConfig = getServerConfig(config); ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(serverConfig.getDataLogDir()), new File(serverConfig.getDataDir())); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(serverConfig.getTickTime()); zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout()); NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory() { protected void configureSaslLogin() throws IOException { } }; InetSocketAddress clientPortAddress = serverConfig.getClientPortAddress(); cnxnFactory.configure(clientPortAddress, serverConfig.getMaxClientCnxns()); updateZooKeeperURL(cnxnFactory.getLocalAddress(), cnxnFactory.getLocalPort()); try { LOGGER.debug("Starting ZooKeeper server on address %s", serverConfig.getClientPortAddress()); cnxnFactory.startup(zkServer); LOGGER.debug("Started ZooKeeper server"); } catch (Exception e) { LOGGER.warn(String.format("Failed to start ZooKeeper server, reason : %s", e)); cnxnFactory.shutdown(); throw e; } }
public void shutdown() throws Exception { try { connectionFactory.shutdown(); connectionFactory.join(); zkServer.shutdown(); while (zkServer.isRunning()) { zkServer.shutdown(); Thread.sleep(100); } } finally { try { cleanZookeeperDir(); } catch (Exception e) { LOG.warn("Error cleaning up ZK data directory {}", e); } } }
/** * Kill one back up ZK servers. * * @throws IOException if waiting for the shutdown of a server fails */ public void killOneBackupZooKeeperServer() throws IOException, InterruptedException { if (!started || activeZKServerIndex < 0 || standaloneServerFactoryList.size() <= 1) { return ; } int backupZKServerIndex = activeZKServerIndex+1; // Shutdown the current active one NIOServerCnxnFactory standaloneServerFactory = standaloneServerFactoryList.get(backupZKServerIndex); int clientPort = clientPortList.get(backupZKServerIndex); standaloneServerFactory.shutdown(); if (!waitForServerDown(clientPort, connectionTimeout)) { throw new IOException("Waiting for shutdown of standalone server"); } zooKeeperServers.get(backupZKServerIndex).getZKDatabase().close(); // remove this backup zk server standaloneServerFactoryList.remove(backupZKServerIndex); clientPortList.remove(backupZKServerIndex); zooKeeperServers.remove(backupZKServerIndex); LOG.info("Kill one backup ZK servers in the cluster " + "on client port: " + clientPort); }
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); }