From d3dfec4d0c8fe20c9603bec919cf7572cf190aad Mon Sep 17 00:00:00 2001 From: Andrea Aime Date: Fri, 17 Dec 2021 18:46:33 +0100 Subject: [PATCH] Have the tilesets collection portion work in background as well --- .../diskquota/LayerCacheInfoBuilder.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/LayerCacheInfoBuilder.java b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/LayerCacheInfoBuilder.java index dbc202a93..c0a7ba13e 100644 --- a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/LayerCacheInfoBuilder.java +++ b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/LayerCacheInfoBuilder.java @@ -53,7 +53,7 @@ final class LayerCacheInfoBuilder { private final ExecutorService threadPool; - private final Map>> perLayerRunningTasks; + private final Map>> perLayerRunningTasks; private final QuotaUpdatesMonitor quotaUsageMonitor; @@ -73,15 +73,8 @@ public LayerCacheInfoBuilder( * Asynchronously collects cache usage information for the given {@code tileLayer} into the * given {@code layerQuota} by using the provided {@link ExecutorService} at construction time. * - *

This method discards any {@link LayerQuota#getUsedQuota() used quota} information - * available for {@code layerQuota} and updates it by collecting the usage information for the - * layer. - * - *

In addition to collecting the cache usage information for the layer, the {@code - * layerQuota}'s {@link ExpirationPolicy expiration policy} will be given the opportunity to - * gather any additional information by calling the {@link - * ExpirationPolicy#createInfoFor(LayerQuota, String, long[], File) createInforFor(layerQuota, - * gridSetId, tileXYZ, file)} method for each available tile on the layer's cache. + *

This method discards any {@link LayerQuota#getQuota()} used quota} information available + * for {@code layerQuota} and updates it by collecting the usage information for the layer. * *

Note the cache information gathering is performed asynchronously and hence this method * returns immediately. To check whether the information collect for a given layer has finished @@ -100,6 +93,16 @@ public void buildCacheInfo(final TileLayer tileLayer) { perLayerRunningTasks.put(layerName, new ArrayList<>()); + // gathering the on disk tilesets can take a very long time, in case there are + // many parameters (e.g., long list of times), so moving this task also on background exec + Future tilesetCollector = + threadPool.submit(() -> gatherStatsByTileset(tileLayer, layerName, layerDir)); + // make sure the list has at this task too, so early calls to #isRunning find + // that something is executing, even if the stats collectors have not been created yet + perLayerRunningTasks.get(layerName).add(tilesetCollector); + } + + private void gatherStatsByTileset(TileLayer tileLayer, String layerName, File layerDir) { final Set onDiskTileSets = findOnDiskTileSets(tileLayer, layerDir); for (TileSet tileSet : onDiskTileSets) { @@ -314,15 +317,14 @@ private class TraversalCanceledException extends RuntimeException { */ public boolean isRunning(String layerName) { try { - List> layerTasks = perLayerRunningTasks.get(layerName); + List> layerTasks = perLayerRunningTasks.get(layerName); if (layerTasks == null) { return false; } int numRunning = 0; - Future future; - for (Iterator> it = layerTasks.iterator(); - it.hasNext(); ) { + Future future; + for (Iterator> it = layerTasks.iterator(); it.hasNext(); ) { future = it.next(); if (future.isDone()) { it.remove();