memcached_return memcachd_key_test(char **keys, size_t *key_length,
unsigned int number_of_keys);
+void sort_hosts(memcached_st *ptr);
+
#endif /* __COMMON_H__ */
set_behavior_flag(ptr, MEM_USE_KETAMA, data);
break;
case MEMCACHED_BEHAVIOR_SORT_HOSTS:
- set_behavior_flag(ptr, MEM_USE_SORT_HOSTS, data);
- break;
+ {
+ set_behavior_flag(ptr, MEM_USE_SORT_HOSTS, data);
+
+ if (ptr->flags & MEM_USE_SORT_HOSTS)
+ {
+ memcached_quit(ptr);
+ sort_hosts(ptr);
+ }
+
+ break;
+ }
case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
ptr->poll_timeout= (int32_t)data;
break;
return return_value;
}
+void sort_hosts(memcached_st *ptr)
+{
+ qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers);
+}
+
static void host_reset(memcached_st *ptr, memcached_server_st *host,
char *hostname, unsigned int port,
memcached_connection type)
ptr->hosts[0].count= ptr->number_of_hosts;
if (ptr->number_of_hosts > 1 && ptr->flags & MEM_USE_SORT_HOSTS)
- qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers);
+ sort_hosts(ptr);
rebalance_wheel(ptr);
ptr->number_of_hosts++;
if (ptr->number_of_hosts > 1 && ptr->flags & MEM_USE_SORT_HOSTS)
- qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers);
+ sort_hosts(ptr);
ptr->hosts[0].count= ptr->number_of_hosts;
{
uint8_t x;
uint32_t counter= 0; /* Prime the value for the assert in server_display_function */
+ uint32_t bigger= 0; /* Prime the value for the assert in server_display_function */
memcached_return rc;
memcached_server_function callbacks[1];
memcached_st *local_memc;
callbacks[0]= server_display_unsort_function;
memcached_server_cursor(local_memc, callbacks, (void *)&counter, 1);
+ /* Now we sort old data! */
+ memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1);
+ callbacks[0]= server_display_function;
+ memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1);
+
memcached_free(local_memc);