MCPcopy Index your code
hub / github.com/ContentSquare/chproxy / waitUntilAllowStart

Method waitUntilAllowStart

scope.go:163–199  ·  view source on GitHub ↗
(sleep time.Duration, deadline time.Time, labels prometheus.Labels)

Source from the content-addressed store, hash-verified

161}
162
163func (s *scope) waitUntilAllowStart(sleep time.Duration, deadline time.Time, labels prometheus.Labels) error {
164 for {
165 err := s.inc()
166 if err == nil {
167 // The request is allowed to start.
168 return nil
169 }
170
171 dLeft := time.Until(deadline)
172 if dLeft <= 0 {
173 // Give up: the request exceeded its wait time
174 // in the queue :(
175 return err
176 }
177
178 // The request has dLeft remaining time to wait in the queue.
179 // Sleep for a bit and try starting it again.
180 if sleep > dLeft {
181 time.Sleep(dLeft)
182 } else {
183 time.Sleep(sleep)
184 }
185 var h *topology.Node
186 // Choose new host, since the previous one may become obsolete
187 // after sleeping.
188 if s.sessionId == "" {
189 h = s.cluster.getHost()
190 } else {
191 // if request has session_id, set same host
192 h = s.cluster.getHostSticky(s.sessionId)
193 }
194
195 s.host = h
196 s.labels["replica"] = h.ReplicaName()
197 s.labels["cluster_node"] = h.Host()
198 }
199}
200
201func (s *scope) calculateQueueDeadlineAndSleep() (time.Duration, time.Time) {
202 d := s.maxQueueTime()

Callers 1

incQueuedMethod · 0.95

Calls 5

incMethod · 0.95
ReplicaNameMethod · 0.95
HostMethod · 0.95
getHostMethod · 0.45
getHostStickyMethod · 0.45

Tested by

no test coverage detected