Replace ProjectCacheClock with refreshAfterWrite

This commit replaces a home-grown piece of infrastructure with
a standard component that has the same behavior.

ProjectCacheClock was used to detect values in ProjectCache that
are old enough that they might be out of date. It would then
schedule a task on a background thread to check the value.

Both Guava Caches and Caffeine Caches offer this as standard
functionality: refreshAfterWrite.

This is even better than what we had with ProjectCacheClock
because it does the actual refreshing (= reloading the value)
on the background thread.

In a prior commit, we have implemented this option in our own
Cache config framework and the H2 persistent store.

This commit makes use of that prework in the ProjectCache. We
set the default refreshAfterWrite to 15 minutes and the
expireAfterWrite - the duration after which a value is not
read anymore - to 1 hour. Both are configurable. It is also
possible to disable this behavior entirely.

Similar to ProjectCacheClock, we use a dedicated executor for
refreshing cached values. The executor is generic and not
specific to ProjectCache. It's size is configurable.

Change-Id: I8b163853ae092444edf9ff44bef4f7910f21ba0e
This commit is contained in:
Patrick Hiesel
2020-04-16 14:12:31 +02:00
parent ef9fafd8f9
commit d70f37fc45
10 changed files with 160 additions and 176 deletions

View File

@@ -15,10 +15,11 @@
package com.google.gerrit.testing;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService;
import static com.google.inject.Scopes.SINGLETON;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
import com.google.gerrit.acceptance.testsuite.project.ProjectOperationsImpl;
import com.google.gerrit.extensions.client.AuthType;
@@ -30,6 +31,7 @@ import com.google.gerrit.index.SchemaDefinitions;
import com.google.gerrit.index.project.ProjectSchemaDefinitions;
import com.google.gerrit.metrics.DisabledMetricMaker;
import com.google.gerrit.metrics.MetricMaker;
import com.google.gerrit.server.CacheRefreshExecutor;
import com.google.gerrit.server.FanOutExecutor;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.GerritPersonIdentProvider;
@@ -209,7 +211,7 @@ public class InMemoryModule extends FactoryModule {
@Singleton
@DiffExecutor
public ExecutorService createDiffExecutor() {
return MoreExecutors.newDirectExecutorService();
return newDirectExecutorService();
}
});
install(new DefaultMemoryCacheModule());
@@ -277,7 +279,7 @@ public class InMemoryModule extends FactoryModule {
@Singleton
@SendEmailExecutor
public ExecutorService createSendEmailExecutor() {
return MoreExecutors.newDirectExecutorService();
return newDirectExecutorService();
}
@Provides
@@ -287,6 +289,13 @@ public class InMemoryModule extends FactoryModule {
return queues.createQueue(2, "FanOut");
}
@Provides
@Singleton
@CacheRefreshExecutor
public ListeningExecutorService createCacheRefreshExecutor() {
return newDirectExecutorService();
}
private Module luceneIndexModule() {
return indexModule("com.google.gerrit.lucene.LuceneIndexModule");
}