mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

boli
20.38.2007 5be4cbbaa9065ea0149c6d0b4c58e4c7ae95d247
Fixed an issue where the fixed time log rotation policy is not rotating the logs at the time configured. The rotation time was interpreted as UTC time instead of the local time zone.

Fix for issue 2279
3 files modified
73 ■■■■■ changed files
opends/src/server/org/opends/server/loggers/FixedTimeRotationPolicy.java 56 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/loggers/MultifileTextWriter.java 13 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/loggers/TimeLimitRotationPolicy.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/loggers/FixedTimeRotationPolicy.java
@@ -56,22 +56,19 @@
  private static final long MS_IN_DAY = 24 * 3600 * 1000;
  // The scheduled rotation times as ms offsets from the beginnging of the day.
  private long[] rotationTimes;
  private int[] rotationTimes;
  /**
   * {@inheritDoc}
   */
  public void initializeLogRotationPolicy(FixedTimeLogRotationPolicyCfg config)
  {
    rotationTimes = new long[config.getTimeOfDay().size()];
    rotationTimes = new int[config.getTimeOfDay().size()];
    int i = 0;
    for(String time : config.getTimeOfDay())
    {
      int hour = Integer.valueOf(time)/100;
      int min = Integer.valueOf(time) - hour*100;
      rotationTimes[i++] = hour*3600*1000 + min*60*1000;
      rotationTimes[i++] = Integer.valueOf(time);
    }
    Arrays.sort(rotationTimes);
@@ -100,15 +97,12 @@
    boolean adminActionRequired = false;
    ArrayList<Message> messages = new ArrayList<Message>();
    rotationTimes = new long[config.getTimeOfDay().size()];
    rotationTimes = new int[config.getTimeOfDay().size()];
    int i = 0;
    for(String time : config.getTimeOfDay())
    {
      int hour = Integer.valueOf(time)/100;
      int min = Integer.valueOf(time) - hour*100;
      rotationTimes[i++] = hour*3600*1000 + min*60*1000;
      rotationTimes[i++] = Integer.valueOf(time);
    }
    Arrays.sort(rotationTimes);
@@ -121,39 +115,35 @@
   */
  public boolean rotateFile(MultifileTextWriter writer)
  {
    long currTime = TimeThread.getTime();
    long lastRotationTime = writer.getLastRotationTime();
    long dayOfLastRotation = MS_IN_DAY * (lastRotationTime / MS_IN_DAY);
    long hourOfLastRotation = lastRotationTime - dayOfLastRotation;
    Calendar lastRotationTime = writer.getLastRotationTime();
    // Find a scheduled rotation time thats right after the last rotation time.
    long hourOfNextRotation = 0;
    for(long time : rotationTimes)
    Calendar nextRotationTime = (Calendar)lastRotationTime.clone();
    int i = 0;
    nextRotationTime.set(Calendar.HOUR_OF_DAY, rotationTimes[i] / 100);
    nextRotationTime.set(Calendar.MINUTE, rotationTimes[i] % 100);
    nextRotationTime.set(Calendar.SECOND, 0);
    while(lastRotationTime.after(nextRotationTime))
    {
      if(time > hourOfLastRotation)
      if(i == rotationTimes.length - 1)
      {
        hourOfNextRotation = time;
        break;
        nextRotationTime.add(Calendar.DATE, 1);
        i = 0;
      }
    }
      else
      {
        i++;
      }
    if(hourOfNextRotation <= 0)
    {
      // Rotation alrealy happened after the latest fixed time for that day.
      // Set it the first rotation time for the next day.
      hourOfNextRotation = rotationTimes[0] + MS_IN_DAY;
      nextRotationTime.set(Calendar.HOUR_OF_DAY, rotationTimes[i] / 100);
      nextRotationTime.set(Calendar.MINUTE, rotationTimes[i] % 100);
    }
    long nextRotationTime = dayOfLastRotation + hourOfNextRotation;
    if (debugEnabled())
    {
      TRACER.debugInfo("The next fixed rotation time in %ds",
                       (currTime - nextRotationTime)/1000);
      TRACER.debugInfo("The next fixed rotation time is %s", rotationTimes[i]);
    }
    return currTime > nextRotationTime;
    return TimeThread.getCalendar().after(nextRotationTime);
  }
}
opends/src/server/org/opends/server/loggers/MultifileTextWriter.java
@@ -46,6 +46,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.Calendar;
/**
 * A MultiFileTextWriter is a specialized TextWriter which supports publishing
@@ -89,8 +90,8 @@
  private Thread rotaterThread;
  private long lastRotationTime = TimeThread.getTime();
  private long lastCleanTime = TimeThread.getTime();
  private Calendar lastRotationTime = TimeThread.getCalendar();
  private Calendar lastCleanTime = TimeThread.getCalendar();
  private long lastCleanCount = 0;
  private long totalFilesRotated = 0;
  private long totalFilesCleaned = 0;
@@ -430,7 +431,7 @@
              retentionPolicy.deleteFiles(writer);
          if(numFilesDeleted > 0)
          {
            lastCleanTime = TimeThread.getTime();
            lastCleanTime = TimeThread.getCalendar();
            lastCleanCount = numFilesDeleted;
            totalFilesCleaned++;
          }
@@ -612,7 +613,7 @@
    }
    totalFilesRotated++;
    lastRotationTime = TimeThread.getTime();
    lastRotationTime = TimeThread.getCalendar();
  }
  /**
@@ -642,7 +643,7 @@
   *
   * @return The last time log files are cleaned.
   */
  public long getLastCleanTime()
  public Calendar getLastCleanTime()
  {
    return lastCleanTime;
  }
@@ -664,7 +665,7 @@
   *
   * @return The last time log rotation occurred.
   */
  public long getLastRotationTime()
  public Calendar getLastRotationTime()
  {
    return lastRotationTime;
  }
opends/src/server/org/opends/server/loggers/TimeLimitRotationPolicy.java
@@ -100,8 +100,8 @@
   */
  public boolean rotateFile(MultifileTextWriter writer)
  {
    long currTime = TimeThread.getTime();
    long currInterval = currTime - writer.getLastRotationTime();
    long currInterval = TimeThread.getTime() -
        writer.getLastRotationTime().getTimeInMillis();
    if (debugEnabled())
    {