diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2019-10-10 17:00:04 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2019-10-10 17:00:04 +0200 |
commit | d301e736011dd8146a0675e7603ebbbd33ab5499 (patch) | |
tree | 10a797bcf0a7a97b1d3a56ae46094ec215c55a03 /node-admin/src/main | |
parent | 607c054896d7034175ee2958ebabbfe79038c5a3 (diff) |
Log deletion of files in FileFinder
Diffstat (limited to 'node-admin/src/main')
4 files changed, 37 insertions, 11 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java index 91f4924cefa..e9dd8a859cc 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java @@ -103,24 +103,24 @@ public class StorageMaintainer { FileFinder.files(path) .match(olderThan(Duration.ofDays(3)).and(nameMatches(Pattern.compile(".*\\.log.+")))) .maxDepth(1) - .deleteRecursively(); + .deleteRecursively(context); } FileFinder.files(context.pathOnHostFromPathInNode(context.pathInNodeUnderVespaHome("logs/vespa/qrs"))) .match(olderThan(Duration.ofDays(3))) - .deleteRecursively(); + .deleteRecursively(context); FileFinder.files(context.pathOnHostFromPathInNode(context.pathInNodeUnderVespaHome("logs/vespa/logarchive"))) .match(olderThan(Duration.ofDays(31))) - .deleteRecursively(); + .deleteRecursively(context); FileFinder.directories(context.pathOnHostFromPathInNode(context.pathInNodeUnderVespaHome("var/db/vespa/filedistribution"))) .match(olderThan(Duration.ofDays(31))) - .deleteRecursively(); + .deleteRecursively(context); FileFinder.directories(context.pathOnHostFromPathInNode(context.pathInNodeUnderVespaHome("var/db/vespa/download"))) .match(olderThan(Duration.ofDays(31))) - .deleteRecursively(); + .deleteRecursively(context); } /** Checks if container has any new coredumps, reports and archives them if so */ diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandler.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandler.java index 80a280b6a8f..3b2c635992e 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandler.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandler.java @@ -80,7 +80,7 @@ public class CoredumpHandler { FileFinder.files(containerCrashPathOnHost) .match(nameMatches(JAVA_CORE_PATTERN)) .maxDepth(1) - .deleteRecursively(); + .deleteRecursively(context); // Check if we have already started to process a core dump or we can enqueue a new core one getCoredumpToProcess(containerCrashPathOnHost, containerProcessingPathOnHost) diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/identity/AthenzCredentialsMaintainer.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/identity/AthenzCredentialsMaintainer.java index bd7732db1d6..59b4a671c55 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/identity/AthenzCredentialsMaintainer.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/identity/AthenzCredentialsMaintainer.java @@ -141,7 +141,7 @@ public class AthenzCredentialsMaintainer implements CredentialsMaintainer { public void clearCredentials(NodeAgentContext context) { FileFinder.files(context.pathOnHostFromPathInNode(CONTAINER_SIA_DIRECTORY)) - .deleteRecursively(); + .deleteRecursively(context); lastRefreshAttempt.remove(context.containerName()); } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java index b5c6b6ab91d..851289eccc4 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java @@ -1,6 +1,8 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.node.admin.task.util.file; +import com.yahoo.vespa.hosted.node.admin.component.TaskContext; + import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.FileVisitResult; @@ -11,13 +13,17 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.time.Duration; import java.time.Instant; +import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.Stack; import java.util.function.Consumer; import java.util.function.Predicate; +import java.util.logging.Logger; import java.util.regex.Pattern; +import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -27,6 +33,7 @@ import java.util.stream.Stream; * @author freva */ public class FileFinder { + private static final Logger logger = Logger.getLogger(FileFinder.class.getName()); private final Path basePath; private Predicate<FileAttributes> matcher; @@ -79,10 +86,29 @@ public class FileFinder { * * @return true iff anything was matched and deleted */ - public boolean deleteRecursively() { - boolean[] deletedAnything = { false }; // :( - forEach(attributes -> deletedAnything[0] |= attributes.unixPath().deleteRecursively()); - return deletedAnything[0]; + public boolean deleteRecursively(TaskContext context) { + List<UnixPath> pathsToDelete = new ArrayList<>(); + forEach(attributes -> { + if (Files.exists(attributes.path())) { + pathsToDelete.add(attributes.unixPath()); + } + }); + + if (pathsToDelete.isEmpty()) return false; + + if (pathsToDelete.size() < 20) { + List<Path> paths = pathsToDelete.stream() + .map(x -> basePath.relativize(x.toPath())) + .sorted() + .collect(Collectors.toList()); + context.log(logger, "Deleting these files in " + basePath + ": " + paths); + } else { + context.log(logger, "Deleting " + pathsToDelete.size() + " paths under " + basePath); + } + + pathsToDelete.sort(Comparator.comparing(UnixPath::toPath)); + pathsToDelete.forEach(UnixPath::deleteRecursively); + return true; } public List<FileAttributes> list() { |