Package org.elasticsearch.cluster.routing


package org.elasticsearch.cluster.routing

The cluster routing package provides routing information and manages shard allocations in a cluster. The routing part contains two different views of shards in RoutingTable and RoutingNodes. RoutingTable provides a view from index to shard to node. RoutingNodes provides view from node to shard. Shard allocation is a process of assigning and moving shards between nodes. For more details about allocation see org.elasticsearch.cluster.routing.allocation.

Routing Table

The routing table provide a view of global cluster state from an index perspective. It's a mapping from indices to shards and shards to nodes, where the relationship between shard and node may not exist if a shard allocation is not possible.

RoutingTable is the access point to the routing information. RoutingTable is a part of the ClusterState. It maps index names to IndexRoutingTable. IndexRoutingTable, in turn, holds a list of shards in that index, IndexShardRoutingTable. Each shard has one or more instances: a primary and replicas. An IndexShardRoutingTable contains information about all shard instances for a specific shard, ShardRouting. The ShardRouting is the state of a shard instance in a cluster. There are several states of ShardRouting: unassigned, initializing, relocating, started.

An example of routing table:
 
 └── ClusterState
     └── RoutingTable
         ├── index1-IndexRoutingTable
         │   ├── shard1-IndexShardRoutingTable
         │   │   ├── primary-ShardRouting
         │   │   │   └── STARTED-node1
         │   │   ├── replica1-ShardRouting
         │   │   │   └── INITIALIZING-node2
         │   │   └── replica2-ShardRouting
         │   │       └── UNASSIGNED
         │   └── shard2-IndexShardRoutingTable ...
         └── index2-IndexRoutingTable ...
 
 
Routing Nodes

RoutingNode provides a view from node to shard routing. There is a RoutingNode for every DiscoveryNode. It contains information about all shards and their state on this node. RoutingNodes (plural) provide aggregated view from all cluster nodes. It supports finding all shards by specific node or finding all nodes for specific shard.

Reroute

Reroute is a process of routing update in the cluster. Routing update may start allocation process, which assign or move shards around. When cluster has an update that impacts routing (for example: node join cluster, index created, snapshot restored, ...) the code that handles cluster update should trigger reroute. There are 2 ways to trigger reroute - batched with BatchedRerouteService and unbatched AllocationService. Batched reroute can combine multiple requests into one (used when starting initializing shards). Unbatched reroute allows to mix other cluster state changes that might be required to create or delete index.