@Override
    protected double maintain() {
        Map<HostName, List<Snapshot>> snapshotsByHostname = nodeRepository().snapshots().read().stream()
                                                                            .collect(Collectors.groupingBy(Snapshot::hostname));
        NodeList nodes = nodeRepository().nodes().list().nodeType(NodeType.tenant);
        Instant now = nodeRepository().clock().instant();
        snapshotsByHostname.forEach((hostname, snapshots) -> {
            if (!shouldRemoveAny(snapshots, nodes, now)) return;
            try (var lock = nodeRepository().snapshots().lock(hostname.value())) {
                // Re-read and check while holding lock
                snapshots = nodeRepository().snapshots().read(hostname.value());
                for (var snapshot : snapshots) {
                    if (shouldRemove(snapshot, nodes, now)) {
                        try {
                            remove(snapshot, hostname);
                        } catch (Exception e) {
                            LOG.warning("Failed to remove snapshot " + snapshot.id() + " of " + hostname + ": " +
                                        Exceptions.toMessageString(e) +
                                        ". Will retry in " + interval());
                        }
                    }
                }
            }
        });
        return 0;
    }
Remove stale node {@link Snapshot}s.

@author mpolden
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/SnapshotExpirer.java