private void deleteShardsFromDisk(final IndexShardWriterCache indexShardWriterCache,
                                      final ResultPage<IndexShard> shards) {
        final Runnable runnable = taskContextFactory.context(
                "Delete Logically Deleted Shards",
                TerminateHandlerFactory.NOOP_FACTORY,
                taskContext -> {
                    try {
                        taskContext.info(() -> LogUtil.message("Deleting {} Logically Deleted Shard{}...",
                                shards.size(), StringUtil.pluralSuffix(shards.size())));

                        LOGGER.logDurationIfDebugEnabled(() -> {
                            final Iterator<IndexShard> iter = shards.getValues().iterator();
                            while (!Thread.currentThread().isInterrupted() && iter.hasNext()) {
                                final IndexShard shard = iter.next();
                                final Optional<IndexShardWriter> optional =
                                        indexShardWriterCache.getIfPresent(shard.getId());
                                try {
                                    if (optional.isPresent()) {
                                        LOGGER.debug(() ->
                                                "deleteShardsFromDisk() - Unable to delete index " +
                                                "shard " + shard.getId() + " as it is currently " +
                                                "in use");
                                    } else {
                                        deleteFromDisk(shard);
                                    }
                                } catch (final RuntimeException e) {
                                    LOGGER.error(e::getMessage, e);
                                }
                            }
                        }, "deleteShardsFromDisk()");
                    } finally {
                        deletingShards.set(false);
                    }
                });

        // In tests we don't have a task manager.
        NullSafe.consumeOr(
                executor,
                ex -> ex.execute(runnable),
                runnable);
    }
Delete anything that has been marked to delete
stroom-index/stroom-index-impl/src/main/java/stroom/index/impl/IndexShardManager.java