Move default memory cache implementation out of H2 package

The memory cache doesn't depend on H2 at all, and this separation of
packages makes it harder to reintroduce the kind of source-level
dependency that was removed in I570fd54adf.

Change-Id: Ie23e39cd7ea9a0813a914e65614b889c248342ae
This commit is contained in:
Dave Borowitz 2018-05-08 21:24:24 +02:00 committed by David Pursehouse
parent 5517ec316f
commit a3cc510fc1
13 changed files with 94 additions and 37 deletions

View File

@ -0,0 +1,28 @@
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.cache.h2;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.server.cache.CacheImpl;
import com.google.gerrit.server.cache.PersistentCacheFactory;
@CacheImpl(type = CacheImpl.Type.PERSISTENT)
public class H2CacheModule extends LifecycleModule {
@Override
protected void configure() {
bind(PersistentCacheFactory.class).to(H2CacheFactory.class);
listener().to(H2CacheFactory.class);
}
}

12
gerrit-cache-mem/BUILD Normal file
View File

@ -0,0 +1,12 @@
java_library(
name = "mem",
srcs = glob(["src/main/java/**/*.java"]),
visibility = ["//visibility:public"],
deps = [
"//gerrit-extension-api:api",
"//gerrit-server:server",
"//lib:guava",
"//lib/guice",
"//lib/jgit/org.eclipse.jgit:jgit",
],
)

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.cache.h2;
package com.google.gerrit.server.cache.mem;
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
@ -20,43 +20,21 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.Weigher;
import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.server.cache.CacheBinding;
import com.google.gerrit.server.cache.CacheImpl;
import com.google.gerrit.server.cache.ForwardingRemovalListener;
import com.google.gerrit.server.cache.MemoryCacheFactory;
import com.google.gerrit.server.cache.PersistentCacheFactory;
import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.inject.Inject;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.lib.Config;
public class DefaultCacheFactory implements MemoryCacheFactory {
@CacheImpl(type = CacheImpl.Type.MEMORY)
public static class MemoryCacheModule extends FactoryModule {
@Override
protected void configure() {
factory(ForwardingRemovalListener.Factory.class);
bind(MemoryCacheFactory.class).to(DefaultCacheFactory.class);
}
}
@CacheImpl(type = CacheImpl.Type.PERSISTENT)
public static class PersistentCacheModule extends LifecycleModule {
@Override
protected void configure() {
bind(PersistentCacheFactory.class).to(H2CacheFactory.class);
listener().to(H2CacheFactory.class);
}
}
public class DefaultMemoryCacheFactory implements MemoryCacheFactory {
private final Config cfg;
private final ForwardingRemovalListener.Factory forwardingRemovalListenerFactory;
@Inject
public DefaultCacheFactory(
DefaultMemoryCacheFactory(
@GerritServerConfig Config config,
ForwardingRemovalListener.Factory forwardingRemovalListenerFactory) {
this.cfg = config;

View File

@ -0,0 +1,29 @@
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.cache.mem;
import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.server.cache.CacheImpl;
import com.google.gerrit.server.cache.ForwardingRemovalListener;
import com.google.gerrit.server.cache.MemoryCacheFactory;
@CacheImpl(type = CacheImpl.Type.MEMORY)
public class DefaultMemoryCacheModule extends FactoryModule {
@Override
protected void configure() {
factory(ForwardingRemovalListener.Factory.class);
bind(MemoryCacheFactory.class).to(DefaultMemoryCacheFactory.class);
}
}

View File

@ -49,6 +49,7 @@ junit_tests(
":gpg",
":testutil",
"//gerrit-cache-h2:cache-h2",
"//gerrit-cache-mem:mem",
"//gerrit-lucene:lucene",
"//gerrit-server:testutil",
"//lib:truth",

View File

@ -62,6 +62,7 @@ java_library(
REST_UTIL_DEPS = [
"//gerrit-cache-h2:cache-h2",
"//gerrit-cache-mem:mem",
"//gerrit-util-cli:cli",
"//lib:args4j",
"//lib:gwtorm",
@ -113,6 +114,7 @@ REST_PGM_DEPS = [
":init-api",
":util",
"//gerrit-cache-h2:cache-h2",
"//gerrit-cache-mem:mem",
"//gerrit-elasticsearch:elasticsearch",
"//gerrit-gpg:gpg",
"//gerrit-lucene:lucene",

View File

@ -51,7 +51,8 @@ import com.google.gerrit.server.LibModuleLoader;
import com.google.gerrit.server.StartupChecks;
import com.google.gerrit.server.account.InternalAccountDirectory;
import com.google.gerrit.server.cache.CacheOverrides;
import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
import com.google.gerrit.server.cache.h2.H2CacheModule;
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
import com.google.gerrit.server.change.ChangeCleanupRunner;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.AuthConfigModule;
@ -386,8 +387,8 @@ public class Daemon extends SiteProgram {
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
modules.add(new SearchingChangeCacheImpl.Module(slave));
modules.add(new InternalAccountDirectory.Module());
modules.add(new DefaultCacheFactory.MemoryCacheModule());
modules.add(new DefaultCacheFactory.PersistentCacheModule());
modules.add(new DefaultMemoryCacheModule());
modules.add(new H2CacheModule());
modules.add(cfgInjector.getInstance(MailReceiver.Module.class));
if (emailModule != null) {
modules.add(emailModule);

View File

@ -38,7 +38,8 @@ import com.google.gerrit.server.account.GroupCacheImpl;
import com.google.gerrit.server.account.GroupIncludeCacheImpl;
import com.google.gerrit.server.account.Realm;
import com.google.gerrit.server.cache.CacheRemovalListener;
import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
import com.google.gerrit.server.cache.h2.H2CacheModule;
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
import com.google.gerrit.server.change.ChangeJson;
import com.google.gerrit.server.change.ChangeKindCacheImpl;
import com.google.gerrit.server.change.MergeabilityCacheImpl;
@ -148,8 +149,8 @@ public class BatchProgramModule extends FactoryModule {
factory(ProjectControl.AssistedFactory.class);
install(new BatchGitModule());
install(new DefaultCacheFactory.MemoryCacheModule());
install(new DefaultCacheFactory.PersistentCacheModule());
install(new DefaultMemoryCacheModule());
install(new H2CacheModule());
install(new GroupModule());
install(new NoteDbModule(cfg));
install(new PrologModule());

View File

@ -91,6 +91,7 @@ TESTUTIL_DEPS = [
"//gerrit-common:annotations",
"//gerrit-common:server",
"//gerrit-cache-h2:cache-h2",
"//gerrit-cache-mem:mem",
"//gerrit-extension-api:api",
"//gerrit-gpg:gpg",
"//gerrit-lucene:lucene",

View File

@ -26,7 +26,8 @@ import com.google.gerrit.metrics.MetricMaker;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.GerritPersonIdentProvider;
import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
import com.google.gerrit.server.cache.h2.H2CacheModule;
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.config.AllProjectsNameProvider;
import com.google.gerrit.server.config.AllUsersName;
@ -199,8 +200,8 @@ public class InMemoryModule extends FactoryModule {
return MoreExecutors.newDirectExecutorService();
}
});
install(new DefaultCacheFactory.MemoryCacheModule());
install(new DefaultCacheFactory.PersistentCacheModule());
install(new DefaultMemoryCacheModule());
install(new H2CacheModule());
install(new FakeEmailSender.Module());
install(new SignedTokenEmailTokenVerifier.Module());
install(new GpgModule(cfg));

View File

@ -8,6 +8,7 @@ java_library(
visibility = ["//visibility:public"],
deps = [
"//gerrit-cache-h2:cache-h2",
"//gerrit-cache-mem:mem",
"//gerrit-common:annotations",
"//gerrit-common:server",
"//gerrit-extension-api:api",

View File

@ -6,6 +6,7 @@ java_library(
visibility = ["//visibility:public"],
deps = [
"//gerrit-cache-h2:cache-h2",
"//gerrit-cache-mem:mem",
"//gerrit-elasticsearch:elasticsearch",
"//gerrit-extension-api:api",
"//gerrit-gpg:gpg",

View File

@ -35,7 +35,8 @@ import com.google.gerrit.server.LibModuleLoader;
import com.google.gerrit.server.StartupChecks;
import com.google.gerrit.server.account.InternalAccountDirectory;
import com.google.gerrit.server.cache.CacheOverrides;
import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
import com.google.gerrit.server.cache.h2.H2CacheModule;
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
import com.google.gerrit.server.change.ChangeCleanupRunner;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.AuthConfigModule;
@ -319,8 +320,8 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
modules.add(new SearchingChangeCacheImpl.Module());
modules.add(new InternalAccountDirectory.Module());
modules.add(new DefaultCacheFactory.MemoryCacheModule());
modules.add(new DefaultCacheFactory.PersistentCacheModule());
modules.add(new DefaultMemoryCacheModule());
modules.add(new H2CacheModule());
modules.add(cfgInjector.getInstance(MailReceiver.Module.class));
modules.add(new SmtpEmailSender.Module());
modules.add(new SignedTokenEmailTokenVerifier.Module());