You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/02/29 15:33:28 UTC

[GitHub] [servicecomb-kie] zhulijian1 opened a new pull request #108: improve client

zhulijian1 opened a new pull request #108: improve client
URL: https://github.com/apache/servicecomb-kie/pull/108
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-kie] tianxiaoliang commented on a change in pull request #108: #109 client支持指定revision

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #108: #109 client支持指定revision
URL: https://github.com/apache/servicecomb-kie/pull/108#discussion_r386241206
 
 

 ##########
 File path: client/client.go
 ##########
 @@ -158,31 +161,39 @@ func (c *Client) Get(ctx context.Context, opts ...GetOption) (*model.KVResponse,
 	h := http.Header{}
 	resp, err := c.c.Do(ctx, http.MethodGet, url, h, nil)
 	if err != nil {
-		return nil, err
+		return nil, -1, err
+	}
+	responseRevision, errRevision := strconv.Atoi(resp.Header.Get(common.HeaderRevision))
+	if errRevision != nil {
+		responseRevision = -1
 	}
 	b := httputil.ReadBody(resp)
 	if resp.StatusCode != http.StatusOK {
 		if resp.StatusCode == http.StatusNotFound {
-			return nil, ErrKeyNotExist
+			return nil, responseRevision, ErrKeyNotExist
 		}
 		if resp.StatusCode == http.StatusNotModified {
-			return nil, ErrNoChanges
+			return nil, responseRevision, ErrNoChanges
 		}
 		openlogging.Error(MsgGetFailed, openlogging.WithTags(openlogging.Tags{
 			"k":      options.Key,
 			"status": resp.Status,
 			"body":   b,
 		}))
-		return nil, fmt.Errorf(FmtGetFailed, options.Key, resp.Status, b)
+		return nil, responseRevision, fmt.Errorf(FmtGetFailed, options.Key, resp.Status, b)
+	} else if errRevision != nil {
+		msg := fmt.Sprintf("get revision from response header failed when the request status is OK: %v", err)
+		openlogging.Error(msg)
+		return nil, responseRevision, fmt.Errorf(msg)
 	}
 	var kvs *model.KVResponse
 	err = json.Unmarshal(b, &kvs)
 	if err != nil {
 		openlogging.Error("unmarshal kv failed:" + err.Error())
-		return nil, err
+		return nil, responseRevision, err
 	}
-	c.CurrentRevision = resp.Header.Get(common.HeaderRevision)
-	return kvs, nil
+	c.currentRevision = responseRevision
+	return kvs, responseRevision, nil
 
 Review comment:
   调用者为何要关心这个responseRevision,你已经给了API专门用于拿当前revison了

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-kie] zhulijian1 commented on a change in pull request #108: #109 client支持指定revision

Posted by GitBox <gi...@apache.org>.
zhulijian1 commented on a change in pull request #108: #109 client支持指定revision
URL: https://github.com/apache/servicecomb-kie/pull/108#discussion_r386258199
 
 

 ##########
 File path: client/client.go
 ##########
 @@ -158,31 +161,39 @@ func (c *Client) Get(ctx context.Context, opts ...GetOption) (*model.KVResponse,
 	h := http.Header{}
 	resp, err := c.c.Do(ctx, http.MethodGet, url, h, nil)
 	if err != nil {
-		return nil, err
+		return nil, -1, err
+	}
+	responseRevision, errRevision := strconv.Atoi(resp.Header.Get(common.HeaderRevision))
 
 Review comment:
   fixed

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-kie] tianxiaoliang merged pull request #108: #109 client支持指定revision

Posted by GitBox <gi...@apache.org>.
tianxiaoliang merged pull request #108: #109 client支持指定revision
URL: https://github.com/apache/servicecomb-kie/pull/108
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-kie] tianxiaoliang commented on a change in pull request #108: #109 client支持指定revision

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #108: #109 client支持指定revision
URL: https://github.com/apache/servicecomb-kie/pull/108#discussion_r386241330
 
 

 ##########
 File path: client/client.go
 ##########
 @@ -158,31 +161,39 @@ func (c *Client) Get(ctx context.Context, opts ...GetOption) (*model.KVResponse,
 	h := http.Header{}
 	resp, err := c.c.Do(ctx, http.MethodGet, url, h, nil)
 	if err != nil {
-		return nil, err
+		return nil, -1, err
+	}
+	responseRevision, errRevision := strconv.Atoi(resp.Header.Get(common.HeaderRevision))
 
 Review comment:
   errRevision 没必要,用err就好了吧?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-kie] zhulijian1 commented on a change in pull request #108: #109 client支持指定revision

Posted by GitBox <gi...@apache.org>.
zhulijian1 commented on a change in pull request #108: #109 client支持指定revision
URL: https://github.com/apache/servicecomb-kie/pull/108#discussion_r386248676
 
 

 ##########
 File path: client/client.go
 ##########
 @@ -158,31 +161,39 @@ func (c *Client) Get(ctx context.Context, opts ...GetOption) (*model.KVResponse,
 	h := http.Header{}
 	resp, err := c.c.Do(ctx, http.MethodGet, url, h, nil)
 	if err != nil {
-		return nil, err
+		return nil, -1, err
+	}
+	responseRevision, errRevision := strconv.Atoi(resp.Header.Get(common.HeaderRevision))
+	if errRevision != nil {
+		responseRevision = -1
 	}
 	b := httputil.ReadBody(resp)
 	if resp.StatusCode != http.StatusOK {
 		if resp.StatusCode == http.StatusNotFound {
-			return nil, ErrKeyNotExist
+			return nil, responseRevision, ErrKeyNotExist
 		}
 		if resp.StatusCode == http.StatusNotModified {
-			return nil, ErrNoChanges
+			return nil, responseRevision, ErrNoChanges
 		}
 		openlogging.Error(MsgGetFailed, openlogging.WithTags(openlogging.Tags{
 			"k":      options.Key,
 			"status": resp.Status,
 			"body":   b,
 		}))
-		return nil, fmt.Errorf(FmtGetFailed, options.Key, resp.Status, b)
+		return nil, responseRevision, fmt.Errorf(FmtGetFailed, options.Key, resp.Status, b)
+	} else if errRevision != nil {
+		msg := fmt.Sprintf("get revision from response header failed when the request status is OK: %v", err)
+		openlogging.Error(msg)
+		return nil, responseRevision, fmt.Errorf(msg)
 	}
 	var kvs *model.KVResponse
 	err = json.Unmarshal(b, &kvs)
 	if err != nil {
 		openlogging.Error("unmarshal kv failed:" + err.Error())
-		return nil, err
+		return nil, responseRevision, err
 	}
-	c.CurrentRevision = resp.Header.Get(common.HeaderRevision)
-	return kvs, nil
+	c.currentRevision = responseRevision
+	return kvs, responseRevision, nil
 
 Review comment:
   revision和response必须同时返回,调用者之后再调CurrentRevisio()的时候可能已经变了,不是上次get时候的revision了。协程1get -> put更新 -> 协程2get ->协程1查CurrentRevisio ->协程1用CurrentRevisio get

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services