当前位置: 首页>>代码示例>>Java>>正文


Java FileTxnSnapLog.version方法代码示例

本文整理汇总了Java中org.apache.zookeeper.server.persistence.FileTxnSnapLog.version方法的典型用法代码示例。如果您正苦于以下问题:Java FileTxnSnapLog.version方法的具体用法?Java FileTxnSnapLog.version怎么用?Java FileTxnSnapLog.version使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.server.persistence.FileTxnSnapLog的用法示例。


在下文中一共展示了FileTxnSnapLog.version方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReadOnlySnapshotDir

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入方法依赖的package包/类
/**
 * Tests that the ZooKeeper server will fail to start if the
 * snapshot directory is read only.
 *
 * This test will fail if it is executed as root user.
 */
@Test(timeout = 30000)
public void testReadOnlySnapshotDir() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT = PortAssignment.unique();

    // Start up the ZK server to automatically create the necessary directories
    // and capture the directory where data is stored
    MainThread main = new MainThread(CLIENT_PORT, true, null);
    File tmpDir = main.tmpDir;
    main.start();
    Assert.assertTrue("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));
    main.shutdown();

    // Make the snapshot directory read only
    File snapDir = new File(main.dataDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    snapDir.setWritable(false);

    // Restart ZK and observe a failure
    main = new MainThread(CLIENT_PORT, false, tmpDir, null);
    main.start();

    Assert.assertFalse("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));

    main.shutdown();

    snapDir.setWritable(true);

    main.deleteDirs();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:40,代码来源:ZooKeeperServerMainTest.java

示例2: testReadOnlyTxnLogDir

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入方法依赖的package包/类
/**
 * Tests that the ZooKeeper server will fail to start if the
 * transaction log directory is read only.
 *
 * This test will fail if it is executed as root user.
 */
@Test(timeout = 30000)
public void testReadOnlyTxnLogDir() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT = PortAssignment.unique();

    // Start up the ZK server to automatically create the necessary directories
    // and capture the directory where data is stored
    MainThread main = new MainThread(CLIENT_PORT, true, null);
    File tmpDir = main.tmpDir;
    main.start();
    Assert.assertTrue("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));
    main.shutdown();

    // Make the transaction log directory read only
    File logDir = new File(main.logDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    logDir.setWritable(false);

    // Restart ZK and observe a failure
    main = new MainThread(CLIENT_PORT, false, tmpDir, null);
    main.start();

    Assert.assertFalse("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));

    main.shutdown();

    logDir.setWritable(true);

    main.deleteDirs();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:40,代码来源:ZooKeeperServerMainTest.java

示例3: testReadOnlySnapshotDir

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入方法依赖的package包/类
/**
 * Tests that the ZooKeeper server will fail to start if the
 * snapshot directory is read only.
 *
 * This test will fail if it is executed as root user.
 */
@Test(timeout = 30000)
public void testReadOnlySnapshotDir() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT = PortAssignment.unique();

    // Start up the ZK server to automatically create the necessary directories
    // and capture the directory where data is stored
    MainThread main = new MainThread(CLIENT_PORT, true);
    File tmpDir = main.tmpDir;
    main.start();
    Assert.assertTrue("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));
    main.shutdown();

    // Make the snapshot directory read only
    File snapDir = new File(main.dataDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    snapDir.setWritable(false);

    // Restart ZK and observe a failure
    main = new MainThread(CLIENT_PORT, false, tmpDir);
    main.start();

    Assert.assertFalse("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));

    main.shutdown();

    snapDir.setWritable(true);

    main.deleteDirs();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:40,代码来源:ZooKeeperServerMainTest.java

示例4: testReadOnlyTxnLogDir

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入方法依赖的package包/类
/**
 * Tests that the ZooKeeper server will fail to start if the
 * transaction log directory is read only.
 *
 * This test will fail if it is executed as root user.
 */
@Test(timeout = 30000)
public void testReadOnlyTxnLogDir() throws Exception {
    ClientBase.setupTestEnv();
    final int CLIENT_PORT = PortAssignment.unique();

    // Start up the ZK server to automatically create the necessary directories
    // and capture the directory where data is stored
    MainThread main = new MainThread(CLIENT_PORT, true);
    File tmpDir = main.tmpDir;
    main.start();
    Assert.assertTrue("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));
    main.shutdown();

    // Make the transaction log directory read only
    File logDir = new File(main.logDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    logDir.setWritable(false);

    // Restart ZK and observe a failure
    main = new MainThread(CLIENT_PORT, false, tmpDir);
    main.start();

    Assert.assertFalse("waiting for server being up", ClientBase
            .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
                    CONNECTION_TIMEOUT / 2));

    main.shutdown();

    logDir.setWritable(true);

    main.deleteDirs();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:40,代码来源:ZooKeeperServerMainTest.java

示例5: testDirtySnapshot

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入方法依赖的package包/类
/**
 * verify that a peer with dirty snapshot joining an established cluster
 * does not go into an inconsistent state.
 *
 * {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1558}
 */
@Test
public void testDirtySnapshot()
throws IOException,
    InterruptedException,
    KeeperException,
    NoSuchFieldException,
    IllegalAccessException {
    Socket pair[] = getSocketPair();
    Socket leaderSocket = pair[0];
    Socket followerSocket = pair[1];
    File tmpDir = File.createTempFile("test", "dir");
    tmpDir.delete();
    tmpDir.mkdir();
    LeadThread leadThread = null;
    Leader leader = null;
    try {
        // Setup a database with two znodes
        FileTxnSnapLog snapLog = new FileTxnSnapLog(tmpDir, tmpDir);
        ZKDatabase zkDb = new ZKDatabase(snapLog);

        long zxid = ZxidUtils.makeZxid(0, 1);
        String path = "/foo";
        zkDb.processTxn(new TxnHeader(13,1000,zxid,30,ZooDefs.OpCode.create),
                                        new CreateTxn(path, "fpjwasalsohere".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, false, 1));
        Stat stat = new Stat();
        Assert.assertEquals("fpjwasalsohere", new String(zkDb.getData(path, stat, null)));

        // Close files
        snapLog.close();

        QuorumPeer peer = createQuorumPeer(tmpDir);

        leader = createLeader(tmpDir, peer);
        peer.leader = leader;

        // Set the last accepted epoch and current epochs to be 1
        peer.setAcceptedEpoch(0);
        peer.setCurrentEpoch(0);

        leadThread = new LeadThread(leader);
        leadThread.start();

        while(leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) {
            Thread.sleep(20);
        }

        leader.shutdown("Shutting down the leader");

        // Check if there is a valid snapshot (we better not have it)
        File snapDir = new File (tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
        List<File> files = Util.sortDataDir(snapDir.listFiles(),"snapshot", false);

        for (File f : files) {
            try {
                Assert.assertFalse("Found a valid snapshot", Util.isValidSnapshot(f));
            } catch (IOException e) {
                LOG.info("invalid snapshot " + f, e);
            }
        }

    } finally {
        if (leader != null) {
            leader.shutdown("end of test");
        }
        if (leadThread != null) {
            leadThread.interrupt();
            leadThread.join();
        }
        recursiveDelete(tmpDir);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:78,代码来源:Zab1_0Test.java

示例6: testLoad

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入方法依赖的package包/类
/**
 * test that all transactions from the Log are loaded, and only once
 * @throws Exception an exception might be thrown here
 */
@Test
public void testLoad() throws Exception {
    // setup a single server cluster
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);

    // generate some transactions that will get logged
    try {
        for (int i = 0; i< NUM_MESSAGES; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));

    // now verify that the FileTxnLog reads every transaction only once
    File logDir = new File(tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    FileTxnLog txnLog = new FileTxnLog(logDir);

    TxnIterator itr = txnLog.read(0);
    long expectedZxid = 0;
    long lastZxid = 0;
    TxnHeader hdr;
    do {
        hdr = itr.getHeader();
        expectedZxid++;
        Assert.assertTrue("not the same transaction. lastZxid=" + lastZxid + ", zxid=" + hdr.getZxid(), lastZxid != hdr.getZxid());
        Assert.assertTrue("excepting next transaction. expected=" + expectedZxid + ", retreived=" + hdr.getZxid(), (hdr.getZxid() == expectedZxid));
        lastZxid = hdr.getZxid();
    }while(itr.next());
	
    Assert.assertTrue("processed all transactions. " + expectedZxid + " == " + TOTAL_TRANSACTIONS, (expectedZxid == TOTAL_TRANSACTIONS));
    zks.shutdown();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:51,代码来源:LoadFromLogTest.java

示例7: testLoad

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入方法依赖的package包/类
/**
 * test that all transactions from the Log are loaded, and only once
 * @throws Exception an exception might be thrown here
 */
@Test
public void testLoad() throws Exception {
    final String hostPort = HOST + PortAssignment.unique();
    // setup a single server cluster
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(hostPort.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(hostPort,CONNECTION_TIMEOUT));
    ZooKeeper zk = ClientBase.createZKClient(hostPort);

    // generate some transactions that will get logged
    try {
        for (int i = 0; i< NUM_MESSAGES; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(hostPort, CONNECTION_TIMEOUT));

    // now verify that the FileTxnLog reads every transaction only once
    File logDir = new File(tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    FileTxnLog txnLog = new FileTxnLog(logDir);

    TxnIterator itr = txnLog.read(0);
    
    // Check that storage space return some value
    FileTxnIterator fileItr = (FileTxnIterator) itr;
    long storageSize = fileItr.getStorageSize();
    LOG.info("Txnlog size: " + storageSize + " bytes");
    Assert.assertTrue("Storage size is greater than zero ",
            (storageSize > 0));
    
    long expectedZxid = 0;
    long lastZxid = 0;
    TxnHeader hdr;
    do {
        hdr = itr.getHeader();
        expectedZxid++;
        Assert.assertTrue("not the same transaction. lastZxid=" + lastZxid + ", zxid=" + hdr.getZxid(), lastZxid != hdr.getZxid());
        Assert.assertTrue("excepting next transaction. expected=" + expectedZxid + ", retreived=" + hdr.getZxid(), (hdr.getZxid() == expectedZxid));
        lastZxid = hdr.getZxid();
    }while(itr.next());

    Assert.assertTrue("processed all transactions. " + expectedZxid + " == " + TOTAL_TRANSACTIONS, (expectedZxid == TOTAL_TRANSACTIONS));
    zks.shutdown();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:60,代码来源:LoadFromLogTest.java

示例8: testLoadFailure

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入方法依赖的package包/类
/**
 * test that we fail to load txnlog of a request zxid that is older
 * than what exist on disk
 * @throws Exception an exception might be thrown here
 */
@Test
public void testLoadFailure() throws Exception {
    final String hostPort = HOST + PortAssignment.unique();
    // setup a single server cluster
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    // So we have at least 4 logs
    SyncRequestProcessor.setSnapCount(50);
    final int PORT = Integer.parseInt(hostPort.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(hostPort,CONNECTION_TIMEOUT));
    ZooKeeper zk = ClientBase.createZKClient(hostPort);

    // generate some transactions that will get logged
    try {
        for (int i = 0; i< NUM_MESSAGES; i++) {
            zk.create("/data-", new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT_SEQUENTIAL);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(hostPort, CONNECTION_TIMEOUT));

    File logDir = new File(tmpDir, FileTxnSnapLog.version + FileTxnSnapLog.VERSION);
    File[] logFiles = FileTxnLog.getLogFiles(logDir.listFiles(), 0);
    // Verify that we have at least 4 txnlog
    Assert.assertTrue(logFiles.length > 4);
    // Delete the first log file, so we will fail to read it back from disk
    Assert.assertTrue("delete the first log file", logFiles[0].delete());

    // Find zxid for the second log
    long secondStartZxid = Util.getZxidFromName(logFiles[1].getName(), "log");

    FileTxnLog txnLog = new FileTxnLog(logDir);
    TxnIterator itr = txnLog.read(1, false);

    // Oldest log is already remove, so this should point to the start of
    // of zxid on the second log
    Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid());

    itr = txnLog.read(secondStartZxid, false);
    Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid());
    Assert.assertTrue(itr.next());

    // Trying to get a second txn on second txnlog give us the
    // the start of second log, since the first one is removed
    long nextZxid = itr.getHeader().getZxid();

    itr = txnLog.read(nextZxid, false);
    Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid());

    // Trying to get a first txn on the third give us the
    // the start of second log, since the first one is removed
    long thirdStartZxid = Util.getZxidFromName(logFiles[2].getName(), "log");
    itr = txnLog.read(thirdStartZxid, false);
    Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid());
    Assert.assertTrue(itr.next());

    nextZxid = itr.getHeader().getZxid();
    itr = txnLog.read(nextZxid, false);
    Assert.assertEquals(secondStartZxid, itr.getHeader().getZxid());

}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:75,代码来源:LoadFromLogTest.java


注:本文中的org.apache.zookeeper.server.persistence.FileTxnSnapLog.version方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。