-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API call for retrieving db index #285
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename modifiedIndex to currentEtcdIndex
@@ -257,6 +257,40 @@ static long long etcd_get_current_index(const char* headerData) { | |||
} | |||
|
|||
|
|||
int etcdlib_get_db_index(etcdlib_t *etcdlib, int* modifiedIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.