free(ptr->continuum);
}
- if (ptr->wheel)
- {
- if (ptr->call_free)
- ptr->call_free(ptr, ptr->wheel);
- else
- free(ptr->wheel);
- }
-
if (ptr->is_allocated == MEMCACHED_ALLOCATED)
{
if (ptr->call_free)
memcached_hash hash;
memcached_server_distribution distribution;
void *user_data;
- unsigned int *wheel;
- uint32_t wheel_count;
uint32_t continuum_count;
memcached_continuum_item_st *continuum;
memcached_clone_func on_clone;
memcached_trigger_delete_key delete_trigger;
char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
size_t prefix_key_length;
-#ifdef NOT_USED /* Future Use */
- uint8_t replicas;
- memcached_return warning;
-#endif
};
typedef enum {
MEMCACHED_DISTRIBUTION_MODULA,
MEMCACHED_DISTRIBUTION_CONSISTENT,
- MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL,
MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA,
} memcached_server_distribution;
}
}
break;
- case MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL:
- {
- unsigned int server_key;
-
- server_key= hash % MEMCACHED_STRIDE * ptr->wheel_count;
-
- return ptr->wheel[server_key];
- }
case MEMCACHED_DISTRIBUTION_MODULA:
return hash % ptr->number_of_hosts;
default:
memcached_connection type);
memcached_return update_continuum(memcached_st *ptr);
-#define MEMCACHED_WHEEL_SIZE 1024
-#define MEMCACHED_STRIDE 4
-static memcached_return rebalance_wheel(memcached_st *ptr)
-{
- unsigned int x;
- unsigned int y;
- unsigned int latch;
-
- if (ptr->number_of_hosts > ptr->wheel_count)
- {
- uint32_t *new_ptr;
-
- if (ptr->call_realloc)
- new_ptr= (uint32_t *)ptr->call_realloc(ptr, ptr->wheel, sizeof(uint32_t) * (ptr->number_of_hosts + MEMCACHED_CONTINUUM_ADDITION) * MEMCACHED_STRIDE);
- else
- new_ptr= (uint32_t *)realloc(ptr->wheel, sizeof(uint32_t) * (ptr->number_of_hosts + MEMCACHED_CONTINUUM_ADDITION) * MEMCACHED_STRIDE);
-
- if (new_ptr == 0)
- return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
-
- ptr->wheel= new_ptr;
- ptr->wheel_count= ptr->number_of_hosts + MEMCACHED_CONTINUUM_ADDITION;
- }
-
- /* Seed the Wheel */
- memset(ptr->wheel, 0, sizeof(uint32_t) * MEMCACHED_STRIDE * ptr->wheel_count);
-
- for (latch= y= x= 0; x < MEMCACHED_STRIDE * ptr->wheel_count; x++, latch++)
- {
- if (latch == MEMCACHED_STRIDE)
- {
- y++;
- if (y == ptr->number_of_hosts)
- y= 0;
- latch= 0;
- }
-
- ptr->wheel[x]= y;
- }
-
- return MEMCACHED_SUCCESS;
-}
-
static int compare_servers(const void *p1, const void *p2)
{
int return_value;
case MEMCACHED_DISTRIBUTION_CONSISTENT:
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
return update_continuum(ptr);
- case MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL:
- return rebalance_wheel(ptr);
- break;
case MEMCACHED_DISTRIBUTION_MODULA:
if (ptr->flags & MEM_USE_SORT_HOSTS)
sort_hosts(ptr);
return MEMCACHED_SUCCESS;
}
-memcached_return enable_wheel(memcached_st *memc)
-{
- memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL;
- memcached_hash hash;
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
- pre_hsieh(memc);
-
- value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
- assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL);
-
- hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
- assert(hash == MEMCACHED_HASH_HSIEH);
-
-
- return MEMCACHED_SUCCESS;
-}
-
memcached_return enable_consistent(memcached_st *memc)
{
memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT;
{"poll_timeout", poll_timeout, 0, tests},
{"gets", enable_cas, 0, tests},
{"consistent", enable_consistent, 0, tests},
- {"wheel", enable_wheel, 0, tests},
{"memory_allocators", set_memory_alloc, 0, tests},
{"prefix", set_prefix, 0, tests},
// {"udp", pre_udp, 0, tests},
{"generate_nonblock", pre_nonblock, 0, generate_tests},
{"consistent_not", 0, 0, consistent_tests},
{"consistent_ketama", pre_behavior_ketama, 0, consistent_tests},
- {"consistent_wheel", enable_wheel, 0, consistent_tests},
{0, 0, 0, 0}
};