LockFailureException: Expose ref names

Change-Id: I0bc3c077fe8e0a05e5b36987c959193058ce363e
This commit is contained in:
Dave Borowitz
2017-10-30 16:20:26 -04:00
parent f510300d31
commit 528b4d257b
4 changed files with 30 additions and 4 deletions

View File

@@ -840,7 +840,7 @@ public class ExternalIdsUpdate {
case FORCED: case FORCED:
break; break;
case LOCK_FAILURE: case LOCK_FAILURE:
throw new LockFailureException("Updating external IDs failed with " + res); throw new LockFailureException("Updating external IDs failed with " + res, u);
case IO_FAILURE: case IO_FAILURE:
case NOT_ATTEMPTED: case NOT_ATTEMPTED:
case REJECTED: case REJECTED:

View File

@@ -14,13 +14,38 @@
package com.google.gerrit.server.git; package com.google.gerrit.server.git;
import static com.google.common.collect.ImmutableList.toImmutableList;
import com.google.common.collect.ImmutableList;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.lib.BatchRefUpdate;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.transport.ReceiveCommand;
/** Thrown when updating a ref in Git fails with LOCK_FAILURE. */ /** Thrown when updating a ref in Git fails with LOCK_FAILURE. */
public class LockFailureException extends IOException { public class LockFailureException extends IOException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public LockFailureException(String message) { private final ImmutableList<String> refs;
public LockFailureException(String message, RefUpdate refUpdate) {
super(message); super(message);
refs = ImmutableList.of(refUpdate.getName());
}
public LockFailureException(String message, BatchRefUpdate batchRefUpdate) {
super(message);
refs =
batchRefUpdate
.getCommands()
.stream()
.filter(c -> c.getResult() == ReceiveCommand.Result.LOCK_FAILURE)
.map(ReceiveCommand::getRefName)
.collect(toImmutableList());
}
/** Subset of ref names that caused the lock failure. */
public ImmutableList<String> getFailedRefs() {
return refs;
} }
} }

View File

@@ -395,7 +395,8 @@ public abstract class VersionedMetaData {
+ " in " + " in "
+ db.getDirectory() + db.getDirectory()
+ ": " + ": "
+ ru.getResult()); + ru.getResult(),
ru);
case FORCED: case FORCED:
case IO_FAILURE: case IO_FAILURE:
case NOT_ATTEMPTED: case NOT_ATTEMPTED:

View File

@@ -74,7 +74,7 @@ public class RefUpdateUtil {
} }
if (lockFailure + aborted == bru.getCommands().size()) { if (lockFailure + aborted == bru.getCommands().size()) {
throw new LockFailureException("Update aborted with one or more lock failures: " + bru); throw new LockFailureException("Update aborted with one or more lock failures: " + bru, bru);
} else if (failure > 0) { } else if (failure > 0) {
throw new IOException("Update failed: " + bru); throw new IOException("Update failed: " + bru);
} }