+ uint32_t is_auto_ejecting= 0;
+ uint32_t points_per_server= 0;
+ uint32_t live_servers= 0;
+ struct timeval now;
+
+ if (gettimeofday(&now, NULL) != 0)
+ {
+ ptr->cached_errno = errno;
+ return MEMCACHED_ERRNO;
+ }
+
+ list = ptr->hosts;
+
+ /* count live servers (those without a retry delay set) */
+ is_auto_ejecting= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS);
+ if (is_auto_ejecting)
+ {
+ live_servers= 0;
+ ptr->next_distribution_rebuild= 0;
+ for (host_index= 0; host_index < ptr->number_of_hosts; ++host_index)
+ {
+ if (list[host_index].next_retry <= now.tv_sec)
+ live_servers++;
+ else
+ {
+ if (ptr->next_distribution_rebuild == 0 || list[host_index].next_retry < ptr->next_distribution_rebuild)
+ ptr->next_distribution_rebuild= list[host_index].next_retry;
+ }
+ }
+ }
+ else
+ live_servers= ptr->number_of_hosts;
+
+ is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
+ points_per_server= is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER;
+
+ if (live_servers == 0)
+ return MEMCACHED_SUCCESS;