Skip to content

Add to allocation architecture guide #125328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

DiannaHohensee
Copy link
Contributor

@DiannaHohensee DiannaHohensee commented Mar 20, 2025

Adds discussion of index shards and their states, as well as
the communication flow between the master node and data
nodes for shard allocation changes.

Relates ES-7874

The first section is an attempt to move some of the allocation brain dump google document into the architecture guide.

@DiannaHohensee DiannaHohensee added >non-issue :Distributed Coordination/Allocation All issues relating to the decision making around placing a shard (both master logic & on the nodes) Team:Distributed Coordination Meta label for Distributed Coordination team labels Mar 20, 2025
@DiannaHohensee DiannaHohensee self-assigned this Mar 20, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

@DiannaHohensee
Copy link
Contributor Author

CC @JeremyDahlgren just fyi.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Info is all good but I think would be better placed in Javadocs, either duplicated here or else with pointers from here to the Javadocs.

### Indexes and Shards

Each index consists of a fixed number of primary shards. The number of primary shards cannot be changed for the lifetime of the index. Each
primary shard can have zero-to-many replicas used for data redundancy. The number of replicas per shard can be changed in runtime. Each
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
primary shard can have zero-to-many replicas used for data redundancy. The number of replicas per shard can be changed in runtime. Each
primary shard can have zero-to-many replicas used for data redundancy. The number of replicas per shard can be changed dynamically. Each

(or maybe "at runtime")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied dynamically 👍


Each index consists of a fixed number of primary shards. The number of primary shards cannot be changed for the lifetime of the index. Each
primary shard can have zero-to-many replicas used for data redundancy. The number of replicas per shard can be changed in runtime. Each
shard copy (primary or replica) can be in one of four states:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth mentioning here that these states are org.elasticsearch.cluster.routing.ShardRoutingState the ones in the routing table (i.e. within the ClusterState) and the transitions between these states are part of the dance between data node and master node to reflect the lifecycle of a shard:

UNASSIGNED -> INITIALIZING happens when the master wants the data node to start creating this shard copy.
INITIALIZING -> STARTED happens when recovery is fully complete and the data node tells the master it's ready to serve requests.
STARTED -> RELOCATING happens when the master wants to initialize the node elsewhere.

A failure can take a shard in any state back to UNASSIGNED. Or the shard entry can be removed entirely from the cluster state. In either case, that tells the data node to stop whatever it is doing and shut down the shard.

Also IMO it'd be more discoverable to expand the Javadocs for ShardRoutingState with all this detail rather than hiding it away here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. I was trying to shove Ievgen's brain dump info into here, but I wasn't that familiar with the relevant code. I agree, this information is too low-level. I pushed it down into ShardRoutingState in a separate PR because I want to add a reference to the new documentation in this PR.

I wasn't too sure where to push the state transitions. I guess we can prescribe how to transition states in the ShardRoutingState, too, but it's a little strange to describe how the class is used by other classes when ShardRoutingState doesn't enforce those transitions itself. Oh well 🤷‍♀️

updated `RoutingTable`. The `RoutingTable` is part of the cluster state, so the master node updates the cluster state with the new
(incremental) desired shard allocation information. The updated cluster state is then published to the data nodes. Each data node will
observe any change in shard allocation related to that node and take action to achieve the new shard allocation by initiating creation of a
new empty shard, starting recovery (copying) of an existing shard from another data node, or remove a shard. When the data node finishes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar nit:

Suggested change
new empty shard, starting recovery (copying) of an existing shard from another data node, or remove a shard. When the data node finishes
new empty shard, starting recovery (copying) of an existing shard from another data node, or removing a shard. When the data node finishes

but also I feel we should expand a bit on what "removing a shard" means in this context? It means actively shutting down the corresponding running (or recovering) IndexShard instance, releasing all its resources.

Again, this feels like detail that should be in a Javadoc somewhere, maybe org.elasticsearch.cluster.routing.GlobalRoutingTable, and linked to from RoutingTable, IndexRoutingTable, IndexShardRoutingTable and ShardRouting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied removing 👍

but also I feel we should expand a bit on what "removing a shard" means in this context? It means actively shutting down the corresponding running (or recovering) IndexShard instance, releasing all its resources.

The details of removal of a shard seem akin to the details of recovery of a shard, which is a separate component than allocation? It seems off topic to me: this section explains how the master and a data node communicate to change shard allocations. Though perhaps you're thinking about it from a some other angle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this feels like detail that should be in a Javadoc somewhere, maybe org.elasticsearch.cluster.routing.GlobalRoutingTable, and linked to from RoutingTable, IndexRoutingTable, IndexShardRoutingTable and ShardRouting.

We should be able to drill down from the high level architecture guide to the package-info and down into a class file, with increasing amounts of detail. The presence of lower level documentation wouldn't eliminate the need for the architecture guide.

I can't find the classes that would contain additional documentation unless I know how to find them. I had not previously heard of GlobalRoutingTable. I consider this documentation's level of detail insufficient for a class level comment and too wide ranging across multiple classes.

Copy link
Contributor Author

@DiannaHohensee DiannaHohensee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, I've finally updated the text.

Info is all good but I think would be better placed in Javadocs, either duplicated here or else with pointers from here to the Javadocs.

I think it depends on the level of detail, and there's a discoverability concern. I've responded in the threads. I've also spun off a separate PR that should go in first.

### Indexes and Shards

Each index consists of a fixed number of primary shards. The number of primary shards cannot be changed for the lifetime of the index. Each
primary shard can have zero-to-many replicas used for data redundancy. The number of replicas per shard can be changed in runtime. Each
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied dynamically 👍

updated `RoutingTable`. The `RoutingTable` is part of the cluster state, so the master node updates the cluster state with the new
(incremental) desired shard allocation information. The updated cluster state is then published to the data nodes. Each data node will
observe any change in shard allocation related to that node and take action to achieve the new shard allocation by initiating creation of a
new empty shard, starting recovery (copying) of an existing shard from another data node, or remove a shard. When the data node finishes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied removing 👍

but also I feel we should expand a bit on what "removing a shard" means in this context? It means actively shutting down the corresponding running (or recovering) IndexShard instance, releasing all its resources.

The details of removal of a shard seem akin to the details of recovery of a shard, which is a separate component than allocation? It seems off topic to me: this section explains how the master and a data node communicate to change shard allocations. Though perhaps you're thinking about it from a some other angle?

updated `RoutingTable`. The `RoutingTable` is part of the cluster state, so the master node updates the cluster state with the new
(incremental) desired shard allocation information. The updated cluster state is then published to the data nodes. Each data node will
observe any change in shard allocation related to that node and take action to achieve the new shard allocation by initiating creation of a
new empty shard, starting recovery (copying) of an existing shard from another data node, or remove a shard. When the data node finishes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this feels like detail that should be in a Javadoc somewhere, maybe org.elasticsearch.cluster.routing.GlobalRoutingTable, and linked to from RoutingTable, IndexRoutingTable, IndexShardRoutingTable and ShardRouting.

We should be able to drill down from the high level architecture guide to the package-info and down into a class file, with increasing amounts of detail. The presence of lower level documentation wouldn't eliminate the need for the architecture guide.

I can't find the classes that would contain additional documentation unless I know how to find them. I had not previously heard of GlobalRoutingTable. I consider this documentation's level of detail insufficient for a class level comment and too wide ranging across multiple classes.


Each index consists of a fixed number of primary shards. The number of primary shards cannot be changed for the lifetime of the index. Each
primary shard can have zero-to-many replicas used for data redundancy. The number of replicas per shard can be changed in runtime. Each
shard copy (primary or replica) can be in one of four states:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. I was trying to shove Ievgen's brain dump info into here, but I wasn't that familiar with the relevant code. I agree, this information is too low-level. I pushed it down into ShardRoutingState in a separate PR because I want to add a reference to the new documentation in this PR.

I wasn't too sure where to push the state transitions. I guess we can prescribe how to transition states in the ShardRoutingState, too, but it's a little strange to describe how the class is used by other classes when ShardRoutingState doesn't enforce those transitions itself. Oh well 🤷‍♀️

@DiannaHohensee
Copy link
Contributor Author

#126875 has been committed and I've updated the text here to reference it. Ready for another review 👍

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; we could reasonably link to here from the new ShardRoutingState docs to aid with discoverability.

@DiannaHohensee
Copy link
Contributor Author

we could reasonably link to here from the new ShardRoutingState docs to aid with discoverability.

I was thinking that the java class level documentation was hard to find, not the architecture guide 🙃 I see expectations vary 😁

@DaveCTurner
Copy link
Contributor

Links all round :)

@DiannaHohensee DiannaHohensee added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Apr 18, 2025
@DiannaHohensee DiannaHohensee merged commit 72b4ed2 into elastic:main Apr 18, 2025
6 of 7 checks passed
@DiannaHohensee DiannaHohensee deleted the 2025/03/20/allocation-guide branch April 18, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed Coordination/Allocation All issues relating to the decision making around placing a shard (both master logic & on the nodes) >non-issue Team:Distributed Coordination Meta label for Distributed Coordination team v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants