本文整理汇总了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();
}
示例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());
}
示例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));
}
}
示例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();
}
示例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();
}
示例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);
}