From: Vsevolod Stakhov Date: Tue, 23 Dec 2014 13:42:14 +0000 (+0000) Subject: Add sequential order for upstreams. X-Git-Tag: 0.8.0~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ba06982886382ec25a53b1672fe04d6b97a7a461;p=rspamd.git Add sequential order for upstreams. --- diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index f4705b229..d2c1d2ee0 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -64,6 +64,7 @@ struct upstream_list { GPtrArray *alive; rspamd_mutex_t *lock; guint64 hash_seed; + guint cur_elt; }; static struct rdns_resolver *res = NULL; @@ -354,6 +355,7 @@ rspamd_upstreams_create (void) ls->ups = g_ptr_array_new (); ls->alive = g_ptr_array_new (); ls->lock = rspamd_mutex_new (); + ls->cur_elt = 0; return ls; } @@ -678,5 +680,12 @@ rspamd_upstream_get (struct upstream_list *ups, return rspamd_upstream_get_round_robin (ups, TRUE); case RSPAMD_UPSTREAM_MASTER_SLAVE: return rspamd_upstream_get_round_robin (ups, FALSE); + case RSPAMD_UPSTREAM_SEQUENTIAL: + if (ups->cur_elt >= ups->alive->len) { + ups->cur_elt = 0; + return NULL; + } + + return g_ptr_array_index (ups->alive, ups->cur_elt ++); } } diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index cff6acfb1..8c399ab03 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -10,7 +10,8 @@ enum rspamd_upstream_rotation { RSPAMD_UPSTREAM_RANDOM, RSPAMD_UPSTREAM_HASHED, RSPAMD_UPSTREAM_ROUND_ROBIN, - RSPAMD_UPSTREAM_MASTER_SLAVE + RSPAMD_UPSTREAM_MASTER_SLAVE, + RSPAMD_UPSTREAM_SEQUENTIAL };