Skip to content

Commit cce9862

Browse files
committed
check transaction response in store
rename variable `receiver` into `globalConfigWatcherCH` due to it cause ambiguity of variable meaning Signed-off-by: lemonhx <lemonhx@lemonhx.tech>
1 parent be1faf6 commit cce9862

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

client/client.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1801,23 +1801,23 @@ func (c *client) StoreGlobalConfig(ctx context.Context, items []GlobalConfigItem
18011801
}
18021802

18031803
func (c *client) WatchGlobalConfig(ctx context.Context) (chan []GlobalConfigItem, error) {
1804-
receiver := make(chan []GlobalConfigItem, 16)
1804+
globalConfigWatcherCh := make(chan []GlobalConfigItem, 16)
18051805
res, err := c.getClient().WatchGlobalConfig(ctx, &pdpb.WatchGlobalConfigRequest{})
18061806
if err != nil {
1807-
close(receiver)
1807+
close(globalConfigWatcherCh)
18081808
return nil, err
18091809
}
18101810
go func() {
18111811
defer func() {
18121812
if r := recover(); r != nil {
1813-
log.Error("[pd] panic in client `WatchGlobalConfig` cause by", zap.Any("error:", r))
1813+
log.Error("[pd] panic in client `WatchGlobalConfig`", zap.Any("error", r))
18141814
return
18151815
}
18161816
}()
18171817
for {
18181818
select {
18191819
case <-ctx.Done():
1820-
close(receiver)
1820+
close(globalConfigWatcherCh)
18211821
return
18221822
default:
18231823
m, err := res.Recv()
@@ -1828,9 +1828,9 @@ func (c *client) WatchGlobalConfig(ctx context.Context) (chan []GlobalConfigItem
18281828
for j, i := range m.Changes {
18291829
arr[j] = GlobalConfigItem{i.GetName(), i.GetValue(), nil}
18301830
}
1831-
receiver <- arr
1831+
globalConfigWatcherCh <- arr
18321832
}
18331833
}
18341834
}()
1835-
return receiver, err
1835+
return globalConfigWatcherCh, err
18361836
}

server/grpc_service.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1711,11 +1711,14 @@ func (s *GrpcServer) StoreGlobalConfig(ctx context.Context, request *pdpb.StoreG
17111711
value := item.GetValue()
17121712
ops[i] = clientv3.OpPut(name, value)
17131713
}
1714-
_, err :=
1714+
res, err :=
17151715
kv.NewSlowLogTxn(s.client).Then(ops...).Commit()
17161716
if err != nil {
17171717
return &pdpb.StoreGlobalConfigResponse{Error: &pdpb.Error{Type: pdpb.ErrorType_UNKNOWN, Message: err.Error()}}, err
17181718
}
1719+
if !res.Succeeded {
1720+
return &pdpb.StoreGlobalConfigResponse{Error: &pdpb.Error{Type: pdpb.ErrorType_UNKNOWN, Message: "failed to execute StoreGlobalConfig transaction"}}, errors.Errorf("failed to execute StoreGlobalConfig transaction")
1721+
}
17191722
return &pdpb.StoreGlobalConfigResponse{}, err
17201723
}
17211724

@@ -1773,7 +1776,6 @@ func (s *GrpcServer) WatchGlobalConfig(request *pdpb.WatchGlobalConfigRequest, s
17731776
func (s *GrpcServer) sendAllGlobalConfig(ctx context.Context, server pdpb.PD_WatchGlobalConfigServer) error {
17741777
configList, err := s.client.Get(ctx, globalConfigPath, clientv3.WithPrefix())
17751778
if err != nil {
1776-
log.Error("get global config from etcd failed", zap.Error(err))
17771779
return err
17781780
}
17791781
ls := make([]*pdpb.GlobalConfigItem, configList.Count)

0 commit comments

Comments
 (0)