`IndexMetadataUpdater.applyChanges` asserts the indices lookup for the old and new metadata is the same instance. Somehow this assertion does not always hold.

**Build scan:**
https://gradle-enterprise.elastic.co/s/kbk2xlunkwkfu/tests/:server:internalClusterTest/org.elasticsearch.aliases.IndexAliasesIT/testGetAllAliasesWorks

**Reproduction line:**
`./gradlew ':server:internalClusterTest' --tests "org.elasticsearch.aliases.IndexAliasesIT.testGetAllAliasesWorks" -Dtests.seed=2C9E27B978B87A4E -Dtests.locale=ja-JP -Dtests.timezone=America/Cancun -Druntime.java=17`

**Applicable branches:**
master

**Reproduces locally?:**
No

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.aliases.IndexAliasesIT&tests.test=testGetAllAliasesWorks

**Failure excerpt:**
```
com.carrotsearch.randomizedtesting.UncaughtExceptionError: Captured an uncaught exception in thread: Thread[id=783, name=elasticsearch[node_s0][masterService#updateTask][T#1], state=RUNNABLE, group=TGRP-IndexAliasesIT]

  at __randomizedtesting.SeedInfo.seed([2C9E27B978B87A4E:7B9FD0D51559F652]:0)

  Caused by: java.lang.AssertionError: (No message provided)

    at __randomizedtesting.SeedInfo.seed([2C9E27B978B87A4E]:0)
    at org.elasticsearch.cluster.routing.allocation.IndexMetadataUpdater.applyChanges(IndexMetadataUpdater.java:134)
    at org.elasticsearch.cluster.routing.allocation.RoutingAllocation.updateMetadataWithRoutingChanges(RoutingAllocation.java:274)
    at org.elasticsearch.cluster.routing.allocation.AllocationService.buildResultAndLogHealthChange(AllocationService.java:150)
    at org.elasticsearch.cluster.routing.allocation.AllocationService.applyStartedShards(AllocationService.java:143)
    at org.elasticsearch.cluster.action.shard.ShardStateAction$ShardStartedClusterStateTaskExecutor.execute(ShardStateAction.java:734)
    at org.elasticsearch.cluster.service.MasterService.innerExecuteTasks(MasterService.java:901)
    at org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:871)
    at org.elasticsearch.cluster.service.MasterService.runTasks(MasterService.java:253)
    at org.elasticsearch.cluster.service.MasterService$Batcher.run(MasterService.java:153)
    at org.elasticsearch.cluster.service.TaskBatcher.runIfNotProcessed(TaskBatcher.java:114)
    at org.elasticsearch.cluster.service.TaskBatcher$BatchedTask.run(TaskBatcher.java:170)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:714)
    at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:260)
    at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:223)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.lang.Thread.run(Thread.java:833)

```
server/src/main/java/org/elasticsearch/cluster/routing/allocation/IndexMetadataUpdater.java
Metadata newMetadata = metadataBuilder.build();
            assert oldMetadata.sameIndicesLookup(newMetadata);
            return newMetadata;
        } else {
            return oldMetadata;
        }
    }
    /**
     * Updates in-sync allocations with routing changes that were made to the routing table.
     */
    private static IndexMetadata.Builder updateInSyncAllocations(
        RoutingTable newRoutingTable,
        IndexMetadata oldIndexMetadata,
        IndexMetadata.Builder indexMetadataBuilder,
        ShardId shardId,
        Updates updates
    ) {
        assert Sets.haveEmptyIntersection(updates.addedAllocationIds, updates.removedAllocationIds)
            : "allocation ids cannot be both added and removed in the same allocation round, added ids: "
                + updates.addedAllocationIds
                + ", removed ids: "
                + updates.removedAllocationIds;
        Set<String> oldInSyncAllocationIds = oldIndexMetadata.inSyncAllocationIds(shardId.id());
        
        if (updates.initializedPrimary != null
            && oldInSyncAllocationIds.isEmpty() == false
            && oldInSyncAllocationIds.contains(updates.initializedPrimary.allocationId().getId()) == false) {
            
            
            RecoverySource recoverySource = updates.initializedPrimary.recoverySource();