Search in sources :

Example 1 with FileTxnLog

use of org.apache.zookeeper_voltpatches.server.persistence.FileTxnLog in project voltdb by VoltDB.

the class FileTxnLog method getLastLoggedZxid.

/**
     * get the last zxid that was logged in the transaction logs
     * @return the last zxid logged in the transaction logs
     */
public long getLastLoggedZxid() {
    File[] files = getLogFiles(logDir.listFiles(), 0);
    long maxLog = files.length > 0 ? Util.getZxidFromName(files[files.length - 1].getName(), "log") : -1;
    // if a log file is more recent we must scan it to find
    // the highest zxid
    long zxid = maxLog;
    try {
        FileTxnLog txn = new FileTxnLog(logDir);
        TxnIterator itr = txn.read(maxLog);
        while (true) {
            if (!itr.next())
                break;
            TxnHeader hdr = itr.getHeader();
            zxid = hdr.getZxid();
        }
    } catch (IOException e) {
        LOG.warn("Unexpected exception", e);
    }
    return zxid;
}
Also used : FileTxnLog(org.apache.zookeeper_voltpatches.server.persistence.FileTxnLog) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) TxnHeader(org.apache.zookeeper_voltpatches.txn.TxnHeader)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 FileTxnLog (org.apache.zookeeper_voltpatches.server.persistence.FileTxnLog)1 TxnHeader (org.apache.zookeeper_voltpatches.txn.TxnHeader)1