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
.
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.
└── 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 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.
-
ClassDescriptionUniquely identifies an allocation.A
BatchedRerouteService
is aRerouteService
that batches together reroute requests to avoid unnecessary extra reroutes.TheDelayedAllocationService
listens to cluster state changes and checks if there are unassigned shards with delayed allocation (unassigned shards that have the delay marker).This class implements a compilation ofShardIterator
s.This exception defines illegal states of shard routingGenerates the shard id for(id, routing)
pairs.TheIndexRoutingTable
represents routing information for a single index.IndexShardRoutingTable
encapsulates all instances of a single shard.Hash function based on the Murmur3 algorithm, which is the default as of Elasticsearch 2.0.A simpleShardsIterator
that iterates a list or sub-list ofshard indexRoutings
.Routing Preference TypeRepresents the recovery source of a shard.Recovery from a fresh copyRecovery from an existing on-disk storerecovery from other shards on same node (shrink index action)peer recovery from a primary shardrecovery from a snapshotHolds additional information as to why the shard failed to relocate.Asynchronously performs a cluster reroute, updating any shard states and rebalancing the cluster if appropriate.BasicShardShuffler
implementation that uses anAtomicInteger
to generate seeds and uses a rotation to permute shards.Records changes made toRoutingNodes
during an allocation round.A baseException
s for all exceptions thrown by routing related operations.ARoutingNode
represents a cluster node associated with a singleDiscoveryNode
including all shards that are hosted on that nodes.RoutingNodes
represents a copy the routing information contained in thecluster state
.Represents a global cluster-wide routing table for all indices including the version of the current routing state.Builder for the routing table.Allows to iterate over a set of shard instances (routing) within a shard id group.ShardRouting
immutably encapsulates information about shard indexRoutings like id, state, version, etc.Represents the current state of aShardRouting
as defined by the cluster.A shuffler for shards whose primary goal is to balance load.Allows to iterate over unrelated shards.Holds additional information as to why the shard is in an unassigned state.Captures the status of an unsuccessful allocation attempt for the shard, causing it to remain in the unassigned state.Reason why the shard is in unassigned state.