MCPcopy
hub / github.com/dgraph-io/dgraph / fillTimestampRequests

Method fillTimestampRequests

worker/server_state.go:159–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

157}
158
159func (s *ServerState) fillTimestampRequests() {
160 const (
161 initDelay = 10 * time.Millisecond
162 maxDelay = time.Second
163 )
164
165 defer func() {
166 glog.Infoln("Exiting fillTimestampRequests")
167 }()
168
169 var reqs []tsReq
170 for {
171 // Reset variables.
172 reqs = reqs[:0]
173 delay := initDelay
174
175 select {
176 case <-s.gcCloser.HasBeenClosed():
177 return
178 case req := <-s.needTs:
179 slurpLoop:
180 for {
181 reqs = append(reqs, req)
182 select {
183 case req = <-s.needTs:
184 default:
185 break slurpLoop
186 }
187 }
188 }
189
190 // Generate the request.
191 num := &pb.Num{}
192 for _, r := range reqs {
193 if r.readOnly {
194 num.ReadOnly = true
195 } else {
196 num.Val++
197 }
198 }
199
200 // Execute the request with infinite retries.
201 retry:
202 if s.gcCloser.Ctx().Err() != nil {
203 return
204 }
205 ctx, cancel := context.WithTimeout(s.gcCloser.Ctx(), 10*time.Second)
206 ts, err := Timestamps(ctx, num)
207 cancel()
208 if err != nil {
209 glog.Warningf("Error while retrieving timestamps: %v with delay: %v."+
210 " Will retry...\n", err, delay)
211 time.Sleep(delay)
212 delay *= 2
213 if delay > maxDelay {
214 delay = maxDelay
215 }
216 goto retry

Callers 1

InitServerStateFunction · 0.80

Calls 4

AssertTrueFunction · 0.92
TimestampsFunction · 0.85
WarningfMethod · 0.80
CtxMethod · 0.45

Tested by

no test coverage detected