Skip to content

tonic-xds: Implement subchannel state machine#2587

Draft
gu0keno0 wants to merge 2 commits intohyperium:masterfrom
gu0keno0:channel-states
Draft

tonic-xds: Implement subchannel state machine#2587
gu0keno0 wants to merge 2 commits intohyperium:masterfrom
gu0keno0:channel-states

Conversation

@gu0keno0
Copy link
Copy Markdown
Collaborator

@gu0keno0 gu0keno0 commented Apr 11, 2026

Implement the type-statemachine for load balancer subchannels. This is preparing for implementing the actual load balancer.

Ref: #2444

Motivation

A real world xDS load-balancer needs to deal with outlier detection and reconnects. Therefore, subchannels managed by load balancer needs to implement a state machine. This PR implements it via type-states.

In the next PR, the load balancer tower layer will drive the state transitions in its poll_ready() implementation. This way, we get full control and visibility in to the managed channels. Therefore, we opens up the flexibility of implementing different LB strategies (e.g. sticky, round-robin, etc), compared to the hardcoded P2C stategy offered by tower::balance that we are currently using.

Solution

Define new type for each state, state transition is implemented by consuming the type for the source state. ConnectingChannel and EjectedChannel needs to be implemented as Streams so that load balancer can use StreamMap to poll them to advance their state transitions.

@gu0keno0 gu0keno0 marked this pull request as ready for review April 11, 2026 03:34
@gu0keno0 gu0keno0 marked this pull request as draft April 12, 2026 16:49
@gu0keno0
Copy link
Copy Markdown
Collaborator Author

WIP, will replace stream with futures, because streammap's poll is O(N).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant