Also, re-enable memcached_server_add(many weighted) test which was
presumably disabled because of this issue.
When a continuum was allocated while not in weighted distribution mode,
the actual space allocated at first would be to small to fit further
updates when weighted changed to true at a later time.
live_servers= memcached_server_count(ptr);
}
live_servers= memcached_server_count(ptr);
}
- uint32_t points_per_server= (uint32_t) (memcached_is_weighted_ketama(ptr) ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER);
-
if (live_servers == 0)
{
return MEMCACHED_SUCCESS;
}
if (live_servers == 0)
{
return MEMCACHED_SUCCESS;
}
- if (live_servers > ptr->ketama.continuum_count)
+ uint32_t points_per_server = (uint32_t) (memcached_is_weighted_ketama(ptr) ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER);
+ uint32_t continuum_limit = live_servers * points_per_server;
+ uint32_t continuum_extra = MEMCACHED_CONTINUUM_ADDITION * points_per_server;
+
+ if (continuum_limit > ptr->ketama.continuum_count)
{
memcached_continuum_item_st *new_ptr;
{
memcached_continuum_item_st *new_ptr;
- new_ptr= libmemcached_xrealloc(ptr, ptr->ketama.continuum, (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server, memcached_continuum_item_st);
+ new_ptr= libmemcached_xrealloc(ptr, ptr->ketama.continuum, continuum_limit + continuum_extra, memcached_continuum_item_st);
}
ptr->ketama.continuum= new_ptr;
}
ptr->ketama.continuum= new_ptr;
- ptr->ketama.continuum_count= live_servers + MEMCACHED_CONTINUUM_ADDITION;
+ ptr->ketama.continuum_count= continuum_limit + continuum_extra;
}
assert_msg(ptr->ketama.continuum, "Programmer Error, empty ketama continuum");
}
assert_msg(ptr->ketama.continuum, "Programmer Error, empty ketama continuum");
float pct= (float)list[host_index].weight / (float)total_weight;
pointer_per_server= (uint32_t) ((::floor((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4);
pointer_per_hash= 4;
float pct= (float)list[host_index].weight / (float)total_weight;
pointer_per_server= (uint32_t) ((::floor((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4);
pointer_per_hash= 4;
{
printf("ketama_weighted:%s|%d|%llu|%u\n",
list[host_index]._hostname,
{
printf("ketama_weighted:%s|%d|%llu|%u\n",
list[host_index]._hostname,
memcached_literal_param("snprintf(sizeof(sort_host))"));
}
memcached_literal_param("snprintf(sizeof(sort_host))"));
}
{
fprintf(stdout, "update_continuum: key is %s\n", sort_host);
}
{
fprintf(stdout, "update_continuum: key is %s\n", sort_host);
}
test_return_t memcached_server_many_weighted_TEST(memcached_st* memc)
{
test_return_t memcached_server_many_weighted_TEST(memcached_st* memc)
{
ASSERT_EQ(0, memcached_server_count(memc));
in_port_t base_port= 5555;
ASSERT_EQ(0, memcached_server_count(memc));
in_port_t base_port= 5555;
{
std::string hostname(random_hostname());
ASSERT_TRUE(hostname.size());
{
std::string hostname(random_hostname());
ASSERT_TRUE(hostname.size());
- test_compare(MEMCACHED_SUCCESS, memcached_server_add_with_weight(memc, hostname.c_str(), base_port +x, random() % 10));
+ test_compare(MEMCACHED_SUCCESS, memcached_server_add_with_weight(memc, hostname.c_str(), base_port +x, x % 10));