private void closeWriter(final IndexShardWriter indexShardWriter) {
        final long indexShardId = indexShardWriter.getIndexShardId();
        securityContext.asProcessingUser(() -> {
            try {
                try {
                    LOGGER.debug(() ->
                            "Closing " + indexShardId);
                    LOGGER.trace(() ->
                            "Closing " + indexShardId);

                    // Set the status of the shard to closing so it won't be used again immediately when removed
                    // from the map.
                    indexShardDao.setStatus(indexShardId, IndexShardStatus.CLOSING);

                    // Close the shard.
                    indexShardWriter.close();

                } finally {
                    // Update the shard status.
                    indexShardDao.reset(indexShardId);
                }
            } catch (final RuntimeException e) {
                LOGGER.error(e::getMessage, e);
            }
        });
    }
@param indexShardId The id of the index shard.
@return A writer for the index shard.
stroom-index/stroom-index-impl/src/main/java/stroom/index/impl/IndexShardWriterCacheImpl.java