类org.apache.zookeeper.server.persistence.FileTxnLog源码实例Demo

下面列出了怎么用org.apache.zookeeper.server.persistence.FileTxnLog的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: exhibitor   文件: ZooKeeperLogParser.java
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;
}
 
源代码2 项目: hadoop   文件: ClientBaseWithFixes.java
/**
 * Test specific setup
 */
public static void setupTestEnv() {
    // during the tests we run with 100K prealloc in the logs.
    // on windows systems prealloc of 64M was seen to take ~15seconds
    // resulting in test Assert.failure (client timeout on first session).
    // set env and directly in order to handle static init/gc issues
    System.setProperty("zookeeper.preAllocSize", "100");
    FileTxnLog.setPreallocSize(100 * 1024);
}
 
源代码3 项目: dremio-oss   文件: MiniZooKeeperCluster.java
private static void setupTestEnv() {
  // during the tests we run with 100K prealloc in the logs.
  // on windows systems prealloc of 64M was seen to take ~15seconds
  // resulting in test failure (client timeout on first session).
  // set env and directly in order to handle static init/gc issues
  System.setProperty("zookeeper.preAllocSize", "100");
  FileTxnLog.setPreallocSize(100 * 1024);
}
 
源代码4 项目: big-c   文件: ClientBaseWithFixes.java
/**
 * Test specific setup
 */
public static void setupTestEnv() {
    // during the tests we run with 100K prealloc in the logs.
    // on windows systems prealloc of 64M was seen to take ~15seconds
    // resulting in test Assert.failure (client timeout on first session).
    // set env and directly in order to handle static init/gc issues
    System.setProperty("zookeeper.preAllocSize", "100");
    FileTxnLog.setPreallocSize(100 * 1024);
}
 
源代码5 项目: hudi   文件: ZookeeperTestService.java
private static void setupTestEnv() {
  // during the tests we run with 100K prealloc in the logs.
  // on windows systems prealloc of 64M was seen to take ~15seconds
  // resulting in test failure (client timeout on first session).
  // set env and directly in order to handle static init/gc issues
  System.setProperty("zookeeper.preAllocSize", "100");
  FileTxnLog.setPreallocSize(100 * 1024);
}
 
源代码6 项目: hbase-tools   文件: MiniZooKeeperCluster.java
private static void setupTestEnv() {
  // during the tests we run with 100K prealloc in the logs.
  // on windows systems prealloc of 64M was seen to take ~15seconds
  // resulting in test failure (client timeout on first session).
  // set env and directly in order to handle static init/gc issues
  System.setProperty("zookeeper.preAllocSize", "100");
  FileTxnLog.setPreallocSize(100 * 1024);
}
 
源代码7 项目: hbase-tools   文件: MiniZooKeeperCluster.java
private static void setupTestEnv() {
    // during the tests we run with 100K prealloc in the logs.
    // on windows systems prealloc of 64M was seen to take ~15seconds
    // resulting in test failure (client timeout on first session).
    // set env and directly in order to handle static init/gc issues
    System.setProperty("zookeeper.preAllocSize", "100");
    FileTxnLog.setPreallocSize(100 * 1024);
}
 
源代码8 项目: hbase-tools   文件: MiniZooKeeperCluster.java
private static void setupTestEnv() {
  // during the tests we run with 100K prealloc in the logs.
  // on windows systems prealloc of 64M was seen to take ~15seconds
  // resulting in test failure (client timeout on first session).
  // set env and directly in order to handle static init/gc issues
  System.setProperty("zookeeper.preAllocSize", "100");
  FileTxnLog.setPreallocSize(100 * 1024);
}
 
源代码9 项目: hbase   文件: MiniZooKeeperCluster.java
private static void setupTestEnv() {
  // during the tests we run with 100K prealloc in the logs.
  // on windows systems prealloc of 64M was seen to take ~15seconds
  // resulting in test failure (client timeout on first session).
  // set env and directly in order to handle static init/gc issues
  System.setProperty("zookeeper.preAllocSize", "100");
  FileTxnLog.setPreallocSize(100 * 1024);
  // allow all 4 letter words
  System.setProperty("zookeeper.4lw.commands.whitelist", "*");
}
 
源代码10 项目: kite   文件: ZookeeperService.java
private static void setupTestEnv() {
  // during the tests we run with 100K prealloc in the logs.
  // on windows systems prealloc of 64M was seen to take ~15seconds
  // resulting in test failure (client timeout on first session).
  // set env and directly in order to handle static init/gc issues
  System.setProperty("zookeeper.preAllocSize", "100");
  FileTxnLog.setPreallocSize(100 * 1024);
}
 
源代码11 项目: zooadmin   文件: ZooLog.java
/**
 * 读取多行日志
 * @param total 读取的行数
 * @return
 * @throws IOException
 */
public String getLastLog(int total) throws IOException {
    StringBuilder sb=new StringBuilder(1024);
    FileInputStream fis = new FileInputStream(this.logFile);
    BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");

    if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
        return "Invalid magic number for " + logFile;
    }
    sb.append("ZooKeeper Transactional Log File with dbid "
            + fhdr.getDbid() + " txnlog format version "
            + fhdr.getVersion()+"\r\n");
    int count=0;
    while (count<total) {
        long crcValue;
        byte[] bytes;
        try {
            crcValue = logStream.readLong("crcvalue");
            bytes = logStream.readBuffer("txnEntry");
        } catch (EOFException e) {
            sb.append("EOF reached after " + count + " txns.\r\n");
            break;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            sb.append("EOF reached after " + count + " txns.\r\n");
            break;
        }
        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);
        sb.append(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())
                + " " + ZooLog.op2String(hdr.getType()) + " " + txn+"\r\n");
        if (logStream.readByte("EOR") != 'B') {
            sb.append("Last transaction was partial.");
        }
        count++;
    }
    return sb.toString();
}
 
源代码12 项目: zooadmin   文件: ZooLog.java
/**
 * 读取多行日志
 * @param total 读取的行数
 * @return
 * @throws IOException
 */
public String getLastLog(int total) throws IOException {
    StringBuilder sb=new StringBuilder(1024);
    FileInputStream fis = new FileInputStream(this.logFile);
    BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");

    if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
        return "Invalid magic number for " + logFile;
    }
    sb.append("ZooKeeper Transactional Log File with dbid "
            + fhdr.getDbid() + " txnlog format version "
            + fhdr.getVersion()+"\r\n");
    int count=0;
    while (count<total) {
        long crcValue;
        byte[] bytes;
        try {
            crcValue = logStream.readLong("crcvalue");
            bytes = logStream.readBuffer("txnEntry");
        } catch (EOFException e) {
            sb.append("EOF reached after " + count + " txns.\r\n");
            break;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            sb.append("EOF reached after " + count + " txns.\r\n");
            break;
        }
        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);
        sb.append(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())
                + " " + ZooLog.op2String(hdr.getType()) + " " + txn+"\r\n");
        if (logStream.readByte("EOR") != 'B') {
            sb.append("Last transaction was partial.");
        }
        count++;
    }
    return sb.toString();
}
 
源代码13 项目: helix   文件: ZKLogFormatter.java
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++;
  }
}
 
 类所在包
 类方法
 同包方法