Skip to content

[BUG] Shard routings for closed index are allocated again without opening the index #20200

@SwethaGuptha

Description

@SwethaGuptha

Describe the bug

When an index is closed, all the shardRoutings for the index are set to unassigned state by MetadataIndexStateService.closeRoutingTable. Then, a reroute workflow is initiated on the new built cluster state and the AllocationService starts these shards again without the index being open. The shard routing being unnecessarily unassigned and started again.

Routing table for closed index:

{
  "metadata": {
    "indices": {
      "test-index": {
        "state": "close"
      }
    }
  },
  "routing_table": {
    "indices": {
      "test-index": {
        "shards": {
          "0": [
            {
              "state": "STARTED",
              "primary": true,
              "searchOnly": false,
              "node": "CraQfQgmT3yhxEw4oox1Cw",
              "relocating_node": null,
              "shard": 0,
              "index": "test-index",
              "allocation_id": {
                "id": "dN7WYwTbQ_qbAOaRye1scQ"
              }
            },
            {
              "state": "UNASSIGNED",
              "primary": false,
              "searchOnly": false,
              "node": null,
              "relocating_node": null,
              "shard": 0,
              "index": "test-index",
              "recovery_source": {
                "type": "PEER"
              },
              "unassigned_info": {
                "reason": "INDEX_CLOSED",
                "at": "2025-12-09T11:20:04.874Z",
                "delayed": false,
                "allocation_status": "no_attempt"
              }
            }
          ]
        }
      }
    }
  }
}

Logs:

[2025-12-09T16:50:04,874][INFO ][o.o.c.m.MetadataIndexStateService] [runTask-0] Routing table after close index {test-index=IndexRoutingTable{shards={0=IndexShardRoutingTable([test-index][0]){[test-index][0], node[null], [P], recovery_source[existing store recovery; bootstrap_history_uuid=false], s[UNASSIGNED], unassigned_info[[reason=INDEX_CLOSED], at[2025-12-09T11:20:04.874Z], delayed=false, allocation_status[no_attempt]], [test-index][0], node[null], [R], recovery_source[peer recovery], s[UNASSIGNED], unassigned_info[[reason=INDEX_CLOSED], at[2025-12-09T11:20:04.874Z], delayed=false, allocation_status[no_attempt]]}}, index=[test-index/AqyYtd2RSRWMLdO6h4otZQ]}}
[2025-12-09T16:50:04,875][INFO ][o.o.c.r.a.AllocationService] [runTask-0] Unassigned shards size 2
[2025-12-09T16:50:04,875][WARN ][o.o.c.r.a.AllocationService] [runTask-0] Falling back to single shard assignment since batch mode disable or multiple custom allocators set
[2025-12-09T16:50:04,879][INFO ][o.o.g.G.InternalPrimaryShardAllocator] [runTask-0] Allocation decision for shard routing [test-index][0], node[null], [P], recovery_source[existing store recovery; bootstrap_history_uuid=false], s[UNASSIGNED], unassigned_info[[reason=INDEX_CLOSED], at[2025-12-09T11:20:04.874Z], delayed=false, allocation_status[no_attempt]] ; awaiting_info
[2025-12-09T16:50:04,880][INFO ][o.o.g.G.InternalReplicaShardAllocator] [runTask-0] Allocation decision for shard routing [test-index][0], node[null], [R], recovery_source[peer recovery], s[UNASSIGNED], unassigned_info[[reason=INDEX_CLOSED], at[2025-12-09T11:20:04.874Z], delayed=false, allocation_status[no_attempt]] ; no
[2025-12-09T16:50:04,981][INFO ][o.o.c.r.a.AllocationService] [runTask-0] Unassigned shards size 2
[2025-12-09T16:50:04,981][WARN ][o.o.c.r.a.AllocationService] [runTask-0] Falling back to single shard assignment since batch mode disable or multiple custom allocators set
[2025-12-09T16:50:04,983][INFO ][o.o.g.G.InternalPrimaryShardAllocator] [runTask-0] Allocation decision for shard routing [test-index][0], node[null], [P], recovery_source[existing store recovery; bootstrap_history_uuid=false], s[UNASSIGNED], unassigned_info[[reason=INDEX_CLOSED], at[2025-12-09T11:20:04.874Z], delayed=false, allocation_status[fetching_shard_data]] ; yes
[2025-12-09T16:50:04,983][INFO ][o.o.g.G.InternalReplicaShardAllocator] [runTask-0] Allocation decision for shard routing [test-index][0], node[null], [R], recovery_source[peer recovery], s[UNASSIGNED], unassigned_info[[reason=INDEX_CLOSED], at[2025-12-09T11:20:04.874Z], delayed=false, allocation_status[no_attempt]] ; no
[2025-12-09T16:50:05,050][INFO ][o.o.i.MergeSchedulerConfig] [runTask-0] Updating autoThrottle for index test-index from [false] to [true]
[2025-12-09T16:50:05,050][INFO ][o.o.i.MergeSchedulerConfig] [runTask-0] Updating maxThreadCount from [0] to [4] and maxMergeCount from [0] to [9] for index test-index.
[2025-12-09T16:50:05,050][INFO ][o.o.i.MergeSchedulerConfig] [runTask-0] Initialized index test-index with maxMergeCount=9, maxThreadCount=4, autoThrottleEnabled=true
[2025-12-09T16:50:05,055][INFO ][o.o.p.PluginsService     ] [runTask-0] PluginService:onIndexModule index:[test-index/AqyYtd2RSRWMLdO6h4otZQ]
[2025-12-09T16:50:05,056][INFO ][o.o.i.MergeSchedulerConfig] [runTask-0] Updating autoThrottle for index test-index from [true] to [true]
[2025-12-09T16:50:05,102][INFO ][o.o.c.r.a.AllocationService] [runTask-0] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[test-index][0]]]).
[2025-12-09T16:50:05,189][INFO ][o.o.c.r.a.AllocationService] [runTask-0] Unassigned shards size 1

Related component

Cluster Manager

To Reproduce

Close an index - All shards will be in started stated

Expected behavior

Define shard routing behavior for closed index.
The reroute flow should handle skipping unassigned shard routing due to UnassignedInfo.Reason.INDEX_CLOSED or don't mark the shards as unassigned.

Additional Details

Plugins
Please list all plugins currently enabled.

Screenshots
If applicable, add screenshots to help explain your problem.

Host/Environment (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Labels

Type

No type

Projects

Status

🆕 New

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions