Ketama hashing is now compatable with spymemcached. The server key was not in the...
authormike tsai <mtsai@mtsai>
Mon, 19 Oct 2009 23:37:48 +0000 (16:37 -0700)
committermike tsai <mtsai@mtsai>
Mon, 19 Oct 2009 23:37:48 +0000 (16:37 -0700)
libmemcached/memcached_hosts.c

index d664ab2b5a7b0e7eefa89d88f2b5f28e1d9971be..f0af383ab09b9a500322979812757ae66df48dd8 100644 (file)
@@ -198,28 +198,24 @@ memcached_return update_continuum(memcached_st *ptr)
                pointer_per_server);
 #endif
     }
-    for (pointer_index= 1;
-         pointer_index <= pointer_per_server / pointer_per_hash;
-         ++pointer_index)
+    for (pointer_index= 0;
+         pointer_index < pointer_per_server / pointer_per_hash;
+         pointer_index++)
     {
       char sort_host[MEMCACHED_MAX_HOST_SORT_LENGTH]= "";
       size_t sort_host_length;
 
-      if (list[host_index].port == MEMCACHED_DEFAULT_PORT)
-      {
-        sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH,
-                                            "%s-%d",
-                                            list[host_index].hostname,
-                                            pointer_index - 1);
+      // Spymemcached ketema key format is: hostname/ip:port-index
+      // If hostname is not available then: /ip:port-index
+      sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH,
+                                          "/%s:%d-%d",
+                                          list[host_index].hostname,
+                                          list[host_index].port,
+                                          pointer_index);
+#ifdef DEBUG
+      printf("update_continuum: key is %s\n", sort_host);
+#endif
 
-      }
-      else
-      {
-        sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH,
-                                            "%s:%d-%d",
-                                            list[host_index].hostname,
-                                            list[host_index].port, pointer_index - 1);
-      }
       WATCHPOINT_ASSERT(sort_host_length);
 
       if (is_ketama_weighted)