During the development and review process of the disk health indicator we noticed that it was hard to understand. Since we learnt a lot from the first round of development we want to go through the code one more time and restructure it.
server/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java
shardsByIndex.computeIfAbsent(shard.index(), k -> new HashSet<>()).add(shard);
        assert validate == false || invariant();
    }
    void update(ShardRouting oldShard, ShardRouting newShard) {
        if (shards.containsKey(oldShard.shardId()) == false) {
            
            
            return;
        }
        ShardRouting previousValue = shards.put(newShard.shardId(), newShard);
        assert previousValue == oldShard : "expected shard " + previousValue + " but was " + oldShard;
        if (oldShard.initializing()) {
            boolean exist = initializingShards.remove(oldShard);
            assert exist : "expected shard " + oldShard + " to exist in initializingShards";
        } else if (oldShard.relocating()) {
            boolean exist = relocatingShards.remove(oldShard);
            assert exist : "expected shard " + oldShard + " to exist in relocatingShards";
        } else if (oldShard.started()) {
            boolean exist = startedShards.remove(oldShard);
            assert exist : "expected shard " + oldShard + " to exist in startedShards";
        }
        final Set<ShardRouting> byIndex = shardsByIndex.get(oldShard.index());
        byIndex.remove(oldShard);
        byIndex.add(newShard);
        if (newShard.initializing()) {
            initializingShards.add(newShard);
        } else if (newShard.relocating()) {
            relocatingShards.add(newShard);
        } else if (newShard.started()) {
            startedShards.add(newShard);