Java Code Examples for org.apache.zookeeper.server.persistence.FileTxnLog

The following examples show how to use org.apache.zookeeper.server.persistence.FileTxnLog. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: exhibitor   Source File: ZooKeeperLogParser.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source Project: hadoop   Source File: ClientBaseWithFixes.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source Project: dremio-oss   Source File: MiniZooKeeperCluster.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source Project: big-c   Source File: ClientBaseWithFixes.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source Project: hudi   Source File: ZookeeperTestService.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source Project: hbase-tools   Source File: MiniZooKeeperCluster.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source Project: hbase-tools   Source File: MiniZooKeeperCluster.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 8
Source Project: hbase-tools   Source File: MiniZooKeeperCluster.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source Project: hbase   Source File: MiniZooKeeperCluster.java    License: Apache License 2.0 5 votes vote down vote up
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", "*");
}
 
Example 10
Source Project: kite   Source File: ZookeeperService.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source Project: zooadmin   Source File: ZooLog.java    License: MIT License 4 votes vote down vote up
/**
 * 读取多行日志
 * @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();
}
 
Example 12
Source Project: zooadmin   Source File: ZooLog.java    License: MIT License 4 votes vote down vote up
/**
 * 读取多行日志
 * @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();
}
 
Example 13
Source Project: helix   Source File: ZKLogFormatter.java    License: Apache License 2.0 4 votes vote down vote up
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++;
  }
}