Merge "Permit ProjectCacheClock to be completely disabled"
This commit is contained in:
@@ -684,6 +684,7 @@ access. Values can be specified using standard time unit abbreviations
|
|||||||
('ms', 'sec', 'min', etc.).
|
('ms', 'sec', 'min', etc.).
|
||||||
+
|
+
|
||||||
If set to 0, checks occur every time, which may slow down operations.
|
If set to 0, checks occur every time, which may slow down operations.
|
||||||
|
If set to 'disabled' or 'off', no check will ever be done.
|
||||||
Administrators may force the cache to flush with
|
Administrators may force the cache to flush with
|
||||||
link:cmd-flush-caches.html[gerrit flush-caches].
|
link:cmd-flush-caches.html[gerrit flush-caches].
|
||||||
+
|
+
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.project;
|
package com.google.gerrit.server.project;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import com.google.gerrit.server.config.ConfigUtil;
|
import com.google.gerrit.server.config.ConfigUtil;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -34,29 +35,24 @@ public class ProjectCacheClock {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ProjectCacheClock(@GerritServerConfig Config serverConfig) {
|
public ProjectCacheClock(@GerritServerConfig Config serverConfig) {
|
||||||
this(TimeUnit.MILLISECONDS.convert(
|
this(checkFrequency(serverConfig));
|
||||||
ConfigUtil.getTimeUnit(serverConfig,
|
|
||||||
"cache", "projects", "checkFrequency",
|
|
||||||
5, TimeUnit.MINUTES), TimeUnit.MINUTES));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectCacheClock(long checkFrequencyMillis) {
|
public ProjectCacheClock(long checkFrequencyMillis) {
|
||||||
if (10 < checkFrequencyMillis) {
|
if (checkFrequencyMillis == Long.MAX_VALUE) {
|
||||||
|
// Start with generation 1 (to avoid magic 0 below).
|
||||||
|
// Do not begin background thread, disabling the clock.
|
||||||
|
generation = 1;
|
||||||
|
} else if (10 < checkFrequencyMillis) {
|
||||||
// Start with generation 1 (to avoid magic 0 below).
|
// Start with generation 1 (to avoid magic 0 below).
|
||||||
generation = 1;
|
generation = 1;
|
||||||
ThreadFactory factory = new ThreadFactory() {
|
ScheduledExecutorService executor = Executors.newScheduledThreadPool(
|
||||||
private final AtomicInteger id = new AtomicInteger();
|
1,
|
||||||
|
new ThreadFactoryBuilder()
|
||||||
@Override
|
.setNameFormat("ProjectCacheClock-%d")
|
||||||
public Thread newThread(Runnable runnable) {
|
.setDaemon(true)
|
||||||
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
|
.setPriority(Thread.MIN_PRIORITY)
|
||||||
thread.setName(String.format("ProjectCacheClock-%d", id.incrementAndGet()));
|
.build());
|
||||||
thread.setDaemon(true);
|
|
||||||
thread.setPriority(Thread.MIN_PRIORITY);
|
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1, factory);
|
|
||||||
executor.scheduleAtFixedRate(new Runnable() {
|
executor.scheduleAtFixedRate(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -75,4 +71,16 @@ public class ProjectCacheClock {
|
|||||||
long read() {
|
long read() {
|
||||||
return generation;
|
return generation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long checkFrequency(Config serverConfig) {
|
||||||
|
String freq = serverConfig.getString("cache", "projects", "checkFrequency");
|
||||||
|
if (freq != null
|
||||||
|
&& ("disabled".equalsIgnoreCase(freq) || "off".equalsIgnoreCase(freq))) {
|
||||||
|
return Long.MAX_VALUE;
|
||||||
|
}
|
||||||
|
return TimeUnit.MILLISECONDS.convert(
|
||||||
|
ConfigUtil.getTimeUnit(serverConfig,
|
||||||
|
"cache", "projects", "checkFrequency",
|
||||||
|
5, TimeUnit.MINUTES), TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user