MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / observeLeaderEvent

Method observeLeaderEvent

store/engine/etcd/etcd.go:256–292  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

254}
255
256func (e *Etcd) observeLeaderEvent(ctx context.Context) {
257 defer e.wg.Done()
258 var election *concurrency.Election
259 select {
260 case elect := <-e.electionCh:
261 election = elect
262 case <-e.quitCh:
263 return
264 }
265
266 ch := election.Observe(ctx)
267 for {
268 select {
269 case resp := <-ch:
270 e.isReady.Store(true)
271 if len(resp.Kvs) > 0 {
272 newLeaderID := string(resp.Kvs[0].Value)
273 e.leaderMu.Lock()
274 e.leaderID = newLeaderID
275 e.leaderMu.Unlock()
276 e.leaderChangeCh <- true
277 if newLeaderID != "" && newLeaderID == e.leaderID {
278 continue
279 }
280 } else {
281 ch = election.Observe(ctx)
282 e.leaderChangeCh <- false
283 }
284 case elect := <-e.electionCh:
285 election = elect
286 ch = election.Observe(ctx)
287 case <-e.quitCh:
288 logger.Get().Info("Exit the leader change observe loop")
289 return
290 }
291 }
292}
293
294func (e *Etcd) Close() error {
295 close(e.quitCh)

Callers 1

NewFunction · 0.95

Calls 2

GetFunction · 0.92
InfoMethod · 0.80

Tested by

no test coverage detected