Conversation
|
So X-Etcd-Index is tied to an etcd server (so in a cluster, you can have multiple I think, not sure). If we take a look at the etcd API description:
It's probably best to do an Verifying this locally: |
|
I had two factors that led me to wanting this available:
It may be possible to have multiple X-Etcd-Index values among a cluster, but I'm assuming that they try to sycn them up asap. That issue doesn't bother me for my system. If the code doesnt fit for your project, thats OK. Just thought I'd offer it up as its definitely useful for me. |
There was a problem hiding this comment.
I appreciate the back and forth, making me read the documentation more carefully. I agree that there is a good reason to request the current X-Etcd-Index value before making a watch request. Having a specific function to return that would be valuable. I guess we also need to have etcdlib_watch() return the X-Etcd-Index value if error code 401 is detected in the json response.
If you don't feel like making that last change, let me know. I'll do it later.
| * @param const etcdlib_t* etcdlib. The ETCD-LIB instance | ||
| * @param int* modifiedIndex. The X-Etcd-Index value as retrieved from the etcd server. | ||
| */ | ||
| int etcdlib_get_db_index(etcdlib_t *etcdlib, int* modifiedIndex); |
There was a problem hiding this comment.
Please rename modifiedIndex to currentEtcdIndex
| } | ||
|
|
||
|
|
||
| int etcdlib_get_db_index(etcdlib_t *etcdlib, int* modifiedIndex) { |
There was a problem hiding this comment.
Please rename modifiedIndex to currentEtcdIndex
| fprintf(stderr, "Error getting etcd value, curl error: '%s'\n", curl_easy_strerror(res)); | ||
| } | ||
|
|
||
| if (reply.memory) { |
There was a problem hiding this comment.
Although it happens multiple times in the current code, would you mind removing the if statement here? free() explicitly handles NULL values properly by ignoring them.
Its hard to use the ETCD watch API without knowing the current DB index, so I added it. It works when I test it. Hopefully the method of doing a GET on host/v2/keys just to get the HTTP header is acceptable.