Search in sources :

Example 1 with RolloverManager

use of com.zimbra.cs.redolog.RolloverManager in project zm-mailbox by Zimbra.

the class FileLogWriter method rollover.

@SuppressWarnings("unchecked")
@Override
public synchronized File rollover(LinkedHashMap activeOps) throws IOException {
    RolloverManager romgr = mRedoLogMgr.getRolloverManager();
    long lastSeq = getSequence();
    // Close current log, so it's impossible for its content to change.
    noStat(true);
    close();
    romgr.incrementSequence();
    String currentPath = mFile.getAbsolutePath();
    // Open a temporary logger.
    File tempLogfile = new File(mFile.getParentFile(), romgr.getTempFilename(lastSeq + 1));
    FileLogWriter tempLogger = new FileLogWriter(mRedoLogMgr, tempLogfile, 0);
    tempLogger.open();
    tempLogger.noStat(true);
    // Rewrite change entries for all active operations, maintaining
    // their order of occurrence.  (LinkedHashMap ensures ordering.)
    Set opsSet = activeOps.entrySet();
    for (Iterator it = opsSet.iterator(); it.hasNext(); ) {
        Map.Entry entry = (Map.Entry) it.next();
        RedoableOp op = (RedoableOp) entry.getValue();
        tempLogger.log(op, op.getInputStream(), false);
    }
    tempLogger.close();
    // Rename the current log to rolled-over name.
    File rolloverFile = romgr.getRolloverFile(lastSeq);
    if (RedoConfig.redoLogDeleteOnRollover()) {
        // indexing-only log files after rollover.
        if (!mFile.delete())
            throw new IOException("Unable to delete current redo log " + mFile.getAbsolutePath());
    } else {
        File destDir = rolloverFile.getParentFile();
        if (destDir != null && !destDir.exists())
            destDir.mkdirs();
        if (!mFile.renameTo(rolloverFile))
            throw new IOException("Unable to rename current redo log to " + rolloverFile.getAbsolutePath());
    }
    // Rename the temporary logger to current logfile name.
    String tempPath = tempLogfile.getAbsolutePath();
    mFile = new File(currentPath);
    if (!tempLogfile.renameTo(mFile))
        throw new IOException("Unable to rename " + tempPath + " to " + currentPath);
    // Reopen current log.
    open();
    noStat(false);
    return rolloverFile;
}
Also used : Set(java.util.Set) RedoableOp(com.zimbra.cs.redolog.op.RedoableOp) Iterator(java.util.Iterator) RolloverManager(com.zimbra.cs.redolog.RolloverManager) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

RolloverManager (com.zimbra.cs.redolog.RolloverManager)1 RedoableOp (com.zimbra.cs.redolog.op.RedoableOp)1 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1