`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
}
    /**
     * Helper method that creates update entry for the given shard id if such an entry does not exist yet.
     */
    private Updates changes(ShardId shardId) {
        return shardChanges.computeIfAbsent(shardId, k -> new Updates());
    }
    /**
     * Remove allocation id of this shard from the set of in-sync shard copies
     */
    void removeAllocationId(ShardRouting shardRouting) {
        if (shardRouting.active()) {
            changes(shardRouting.shardId()).removedAllocationIds.add(shardRouting.allocationId().getId());
        }
    }
    /**
     * Increase primary term for this shard id
     */
    private void increasePrimaryTerm(ShardId shardId) {
        changes(shardId).increaseTerm = true;
    }
    private static class Updates {
        private boolean increaseTerm; 
        private Set<String> addedAllocationIds = new HashSet<>(); 
        private Set<String> removedAllocationIds = new HashSet<>(); 
        private ShardRouting initializedPrimary = null; 
        private ShardRouting firstFailedPrimary = null; 
    }
}