Skip to content

Commit

Permalink
bug 1431 - moxi invokes vbucket_compare()
Browse files Browse the repository at this point in the history
so that moxi does a better job of reusing pre-existing
downstream connections.

Change-Id: I9f803b062bf6f94e7d9f0a52d3e697826de29a50
Reviewed-on: http://review.northscale.com:8080/651
Reviewed-by: Dustin Sallings <dustin@spy.net>
Tested-by: Dustin Sallings <dustin@spy.net>
  • Loading branch information
steveyen authored and dustin committed Jun 18, 2010
1 parent 4aa49f5 commit f8ccf9f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cproxy.c
Expand Up @@ -919,14 +919,30 @@ bool cproxy_check_downstream_config(downstream *d) {
rv = true;
} else if (d->config != NULL &&
d->ptd->config != NULL &&
strcmp(d->config,
d->ptd->config) == 0 &&
cproxy_equal_behaviors(d->behaviors_num,
d->behaviors_arr,
d->ptd->behavior_pool.num,
d->ptd->behavior_pool.arr)) {
d->config_ver = d->ptd->config_ver;
rv = true;
// Parse the proxy/parent's config to see if we can
// reuse our existing downstream connections.
//
mcs_st next;

int n = init_mcs_st(&next, d->ptd->config);
if (n > 0) {
if (mcs_stable_update(&d->mst, &next)) {
if (settings.verbose > 2) {
fprintf(stderr, "check_downstream_config stable update\n");
}

free(d->config);
d->config = strdup(d->ptd->config);
d->config_ver = d->ptd->config_ver;
rv = true;
}

mcs_free(&next);
}
}

if (settings.verbose > 2) {
Expand Down
32 changes: 32 additions & 0 deletions mcs.c
Expand Up @@ -91,6 +91,34 @@ mcs_server_st *mcs_server_index(mcs_st *ptr, int i) {
return &ptr->servers[i];
}

/* Returns true if curr_version could be updated with next_version in
* a low-impact stable manner (server-list is the same), allowing the
* same connections to be reused. Or returns false if the delta was
* too large for an in-place updating of curr_version with information
* from next_version.
*
* The next_version may be destroyed in this call, and the caller
* should afterwards only call mcs_free() on the next_version.
*/
bool mcs_stable_update(mcs_st *curr_version, mcs_st *next_version) {
bool rv = false;

VBUCKET_CONFIG_DIFF *diff = vbucket_compare(curr_version->vch, next_version->vch);
if (diff != NULL) {
if (!diff->sequence_changed) {
vbucket_config_destroy(curr_version->vch);
curr_version->vch = next_version->vch;
next_version->vch = 0;

rv = true;
}

vbucket_free_diff(diff);
}

return rv;
}

uint32_t mcs_key_hash(mcs_st *ptr, const char *key, size_t key_length, int *vbucket) {
int v = vbucket_get_vbucket_by_key(ptr->vch, key, key_length);
if (vbucket != NULL) {
Expand Down Expand Up @@ -277,6 +305,10 @@ mcs_server_st *mcs_server_index(mcs_st *ptr, int i) {
return &ptr->hosts[i];
}

bool mcs_stable_update(mcs_st *curr_version, mcs_st *next_version) {
return false;
}

uint32_t mcs_key_hash(mcs_st *ptr, const char *key, size_t key_length, *vbucket) {
if (vbucket != NULL) {
*vbucket = -1;
Expand Down
2 changes: 2 additions & 0 deletions mcs.h
Expand Up @@ -63,6 +63,8 @@ memcached_return memcached_do(memcached_server_st *ptr,
mcs_st *mcs_create(mcs_st *ptr, const char *config);
void mcs_free(mcs_st *ptr);

bool mcs_stable_update(mcs_st *curr_version, mcs_st *next_version);

uint32_t mcs_server_count(mcs_st *ptr);
mcs_return mcs_server_push(mcs_st *ptr, mcs_server_st *list);
mcs_server_st *mcs_server_index(mcs_st *ptr, int i);
Expand Down

0 comments on commit f8ccf9f

Please sign in to comment.