org.apache.zookeeper.server.ZKDatabase Java Examples

The following examples show how to use org.apache.zookeeper.server.ZKDatabase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedZooKeeper.java    From centraldogma with Apache License 2.0 6 votes vote down vote up
@Nullable
private static DataTree dataTree(@Nullable EmbeddedZooKeeper peer) {
    if (peer == null) {
        return null;
    }

    final ZooKeeperServer activeServer = peer.getActiveServer();
    if (activeServer == null) {
        return null;
    }

    final ZKDatabase database = activeServer.getZKDatabase();
    if (database == null) {
        return null;
    }

    return database.getDataTree();
}
 
Example #2
Source File: TestZKClient.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@After
public void tearDown() throws IOException, InterruptedException {
  if (zks != null) {
    ZKDatabase zkDb = zks.getZKDatabase();
    factory.shutdown();
    try {
      zkDb.close();
    } catch (IOException ie) {
    }
    final int PORT = Integer.parseInt(hostPort.split(":")[1]);

    Assert.assertTrue("waiting for server down",
        waitForServerDown("127.0.0.1:" + PORT,
            CONNECTION_TIMEOUT));
  }

}
 
Example #3
Source File: ClientBaseWithFixes.java    From hadoop with Apache License 2.0 6 votes vote down vote up
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = getServer(factory);
    
            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
 
Example #4
Source File: TestZKClient.java    From big-c with Apache License 2.0 6 votes vote down vote up
@After
public void tearDown() throws IOException, InterruptedException {
  if (zks != null) {
    ZKDatabase zkDb = zks.getZKDatabase();
    factory.shutdown();
    try {
      zkDb.close();
    } catch (IOException ie) {
    }
    final int PORT = Integer.parseInt(hostPort.split(":")[1]);

    Assert.assertTrue("waiting for server down",
        waitForServerDown("127.0.0.1:" + PORT,
            CONNECTION_TIMEOUT));
  }

}
 
Example #5
Source File: ClientBaseWithFixes.java    From big-c with Apache License 2.0 6 votes vote down vote up
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = getServer(factory);
    
            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
 
Example #6
Source File: ZookeeperDiscoverySpiSaslAuthAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
private void shutdownServerInstance(ServerCnxnFactory factory)
{
    if (factory != null) {
        ZKDatabase zkDb = null;
        {
            ZooKeeperServer zs = getServer(factory);
            if (zs != null)
                zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            if (zkDb != null)
                zkDb.close();
        } catch (IOException ie) {
            // ignore
        }
    }
}
 
Example #7
Source File: SpliceZoo.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public SpliceZoo(QuorumPeerConfig config, int number) throws IOException {
	this.config = config;
	try {
		if (QuorumPeer.class.getMethod("testingQuorumPeer", null) != null)
			this.peer = (QuorumPeer) QuorumPeer.class.getMethod("testingQuorumPeer", null).invoke(null,null);
		else
			this.peer = QuorumPeer.class.newInstance();
	} catch (Exception e) {
		throw new RuntimeException("Quorum Peer Signature Issue for Unit Tests");
	}
	ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
	cnxnFactory.configure(config.getClientPortAddress(),config.getMaxClientCnxns());
	peer.setClientPortAddress(config.getClientPortAddress());
	peer.setTxnFactory(new FileTxnSnapLog(new File(config.getDataLogDir()),
                    new File(config.getDataDir())));
	peer.setQuorumPeers(config.getServers());
	peer.setElectionType(config.getElectionAlg());
	peer.setMyid(config.getServerId());
	peer.setTickTime(config.getTickTime());
	peer.setMinSessionTimeout(config.getMinSessionTimeout());
	peer.setMaxSessionTimeout(config.getMaxSessionTimeout());
	peer.setInitLimit(config.getInitLimit());
	peer.setSyncLimit(config.getSyncLimit());
	peer.setQuorumVerifier(config.getQuorumVerifier());
	peer.setCnxnFactory(cnxnFactory);
	peer.setZKDatabase(new ZKDatabase(peer.getTxnFactory()));
	peer.setLearnerType(config.getPeerType());
	peer.setMyid(number);
}
 
Example #8
Source File: ZooKeeperStateServer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void startDistributed() throws IOException {
    logger.info("Starting Embedded ZooKeeper Peer");

    try {
        transactionLog = new FileTxnSnapLog(new File(quorumPeerConfig.getDataLogDir()), new File(quorumPeerConfig.getDataDir()));

        connectionFactory = ServerCnxnFactory.createFactory();
        connectionFactory.configure(quorumPeerConfig.getClientPortAddress(), quorumPeerConfig.getMaxClientCnxns());

        quorumPeer = new QuorumPeer();
        quorumPeer.setClientPortAddress(quorumPeerConfig.getClientPortAddress());
        quorumPeer.setTxnFactory(new FileTxnSnapLog(new File(quorumPeerConfig.getDataLogDir()), new File(quorumPeerConfig.getDataDir())));
        quorumPeer.setQuorumPeers(quorumPeerConfig.getServers());
        quorumPeer.setElectionType(quorumPeerConfig.getElectionAlg());
        quorumPeer.setMyid(quorumPeerConfig.getServerId());
        quorumPeer.setTickTime(quorumPeerConfig.getTickTime());
        quorumPeer.setMinSessionTimeout(quorumPeerConfig.getMinSessionTimeout());
        quorumPeer.setMaxSessionTimeout(quorumPeerConfig.getMaxSessionTimeout());
        quorumPeer.setInitLimit(quorumPeerConfig.getInitLimit());
        quorumPeer.setSyncLimit(quorumPeerConfig.getSyncLimit());
        quorumPeer.setQuorumVerifier(quorumPeerConfig.getQuorumVerifier());
        quorumPeer.setCnxnFactory(connectionFactory);
        quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
        quorumPeer.setLearnerType(quorumPeerConfig.getPeerType());
        quorumPeer.setSyncEnabled(quorumPeerConfig.getSyncEnabled());
        quorumPeer.setQuorumListenOnAllIPs(quorumPeerConfig.getQuorumListenOnAllIPs());

        quorumPeer.start();
    } catch (final IOException ioe) {
        throw new IOException("Failed to start embedded ZooKeeper Peer", ioe);
    } catch (final Exception e) {
        throw new RuntimeException("Failed to start embedded ZooKeeper Peer", e);
    }
}
 
Example #9
Source File: ZooKeeperStateServer.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void startDistributed() throws IOException {
    logger.info("Starting Embedded ZooKeeper Peer");

    try {
        transactionLog = new FileTxnSnapLog(quorumPeerConfig.getDataLogDir(), quorumPeerConfig.getDataDir());

        connectionFactory = ServerCnxnFactory.createFactory();
        connectionFactory.configure(quorumPeerConfig.getClientPortAddress(), quorumPeerConfig.getMaxClientCnxns());

        quorumPeer = new QuorumPeer();
        quorumPeer.setTxnFactory(new FileTxnSnapLog(quorumPeerConfig.getDataLogDir(), quorumPeerConfig.getDataDir()));
        quorumPeer.setElectionType(quorumPeerConfig.getElectionAlg());
        quorumPeer.setMyid(quorumPeerConfig.getServerId());
        quorumPeer.setTickTime(quorumPeerConfig.getTickTime());
        quorumPeer.setMinSessionTimeout(quorumPeerConfig.getMinSessionTimeout());
        quorumPeer.setMaxSessionTimeout(quorumPeerConfig.getMaxSessionTimeout());
        quorumPeer.setInitLimit(quorumPeerConfig.getInitLimit());
        quorumPeer.setSyncLimit(quorumPeerConfig.getSyncLimit());
        quorumPeer.setQuorumVerifier(quorumPeerConfig.getQuorumVerifier(), false);
        quorumPeer.setCnxnFactory(connectionFactory);
        quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
        quorumPeer.setLearnerType(quorumPeerConfig.getPeerType());
        quorumPeer.setSyncEnabled(quorumPeerConfig.getSyncEnabled());
        quorumPeer.setQuorumListenOnAllIPs(quorumPeerConfig.getQuorumListenOnAllIPs());

        quorumPeer.start();
    } catch (final IOException ioe) {
        throw new IOException("Failed to start embedded ZooKeeper Peer", ioe);
    } catch (final Exception e) {
        throw new RuntimeException("Failed to start embedded ZooKeeper Peer", e);
    }
}
 
Example #10
Source File: ZkTestServer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Shutdown the serving instance
 * @throws IOException If there is a low-level I/O error.
 */
protected void shutdown() throws IOException {

  // shutting down the cnxnFactory will close the zooKeeperServer
  // zooKeeperServer.shutdown();

  ZKDatabase zkDb = zooKeeperServer.getZKDatabase();
  try {
    if (cnxnFactory != null) {
      while (true) {
        cnxnFactory.shutdown();
        try {
          cnxnFactory.join();
          break;
        } catch (InterruptedException e) {
          // Thread.currentThread().interrupt();
          // don't keep interrupted status
        }
      }
    }
    if (zkDb != null) {
      zkDb.close();
    }

    if (cnxnFactory != null && cnxnFactory.getLocalPort() != 0) {
      waitForServerDown(getZkHost(), 30000);
    }
  } finally {

    ObjectReleaseTracker.release(this);
  }
}
 
Example #11
Source File: ZookeeperInstance.java    From netcrusher-java with Apache License 2.0 5 votes vote down vote up
private QuorumPeer createPeer(ServerCnxnFactory cnxnFactory, QuorumPeerConfig config) throws IOException {
    cnxnFactory.configure(config.getClientPortAddress(),
            config.getMaxClientCnxns());

    QuorumPeer quorumPeer = new QuorumPeer();
    quorumPeer.setClientPortAddress(config.getClientPortAddress());
    quorumPeer.setTxnFactory(new FileTxnSnapLog(
            new File(config.getDataLogDir()),
            new File(config.getDataDir())));
    quorumPeer.setQuorumPeers(config.getServers());
    quorumPeer.setElectionType(config.getElectionAlg());
    quorumPeer.setMyid(config.getServerId());
    quorumPeer.setTickTime(config.getTickTime());
    quorumPeer.setMinSessionTimeout(config.getMinSessionTimeout());
    quorumPeer.setMaxSessionTimeout(config.getMaxSessionTimeout());
    quorumPeer.setInitLimit(config.getInitLimit());
    quorumPeer.setSyncLimit(config.getSyncLimit());
    quorumPeer.setQuorumVerifier(config.getQuorumVerifier());
    quorumPeer.setCnxnFactory(cnxnFactory);
    quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
    quorumPeer.setLearnerType(config.getPeerType());
    quorumPeer.setSyncEnabled(config.getSyncEnabled());
    quorumPeer.setQuorumListenOnAllIPs(config.getQuorumListenOnAllIPs());

    quorumPeer.start();

    return quorumPeer;
}
 
Example #12
Source File: ZkTestServer.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void setZKDatabase(ZKDatabase zkDb) {
  this.zkDb = zkDb;
  zkServer.zooKeeperServer.setZKDatabase(zkDb);
}
 
Example #13
Source File: TestConfigSetsAPIZkFailure.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public FailureDuringCopyZKDatabase(ZKDatabase zkdb, ZkTestServer zkTestServer) {
  super(zkdb);
  this.zkTestServer = zkTestServer;
}
 
Example #14
Source File: TestConfigSetsAPIZkFailure.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public ForwardingZKDatabase(ZKDatabase zkdb) {
  super(null);
  this.zkdb = zkdb;
}
 
Example #15
Source File: KafkaOperatorTestBase.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public TestZookeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout, int maxSessionTimeout, DataTreeBuilder treeBuilder, ZKDatabase zkDb)
{
  super(txnLogFactory, tickTime, minSessionTimeout, maxSessionTimeout, treeBuilder, zkDb);
  // TODO Auto-generated constructor stub
}
 
Example #16
Source File: KafkaOperatorTestBase.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public TestZookeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout,
    int maxSessionTimeout, DataTreeBuilder treeBuilder, ZKDatabase zkDb)
{
  super(txnLogFactory, tickTime, minSessionTimeout, maxSessionTimeout, treeBuilder, zkDb);
  // TODO Auto-generated constructor stub
}
 
Example #17
Source File: KafkaOperatorTestBase.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public TestZookeeperServer(FileTxnSnapLog txnLogFactory, int tickTime, int minSessionTimeout,
    int maxSessionTimeout, DataTreeBuilder treeBuilder, ZKDatabase zkDb)
{
  super(txnLogFactory, tickTime, minSessionTimeout, maxSessionTimeout, treeBuilder, zkDb);
  // TODO Auto-generated constructor stub
}
 
Example #18
Source File: ZkTestServer.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public ZKDatabase getZKDatabase() {
  return zkServer.zooKeeperServer.getZKDatabase();
}