RepoUpdater: Convert ConcurrentRefUpdateException into LockFailureException
Calling the RepoCommand may fail with a ConcurrentRefUpdateException
that represents a LOCK_FAILURE. Convert this exception into a
LockFailureException so that our auto-retrying logic for LOCK_FAILURES
can recognize the LOCK_FAILURE and retry the operation, instead of
failing immediately.
Example stacktrace:
update for foo/manifest:*:default.xml (Repo) => foo/superproject:* (ref refs/heads/main) failed: org.eclipse.jgit.api.errors.ConcurrentRefUpdateException: Cannot lock refs/heads/main. Ensure that no other process has an open file handle on the lock file refs/heads/main.lock, then you may delete the lock file and retry.. RefUpdate return code was: LOCK_FAILURE
at org.eclipse.jgit.gitrepo.BareSuperprojectWriter.commitTreeOnCurrentTip(BareSuperprojectWriter.java:311)
at org.eclipse.jgit.gitrepo.BareSuperprojectWriter.write(BareSuperprojectWriter.java:141)
at org.eclipse.jgit.gitrepo.RepoCommand.call(RepoCommand.java:573)
at com.googlesource.gerrit.plugins.supermanifest.RepoUpdater.update(RepoUpdater.java:74)
at com.googlesource.gerrit.plugins.supermanifest.SuperManifestRefUpdatedListener.updateForConfig(SuperManifestRefUpdatedListener.java:424)
at com.googlesource.gerrit.plugins.supermanifest.SuperManifestRefUpdatedListener.onGitReferenceUpdated(SuperManifestRefUpdatedListener.java:314)
Follow the example of change I2ff60b01a in gerrit core.
Change-Id: I46be2ee251bfef9dee4ea65c3f689415095501dd
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/googlesource/gerrit/plugins/supermanifest/RepoUpdater.java b/java/com/googlesource/gerrit/plugins/supermanifest/RepoUpdater.java
index 950f252..c888d57 100644
--- a/java/com/googlesource/gerrit/plugins/supermanifest/RepoUpdater.java
+++ b/java/com/googlesource/gerrit/plugins/supermanifest/RepoUpdater.java
@@ -14,10 +14,12 @@
package com.googlesource.gerrit.plugins.supermanifest;
+import com.google.gerrit.git.LockFailureException;
import com.googlesource.gerrit.plugins.supermanifest.SuperManifestRefUpdatedListener.GerritRemoteReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.gitrepo.ManifestParser;
import org.eclipse.jgit.gitrepo.RepoCommand;
@@ -64,7 +66,12 @@
// otherwise, which would leak data from the serving machine.
cmd.setIncludedFileReader(new GerritIncludeReader(srcRepo, srcRef));
- cmd.call();
+ try {
+ cmd.call();
+ } catch (ConcurrentRefUpdateException e) {
+ LockFailureException.throwIfLockFailure(e);
+ throw e;
+ }
}
private static class GerritIncludeReader implements ManifestParser.IncludedFileReader {