how etcd processing read request

30 Views Asked by At

When a read request comes to etcd server,it will call linearizableReadNotify() which trigger anthoer goroutine to process read request.

func (s *EtcdServer) linearizableReadNotify(ctx context.Context) error {
    s.readMu.RLock()
    nc := s.readNotifier
    s.readMu.RUnlock()

    // signal linearizable loop for current notify if it hasn't been already
    select {
    case s.readwaitc <- struct{}{}:
    default:
    }

   // wait for read state notification
   select {
   case <-nc.c:
        return nc.err
   case <-ctx.Done():
        return ctx.Err()
   case <-s.done:
        return errors.ErrStopped
   }
}

s.readwaitc is a channel with buffer 1.

My Question is that assuming this solution: there are three request:g1,g2,g3 come sequentially.g1 and g2 read same s.readNotifier.g1 send a signal to trigger processing read request,and g2 send singals too which channel buffer is full now.In this time,g3 comes,getting a channel which is different from the channel g1 and g2 having and selecting default case due to full channel buffer.g3 wait for an channel which is never triggered.Will g3's read request be ignored or retry by client?

I am confused with this source code.

0

There are 0 best solutions below