Skip to content

Commit b9baf26

Browse files
committed
add some comment
1 parent f93314f commit b9baf26

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

middleware/melody-etcd/client.go

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func NewClient(ctx context.Context, machines []string, options ClientOptions) (C
100100

101101
// GetEntries implements the etcd Client interface.
102102
func (c *client) GetEntries(key string) ([]string, error) {
103+
// TODO: bug 如果没有先启动 etcd 这里就会崩掉 并且卡住之后的endpoint的初始化
103104
resp, err := c.v3.Get(c.ctx, key, clientv3.WithPrefix())
104105
if err != nil {
105106
return nil, err

middleware/melody-etcd/subscriber.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package etcd
22

33
import (
44
"context"
5+
"errors"
56
"melody/config"
67
"melody/sd"
78
"sync"
@@ -11,6 +12,7 @@ var (
1112
subscribers = map[string]sd.Subscriber{}
1213
subscribersMutex = &sync.Mutex{}
1314
fallbackSubscriberFactory = sd.FixedSubscriberFactory
15+
NoClientError = errors.New("errors: no SD client")
1416
)
1517

1618
// SubscriberFactory builds a an etcd subscriber SubscriberFactory with the received etcd client
@@ -57,6 +59,10 @@ func NewSubscriber(ctx context.Context, c Client, prefix string) (*Subscriber, e
5759
mutex: &sync.RWMutex{},
5860
}
5961

62+
if s.client == nil {
63+
return nil, NoClientError
64+
}
65+
6066
// 获取 key 为 s.prefix 的所有value
6167
instances, err := s.client.GetEntries(s.prefix)
6268
if err != nil {

proxy/factory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (d defaultFactory) New(cfg *config.EndpointConfig) (p Proxy, err error) {
5555
func (d defaultFactory) NewStack(backend *config.Backend) (p Proxy) {
5656
// 根据config.Backend定制backendProxy 执行顺序:④
5757
p = d.backendFactory(backend)
58-
// 均衡中间件注册 执行顺序:③
58+
// 均衡中间件注册(在此处调用对应的服务发现) 执行顺序:③
5959
p = NewLoadBalancedMiddlewareWithSubscriber(d.subscriberFactory(backend))(p)
6060
if backend.ConcurrentCalls > 1 {
6161
// 并发调用 > 1 执行顺序:②

sd/register.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func RegisterSubscriberFactory(name string, sf SubscriberFactory) error {
1010
return subscriberFactories.Register(name, sf)
1111
}
1212

13-
// GetSubscriber returns a subscriber from package register
13+
// GetSubscriber 在此处选择调用哪种服务发现
1414
func GetSubscriber(cfg *config.Backend) Subscriber {
1515
return subscriberFactories.Get(cfg.SD)(cfg)
1616
}

0 commit comments

Comments
 (0)