Schedule log file compression at 11:00pm

Log file compression was happening every 24 hours but the exact time was
depending on when Gerrit was started. First execution was 1 hour after
Gerrit is started and then every 24 hours. This behavior could confuse
Gerrit administrators because it looks like log compression is random.

Since logs are rotated upon first logging event after midnight,
compressing logs at 11:00pm should give enough time for all logs to
rotate, worst case they will be compressed the day after.

Change-Id: I81d4df8c57996a483378f6107cd6db561fa0d670
This commit is contained in:
Hugo Arès 2016-08-17 14:41:42 -04:00 committed by David Pursehouse
parent 9a662a0755
commit 2f46364950
2 changed files with 12 additions and 1 deletions

View File

@ -16,6 +16,7 @@ BASE_JETTY_DEPS = [
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit/org.eclipse.jgit:jgit',
'//lib/joda:joda-time',
'//lib/log:api',
'//lib/log:log4j',
]

View File

@ -15,6 +15,7 @@
package com.google.gerrit.pgm.util;
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import com.google.common.io.ByteStreams;
import com.google.gerrit.extensions.events.LifecycleListener;
@ -23,6 +24,8 @@ import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.git.WorkQueue;
import com.google.inject.Inject;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -59,7 +62,14 @@ public class LogFileCompressor implements Runnable {
@Override
public void start() {
queue.getDefaultQueue().scheduleAtFixedRate(compressor, 1, 24, HOURS);
//compress log once and then schedule compression every day at 11:00pm
queue.getDefaultQueue().execute(compressor);
DateTime now = DateTime.now();
long milliSecondsUntil11am =
new Duration(now, now.withTimeAtStartOfDay().plusHours(23))
.getMillis();
queue.getDefaultQueue().scheduleAtFixedRate(compressor,
milliSecondsUntil11am, HOURS.toMillis(24), MILLISECONDS);
}
@Override