英文:
Etcd - Outdated index. How to read "X-Etcd-Index" from client
问题
我正在使用github.com/coreos/etcd/client与etcd云进行通信,有时我会收到401错误“请求索引中的事件已过时并已清除”,在服务器页面上有一个解释为什么会发生这种情况以及如何解决。实际上,我想要实现以下场景。
- 获取“key”及其修改的索引
- 进行一些操作
- 从修改的索引开始监视“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.
- Get "key" and its modified index
- do some job
- 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 '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
< ...
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论