diff options
author | David Pursehouse <dpursehouse@digital.ai> | 2020-05-19 10:20:22 +0900 |
---|---|---|
committer | David Pursehouse <dpursehouse@digital.ai> | 2020-05-19 10:20:22 +0900 |
commit | 88eeb9aa1f15fcf0d891a901990efd5574fa8cf3 (patch) | |
tree | 34c6625a2e924a90baa7a82b847b30773541e328 | |
parent | 3ca941e6bc700c6f40ac45c8f3188c4c48bc8620 (diff) | |
parent | 4452ef7bb9cbcac329dc062ab95186a84411c30f (diff) |
Merge branch 'stable-3.1'v3.2.0-rc4
* stable-3.1:
Prevent persistent task listing interruptions on IOExceptions
Change-Id: Iaa7a6e354b629fac9afdb8bf18074a4662b61541
-rw-r--r-- | src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java | 21 |
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 b805c72..49cb059 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java @@ -28,6 +28,7 @@ import java.nio.file.DirectoryIteratorException; import java.nio.file.DirectoryStream; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; +import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; @@ -222,13 +223,21 @@ public class ReplicationTasksStorage { private List<ReplicateRefUpdate> list(Path tasks) { List<ReplicateRefUpdate> results = new ArrayList<>(); try (DirectoryStream<Path> events = Files.newDirectoryStream(tasks)) { - for (Path e : events) { - if (Files.isRegularFile(e)) { - String json = new String(Files.readAllBytes(e), UTF_8); - results.add(GSON.fromJson(json, ReplicateRefUpdate.class)); - } else if (Files.isDirectory(e)) { + for (Path path : events) { + if (Files.isRegularFile(path)) { try { - results.addAll(list(e)); + 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); + } + } else if (Files.isDirectory(path)) { + try { + results.addAll(list(path)); } catch (DirectoryIteratorException d) { // iterating over the sub-directories is expected to have dirs disappear Nfs.throwIfNotStaleFileHandle(d.getCause()); |