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
);
        }
        if (indices.size() == (backingIndexPosition + 1)) {
            throw new IllegalArgumentException(
                String.format(
                    Locale.ROOT,
                    "cannot remove backing index [%s] of data stream [%s] because it is the write index",
                    index.getName(),
                    name
                )
            );
        }
        List<Index> backingIndices = new ArrayList<>(indices);
        backingIndices.remove(index);
        assert backingIndices.size() == indices.size() - 1;
        return new DataStream(name, backingIndices, generation + 1, metadata, hidden, replicated, system, allowCustomRouting, indexMode);
    }
    /**
     * Replaces the specified backing index with a new index and returns a new {@code DataStream} instance with
     * the modified backing indices. An {@code IllegalArgumentException} is thrown if the index to be replaced
     * is not a backing index for this data stream or if it is the {@code DataStream}'s write index.
     *
     * @param existingBackingIndex the backing index to be replaced
     * @param newBackingIndex      the new index that will be part of the {@code DataStream}
     * @return new {@code DataStream} instance with backing indices that contain replacement index instead of the specified
     * existing index.
     */
    public DataStream replaceBackingIndex(Index existingBackingIndex, Index newBackingIndex) {
        List<Index> backingIndices = new ArrayList<>(indices);
        int backingIndexPosition = backingIndices.indexOf(existingBackingIndex);