Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix vbucket_compare() for ketama distribution

The nodes list is unordered, so it sets sequence_changed. It doesn't
matter for vbucket distribution because it takes list from 'serverList'
property, which is ordered by cluster.

Change-Id: I8783a1840bdbf4a19cad384ff9b5540f8c2f5551
Reviewed-on: http://review.couchbase.org/12695
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
commit f9dfa4f4f456c09dac39a7833578dbe89c7a8494 1 parent 6a97edb
@avsej avsej authored trondn committed
Showing with 36 additions and 0 deletions.
  1. +7 −0 src/vbucket.c
  2. +29 −0 tests/testapp.c
View
7 src/vbucket.c
@@ -370,6 +370,12 @@ static int parse_vbucket_config(VBUCKET_CONFIG_HANDLE vb, cJSON *c)
return 0;
}
+static int server_cmp(const void *s1, const void *s2)
+{
+ return strcmp(((const struct server_st *)s1)->authority,
+ ((const struct server_st *)s2)->authority);
+}
+
static int parse_ketama_config(VBUCKET_CONFIG_HANDLE vb, cJSON *config)
{
cJSON *json, *node;
@@ -404,6 +410,7 @@ static int parse_ketama_config(VBUCKET_CONFIG_HANDLE vb, cJSON *config)
}
vb->servers[ii].authority = buf;
}
+ qsort(vb->servers, vb->num_servers, sizeof(struct server_st), server_cmp);
update_ketama_continuum(vb);
return 0;
View
29 tests/testapp.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <sys/stat.h>
#include <libvbucket/vbucket.h>
@@ -44,8 +45,16 @@ static const struct vb_st vbuckets[] =
static char *configPath(const char *fname) {
static char buffer[PATH_MAX];
char *root = getenv("srcdir");
+ struct stat st;
sprintf(buffer, "%s/tests/config/testapp-%s", root, fname);
+ if (stat(buffer, &st) == -1) {
+ sprintf(buffer, "%s/tests/config/%s", root, fname);
+ if (stat(buffer, &st) == -1) {
+ fprintf(stderr, "cannot find config %s\n", fname);
+ abort();
+ }
+ }
return buffer;
}
@@ -193,6 +202,25 @@ static void testConfigDiffSame(void) {
vbucket_config_destroy(vb2);
}
+static void testConfigDiffKetamaSame(void) {
+ VBUCKET_CONFIG_HANDLE vb1 = vbucket_config_parse_file(configPath("ketama-eight-nodes"));
+ VBUCKET_CONFIG_HANDLE vb2 = vbucket_config_parse_file(configPath("ketama-ordered-eight-nodes"));
+ VBUCKET_CONFIG_DIFF *diff;
+ assert(vb1);
+ assert(vb2);
+ diff = vbucket_compare(vb1, vb2);
+ assert(diff);
+
+ assert(diff->sequence_changed == 0);
+ assert(diff->n_vb_changes == 0);
+ assert(diff->servers_added[0] == NULL);
+ assert(diff->servers_removed[0] == NULL);
+
+ vbucket_free_diff(diff);
+ vbucket_config_destroy(vb1);
+ vbucket_config_destroy(vb2);
+}
+
static void testConfigUserPassword(void) {
VBUCKET_CONFIG_HANDLE vb1;
VBUCKET_CONFIG_HANDLE vb2;
@@ -259,5 +287,6 @@ int main(void) {
testConfigDiffSame();
testConfigUserPassword();
testConfigCouchApiBase();
+ testConfigDiffKetamaSame();
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.