(sessionId string)
| 875 | } |
| 876 | |
| 877 | func (c *cluster) getReplicaSticky(sessionId string) *replica { |
| 878 | idx := atomic.AddUint32(&c.nextReplicaIdx, 1) |
| 879 | n := uint32(len(c.replicas)) |
| 880 | if n == 1 { |
| 881 | return c.replicas[0] |
| 882 | } |
| 883 | |
| 884 | idx %= n |
| 885 | r := c.replicas[idx] |
| 886 | |
| 887 | for i := uint32(1); i < n; i++ { |
| 888 | // handling sticky session |
| 889 | sessionId := hash(sessionId) |
| 890 | tmpIdx := (sessionId) % n |
| 891 | tmpRSticky := c.replicas[tmpIdx] |
| 892 | log.Debugf("Sticky replica candidate is: %s", tmpRSticky.name) |
| 893 | if !tmpRSticky.isActive() { |
| 894 | log.Debugf("Sticky session replica has been picked up, but it is not available") |
| 895 | continue |
| 896 | } |
| 897 | log.Debugf("Sticky session replica is: %s, session_id: %d, replica_idx: %d, max replicas in pool: %d", tmpRSticky.name, sessionId, tmpIdx, n) |
| 898 | return tmpRSticky |
| 899 | } |
| 900 | // The returned replica may be inactive. This is OK, |
| 901 | // since this means all the replicas are inactive, |
| 902 | // so let's try proxying the request to any replica. |
| 903 | return r |
| 904 | } |
| 905 | |
| 906 | // getHostSticky returns host by stickiness from replica. |
| 907 | // |
no test coverage detected