當前位置: 首頁>>代碼示例>>Java>>正文


Java FileTxnSnapLog.findNRecentSnapshots方法代碼示例

本文整理匯總了Java中org.apache.zookeeper.server.persistence.FileTxnSnapLog.findNRecentSnapshots方法的典型用法代碼示例。如果您正苦於以下問題:Java FileTxnSnapLog.findNRecentSnapshots方法的具體用法?Java FileTxnSnapLog.findNRecentSnapshots怎麽用?Java FileTxnSnapLog.findNRecentSnapshots使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.zookeeper.server.persistence.FileTxnSnapLog的用法示例。


在下文中一共展示了FileTxnSnapLog.findNRecentSnapshots方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testPurge

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    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);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:43,代碼來源:PurgeTxnTest.java

示例2: testFindNRecentSnapshots

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
/**
 * Tests finding n recent snapshots from set of snapshots and data logs
 */
@Test
public void testFindNRecentSnapshots() throws Exception {
    int nRecentSnap = 4; // n recent snap shots
    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());
    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);
        }
    }

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> nRecentSnapFiles = txnLog.findNRecentSnapshots(nRecentSnap);
    txnLog.close();
    Assert.assertEquals("exactly 4 snapshots ", 4,
            nRecentSnapFiles.size());
    expectedNRecentSnapFiles.removeAll(nRecentSnapFiles);
    Assert.assertEquals("Didn't get the recent snap files", 0,
            expectedNRecentSnapFiles.size());
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:40,代碼來源:PurgeTxnTest.java

示例3: purge

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
/**
 * Purges the snapshot and logs keeping the last num snapshots and the
 * corresponding logs. If logs are rolling or a new snapshot is created
 * during this process, these newest N snapshots or any data logs will be
 * excluded from current purging cycle.
 *
 * @param dataDir the dir that has the logs
 * @param snapDir the dir that has the snapshots
 * @param num the number of snapshots to keep
 * @throws IOException
 */
public static void purge(File dataDir, File snapDir, int num) throws IOException {
    if (num < 3) {
        throw new IllegalArgumentException(COUNT_ERR_MSG);
    }

    FileTxnSnapLog txnLog = new FileTxnSnapLog(dataDir, snapDir);

    List<File> snaps = txnLog.findNRecentSnapshots(num);
    int numSnaps = snaps.size();
    if (numSnaps > 0) {
        purgeOlderSnapshots(txnLog, snaps.get(numSnaps - 1));
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:25,代碼來源:PurgeTxnLog.java

示例4: testPurge

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    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);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:43,代碼來源:PurgeTxnTest.java

示例5: testFindNRecentSnapshots

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
/**
 * Tests finding n recent snapshots from set of snapshots and data logs
 */
@Test
public void testFindNRecentSnapshots() throws Exception {
    int nRecentSnap = 4; // n recent snap shots
    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();
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:58,代碼來源:PurgeTxnTest.java

示例6: purge

import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //導入方法依賴的package包/類
/**
 * Purges[清除,淨化;as clean;好裝x的單詞] the snapshot and logs keeping the last num snapshots and the
 * corresponding logs(保存最近的N個事務日誌以及快照). If logs are rolling or a new snapshot is created
 * during this process, these newest N snapshots or any data logs will be
 * excluded from current purging cycle.
 *
 * @param dataDir the dir that has the logs
 * @param snapDir the dir that has the snapshots
 * @param num the number of snapshots to keep
 * @throws IOException
 */
public static void purge(File dataDir, File snapDir, int num) throws IOException {
    if (num < 3) {
        throw new IllegalArgumentException(COUNT_ERR_MSG);
    }

    FileTxnSnapLog txnLog = new FileTxnSnapLog(dataDir, snapDir);

    List<File> snaps = txnLog.findNRecentSnapshots(num);
    retainNRecentSnapshots(txnLog, snaps);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:22,代碼來源:PurgeTxnLog.java


注:本文中的org.apache.zookeeper.server.persistence.FileTxnSnapLog.findNRecentSnapshots方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。