List of usage examples for org.apache.zookeeper.server DatadirCleanupManager DatadirCleanupManager
public DatadirCleanupManager(File snapDir, File dataLogDir, int snapRetainCount, int purgeInterval)
From source file:com.anhth12.zk.util.LocalZKServer.java
/** * Starts Zookeeper./* www . ja va 2 s . c o m*/ * * @throws IOException if an error occurs during initialization * @throws InterruptedException if an error occurs during initialization */ public synchronized void start() throws IOException, InterruptedException { log.info("Starting Zookeeper on port {}", port); dataDir = Files.createTempDirectory(LocalZKServer.class.getSimpleName()); dataDir.toFile().deleteOnExit(); Properties properties = new Properties(); properties.setProperty("dataDir", dataDir.toAbsolutePath().toString()); properties.setProperty("clientPort", Integer.toString(port)); log.info("ZK config: {}", properties); QuorumPeerConfig quorumConfig = new QuorumPeerConfig(); try { quorumConfig.parseProperties(properties); } catch (QuorumPeerConfig.ConfigException e) { throw new IllegalArgumentException(e); } purgeManager = new DatadirCleanupManager(quorumConfig.getDataDir(), quorumConfig.getDataLogDir(), quorumConfig.getSnapRetainCount(), quorumConfig.getPurgeInterval()); purgeManager.start(); ServerConfig serverConfig = new ServerConfig(); serverConfig.readFrom(quorumConfig); zkServer = new ZooKeeperServer(); zkServer.setTickTime(serverConfig.getTickTime()); zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout()); // These two ServerConfig methods returned String in 3.4.x and File in 3.5.x transactionLog = new FileTxnSnapLog(new File(serverConfig.getDataLogDir().toString()), new File(serverConfig.getDataDir().toString())); zkServer.setTxnLogFactory(transactionLog); connectionFactory = ServerCnxnFactory.createFactory(); connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns()); connectionFactory.startup(zkServer); }
From source file:com.chiralBehaviors.autoconfigure.ZookeeperLauncher.java
License:Open Source License
/** * Copied from QuorumPeerMain because whomever wrote that crap made things * protected. Because freedom.//from ww w.j a va 2 s. c o m */ protected void initializeAndRun(String[] args) throws ConfigException, IOException { QuorumPeerConfig config = new QuorumPeerConfig(); if (args.length == 1) { config.parse(args[0]); } // Start and schedule the the purge task DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config.getDataDir(), config.getDataLogDir(), config.getSnapRetainCount(), config.getPurgeInterval()); purgeMgr.start(); if (args.length == 1 && config.getServers().size() > 0) { runFromConfig(config); } else { LOG.warning("Running in standalone mode"); // there is only server in the quorum -- run as standalone ZooKeeperServerMain.main(args); } }
From source file:com.cloudera.oryx.kafka.util.LocalZKServer.java
License:Open Source License
/** * Starts Zookeeper.//from w w w . j av a 2s .co m * * @throws IOException if an error occurs during initialization * @throws InterruptedException if an error occurs during initialization */ public synchronized void start() throws IOException, InterruptedException { log.info("Starting Zookeeper on port {}", port); dataDir = Files.createTempDirectory(LocalZKServer.class.getSimpleName()); dataDir.toFile().deleteOnExit(); QuorumPeerConfig quorumConfig = new QuorumPeerConfig(); try { quorumConfig.parseProperties( ConfigUtils.keyValueToProperties("dataDir", dataDir.toAbsolutePath(), "clientPort", port)); } catch (QuorumPeerConfig.ConfigException e) { throw new IllegalArgumentException(e); } purgeManager = new DatadirCleanupManager(quorumConfig.getDataDir(), quorumConfig.getDataLogDir(), quorumConfig.getSnapRetainCount(), quorumConfig.getPurgeInterval()); purgeManager.start(); ServerConfig serverConfig = new ServerConfig(); serverConfig.readFrom(quorumConfig); zkServer = new ZooKeeperServer(); zkServer.setTickTime(serverConfig.getTickTime()); zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout()); // These two ServerConfig methods returned String in 3.4.x and File in 3.5.x transactionLog = new FileTxnSnapLog(new File(serverConfig.getDataLogDir().toString()), new File(serverConfig.getDataDir().toString())); zkServer.setTxnLogFactory(transactionLog); connectionFactory = ServerCnxnFactory.createFactory(); connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns()); connectionFactory.startup(zkServer); }
From source file:com.glaf.cluster.catalina.session.QuorumPeerMain.java
License:Apache License
protected void initializeAndRun(String[] args) throws ConfigException, IOException { QuorumPeerConfig config = new QuorumPeerConfig(); if (args.length == 1) { config.parse(args[0]);/*from w w w. j a v a2 s . c om*/ } // Start and schedule the the purge task DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config.getDataDir(), config.getDataLogDir(), config.getSnapRetainCount(), config.getPurgeInterval()); purgeMgr.start(); if (args.length == 1 && config.getServers().size() > 0) { runFromConfig(config); } else { LOG.warn("Either no config or no quorum defined in config, running " + " in standalone mode"); // there is only server in the quorum -- run as standalone ZooKeeperServerMain.main(args); } }
From source file:com.splicemachine.test.SpliceZoo.java
License:Apache License
@Override public void run() { DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config.getDataDir(), config.getDataLogDir(), config.getSnapRetainCount(), config.getPurgeInterval()); purgeMgr.start();/*from ww w .j a v a 2 s.co m*/ SpliceLogUtils.trace(LOG, "Client Address: %s", config.getClientPortAddress()); try { peer.start(); SpliceLogUtils.trace(LOG, "Attempting to Join: %s", config.getClientPortAddress()); peer.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.apache.nifi.controller.state.server.ZooKeeperStateServer.java
License:Apache License
public synchronized void start() throws IOException { if (started) { return;// w ww .j a va 2 s . co m } if (quorumPeerConfig.getPurgeInterval() > 0) { datadirCleanupManager = new DatadirCleanupManager(quorumPeerConfig.getDataDir(), quorumPeerConfig.getDataLogDir(), quorumPeerConfig.getSnapRetainCount(), quorumPeerConfig.getPurgeInterval()); datadirCleanupManager.start(); } if (quorumPeerConfig.isDistributed()) { startDistributed(); } else { startStandalone(); } started = true; }
From source file:org.dcache.zookeeper.service.ZooKeeperCell.java
License:Open Source License
@Override protected void starting() throws Exception { super.starting(); InetSocketAddress socketAddress = Strings.isNullOrEmpty(address) ? new InetSocketAddress(port) : new InetSocketAddress(address, port); checkArgument(autoPurgeInterval > 0, "zookeeper.auto-purge.purge-interval must be non-negative."); zkServer = new PatchedZooKeeperServer(); txnLog = new FileTxnSnapLog(dataLogDir, dataDir); zkServer.setTxnLogFactory(txnLog);//from w ww .ja v a 2 s . c o m zkServer.setTickTime((int) tickTimeUnit.toMillis(tickTime)); zkServer.setMinSessionTimeout( minSessionTimeout == -1 ? -1 : (int) minSessionTimeoutUnit.toMillis(minSessionTimeout)); zkServer.setMaxSessionTimeout( maxSessionTimeout == -1 ? -1 : (int) maxSessionTimeoutUnit.toMillis(maxSessionTimeout)); zkServer.setZKDatabase(new ZKDatabase(txnLog)); // Work-around https://issues.apache.org/jira/browse/ZOOKEEPER-2810 zkServer.createSessionTracker(); // Work around https://issues.apache.org/jira/browse/ZOOKEEPER-2812 ServerCnxnFactory cnxnFactory; cnxnFactory = new NIOServerCnxnFactory() { @Override protected void configureSaslLogin() throws IOException { // ZooKeeper gets confused by dCache configuring a JAAS configuration without a section for ZooKeeper, so // we disable the whole thing. Use a non-embedded ZooKeeper if you want security. } }; cnxnFactory.configure(socketAddress, maxClientConnections); this.cnxnFactory = cnxnFactory; this.cnxnFactory.startup(zkServer); // FileTxnSnapLog constructor creates dataDir and dataLogDir if they // don't already exist, but in a non-thread safe fashion. // Unfortunately, DatadirCleanupManager#start launches an asynchronous // task that runs immediately and creates a FileTxnSnapLog object. This // can creating a race between the constructor above. To avoid this, // we must call DatadirCleanupManager#start after the FileTxnSnapLog // object has been created. int purgeIntervalHours = (int) TimeUnit.HOURS.convert(autoPurgeInterval, autoPurgeIntervalUnit); DatadirCleanupManager purgeMgr = new DatadirCleanupManager(dataDir.getAbsolutePath(), dataLogDir.getAbsolutePath(), autoPurgeRetainCount, purgeIntervalHours); purgeMgr.start(); }