分布式id生成器

  1. etcd

    为什么要使用etcd,主要是要考虑到workid需要抢占锁

https://yuerblog.cc/2017/12/12/etcd-v3-sdk-usage/

分布式锁

https://blog.csdn.net/cadem/article/details/56495834

https://www.jianshu.com/p/d3068d0ac7c1

https://github.com/etcd-io/etcd/blob/master/clientv3/concurrency/mutex.go#L26

github.com\coreos\etcd\clientv3\lease.go recvKeepAliveLoop

for {  
    resp, err := stream.Recv()
    if err != nil {
        if canceledByCaller(l.stopCtx, err) {
            return err
        }

        if toErr(l.stopCtx, err) == rpctypes.ErrNoLeader {
            l.closeRequireLeader()
        }
        break
    }

    l.recvKeepAlive(resp)
}

这样可以知道<-chan *clientv3.LeaseKeepAliveResponse是读取接收报文过后的

    // retryConnWait is how long to wait before retrying request due to an error
    retryConnWait = 500 * time.Millisecond

发生错误时的重试时间

    // send update to all channels
    nextKeepAlive := time.Now().Add((time.Duration(karesp.TTL) * time.Second) / 3.0)

正常keepAlive的时间