Search in sources :

Example 16 with Proposal

use of org.apache.zookeeper.server.quorum.Leader.Proposal in project zookeeper by apache.

the class RestoreCommittedLogTest method testRestoreCommittedLog.

/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
private void testRestoreCommittedLog(int totalTransactions, byte[] data, int minExpectedSnapshots) throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being up ");
    ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    try {
        for (int i = 0; i < totalTransactions; i++) {
            zk.create("/invalidsnap-" + i, data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    final int numSnaps = zks.getTxnLogFactory().findNRecentSnapshots(10 * minExpectedSnapshots).size();
    LOG.info("number of snapshots taken {}", numSnaps);
    f.shutdown();
    zks.shutdown();
    assertTrue(ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server to shutdown");
    assertTrue(numSnaps > minExpectedSnapshots, "too few snapshot files");
    assertTrue(numSnaps <= minExpectedSnapshots * 2, "too many snapshot files");
    // start server again
    zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    zks.startdata();
    Collection<Proposal> committedLog = zks.getZKDatabase().getCommittedLog();
    int logsize = committedLog.size();
    LOG.info("committedLog size = {}", logsize);
    assertTrue((logsize != 0), "log size != 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)

Aggregations

Proposal (org.apache.zookeeper.server.quorum.Leader.Proposal)16 ZooKeeper (org.apache.zookeeper.ZooKeeper)6 Test (org.junit.jupiter.api.Test)6 File (java.io.File)4 KeeperException (org.apache.zookeeper.KeeperException)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 ReadLock (java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock)3 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)3 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)3 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 Stat (org.apache.zookeeper.data.Stat)2 QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 LineNumberReader (java.io.LineNumberReader)1 StringReader (java.io.StringReader)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 SocketChannel (java.nio.channels.SocketChannel)1