memcached_return_t run_distribution(memcached_st *ptr)
{
+ if (ptr->flags.use_sort_hosts)
+ sort_hosts(ptr);
+
switch (ptr->distribution)
{
case MEMCACHED_DISTRIBUTION_CONSISTENT:
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY:
return update_continuum(ptr);
case MEMCACHED_DISTRIBUTION_MODULA:
- if (ptr->flags.use_sort_hosts)
- sort_hosts(ptr);
break;
case MEMCACHED_DISTRIBUTION_RANDOM:
+ srandom((uint32_t) time(NULL));
break;
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX:
default:
WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */
}
// 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",
+ "/%s:%u-%u",
list[host_index].hostname,
- list[host_index].port,
+ (uint32_t)list[host_index].port,
pointer_index);
#ifdef DEBUG
printf("update_continuum: key is %s\n", sort_host);
}
else
{
- value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum);
+ value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->distribution_hash);
ptr->continuum[continuum_index].index= host_index;
ptr->continuum[continuum_index++].value= value;
}
}
else
{
- value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum);
+ value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->distribution_hash);
ptr->continuum[continuum_index].index= host_index;
ptr->continuum[continuum_index++].value= value;
}