commit 49583e0091062e45ee5c1a39ac5195868655f231 Author: Ivan Frade Date: Wed Sep 30 17:01:46 2020 -0700 Inject SuperprojectUpdateSubmissionListener Operators can swith their implementation of the superproject update to fit different reliability profiles or optimize for their storage. Make the SubmissionListener for superproject updates injectable. Change-Id: Ic1717a203fad7f7dfc02192b4fb76cc5ca90cd09 diff --git a/java/com/google/gerrit/httpd/init/WebAppInitializer.java b/java/com/google/gerrit/httpd/init/WebAppInitializer.java index c5f97a3..193c4f1 100644 --- a/java/com/google/gerrit/httpd/init/WebAppInitializer.java +++ b/java/com/google/gerrit/httpd/init/WebAppInitializer.java @@ -97,6 +97,7 @@ import com.google.gerrit.server.ssh.NoSshModule; import com.google.gerrit.server.ssh.SshAddressesModule; import com.google.gerrit.server.submit.LocalMergeSuperSetComputation; import com.google.gerrit.server.submit.SubscriptionGraph; +import com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener; import com.google.gerrit.sshd.SshHostKeyModule; import com.google.gerrit.sshd.SshKeyCacheImpl; import com.google.gerrit.sshd.SshModule; @@ -324,6 +325,7 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi modules.add(new RestApiModule()); modules.add(new SubscriptionGraph.Module()); + modules.add(new SuperprojectUpdateSubmissionListener.Module()); modules.add(new WorkQueue.Module()); modules.add(new GerritInstanceNameModule()); modules.add( diff --git a/java/com/google/gerrit/pgm/Daemon.java b/java/com/google/gerrit/pgm/Daemon.java index 28407a7..ba037d9 100644 --- a/java/com/google/gerrit/pgm/Daemon.java +++ b/java/com/google/gerrit/pgm/Daemon.java @@ -108,6 +108,7 @@ import com.google.gerrit.server.ssh.NoSshModule; import com.google.gerrit.server.ssh.SshAddressesModule; import com.google.gerrit.server.submit.LocalMergeSuperSetComputation; import com.google.gerrit.server.submit.SubscriptionGraph; +import com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener; import com.google.gerrit.sshd.SshHostKeyModule; import com.google.gerrit.sshd.SshKeyCacheImpl; import com.google.gerrit.sshd.SshModule; @@ -411,6 +412,7 @@ public class Daemon extends SiteProgram { modules.add(createIndexModule()); modules.add(new SubscriptionGraph.Module()); + modules.add(new SuperprojectUpdateSubmissionListener.Module()); modules.add(new WorkQueue.Module()); modules.add(new StreamEventsApiListener.Module()); modules.add(new EventBroker.Module()); diff --git a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java index cd378b2..69db066 100644 --- a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java +++ b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java @@ -164,7 +164,6 @@ import com.google.gerrit.server.query.change.InternalChangeQuery; import com.google.gerrit.server.restapi.change.ReplyAttentionSetUpdates; import com.google.gerrit.server.submit.MergeOp; import com.google.gerrit.server.submit.MergeOpRepoManager; -import com.google.gerrit.server.submit.SubmoduleOp; import com.google.gerrit.server.update.BatchUpdate; import com.google.gerrit.server.update.BatchUpdateOp; import com.google.gerrit.server.update.ChangeContext; @@ -173,7 +172,8 @@ import com.google.gerrit.server.update.RepoContext; import com.google.gerrit.server.update.RepoOnlyOp; import com.google.gerrit.server.update.RetryHelper; import com.google.gerrit.server.update.SubmissionExecutor; -import com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener; +import com.google.gerrit.server.update.SubmissionListener; +import com.google.gerrit.server.update.SuperprojectUpdateOnSubmission; import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.util.LabelVote; import com.google.gerrit.server.util.MagicBranch; @@ -344,7 +344,7 @@ class ReceiveCommits { private final RequestScopePropagator requestScopePropagator; private final Sequences seq; private final SetHashtagsOp.Factory hashtagsFactory; - private final SubmoduleOp.Factory subOpFactory; + private final SubmissionListener superprojectUpdateSubmissionListener; private final TagCache tagCache; private final ProjectConfig.Factory projectConfigFactory; private final SetPrivateOp.Factory setPrivateOpFactory; @@ -426,7 +426,7 @@ class ReceiveCommits { RequestScopePropagator requestScopePropagator, Sequences seq, SetHashtagsOp.Factory hashtagsFactory, - SubmoduleOp.Factory subOpFactory, + @SuperprojectUpdateOnSubmission SubmissionListener superprojectUpdateSubmissionListener, TagCache tagCache, SetPrivateOp.Factory setPrivateOpFactory, ReplyAttentionSetUpdates replyAttentionSetUpdates, @@ -474,7 +474,7 @@ class ReceiveCommits { this.retryHelper = retryHelper; this.requestScopePropagator = requestScopePropagator; this.seq = seq; - this.subOpFactory = subOpFactory; + this.superprojectUpdateSubmissionListener = superprojectUpdateSubmissionListener; this.tagCache = tagCache; this.projectConfigFactory = projectConfigFactory; this.setPrivateOpFactory = setPrivateOpFactory; @@ -742,7 +742,7 @@ class ReceiveCommits { logger.atFine().log("Added %d additional ref updates", added); SubmissionExecutor submissionExecutor = - new SubmissionExecutor(false, new SuperprojectUpdateSubmissionListener(subOpFactory)); + new SubmissionExecutor(false, superprojectUpdateSubmissionListener); submissionExecutor.execute(ImmutableList.of(bu)); diff --git a/java/com/google/gerrit/server/submit/MergeOp.java b/java/com/google/gerrit/server/submit/MergeOp.java index a65d297..58b0c8e 100644 --- a/java/com/google/gerrit/server/submit/MergeOp.java +++ b/java/com/google/gerrit/server/submit/MergeOp.java @@ -79,7 +79,7 @@ import com.google.gerrit.server.update.ChangeContext; import com.google.gerrit.server.update.RetryHelper; import com.google.gerrit.server.update.SubmissionExecutor; import com.google.gerrit.server.update.SubmissionListener; -import com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener; +import com.google.gerrit.server.update.SuperprojectUpdateOnSubmission; import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.util.time.TimeUtil; import com.google.inject.Inject; @@ -232,7 +232,7 @@ public class MergeOp implements AutoCloseable { private final SubmitStrategyFactory submitStrategyFactory; private final SubscriptionGraph.Factory subscriptionGraphFactory; private final SubmoduleCommits.Factory submoduleCommitsFactory; - private final SubmoduleOp.Factory submoduleOpFactory; + private final SubmissionListener superprojectUpdateSubmissionListener; private final Provider ormProvider; private final NotifyResolver notifyResolver; private final RetryHelper retryHelper; @@ -264,7 +264,7 @@ public class MergeOp implements AutoCloseable { SubmitStrategyFactory submitStrategyFactory, SubmoduleCommits.Factory submoduleCommitsFactory, SubscriptionGraph.Factory subscriptionGraphFactory, - SubmoduleOp.Factory submoduleOpFactory, + @SuperprojectUpdateOnSubmission SubmissionListener superprojectUpdateSubmissionListener, Provider ormProvider, NotifyResolver notifyResolver, TopicMetrics topicMetrics, @@ -279,7 +279,7 @@ public class MergeOp implements AutoCloseable { this.submitStrategyFactory = submitStrategyFactory; this.submoduleCommitsFactory = submoduleCommitsFactory; this.subscriptionGraphFactory = subscriptionGraphFactory; - this.submoduleOpFactory = submoduleOpFactory; + this.superprojectUpdateSubmissionListener = superprojectUpdateSubmissionListener; this.ormProvider = ormProvider; this.notifyResolver = notifyResolver; this.retryHelper = retryHelper; @@ -497,10 +497,8 @@ public class MergeOp implements AutoCloseable { topicMetrics.topicSubmissions.increment(); } - SubmissionListener updateSuperprojectsAfterSubmission = - new SuperprojectUpdateSubmissionListener(submoduleOpFactory); SubmissionExecutor submissionExecutor = - new SubmissionExecutor(dryrun, updateSuperprojectsAfterSubmission); + new SubmissionExecutor(dryrun, superprojectUpdateSubmissionListener); RetryTracker retryTracker = new RetryTracker(); retryHelper .changeUpdate( diff --git a/java/com/google/gerrit/server/update/SuperprojectUpdateOnSubmission.java b/java/com/google/gerrit/server/update/SuperprojectUpdateOnSubmission.java new file mode 100644 index 0000000..441132c --- /dev/null +++ b/java/com/google/gerrit/server/update/SuperprojectUpdateOnSubmission.java @@ -0,0 +1,25 @@ +// Copyright (C) 2020 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.update; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import com.google.inject.BindingAnnotation; +import java.lang.annotation.Retention; + +/** Marker on a {@link SubmissionListener} that updates the superprojects on submission. */ +@Retention(RUNTIME) +@BindingAnnotation +public @interface SuperprojectUpdateOnSubmission {} diff --git a/java/com/google/gerrit/server/update/SuperprojectUpdateSubmissionListener.java b/java/com/google/gerrit/server/update/SuperprojectUpdateSubmissionListener.java index d6dca38..dffdff0 100644 --- a/java/com/google/gerrit/server/update/SuperprojectUpdateSubmissionListener.java +++ b/java/com/google/gerrit/server/update/SuperprojectUpdateSubmissionListener.java @@ -20,10 +20,12 @@ import com.google.gerrit.entities.BranchNameKey; import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.server.submit.MergeOpRepoManager; import com.google.gerrit.server.submit.SubmoduleOp; +import com.google.inject.AbstractModule; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import javax.inject.Inject; import org.eclipse.jgit.transport.ReceiveCommand; /** Update superprojects after submission is done */ @@ -36,6 +38,16 @@ public class SuperprojectUpdateSubmissionListener implements SubmissionListener private ImmutableList batchUpdates = ImmutableList.of(); private boolean dryrun; + public static class Module extends AbstractModule { + @Override + protected void configure() { + bind(SubmissionListener.class) + .annotatedWith(SuperprojectUpdateOnSubmission.class) + .to(SuperprojectUpdateSubmissionListener.class); + } + } + + @Inject public SuperprojectUpdateSubmissionListener(SubmoduleOp.Factory subOpFactory) { this.subOpFactory = subOpFactory; } diff --git a/java/com/google/gerrit/testing/InMemoryModule.java b/java/com/google/gerrit/testing/InMemoryModule.java index 6c9fbed..1779a18 100644 --- a/java/com/google/gerrit/testing/InMemoryModule.java +++ b/java/com/google/gerrit/testing/InMemoryModule.java @@ -88,6 +88,7 @@ import com.google.gerrit.server.securestore.SecureStore; import com.google.gerrit.server.ssh.NoSshKeyCache; import com.google.gerrit.server.submit.LocalMergeSuperSetComputation; import com.google.gerrit.server.submit.SubscriptionGraph; +import com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener; import com.google.gerrit.server.util.ReplicaUtil; import com.google.inject.AbstractModule; import com.google.inject.Guice; @@ -177,6 +178,7 @@ public class InMemoryModule extends FactoryModule { factory(GarbageCollection.Factory.class); install(new AuditModule()); install(new SubscriptionGraph.Module()); + install(new SuperprojectUpdateSubmissionListener.Module()); bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST);