Apply implements routing.LBAlgorithm with a consistent hash algorithm.
(ctx *routing.LBContext)
| 198 | |
| 199 | // Apply implements routing.LBAlgorithm with a consistent hash algorithm. |
| 200 | func (ch *consistentHash) Apply(ctx *routing.LBContext) routing.LBEndpoint { |
| 201 | if len(ctx.LBEndpoints) == 1 { |
| 202 | return ctx.LBEndpoints[0] |
| 203 | } |
| 204 | |
| 205 | // The index returned from this call is taken from hash ring which is built from data about |
| 206 | // all endpoints, including fading in, unhealthy, etc. ones. The index stored in hash ring is |
| 207 | // the index of the endpoint in the original list of endpoints. |
| 208 | choice := ch.chooseConsistentHashEndpoint(ctx) |
| 209 | return ctx.Route.LBEndpoints[choice] |
| 210 | } |
| 211 | |
| 212 | func (ch *consistentHash) chooseConsistentHashEndpoint(ctx *routing.LBContext) int { |
| 213 | key, ok := ctx.Params[ConsistentHashKey].(string) |
nothing calls this directly
no test coverage detected