summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <dpursehouse@digital.ai>2020-05-18 20:59:03 +0900
committerDavid Pursehouse <dpursehouse@digital.ai>2020-05-18 20:59:03 +0900
commit9392d3ba60dfb2d5535ab8080a5d62c2f7994ef5 (patch)
tree285c27b5d40479a45422762b432b63793e1917a3
parent3639b7ba67e41351f83441e423e486edafce4f2a (diff)
parent8738fded0d6e0240e748b950a4a9b84ac8595896 (diff)
Merge branch 'stable-2.16' into stable-3.0
* stable-2.16: Prevent persistent task listing interruptions on IOExceptions Change-Id: Ib8bd758a3dd9c24968ec58be921c4475a7bde030
-rw-r--r--src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
index 39158f3..19becdf 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
@@ -26,6 +26,7 @@ import com.google.inject.Singleton;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@@ -108,18 +109,26 @@ public class ReplicationTasksStorage {
}
public List<ReplicateRefUpdate> list() {
- ArrayList<ReplicateRefUpdate> result = new ArrayList<>();
+ List<ReplicateRefUpdate> results = new ArrayList<>();
try (DirectoryStream<Path> events = Files.newDirectoryStream(refUpdates())) {
- for (Path e : events) {
- if (Files.isRegularFile(e)) {
- String json = new String(Files.readAllBytes(e), UTF_8);
- result.add(GSON.fromJson(json, ReplicateRefUpdate.class));
+ for (Path path : events) {
+ if (Files.isRegularFile(path)) {
+ try {
+ String json = new String(Files.readAllBytes(path), UTF_8);
+ results.add(GSON.fromJson(json, ReplicateRefUpdate.class));
+ } catch (NoSuchFileException ex) {
+ logger.atFine().log(
+ "File %s not found while listing waiting tasks (likely in-flight or completed by another node)",
+ path);
+ } catch (IOException e) {
+ logger.atSevere().withCause(e).log("Error when firing pending event %s", path);
+ }
}
}
} catch (IOException e) {
logger.atSevere().withCause(e).log("Error when firing pending events");
}
- return result;
+ return results;
}
@SuppressWarnings("deprecation")