Add comment for proxyManager (#8266)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/8166/head
congqixia 2021-09-22 23:55:53 +08:00 committed by GitHub
parent 3759fa5f64
commit 9ebfd43195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import (
"go.uber.org/zap"
)
// proxyManager manages proxy connected to the rootcoord
type proxyManager struct {
ctx context.Context
cancel context.CancelFunc
@ -37,6 +38,9 @@ type proxyManager struct {
delSessions []func(*sessionutil.Session)
}
// newProxyManager helper function to create a proxyManager
// etcdEndpoints is the address list of etcd
// fns are the custom getSessions function list
func newProxyManager(ctx context.Context, etcdEndpoints []string, fns ...func([]*sessionutil.Session)) (*proxyManager, error) {
cli, err := clientv3.New(clientv3.Config{Endpoints: etcdEndpoints})
if err != nil {
@ -53,18 +57,21 @@ func newProxyManager(ctx context.Context, etcdEndpoints []string, fns ...func([]
return p, nil
}
// AddSession adds functions to addSessions function list
func (p *proxyManager) AddSession(fns ...func(*sessionutil.Session)) {
p.lock.Lock()
defer p.lock.Unlock()
p.addSessions = append(p.addSessions, fns...)
}
// DelSession add functions to delSessions function list
func (p *proxyManager) DelSession(fns ...func(*sessionutil.Session)) {
p.lock.Lock()
defer p.lock.Unlock()
p.delSessions = append(p.delSessions, fns...)
}
// WatchProxy starts a goroutine to watch proxy session changes on etcd
func (p *proxyManager) WatchProxy() error {
ctx2, cancel := context.WithTimeout(p.ctx, RequestTimeout)
defer cancel()
@ -160,10 +167,12 @@ func (p *proxyManager) WatchProxy() error {
return nil
}
// Stop stops the proxyManager
func (p *proxyManager) Stop() {
p.cancel()
}
// listProxyInEtcd helper function lists proxy in etcd
func listProxyInEtcd(ctx context.Context, cli *clientv3.Client) (map[int64]*sessionutil.Session, error) {
ctx2, cancel := context.WithTimeout(ctx, RequestTimeout)
defer cancel()