if (strcmp(args[i], DIRECTOR_OPT_CONSISTENT_HASHING) == 0)
consistent_hashing = TRUE;
}
- if (consistent_hashing != conn->dir->set->director_consistent_hashing) {
- i_error("director(%s): director_consistent_hashing settings differ between directors",
+ if (!consistent_hashing) {
+ i_error("director(%s): director_consistent_hashing settings "
+ "differ between directors. Set "
+ "director_consistent_hashing=yes on old directors",
conn->name);
return -1;
}
{
i_assert(conn->version_received);
- if (!conn->dir->set->director_consistent_hashing)
- ;
- else if (conn->minor_version >= DIRECTOR_VERSION_OPTIONS) {
+ if (conn->minor_version >= DIRECTOR_VERSION_OPTIONS) {
director_connection_send(conn,
"OPTIONS\t"DIRECTOR_OPT_CONSISTENT_HASHING"\n");
} else {
DEF(SET_STR, director_flush_socket),
DEF(SET_TIME, director_user_expire),
DEF(SET_TIME, director_user_kick_delay),
- DEF(SET_BOOL, director_consistent_hashing),
SETTING_DEFINE_LIST_END
};
.director_flush_socket = "",
.director_user_expire = 60*15,
.director_user_kick_delay = 2,
- .director_consistent_hashing = TRUE
};
const struct setting_parser_info director_setting_parser_info = {
user_free_hook_t *user_free_hook;
unsigned int hosts_hash;
unsigned int user_expire_secs;
- bool consistent_hashing;
bool vhosts_unsorted;
bool have_vhosts;
};
array_sort(&tag->vhosts, mail_vhost_cmp);
}
-static void
-mail_tag_vhosts_sort_direct(struct mail_host_list *list, struct mail_tag *tag)
-{
- struct mail_vhost *vhost;
- struct mail_host *const *hostp;
- unsigned int i;
-
- /* rebuild vhosts */
- array_clear(&tag->vhosts);
- array_foreach(&list->hosts, hostp) {
- if ((*hostp)->down || (*hostp)->tag != tag)
- continue;
- for (i = 0; i < (*hostp)->vhost_count; i++) {
- vhost = array_append_space(&tag->vhosts);
- vhost->host = *hostp;
- }
- }
-}
-
static void
mail_hosts_sort(struct mail_host_list *list)
{
list->have_vhosts = FALSE;
array_foreach(&list->tags, tagp) {
- if (list->consistent_hashing)
- mail_tag_vhosts_sort_ring(list, *tagp);
- else
- mail_tag_vhosts_sort_direct(list, *tagp);
+ mail_tag_vhosts_sort_ring(list, *tagp);
if (array_count(&(*tagp)->vhosts) > 0)
list->have_vhosts = TRUE;
}
return vhosts[idx % count].host;
}
-static struct mail_host *
-mail_host_get_by_hash_direct(struct mail_tag *tag, unsigned int hash)
-{
- const struct mail_vhost *vhosts;
- unsigned int count;
-
- vhosts = array_get(&tag->vhosts, &count);
- if (count == 0)
- return NULL;
- return vhosts[hash % count].host;
-}
-
struct mail_host *
mail_host_get_by_hash(struct mail_host_list *list, unsigned int hash,
const char *tag_name)
if (tag == NULL)
return NULL;
- if (list->consistent_hashing)
- return mail_host_get_by_hash_ring(tag, hash);
- else
- return mail_host_get_by_hash_direct(tag, hash);
+ return mail_host_get_by_hash_ring(tag, hash);
}
void mail_hosts_set_synced(struct mail_host_list *list)
}
struct mail_host_list *
-mail_hosts_init(unsigned int user_expire_secs, bool consistent_hashing,
+mail_hosts_init(unsigned int user_expire_secs,
user_free_hook_t *user_free_hook)
{
struct mail_host_list *list;
list = i_new(struct mail_host_list, 1);
list->user_expire_secs = user_expire_secs;
- list->consistent_hashing = consistent_hashing;
list->user_free_hook = user_free_hook;
i_array_init(&list->hosts, 16);
struct mail_host_list *dest;
struct mail_host *const *hostp, *dest_host;
- dest = mail_hosts_init(src->user_expire_secs, src->consistent_hashing,
- src->user_free_hook);
+ dest = mail_hosts_init(src->user_expire_secs, src->user_free_hook);
array_foreach(&src->hosts, hostp) {
dest_host = mail_host_dup(dest, *hostp);
array_append(&dest->hosts, &dest_host, 1);