-
Notifications
You must be signed in to change notification settings - Fork 86
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Please rename modifiedIndex to currentEtcdIndex |
||
|
||
int res = -1; | ||
struct MemoryStruct reply; | ||
|
||
reply.memory = malloc(1); /* will be grown as needed by the realloc above */ | ||
reply.memorySize = 0; /* no data at this point */ | ||
reply.header = malloc(1); /* will be grown as needed by the realloc above */ | ||
reply.headerSize = 0; /* no data at this point */ | ||
|
||
int retVal = ETCDLIB_RC_OK; | ||
char *url; | ||
asprintf(&url, "http://%s:%d/v2/keys", etcdlib->host, etcdlib->port); | ||
res = performRequest(&etcdlib->curl, &etcdlib->mutex, url, GET, NULL, (void *) &reply); | ||
free(url); | ||
|
||
if (res == CURLE_OK) { | ||
long long indexFromHeader = etcd_get_current_index(reply.header); | ||
*modifiedIndex = (int)indexFromHeader; | ||
} else if (res == CURLE_OPERATION_TIMEDOUT) { | ||
retVal = ETCDLIB_RC_TIMEOUT; | ||
} else { | ||
retVal = ETCDLIB_RC_ERROR; | ||
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 commentThe 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(reply.memory); | ||
} | ||
free(reply.header); | ||
return retVal; | ||
} | ||
|
||
|
||
int etcd_get_directory(const char* directory, etcdlib_key_value_callback callback, void* arg, long long* modifiedIndex) { | ||
return etcdlib_get_directory(&g_etcdlib, directory, callback, arg, 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