From 7580f88b65ab62979a3888d01b05a28a297918ba Mon Sep 17 00:00:00 2001 From: Jukka Jokiniva Date: Mon, 10 Aug 2020 09:22:12 +0300 Subject: Block parallel processing of stage requests Change-Id: I39356629df4f82e5f813c457fc69079a003473cf Reviewed-by: Daniel Smith --- .../gerrit/plugins/qtcodereview/QtStage.java | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtStage.java b/src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtStage.java index cb7084d..e28063f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtStage.java +++ b/src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtStage.java @@ -46,6 +46,7 @@ import com.google.inject.Singleton; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.Config; @@ -71,6 +72,7 @@ public class QtStage } } + private final ReentrantLock stageLock = new ReentrantLock(); private final GitRepositoryManager repoManager; private final PermissionBackend permissionBackend; private final ChangeData.Factory changeDataFactory; @@ -123,25 +125,32 @@ public class QtStage throws RestApiException, RepositoryNotFoundException, IOException, PermissionBackendException, UpdateException, ConfigInvalidException { - logger.atInfo().log("qtcodereview: stage %s", rsrc.getChange().toString()); + Output output; + logger.atInfo().log("qtcodereview: stage request reveived for %s", rsrc.getChange().toString()); - IdentifiedUser submitter = rsrc.getUser().asIdentifiedUser(); - change = rsrc.getChange(); - projectKey = rsrc.getProject(); - destBranchKey = change.getDest(); - stagingBranchKey = QtUtil.getStagingBranch(destBranchKey); + stageLock.lock(); // block processing of parallel stage requests + try { + IdentifiedUser submitter = rsrc.getUser().asIdentifiedUser(); + change = rsrc.getChange(); + projectKey = rsrc.getProject(); + destBranchKey = change.getDest(); + stagingBranchKey = QtUtil.getStagingBranch(destBranchKey); - rsrc.permissions().check(ChangePermission.QT_STAGE); + rsrc.permissions().check(ChangePermission.QT_STAGE); + projectCache.checkedGet(rsrc.getProject()).checkStatePermitsWrite(); - projectCache.checkedGet(rsrc.getProject()).checkStatePermitsWrite(); + output = new Output(changeToStaging(rsrc, submitter, input)); + } finally { + stageLock.unlock(); + } - return new Output(changeToStaging(rsrc, submitter, input)); + return output; } private Change changeToStaging(RevisionResource rsrc, IdentifiedUser submitter, SubmitInput input) throws RestApiException, IOException, UpdateException, ConfigInvalidException, PermissionBackendException { - logger.atInfo().log("qtcodereview: changeToStaging starts"); + logger.atInfo().log("qtcodereview: changeToStaging starts for %s", change.toString()); if (change.getStatus() != Change.Status.NEW) { logger.atSevere().log( -- cgit v1.2.3