Search in sources :

Example 1 with InputArchive

use of org.apache.jute_voltpatches.InputArchive in project voltdb by VoltDB.

the class LogFormatter method 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++;
    }
}
Also used : BinaryInputArchive(org.apache.jute_voltpatches.BinaryInputArchive) InputArchive(org.apache.jute_voltpatches.InputArchive) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Adler32(java.util.zip.Adler32) Date(java.util.Date) BinaryInputArchive(org.apache.jute_voltpatches.BinaryInputArchive) ByteArrayInputStream(java.io.ByteArrayInputStream) Checksum(java.util.zip.Checksum) EOFException(java.io.EOFException) FileHeader(org.apache.zookeeper_voltpatches.server.persistence.FileHeader) TxnHeader(org.apache.zookeeper_voltpatches.txn.TxnHeader)

Example 2 with InputArchive

use of org.apache.jute_voltpatches.InputArchive in project voltdb by VoltDB.

the class FileTxnLog method readHeader.

/**
     * read the header of the transaction file
     * @param file the transaction file to read
     * @return header that was read fomr the file
     * @throws IOException
     */
private static FileHeader readHeader(File file) throws IOException {
    InputStream is = null;
    try {
        is = new BufferedInputStream(new FileInputStream(file));
        InputArchive ia = BinaryInputArchive.getArchive(is);
        FileHeader hdr = new FileHeader();
        hdr.deserialize(ia, "fileheader");
        return hdr;
    } finally {
        try {
            if (is != null)
                is.close();
        } catch (IOException e) {
            LOG.warn("Ignoring exception during close", e);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FilterInputStream(java.io.FilterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InputArchive(org.apache.jute_voltpatches.InputArchive) BinaryInputArchive(org.apache.jute_voltpatches.BinaryInputArchive) IOException(java.io.IOException) FileHeader(org.apache.zookeeper_voltpatches.server.persistence.FileHeader) FileInputStream(java.io.FileInputStream)

Example 3 with InputArchive

use of org.apache.jute_voltpatches.InputArchive in project voltdb by VoltDB.

the class FileSnap method deserialize.

/**
     * deserialize a data tree from the most recent snapshot
     * @return the zxid of the snapshot
     */
@Override
public long deserialize(DataTree dt, Map<Long, Long> sessions) throws IOException {
    // we run through 100 snapshots (not all of them)
    // if we cannot get it running within 100 snapshots
    // we should  give up
    List<File> snapList = findNValidSnapshots(100);
    if (snapList.size() == 0) {
        return -1L;
    }
    File snap = null;
    boolean foundValid = false;
    for (int i = 0; i < snapList.size(); i++) {
        snap = snapList.get(i);
        InputStream snapIS = null;
        CheckedInputStream crcIn = null;
        try {
            LOG.info("Reading snapshot " + snap);
            snapIS = new BufferedInputStream(new FileInputStream(snap));
            crcIn = new CheckedInputStream(snapIS, new Adler32());
            InputArchive ia = BinaryInputArchive.getArchive(crcIn);
            deserialize(dt, sessions, ia);
            long checkSum = crcIn.getChecksum().getValue();
            long val = ia.readLong("val");
            if (val != checkSum) {
                throw new IOException("CRC corruption in snapshot :  " + snap);
            }
            foundValid = true;
            break;
        } catch (IOException e) {
            LOG.warn("problem reading snap file " + snap, e);
        } finally {
            if (snapIS != null)
                snapIS.close();
            if (crcIn != null)
                crcIn.close();
        }
    }
    if (!foundValid) {
        throw new IOException("Not able to find valid snapshots in " + snapDir);
    }
    dt.lastProcessedZxid = Util.getZxidFromName(snap.getName(), "snapshot");
    return dt.lastProcessedZxid;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) CheckedInputStream(java.util.zip.CheckedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InputArchive(org.apache.jute_voltpatches.InputArchive) BinaryInputArchive(org.apache.jute_voltpatches.BinaryInputArchive) IOException(java.io.IOException) File(java.io.File) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream) Adler32(java.util.zip.Adler32)

Aggregations

FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 BinaryInputArchive (org.apache.jute_voltpatches.BinaryInputArchive)3 InputArchive (org.apache.jute_voltpatches.InputArchive)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Adler32 (java.util.zip.Adler32)2 FileHeader (org.apache.zookeeper_voltpatches.server.persistence.FileHeader)2 EOFException (java.io.EOFException)1 File (java.io.File)1 FilterInputStream (java.io.FilterInputStream)1 Date (java.util.Date)1 CheckedInputStream (java.util.zip.CheckedInputStream)1 Checksum (java.util.zip.Checksum)1 TxnHeader (org.apache.zookeeper_voltpatches.txn.TxnHeader)1