Search in sources :

Example 1 with CacheModule

use of com.google.gerrit.server.cache.CacheModule in project gerrit by GerritCodeReview.

the class HttpPluginModule method configureServlets.

@Override
protected void configureServlets() {
    bind(HttpPluginServlet.class);
    serveRegex("^/(?:a/)?plugins/(.*)?$").with(HttpPluginServlet.class);
    bind(LfsPluginServlet.class);
    serveRegex(LfsDefinitions.LFS_URL_REGEX).with(LfsPluginServlet.class);
    bind(StartPluginListener.class).annotatedWith(UniqueAnnotations.create()).to(HttpPluginServlet.class);
    bind(ReloadPluginListener.class).annotatedWith(UniqueAnnotations.create()).to(HttpPluginServlet.class);
    bind(StartPluginListener.class).annotatedWith(UniqueAnnotations.create()).to(LfsPluginServlet.class);
    bind(ReloadPluginListener.class).annotatedWith(UniqueAnnotations.create()).to(LfsPluginServlet.class);
    bind(ModuleGenerator.class).to(HttpAutoRegisterModuleGenerator.class);
    install(new CacheModule() {

        @Override
        protected void configure() {
            cache(PLUGIN_RESOURCES, ResourceKey.class, Resource.class).maximumWeight(2 << 20).weigher(ResourceWeigher.class);
        }
    });
}
Also used : Resource(com.google.gerrit.httpd.resources.Resource) ResourceWeigher(com.google.gerrit.httpd.resources.ResourceWeigher) CacheModule(com.google.gerrit.server.cache.CacheModule) ModuleGenerator(com.google.gerrit.server.plugins.ModuleGenerator) ResourceKey(com.google.gerrit.httpd.resources.ResourceKey)

Example 2 with CacheModule

use of com.google.gerrit.server.cache.CacheModule in project gerrit by GerritCodeReview.

the class LdapRealmTest method setUpInjector.

@Before
public void setUpInjector() throws Exception {
    Injector injector = Guice.createInjector(new InMemoryModule(), new CacheModule() {

        @Override
        protected void configure() {
            cache(GROUP_CACHE, String.class, new TypeLiteral<Set<AccountGroup.UUID>>() {
            }).loader(LdapRealm.MemberLoader.class);
            cache(USERNAME_CACHE, String.class, new TypeLiteral<Optional<Account.Id>>() {
            }).loader(LdapRealm.UserLoader.class);
            cache(GROUP_EXIST_CACHE, String.class, new TypeLiteral<Boolean>() {
            }).loader(LdapRealm.ExistenceLoader.class);
            cache(PARENT_GROUPS_CACHE, String.class, new TypeLiteral<ImmutableSet<String>>() {
            });
        }
    });
    injector.injectMembers(this);
}
Also used : Account(com.google.gerrit.entities.Account) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Optional(java.util.Optional) CacheModule(com.google.gerrit.server.cache.CacheModule) AccountGroup(com.google.gerrit.entities.AccountGroup) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) InMemoryModule(com.google.gerrit.testing.InMemoryModule) Before(org.junit.Before)

Example 3 with CacheModule

use of com.google.gerrit.server.cache.CacheModule in project gerrit by GerritCodeReview.

the class ProjectCacheImpl method module.

public static Module module() {
    return new CacheModule() {

        @Override
        protected void configure() {
            // We split the project cache into two parts for performance reasons:
            // 1) An in-memory part that has only the project name as key.
            // 2) A persisted part that has the name and revision as key.
            // 
            // When loading dashboards or returning change query results we potentially
            // need to access hundreds of projects because each change could originate in
            // a different project and, through inheritance, require us to check even more
            // projects when evaluating permissions. It's not feasible to read the revision
            // of refs/meta/config from each of these repos as that would require opening
            // them all and reading their ref list or table.
            // At the same time, we want the persisted cache to be immutable and we want it
            // to be impossible that a value for a given key is out of date. We therefore
            // require a revision in the key. That is in line with the rest of the caches in
            // Gerrit.
            // 
            // Splitting the cache into two chunks internally in this class allows us to retain
            // the existing performance guarantees of not requiring reads for the repo for values
            // cached in-memory but also to persist the cache which leads to a much improved
            // cold-start behavior and in-memory miss latency.
            cache(CACHE_NAME, Project.NameKey.class, CachedProjectConfig.class).loader(InMemoryLoader.class).refreshAfterWrite(Duration.ofMinutes(15)).expireAfterWrite(Duration.ofHours(1));
            persist(PERSISTED_CACHE_NAME, Cache.ProjectCacheKeyProto.class, CachedProjectConfig.class).loader(PersistedLoader.class).keySerializer(new ProtobufSerializer<>(Cache.ProjectCacheKeyProto.parser())).valueSerializer(PersistedProjectConfigSerializer.INSTANCE).diskLimit(// 1 GiB
            1 << 30).version(4).maximumWeight(0);
            cache(CACHE_LIST, ListKey.class, new TypeLiteral<ImmutableSortedSet<Project.NameKey>>() {
            }).maximumWeight(1).loader(Lister.class);
            bind(ProjectCacheImpl.class);
            bind(ProjectCache.class).to(ProjectCacheImpl.class);
            install(new LifecycleModule() {

                @Override
                protected void configure() {
                    listener().to(ProjectCacheWarmer.class);
                }
            });
        }
    };
}
Also used : CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) CacheModule(com.google.gerrit.server.cache.CacheModule) Project(com.google.gerrit.entities.Project) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) LoadingCache(com.google.common.cache.LoadingCache) Cache(com.google.gerrit.server.cache.proto.Cache) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule)

Example 4 with CacheModule

use of com.google.gerrit.server.cache.CacheModule in project gerrit by GerritCodeReview.

the class StaticModule method configureServlets.

@Override
protected void configureServlets() {
    serveRegex("^/Documentation$").with(named(DOC_SERVLET));
    serveRegex("^/Documentation/$").with(named(DOC_SERVLET));
    serveRegex("^/Documentation/(.+)$").with(named(DOC_SERVLET));
    serve("/static/*").with(SiteStaticDirectoryServlet.class);
    install(new CacheModule() {

        @Override
        protected void configure() {
            cache(CACHE, Path.class, Resource.class).maximumWeight(1 << 20).weigher(ResourceServlet.Weigher.class);
        }
    });
    if (!options.headless()) {
        install(new CoreStaticModule());
        install(new PolyGerritModule());
    }
}
Also used : Path(java.nio.file.Path) Resource(com.google.gerrit.httpd.raw.ResourceServlet.Resource) CacheModule(com.google.gerrit.server.cache.CacheModule)

Aggregations

CacheModule (com.google.gerrit.server.cache.CacheModule)4 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Account (com.google.gerrit.entities.Account)1 AccountGroup (com.google.gerrit.entities.AccountGroup)1 CachedProjectConfig (com.google.gerrit.entities.CachedProjectConfig)1 Project (com.google.gerrit.entities.Project)1 Resource (com.google.gerrit.httpd.raw.ResourceServlet.Resource)1 Resource (com.google.gerrit.httpd.resources.Resource)1 ResourceKey (com.google.gerrit.httpd.resources.ResourceKey)1 ResourceWeigher (com.google.gerrit.httpd.resources.ResourceWeigher)1 LifecycleModule (com.google.gerrit.lifecycle.LifecycleModule)1 Cache (com.google.gerrit.server.cache.proto.Cache)1 ModuleGenerator (com.google.gerrit.server.plugins.ModuleGenerator)1 InMemoryModule (com.google.gerrit.testing.InMemoryModule)1 Injector (com.google.inject.Injector)1 TypeLiteral (com.google.inject.TypeLiteral)1 Path (java.nio.file.Path)1 Optional (java.util.Optional)1