Skip to content

Commit

Permalink
Allow to detect which node gave current configuration
Browse files Browse the repository at this point in the history
This feature used in libcouchbase to judge about healthness of REST
connection.

Change-Id: Ie6370ca2d6e7313228965870d70d419e6b79a0f5
Reviewed-on: http://review.couchbase.org/30833
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information
avsej authored and trondn committed Dec 4, 2013
1 parent e992f5f commit 56bc1cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/libvbucket/vbucket.h
Expand Up @@ -254,6 +254,14 @@ extern "C" {
LIBVBUCKET_PUBLIC_API
const char *vbucket_config_get_rest_api_server(VBUCKET_CONFIG_HANDLE vb, int i);

/**
* Check if the server was used for configuration
*
* @return non-zero for configuration node
*/
LIBVBUCKET_PUBLIC_API
int vbucket_config_is_config_node(VBUCKET_CONFIG_HANDLE h, int i);

/**
* Get the distribution type. Currently can be or "vbucket" (for
* eventually persisted nodes) either "ketama" (for plain memcached
Expand Down
10 changes: 10 additions & 0 deletions src/vbucket.c
Expand Up @@ -36,6 +36,8 @@ struct server_st {
char *authority; /* host:port */
char *rest_api_authority;
char *couchdb_api_base;
int config_node; /* non-zero if server struct describes node,
which is listening */
};

struct vbucket_st {
Expand Down Expand Up @@ -253,6 +255,10 @@ static int update_server_info(struct vbucket_config_st *vb, cJSON *config) {
}
vb->servers[idx].rest_api_authority = value;
}
json = cJSON_GetObjectItem(node, "thisNode");
if (json != NULL && json->type == cJSON_True) {
vb->servers[idx].config_node = 1;
}
}
}
}
Expand Down Expand Up @@ -672,6 +678,10 @@ const char *vbucket_config_get_rest_api_server(VBUCKET_CONFIG_HANDLE vb, int i)
return vb->servers[i].rest_api_authority;
}

int vbucket_config_is_config_node(VBUCKET_CONFIG_HANDLE vb, int i) {
return vb->servers[i].config_node;
}

VBUCKET_DISTRIBUTION_TYPE vbucket_config_get_distribution_type(VBUCKET_CONFIG_HANDLE vb) {
return vb->distribution;
}
Expand Down

0 comments on commit 56bc1cf

Please sign in to comment.