This is an automated email from the ASF dual-hosted git repository.
littlecui pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git
The following commit(s) were added to refs/heads/dev by this push:
new ceb527d fix the bug of do not report the error which occured in
action of get kvdocs from etcd (#305)
ceb527d is described below
commit ceb527d794c787e266e7edfbbbcd6177b7c07b76
Author: tornado-ssy <[email protected]>
AuthorDate: Wed Dec 13 01:04:12 2023 +0800
fix the bug of do not report the error which occured in action of get
kvdocs from etcd (#305)
* fix the concurrent bug of KvIdCache
* fix the bug of do not report the error which occured in action of get
kvdocs from etcd
* fix the bug of do not report the error which occured in action of get
kvdocs from etcd
---------
Co-authored-by: songshiyuan 00649746 <[email protected]>
---
server/datasource/etcd/kv/kv_cache.go | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/server/datasource/etcd/kv/kv_cache.go
b/server/datasource/etcd/kv/kv_cache.go
index 4aadfb1..e394bea 100644
--- a/server/datasource/etcd/kv/kv_cache.go
+++ b/server/datasource/etcd/kv/kv_cache.go
@@ -248,7 +248,10 @@ func Search(ctx context.Context, req *CacheSearchReq)
(*model.KVResponse, bool,
}
return true
})
- tpData := kvCache.getKvFromEtcd(ctx, req, kvIdsLeft)
+ tpData, err := kvCache.getKvFromEtcd(ctx, req, kvIdsLeft)
+ if err != nil {
+ return nil, true, err
+ }
docs = append(docs, tpData...)
for _, doc := range docs {
@@ -261,14 +264,15 @@ func Search(ctx context.Context, req *CacheSearchReq)
(*model.KVResponse, bool,
return result, true, nil
}
-func (kc *Cache) getKvFromEtcd(ctx context.Context, req *CacheSearchReq,
kvIdsLeft []string) []*model.KVDoc {
+func (kc *Cache) getKvFromEtcd(ctx context.Context, req *CacheSearchReq,
kvIdsLeft []string) ([]*model.KVDoc, error) {
if len(kvIdsLeft) == 0 {
- return nil
+ return nil, nil
}
openlog.Debug("get kv from etcd by kvId")
wg := sync.WaitGroup{}
docs := make([]*model.KVDoc, len(kvIdsLeft))
+ var getKvErr error
for i, kvID := range kvIdsLeft {
wg.Add(1)
go func(kvID string, cnt int) {
@@ -278,12 +282,14 @@ func (kc *Cache) getKvFromEtcd(ctx context.Context, req
*CacheSearchReq, kvIdsLe
kv, err := etcdadpt.Get(ctx, docKey)
if err != nil {
openlog.Error(fmt.Sprintf("failed to get kv
from etcd, err %v", err))
+ getKvErr = err
return
}
doc, err := kc.GetKvDoc(kv)
if err != nil {
openlog.Error(fmt.Sprintf("failed to unmarshal
kv, err %v", err))
+ getKvErr = err
return
}
@@ -292,7 +298,10 @@ func (kc *Cache) getKvFromEtcd(ctx context.Context, req
*CacheSearchReq, kvIdsLe
}(kvID, i)
}
wg.Wait()
- return docs
+ if getKvErr != nil {
+ return nil, getKvErr
+ }
+ return docs, nil
}
func isMatch(req *CacheSearchReq, doc *model.KVDoc) bool {