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;
}
Aggregations