List of usage examples for org.apache.zookeeper.server.persistence FileTxnLog TXNLOG_MAGIC
int TXNLOG_MAGIC
To view the source code for org.apache.zookeeper.server.persistence FileTxnLog TXNLOG_MAGIC.
Click Source Link
From source file:com.linkedin.helix.tools.ZKLogFormatter.java
License:Apache License
private static void readTransactionLog(String logfilepath) throws FileNotFoundException, IOException, EOFException { FileInputStream fis = new FileInputStream(logfilepath); BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis); FileHeader fhdr = new FileHeader(); fhdr.deserialize(logStream, "fileheader"); if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) { System.err.println("Invalid magic number for " + logfilepath); System.exit(2);//from w w w .j a v a 2 s.c om } if (bw != null) { bw.write("ZooKeeper Transactional Log File with dbid " + fhdr.getDbid() + " txnlog format version " + fhdr.getVersion()); bw.newLine(); } else { System.out.println("ZooKeeper Transactional Log File with dbid " + fhdr.getDbid() + " txnlog format version " + fhdr.getVersion()); } int count = 0; while (true) { long crcValue; byte[] bytes; try { crcValue = logStream.readLong("crcvalue"); bytes = logStream.readBuffer("txnEntry"); } catch (EOFException e) { if (bw != null) { bw.write("EOF reached after " + count + " txns."); bw.newLine(); } else { System.out.println("EOF reached after " + count + " txns."); } break; } if (bytes.length == 0) { // Since we preallocate, we define EOF to be an // empty transaction if (bw != null) { bw.write("EOF reached after " + count + " txns."); bw.newLine(); } else { System.out.println("EOF reached after " + count + " txns."); } return; } Checksum crc = new Adler32(); crc.update(bytes, 0, bytes.length); if (crcValue != crc.getValue()) { throw new IOException("CRC doesn't match " + crcValue + " vs " + crc.getValue()); } InputArchive iab = BinaryInputArchive.getArchive(new ByteArrayInputStream(bytes)); TxnHeader hdr = new TxnHeader(); Record txn = SerializeUtils.deserializeTxn(iab, hdr); if (bw != null) { bw.write(formatTransaction(hdr, txn)); bw.newLine(); } else { System.out.println(formatTransaction(hdr, txn)); } if (logStream.readByte("EOR") != 'B') { LOG.error("Last transaction was partial."); throw new EOFException("Last transaction was partial."); } count++; } }
From source file:com.netflix.exhibitor.core.index.ZooKeeperLogParser.java
License:Apache License
public ZooKeeperLogParser(InputStream log) { logStream = BinaryInputArchive.getArchive(log); boolean localValidHeader = false; try {//ww w . j a v a 2 s . co m FileHeader fhdr = new FileHeader(); fhdr.deserialize(logStream, "fileheader"); localValidHeader = (fhdr.getMagic() == FileTxnLog.TXNLOG_MAGIC); } catch (IOException e) { // ignore } validHeader = localValidHeader; }
From source file:com.zklogtool.reader.TransactionLogFileReader.java
License:Apache License
/** * * @param transactionLogFile Transaction log file. * @throws FileNotFoundException Thrown if file is not found. * @throws IOException Thrown if there is a problem with reading * <code>transactionLogFile</code>. *///from w w w .jav a2s. c o m public TransactionLogFileReader(File transactionLogFile) throws FileNotFoundException, IOException { this.transactionLogFile = transactionLogFile; raf = new RandomAccessFile(transactionLogFile, "r"); ia = new BinaryInputArchive(raf); header = new FileHeader(); header.deserialize(ia, "fileheader"); if (header.getMagic() != TXNLOG_MAGIC) { throw new IOException( "Mismatching magic headers " + header.getMagic() + " != " + FileTxnLog.TXNLOG_MAGIC); } resetFilePointer = raf.getFilePointer(); lastTransactionFilePointer = resetFilePointer; }