本文整理汇总了Java中org.apache.zookeeper.server.persistence.FileTxnLog.getLogFiles方法的典型用法代码示例。如果您正苦于以下问题:Java FileTxnLog.getLogFiles方法的具体用法?Java FileTxnLog.getLogFiles怎么用?Java FileTxnLog.getLogFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.server.persistence.FileTxnLog
的用法示例。
在下文中一共展示了FileTxnLog.getLogFiles方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadThisSnapShot
import org.apache.zookeeper.server.persistence.FileTxnLog; //导入方法依赖的package包/类
/**
* create the old snapshot database
* apply logs to it and create the final
* database
* @throws IOException
*/
private void loadThisSnapShot() throws IOException {
// pick the most recent snapshot
File snapshot = findMostRecentSnapshot();
if (snapshot == null) {
throw new IOException("Invalid snapshots " +
"or not snapshots in " + snapShotDir);
}
InputStream inputstream = new BufferedInputStream(
new FileInputStream(snapshot));
InputArchive ia = BinaryInputArchive.getArchive(inputstream);
deserializeSnapshot(oldDataTree, ia, sessionsWithTimeouts);
//ok done with the snapshot
// now apply the logs
long snapshotZxid = oldDataTree.lastProcessedZxid;
File[] files = FileTxnLog.getLogFiles(
dataDir.listFiles(), snapshotZxid);
long zxid = processLogFiles(oldDataTree, files);
//check for this zxid to be sane
if (zxid != oldDataTree.lastProcessedZxid) {
LOG.error("Zxids not equal " + " log zxid " +
zxid + " datatree processed " + oldDataTree.lastProcessedZxid);
}
}
示例2: testGetLogFiles
import org.apache.zookeeper.server.persistence.FileTxnLog; //导入方法依赖的package包/类
@Test
public void testGetLogFiles() {
File[] files = new File[5];
files[0] = new File("log.10027c6de");
files[1] = new File("log.10027c6df");
files[2] = new File("snapshot.10027c6dd");
files[3] = new File("log.10027c6dc");
files[4] = new File("log.20027c6dc");
File[] orig = files.clone();
File[] filelist =
FileTxnLog.getLogFiles(files,
Long.parseLong("10027c6de", 16));
Assert.assertEquals(3, filelist.length);
Assert.assertEquals(orig[0], filelist[0]);
Assert.assertEquals(orig[1], filelist[1]);
Assert.assertEquals(orig[4], filelist[2]);
}
示例3: testGetLogFiles
import org.apache.zookeeper.server.persistence.FileTxnLog; //导入方法依赖的package包/类
@Test
public void testGetLogFiles() {
File[] files = new File[5];
files[0] = new File("log.10027c6de");
files[1] = new File("log.10027c6df");
files[2] = new File("snapshot.10027c6dd");
files[3] = new File("log.10027c6dc");
files[4] = new File("log.20027c6dc");
File[] orig = files.clone();
File[] filelist =
FileTxnLog.getLogFiles(files,
Long.parseLong("10027c6de", 16));
assertEquals(3, filelist.length);
assertEquals(orig[0], filelist[0]);
assertEquals(orig[1], filelist[1]);
assertEquals(orig[4], filelist[2]);
}
示例4: testLoadFailure
import org.apache.zookeeper.server.persistence.FileTxnLog; //导入方法依赖的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());
}
示例5: testLoadFailure
import org.apache.zookeeper.server.persistence.FileTxnLog; //导入方法依赖的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 {
// 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 = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
// 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());
}