Search in sources :

Example 1 with FileTxnSnapLog

use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project camel by apache.

the class ZKServerFactoryBean method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    if (purge) {
        deleteFilesInDir(getDataLogDir());
        deleteFilesInDir(getDataDir());
    }
    FileTxnSnapLog ftxn = new FileTxnSnapLog(getDataLogDir(), getDataDir());
    zooKeeperServer.setTxnLogFactory(ftxn);
    zooKeeperServer.setTickTime(getTickTime());
    zooKeeperServer.setMinSessionTimeout(getMinSessionTimeout());
    zooKeeperServer.setMaxSessionTimeout(getMaxSessionTimeout());
    connectionFactory = new NIOServerCnxnFactory();
    connectionFactory.configure(getClientPortAddress(), getMaxClientConnections());
    connectionFactory.startup(zooKeeperServer);
}
Also used : NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Example 2 with FileTxnSnapLog

use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project nifi by apache.

the class EmbeddedKafka method startZookeeper.

/**
 * Will start Zookeeper server via {@link ServerCnxnFactory}
 */
private void startZookeeper() {
    QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
    try {
        quorumConfiguration.parseProperties(this.zookeeperConfig);
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumConfiguration);
        FileTxnSnapLog txnLog = new FileTxnSnapLog(new File(configuration.getDataLogDir()), new File(configuration.getDataDir()));
        zkServer.setTxnLogFactory(txnLog);
        zkServer.setTickTime(configuration.getTickTime());
        zkServer.setMinSessionTimeout(configuration.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(configuration.getMaxSessionTimeout());
        ServerCnxnFactory zookeeperConnectionFactory = ServerCnxnFactory.createFactory();
        zookeeperConnectionFactory.configure(configuration.getClientPortAddress(), configuration.getMaxClientCnxns());
        zookeeperConnectionFactory.startup(zkServer);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start Zookeeper server", e);
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) File(java.io.File) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) IOException(java.io.IOException)

Example 3 with FileTxnSnapLog

use of org.apache.zookeeper.server.persistence.FileTxnSnapLog in project zookeeper by apache.

the class PurgeTxnTest method testFindNRecentSnapshots.

/**
 * Tests finding n recent snapshots from set of snapshots and data logs
 */
@Test
public void testFindNRecentSnapshots() throws Exception {
    // n recent snap shots
    int nRecentSnap = 4;
    int nRecentCount = 30;
    int offset = 0;
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(), version2.mkdir());
    // Test that with no snaps, findNRecentSnapshots returns empty list
    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> foundSnaps = txnLog.findNRecentSnapshots(1);
    assertEquals(0, foundSnaps.size());
    List<File> expectedNRecentSnapFiles = new ArrayList<File>();
    int counter = offset + (2 * nRecentCount);
    for (int i = 0; i < nRecentCount; i++) {
        // simulate log file
        File logFile = new File(version2 + "/log." + Long.toHexString(--counter));
        Assert.assertTrue("Failed to create log File:" + logFile.toString(), logFile.createNewFile());
        // simulate snapshot file
        File snapFile = new File(version2 + "/snapshot." + Long.toHexString(--counter));
        Assert.assertTrue("Failed to create snap File:" + snapFile.toString(), snapFile.createNewFile());
        // add the n recent snap files for assertion
        if (i < nRecentSnap) {
            expectedNRecentSnapFiles.add(snapFile);
        }
    }
    // Test that when we ask for recent snaps we get the number we asked for and
    // the files we expected
    List<File> nRecentSnapFiles = txnLog.findNRecentSnapshots(nRecentSnap);
    Assert.assertEquals("exactly 4 snapshots ", 4, nRecentSnapFiles.size());
    expectedNRecentSnapFiles.removeAll(nRecentSnapFiles);
    Assert.assertEquals("Didn't get the recent snap files", 0, expectedNRecentSnapFiles.size());
    // Test that when asking for more snaps than we created, we still only get snaps
    // not logs or anything else (per ZOOKEEPER-2420)
    nRecentSnapFiles = txnLog.findNRecentSnapshots(nRecentCount + 5);
    assertEquals(nRecentCount, nRecentSnapFiles.size());
    for (File f : nRecentSnapFiles) {
        Assert.assertTrue("findNRecentSnapshots() returned a non-snapshot: " + f.getPath(), (Util.getZxidFromName(f.getName(), "snapshot") != -1));
    }
    txnLog.close();
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) Test(org.junit.Test)

Example 4 with FileTxnSnapLog

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

the class GroupTest method startZooKeeper.

private NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
    ServerConfig cfg = new ServerConfig();
    cfg.parse(new String[] { Integer.toString(port), "target/zk/data" });
    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(6000);
    zkServer.setMaxSessionTimeout(9000);
    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) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Example 5 with FileTxnSnapLog

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

the class ZookeeperPortServiceTest method startZooKeeper.

private NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
    String testDirectory = "target/zk-ports/data" + System.currentTimeMillis();
    FileUtils.deleteDirectory(new File(testDirectory));
    ServerConfig cfg = new ServerConfig();
    cfg.parse(new String[] { Integer.toString(port), testDirectory });
    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) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Aggregations

FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)54 File (java.io.File)37 Test (org.junit.jupiter.api.Test)20 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)17 IOException (java.io.IOException)13 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)10 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)10 ServerConfig (org.apache.zookeeper.server.ServerConfig)8 ZooKeeper (org.apache.zookeeper.ZooKeeper)6 QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)6 ArrayList (java.util.ArrayList)5 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)5 TxnHeader (org.apache.zookeeper.txn.TxnHeader)5 BinaryOutputArchive (org.apache.jute.BinaryOutputArchive)4 ConfigException (org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Socket (java.net.Socket)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Record (org.apache.jute.Record)3 Test (org.junit.Test)3