Etcd – 过时的索引。如何从客户端读取 “X-Etcd-Index”?

huangapple go评论85阅读模式
英文:

Etcd - Outdated index. How to read "X-Etcd-Index" from client

问题

我正在使用github.com/coreos/etcd/client与etcd云进行通信,有时我会收到401错误“请求索引中的事件已过时并已清除”,在服务器页面上有一个解释为什么会发生这种情况以及如何解决。实际上,我想要实现以下场景。

  1. 获取“key”及其修改的索引
  2. 进行一些操作
  3. 从修改的索引开始监视“key”

这样,我可以确保在第2步期间发生的所有更改也会被接收到。但是Etcd只保存前N个更改,有时我会收到401错误。根据文档,我可以使用Get key请求中的“X-Etcd-Index” + 1标头作为修改的索引来进行监视。

curl 'http://127.0.0.1:2379/v2/keys/foo' -vv
< HTTP/1.1 200 OK
< Content-Type: application/json
< X-Etcd-Cluster-Id: f63cd37d2ff4f650
< X-Etcd-Index: 17245
< X-Raft-Index: 2107637
< X-Raft-Term: 360
< Date: Tue, 15 Dec 2015 09:02:20 GMT
< Content-Length: 791
< ...

但是我不使用直接的http调用,只使用github.com/coreos/etcd/client。我如何获取(并且是否可以使用API)来自get key请求的http标头信息?

英文:

I am using github.com/coreos/etcd/client for communicating with etcd cloud, sometimes i am receiving 401 error "The event in requested index is outdated and cleared" , on server page there is a explanation why it happened and how it can be solved. Actually I want to implement the following scenario.

  1. Get "key" and its modified index
  2. do some job
  3. start watching on "key" from modified index

this way I can be shure that all changes during 2 step will be also received. But Etcd saves only top N changes and sometimes I am receiving 401 error. Acording docu I can use "X-Etcd-Index" + 1 header from Get key request as modified index to watch.

curl &#39;http://127.0.0.1:2379/v2/keys/foo&#39; -vv
&lt; HTTP/1.1 200 OK
&lt; Content-Type: application/json
&lt; X-Etcd-Cluster-Id: f63cd37d2ff4f650
&lt; X-Etcd-Index: 17245
&lt; X-Raft-Index: 2107637
&lt; X-Raft-Term: 360
&lt; Date: Tue, 15 Dec 2015 09:02:20 GMT
&lt; Content-Length: 791
&lt; ...

But I don't use direct http calls , only github.com/coreos/etcd/client. How can I get (and is it actually possible using api) a http header info on from get key request ?

答案1

得分: 1

X-Etcd-Index 头部对应于 Response.Index 字段。

英文:

The X-Etcd-Index header corresponds to the Response.Index field.

答案2

得分: 1

索引在响应字段中作为“Index”对象提供。请参阅此处的文档:https://godoc.org/github.com/coreos/etcd/client#Response

英文:

The index is available in the response field as the "Index" object. See the documentation here: https://godoc.org/github.com/coreos/etcd/client#Response

huangapple
  • 本文由 发表于 2015年12月15日 17:14:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/34285119.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定