|
15 | 15 |
|
16 | 16 | import static com.google.common.base.Preconditions.checkNotNull; |
17 | 17 | import static java.util.Objects.isNull; |
| 18 | +import static org.geowebcache.azure.DeleteManager.PAGE_SIZE; |
18 | 19 |
|
19 | 20 | import com.azure.core.util.BinaryData; |
20 | 21 | import com.azure.storage.blob.models.BlobDownloadContentResponse; |
21 | 22 | import com.azure.storage.blob.models.BlobItem; |
22 | 23 | import com.azure.storage.blob.models.BlobProperties; |
23 | 24 | import com.azure.storage.blob.models.BlobStorageException; |
24 | 25 | import com.azure.storage.blob.specialized.BlockBlobClient; |
25 | | -import com.google.common.collect.Iterators; |
26 | 26 | import java.io.IOException; |
27 | 27 | import java.io.InputStream; |
28 | 28 | import java.io.UncheckedIOException; |
29 | 29 | import java.time.OffsetDateTime; |
| 30 | +import java.util.ArrayList; |
30 | 31 | import java.util.Iterator; |
31 | 32 | import java.util.List; |
32 | 33 | import java.util.Map; |
@@ -198,26 +199,18 @@ public boolean delete(TileRange tileRange) throws StorageException { |
198 | 199 | if (listeners.isEmpty()) { |
199 | 200 | // if there are no listeners, don't bother requesting every tile |
200 | 201 | // metadata to notify the listeners |
201 | | - List<String> keysToDelete = blobsToDelete.map(BlobItem::getName).collect(Collectors.toList()); |
202 | | - |
203 | | - // split the iteration in parts to avoid memory accumulation |
204 | | - Iterator<List<String>> partition = Iterators.partition(keysToDelete.iterator(), DeleteManager.PAGE_SIZE); |
205 | | - |
206 | | - while (partition.hasNext() && !shutDown) { |
207 | | - deleteManager.deleteParallel(partition.next()); |
| 202 | + if (!shutDown) { |
| 203 | + deleteManager.deleteStreamed(blobsToDelete); |
208 | 204 | } |
209 | | - |
210 | 205 | } else { |
211 | 206 | // if we need to gather info, we'll end up just calling "delete" on each tile |
212 | 207 | // this is run here instead of inside the delete manager as we need high level info |
213 | 208 | // about tiles, e.g., TileObject, to inform the listeners |
214 | | - List<Callable<?>> tilesDeletions = blobsToDelete |
215 | | - .map(blobItem -> { |
216 | | - TileObject tile = createTileObject(blobItem, tileRange); |
217 | | - tile.setParametersId(tileRange.getParametersId()); |
218 | | - return (Callable<Object>) () -> delete(tile); |
219 | | - }) |
220 | | - .collect(Collectors.toList()); |
| 209 | + Stream<Callable<?>> tilesDeletions = blobsToDelete.map(blobItem -> { |
| 210 | + TileObject tile = createTileObject(blobItem, tileRange); |
| 211 | + tile.setParametersId(tileRange.getParametersId()); |
| 212 | + return () -> delete(tile); |
| 213 | + }); |
221 | 214 |
|
222 | 215 | executeParallelDeletions(tilesDeletions); |
223 | 216 | } |
@@ -278,13 +271,18 @@ private long[] extractTileIndex(BlobItem blobItem) { |
278 | 271 | }; |
279 | 272 | } |
280 | 273 |
|
281 | | - private void executeParallelDeletions(List<Callable<?>> tilesDeletions) throws StorageException { |
282 | | - Iterator<List<Callable<?>>> tilesDeletionsPartitions = |
283 | | - Iterators.partition(tilesDeletions.iterator(), DeleteManager.PAGE_SIZE); |
| 274 | + private void executeParallelDeletions(Stream<Callable<?>> tilesDeletions) throws StorageException { |
| 275 | + Iterator<Callable<?>> tilesDeletionsIterator = tilesDeletions.iterator(); |
| 276 | + |
| 277 | + while (tilesDeletionsIterator.hasNext() && !shutDown) { |
| 278 | + |
| 279 | + // once a page of callables is ready, run them in parallel on the delete manager |
| 280 | + List<Callable<?>> callables = new ArrayList<>(PAGE_SIZE); |
| 281 | + for (int i = 0; i < PAGE_SIZE && tilesDeletionsIterator.hasNext(); i++) { |
| 282 | + callables.add(tilesDeletionsIterator.next()); |
| 283 | + } |
284 | 284 |
|
285 | | - // once a page of callables is ready, run them in parallel on the delete manager |
286 | | - while (tilesDeletionsPartitions.hasNext() && !shutDown) { |
287 | | - deleteManager.executeParallel(tilesDeletionsPartitions.next()); |
| 285 | + deleteManager.executeParallel(callables); |
288 | 286 | } |
289 | 287 | } |
290 | 288 |
|
|
0 commit comments