diff options
author | Jukka Jokiniva <jukka.jokiniva@qt.io> | 2020-08-10 09:22:12 +0300 |
---|---|---|
committer | Jukka Jokiniva <jukka.jokiniva@qt.io> | 2020-08-13 10:00:03 +0000 |
commit | 2b6a3bab908ac83320b9c55d586af5b5434ec11f (patch) | |
tree | ff1ba53260e462280354194198c0cb19b1cddb1b | |
parent | 2ed61624b862352b9b21e5e5482607f981e982d0 (diff) |
Block parallel processing of stage requests
Change-Id: I39356629df4f82e5f813c457fc69079a003473cf
Reviewed-by: Daniel Smith <Daniel.Smith@qt.io>
(cherry picked from commit 7580f88b65ab62979a3888d01b05a28a297918ba)
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtStage.java | 29 |
1 files 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 733bbd0..c18b7fb 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 Response.ok(new Output(changeToStaging(rsrc, submitter, input))); + return Response.ok(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( |