Skip to content

Commit 989ef19

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 989ef19

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1711,10 +1711,10 @@ 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()
1716-
if err != nil {
1717-
return &pdpb.StoreGlobalConfigResponse{Error: &pdpb.Error{Type: pdpb.ErrorType_UNKNOWN, Message: err.Error()}}, err
1716+
if err != nil || !res.Succeeded {
1717+
return &pdpb.StoreGlobalConfigResponse{Error: &pdpb.Error{Type: pdpb.ErrorType_UNKNOWN, Message: "failed to execute StoreGlobalConfig transaction"}}, errors.Errorf("failed to execute StoreGlobalConfig transaction")
17181718
}
17191719
return &pdpb.StoreGlobalConfigResponse{}, err
17201720
}

0 commit comments

Comments
 (0)