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


Java FileTxnLog.TXNLOG_MAGIC属性代码示例

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


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

示例1: ZooKeeperLogParser

public ZooKeeperLogParser(InputStream log)
{
    logStream = BinaryInputArchive.getArchive(log);

    boolean         localValidHeader = false;
    try
    {
        FileHeader fhdr = new FileHeader();
        fhdr.deserialize(logStream, "fileheader");
        localValidHeader = (fhdr.getMagic() == FileTxnLog.TXNLOG_MAGIC);
    }
    catch ( IOException e )
    {
        // ignore
    }
    validHeader = localValidHeader;
}
 
开发者ID:dcos,项目名称:exhibitor,代码行数:17,代码来源:ZooKeeperLogParser.java

示例2: isTransactionFile

public static boolean isTransactionFile(String file) throws IOException {
       RandomAccessFileReader reader = new RandomAccessFileReader(new File(file));
       BinaryInputArchive logStream = new BinaryInputArchive(reader);
       FileHeader fhdr = new FileHeader();
       fhdr.deserialize(logStream, "fileheader");
reader.close();

       return fhdr.getMagic() == FileTxnLog.TXNLOG_MAGIC;
   }
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:9,代码来源:TxnLogSource.java

示例3: main

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("USAGE: LogFormatter log_file");
        System.exit(2);
    }
    FileInputStream fis = new FileInputStream(args[0]);
    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 " + args[0]);
        System.exit(2);
    }
    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) {
            System.out.println("EOF reached after " + count + " txns.");
            return;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            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());
        }
        TxnHeader hdr = new TxnHeader();
        Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
        System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
                DateFormat.LONG).format(new Date(hdr.getTime()))
                + " session 0x"
                + Long.toHexString(hdr.getClientId())
                + " cxid 0x"
                + Long.toHexString(hdr.getCxid())
                + " zxid 0x"
                + Long.toHexString(hdr.getZxid())
                + " " + TraceFormatter.op2String(hdr.getType()) + " " + txn);
        if (logStream.readByte("EOR") != 'B') {
            LOG.error("Last transaction was partial.");
            throw new EOFException("Last transaction was partial.");
        }
        count++;
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:63,代码来源:LogFormatter.java

示例4: TransactionLogFileReader

/**
 *
 * @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>.
 */
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;

}
 
开发者ID:alenca,项目名称:zklogtool,代码行数:28,代码来源:TransactionLogFileReader.java

示例5: readTransactionLog

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);
  }

  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());
    }
    TxnHeader hdr = new TxnHeader();
    Record txn = SerializeUtils.deserializeTxn(bytes, 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++;
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:72,代码来源:ZKLogFormatter.java

示例6: main

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("USAGE: LogFormatter log_file");
        System.exit(2);
    }
    FileInputStream fis = new FileInputStream(args[0]);
    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 " + args[0]);
        System.exit(2);
    }
    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) {
            System.out.println("EOF reached after " + count + " txns.");
            return;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            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();
        SerializeUtils.deserializeTxn(iab, hdr);
        System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
                DateFormat.LONG).format(new Date(hdr.getTime()))
                + " session 0x"
                + Long.toHexString(hdr.getClientId())
                + " cxid 0x"
                + Long.toHexString(hdr.getCxid())
                + " zxid 0x"
                + Long.toHexString(hdr.getZxid())
                + " " + TraceFormatter.op2String(hdr.getType()));
        if (logStream.readByte("EOR") != 'B') {
            LOG.error("Last transaction was partial.");
            throw new EOFException("Last transaction was partial.");
        }
        count++;
    }
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:65,代码来源:LogFormatter.java


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