MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / getReplicaSticky

Method getReplicaSticky

scope.go:877–904  ·  view source on GitHub ↗
(sessionId string)

Source from the content-addressed store, hash-verified

875}
876
877func (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//

Callers 1

getHostStickyMethod · 0.95

Calls 3

DebugfFunction · 0.92
hashFunction · 0.85
isActiveMethod · 0.80

Tested by

no test coverage detected