A transport put follow-action can be triggered for an index that is part of a data stream and already exists.
Normally this is not an issue because the restore operation will just fail because the index already exists.
If however, the index is currently closed (for example due to ILM doing a force-merge with codec change step on the index),
this causes the currently closed index to be restored into. As a result we run into a bug in the following code in

`org.elasticsearch.xpack.ccr.action.TransportPutFollowAction#createFollowerIndex`:

```java
BiConsumer<ClusterState, Metadata.Builder> updater = (currentState, mdBuilder) -> {
   DataStream localDataStream = currentState.getMetadata().dataStreams().get(remoteDataStream.getName());
   Index followerIndex = mdBuilder.get(followerIndexName).getIndex();
   assert followerIndex != null;

   DataStream updatedDataStream = updateLocalDataStream(followerIndex, localDataStream, remoteDataStream);
      mdBuilder.put(updatedDataStream);
   };
   restoreService.restoreSnapshot(restoreRequest, delegatelistener, updater);
 }
```

This code updates the local data stream when following an index without checking if that index already is part of the data stream, thus now creating two entries for the same `Index` in the data stream's indices list. Code like `org.elasticsearch.cluster.metadata.DataStream#removeBackingIndex` however assumes no duplicates and will when deleting an index, only remove it from the data stream once. Thus leaving a dangling `Index` instance that does not point to any existing index any more, corrupting the cluster state.


cc @martijnvg thanks for the help with reasoning this out
server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java
/**
     * Like {@link #nextWriteIndexAndGeneration(Metadata)}, but does no validation, use with care only.
     */
    public Tuple<String, Long> unsafeNextWriteIndexAndGeneration(Metadata clusterMetadata) {
        String newWriteIndexName;
        long generation = this.generation;
        long currentTimeMillis = timeProvider.getAsLong();
        do {
            newWriteIndexName = DataStream.getDefaultBackingIndexName(getName(), ++generation, currentTimeMillis);
        } while (clusterMetadata.hasIndexAbstraction(newWriteIndexName));
        return Tuple.tuple(newWriteIndexName, generation);
    }
    private void ensureNotReplicated() {
        if (replicated) {
            throw new IllegalArgumentException("data stream [" + name + "] cannot be rolled over, because it is a replicated data stream");
        }
    }
    /**
     * Removes the specified backing index and returns a new {@code DataStream} instance with
     * the remaining backing indices.
     *
     * @param index the backing index to remove
     * @return new {@code DataStream} instance with the remaining backing indices
     * @throws IllegalArgumentException if {@code index} is not a backing index or is the current write index of the data stream
     */
    public DataStream removeBackingIndex(Index index) {
        int backingIndexPosition = indices.indexOf(index);
        if (backingIndexPosition == -1) {
            throw new IllegalArgumentException(
                String.format(Locale.ROOT, "index [%s] is not part of data stream [%s]", index.getName(), name)