Skip to content

Commit

Permalink
Merge branch 'stable-3.8'
Browse files Browse the repository at this point in the history
* stable-3.8:
  Add in memory change data cache by project

Change-Id: I84a278b0d3f5bf081143a891009c8be15849ee7b
Release-Notes: skip
  • Loading branch information
Martin Fick committed Sep 29, 2023
2 parents eb015f2 + 3759af5 commit 4732870
Show file tree
Hide file tree
Showing 16 changed files with 581 additions and 111 deletions.
7 changes: 7 additions & 0 deletions Documentation/config-gerrit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,13 @@ or multiple replica nodes.
The cache should be flushed whenever NoteDb change metadata in a repository is
modified outside of Gerrit.

cache `"changes_by_project"`::
+
Ideally, the memorylimit of this cache is large enough to cover all projects.
This should significantly speed up change ref advertisements and git pushes,
especially for projects with lots of changes, and particularly on replicas
where there is no index.

cache `"git_modified_files"`::
+
Each item caches the list of git modified files between two git trees
Expand Down
4 changes: 2 additions & 2 deletions java/com/google/gerrit/httpd/init/WebAppInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
import com.google.gerrit.server.config.SysExecutorModule;
import com.google.gerrit.server.events.EventBroker.EventBrokerModule;
import com.google.gerrit.server.events.StreamEventsApiListener.StreamEventsApiListenerModule;
import com.google.gerrit.server.git.ChangesByProjectCache;
import com.google.gerrit.server.git.GarbageCollectionModule;
import com.google.gerrit.server.git.GitRepositoryManagerModule;
import com.google.gerrit.server.git.SearchingChangeCacheImpl.SearchingChangeCacheImplModule;
import com.google.gerrit.server.git.SystemReaderInstaller;
import com.google.gerrit.server.git.WorkQueue.WorkQueueModule;
import com.google.gerrit.server.index.IndexModule;
Expand Down Expand Up @@ -317,7 +317,7 @@ private Injector createSysInjector() {
modules.add(new ProjectQueryBuilderModule());
modules.add(new DefaultRefLogIdentityProvider.Module());
modules.add(new PluginApiModule());
modules.add(new SearchingChangeCacheImplModule());
modules.add(new ChangesByProjectCache.Module(ChangesByProjectCache.UseIndex.TRUE, config));
modules.add(new InternalAccountDirectoryModule());
modules.add(new DefaultPermissionBackendModule());
modules.add(new DefaultMemoryCacheModule());
Expand Down
7 changes: 5 additions & 2 deletions java/com/google/gerrit/pgm/Daemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
import com.google.gerrit.server.config.SysExecutorModule;
import com.google.gerrit.server.events.EventBroker.EventBrokerModule;
import com.google.gerrit.server.events.StreamEventsApiListener.StreamEventsApiListenerModule;
import com.google.gerrit.server.git.ChangesByProjectCache;
import com.google.gerrit.server.git.GarbageCollectionModule;
import com.google.gerrit.server.git.SearchingChangeCacheImpl.SearchingChangeCacheImplModule;
import com.google.gerrit.server.git.WorkQueue.WorkQueueModule;
import com.google.gerrit.server.group.PeriodicGroupIndexer.PeriodicGroupIndexerModule;
import com.google.gerrit.server.index.AbstractIndexModule;
Expand Down Expand Up @@ -476,7 +476,10 @@ private Injector createSysInjector() {
modules.add(new DefaultRefLogIdentityProvider.Module());
modules.add(new PluginApiModule());

modules.add(new SearchingChangeCacheImplModule(replica));
modules.add(
new ChangesByProjectCache.Module(
replica ? ChangesByProjectCache.UseIndex.FALSE : ChangesByProjectCache.UseIndex.TRUE,
config));
modules.add(new InternalAccountDirectoryModule());
modules.add(new DefaultPermissionBackendModule());
modules.add(new DefaultMemoryCacheModule());
Expand Down
8 changes: 3 additions & 5 deletions java/com/google/gerrit/pgm/util/BatchProgramModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.extensions.events.RevisionCreated;
import com.google.gerrit.server.extensions.events.WorkInProgressStateChanged;
import com.google.gerrit.server.git.ChangesByProjectCache;
import com.google.gerrit.server.git.PureRevertCache;
import com.google.gerrit.server.git.SearchingChangeCacheImpl;
import com.google.gerrit.server.git.TagCache;
import com.google.gerrit.server.notedb.ChangeDraftNotesUpdate;
import com.google.gerrit.server.notedb.NoteDbModule;
Expand Down Expand Up @@ -164,10 +164,6 @@ protected void configure() {
factory(PatchSetInserter.Factory.class);
factory(RebaseChangeOp.Factory.class);

// As Reindex is a batch program, don't assume the index is available for
// the change cache.
bind(SearchingChangeCacheImpl.class).toProvider(Providers.of(null));

bind(new TypeLiteral<ImmutableSet<GroupReference>>() {})
.annotatedWith(AdministrateServerGroups.class)
.toInstance(ImmutableSet.of());
Expand All @@ -179,6 +175,8 @@ protected void configure() {
.toInstance(Collections.emptySet());

modules.add(new BatchGitModule());
modules.add(
new ChangesByProjectCache.Module(ChangesByProjectCache.UseIndex.FALSE, getConfig()));
modules.add(new DefaultPermissionBackendModule());
modules.add(new DefaultMemoryCacheModule());
modules.add(new H2CacheModule());
Expand Down
63 changes: 63 additions & 0 deletions java/com/google/gerrit/server/git/ChangesByProjectCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) 2023 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.git;

import com.google.gerrit.entities.Project;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.inject.AbstractModule;
import java.io.IOException;
import java.util.stream.Stream;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Repository;

public interface ChangesByProjectCache {
public enum UseIndex {
TRUE,
FALSE;
}

public static class Module extends AbstractModule {
private UseIndex useIndex;
private @GerritServerConfig Config config;

public Module(UseIndex useIndex, @GerritServerConfig Config config) {
this.useIndex = useIndex;
this.config = config;
}

@Override
protected void configure() {
boolean searchingCacheEnabled =
config.getLong("cache", SearchingChangeCacheImpl.ID_CACHE, "memoryLimit", 0) > 0;
if (searchingCacheEnabled && UseIndex.TRUE.equals(useIndex)) {
install(new SearchingChangeCacheImpl.SearchingChangeCacheImplModule());
} else {
bind(UseIndex.class).toInstance(useIndex);
install(new ChangesByProjectCacheImpl.Module());
}
}
}

/**
* Stream changeDatas for the project
*
* @param project project to read.
* @param repository repository for the project to read.
* @return Stream of known changes; empty if no changes.
*/
Stream<ChangeData> streamChangeDatas(Project.NameKey project, Repository repository)
throws IOException;
}
Loading

0 comments on commit 4732870

Please sign in to comment.