daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Dec 28th, 2018 29 in 345 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/include/proto/lb_chash.h b/include/proto/lb_chash.h
  2. index a0ebf696e..679dff363 100644
  3. --- a/include/proto/lb_chash.h
  4. +++ b/include/proto/lb_chash.h
  5. @@ -28,7 +28,7 @@
  6.  
  7.  void chash_init_server_tree(struct proxy *p);
  8.  struct server *chash_get_next_server(struct proxy *p, struct server *srvtoavoid);
  9. -struct server *chash_get_server_hash(struct proxy *p, unsigned int hash);
  10. +struct server *chash_get_server_hash(struct proxy *p, unsigned int hash, const struct server *avoid);
  11.  
  12.  #endif /* _PROTO_LB_CHASH_H */
  13.  
  14. diff --git a/src/backend.c b/src/backend.c
  15. index bc38c5710..95b7cd4fa 100644
  16. --- a/src/backend.c
  17. +++ b/src/backend.c
  18. @@ -165,7 +165,7 @@ void update_backend_weight(struct proxy *px)
  19.   * If any server is found, it will be returned. If no valid server is found,
  20.   * NULL is returned.
  21.   */
  22. -static struct server *get_server_sh(struct proxy *px, const char *addr, int len)
  23. +static struct server *get_server_sh(struct proxy *px, const char *addr, int len, const struct server *avoid)
  24.  {
  25.     unsigned int h, l;
  26.  
  27. @@ -186,7 +186,7 @@ static struct server *get_server_sh(struct proxy *px, const char *addr, int len)
  28.         h = full_hash(h);
  29.   hash_done:
  30.     if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
  31. -       return chash_get_server_hash(px, h);
  32. +       return chash_get_server_hash(px, h, avoid);
  33.     else
  34.         return map_get_server_hash(px, h);
  35.  }
  36. @@ -203,7 +203,7 @@ static struct server *get_server_sh(struct proxy *px, const char *addr, int len)
  37.   * algorithm out of a tens because it gave him the best results.
  38.   *
  39.   */
  40. -static struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
  41. +static struct server *get_server_uh(struct proxy *px, char *uri, int uri_len, const struct server *avoid)
  42.  {
  43.     unsigned int hash = 0;
  44.     int c;
  45. @@ -239,7 +239,7 @@ static struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
  46.         hash = full_hash(hash);
  47.   hash_done:
  48.     if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
  49. -       return chash_get_server_hash(px, hash);
  50. +       return chash_get_server_hash(px, hash, avoid);
  51.     else
  52.         return map_get_server_hash(px, hash);
  53.  }
  54. @@ -253,7 +253,7 @@ static struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
  55.   * is returned. If any server is found, it will be returned. If no valid server
  56.   * is found, NULL is returned.
  57.   */
  58. -static struct server *get_server_ph(struct proxy *px, const char *uri, int uri_len)
  59. +static struct server *get_server_ph(struct proxy *px, const char *uri, int uri_len, const struct server *avoid)
  60.  {
  61.     unsigned int hash = 0;
  62.     const char *start, *end;
  63. @@ -296,7 +296,7 @@ static struct server *get_server_ph(struct proxy *px, const char *uri, int uri_l
  64.                     hash = full_hash(hash);
  65.  
  66.                 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
  67. -                   return chash_get_server_hash(px, hash);
  68. +                   return chash_get_server_hash(px, hash, avoid);
  69.                 else
  70.                     return map_get_server_hash(px, hash);
  71.             }
  72. @@ -315,7 +315,7 @@ static struct server *get_server_ph(struct proxy *px, const char *uri, int uri_l
  73.  /*
  74.   * this does the same as the previous server_ph, but check the body contents
  75.   */
  76. -static struct server *get_server_ph_post(struct stream *s)
  77. +static struct server *get_server_ph_post(struct stream *s, const struct server *avoid)
  78.  {
  79.     unsigned int hash = 0;
  80.     struct http_txn *txn  = s->txn;
  81. @@ -370,7 +370,7 @@ static struct server *get_server_ph_post(struct stream *s)
  82.                     hash = full_hash(hash);
  83.  
  84.                 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
  85. -                   return chash_get_server_hash(px, hash);
  86. +                   return chash_get_server_hash(px, hash, avoid);
  87.                 else
  88.                     return map_get_server_hash(px, hash);
  89.             }
  90. @@ -396,7 +396,7 @@ static struct server *get_server_ph_post(struct stream *s)
  91.   * is returned. If any server is found, it will be returned. If no valid server
  92.   * is found, NULL is returned.
  93.   */
  94. -static struct server *get_server_hh(struct stream *s)
  95. +static struct server *get_server_hh(struct stream *s, const struct server *avoid)
  96.  {
  97.     unsigned int hash = 0;
  98.     struct http_txn *txn  = s->txn;
  99. @@ -466,13 +466,13 @@ static struct server *get_server_hh(struct stream *s)
  100.         hash = full_hash(hash);
  101.   hash_done:
  102.     if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
  103. -       return chash_get_server_hash(px, hash);
  104. +       return chash_get_server_hash(px, hash, avoid);
  105.     else
  106.         return map_get_server_hash(px, hash);
  107.  }
  108.  
  109.  /* RDP Cookie HASH.  */
  110. -static struct server *get_server_rch(struct stream *s)
  111. +static struct server *get_server_rch(struct stream *s, const struct server *avoid)
  112.  {
  113.     unsigned int hash = 0;
  114.     struct proxy    *px   = s->be;
  115. @@ -511,13 +511,13 @@ static struct server *get_server_rch(struct stream *s)
  116.         hash = full_hash(hash);
  117.   hash_done:
  118.     if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
  119. -       return chash_get_server_hash(px, hash);
  120. +       return chash_get_server_hash(px, hash, avoid);
  121.     else
  122.         return map_get_server_hash(px, hash);
  123.  }
  124.  
  125.  /* random value  */
  126. -static struct server *get_server_rnd(struct stream *s)
  127. +static struct server *get_server_rnd(struct stream *s, const struct server *avoid)
  128.  {
  129.     unsigned int hash = 0;
  130.     struct proxy  *px = s->be;
  131. @@ -528,7 +528,7 @@ static struct server *get_server_rnd(struct stream *s)
  132.  
  133.     /* ensure all 32 bits are covered as long as RAND_MAX >= 65535 */
  134.     hash = ((uint64_t)random() * ((uint64_t)RAND_MAX + 1)) ^ random();
  135. -   return chash_get_server_hash(px, hash);
  136. +   return chash_get_server_hash(px, hash, avoid);
  137.  }
  138.  
  139.  /*
  140. @@ -639,7 +639,7 @@ int assign_server(struct stream *s)
  141.         case BE_LB_LKUP_MAP:
  142.             if ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR) {
  143.                 if ((s->be->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM)
  144. -                   srv = get_server_rnd(s);
  145. +                   srv = get_server_rnd(s, prev_srv);
  146.                 else if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
  147.                     srv = chash_get_next_server(s->be, prev_srv);
  148.                 else
  149. @@ -658,12 +658,12 @@ int assign_server(struct stream *s)
  150.                 if (conn && conn->addr.from.ss_family == AF_INET) {
  151.                     srv = get_server_sh(s->be,
  152.                                 (void *)&((struct sockaddr_in *)&conn->addr.from)->sin_addr,
  153. -                               4);
  154. +                               4, prev_srv);
  155.                 }
  156.                 else if (conn && conn->addr.from.ss_family == AF_INET6) {
  157.                     srv = get_server_sh(s->be,
  158.                                 (void *)&((struct sockaddr_in6 *)&conn->addr.from)->sin6_addr,
  159. -                               16);
  160. +                               16, prev_srv);
  161.                 }
  162.                 else {
  163.                     /* unknown IP family */
  164. @@ -678,7 +678,7 @@ int assign_server(struct stream *s)
  165.                     break;
  166.                 srv = get_server_uh(s->be,
  167.                             c_ptr(&s->req, -http_uri_rewind(&s->txn->req)),
  168. -                           s->txn->req.sl.rq.u_l);
  169. +                           s->txn->req.sl.rq.u_l, prev_srv);
  170.                 break;
  171.  
  172.             case BE_LB_HASH_PRM:
  173. @@ -688,22 +688,22 @@ int assign_server(struct stream *s)
  174.  
  175.                 srv = get_server_ph(s->be,
  176.                             c_ptr(&s->req, -http_uri_rewind(&s->txn->req)),
  177. -                           s->txn->req.sl.rq.u_l);
  178. +                           s->txn->req.sl.rq.u_l, prev_srv);
  179.  
  180.                 if (!srv && s->txn->meth == HTTP_METH_POST)
  181. -                   srv = get_server_ph_post(s);
  182. +                   srv = get_server_ph_post(s, prev_srv);
  183.                 break;
  184.  
  185.             case BE_LB_HASH_HDR:
  186.                 /* Header Parameter hashing */
  187.                 if (!s->txn || s->txn->req.msg_state < HTTP_MSG_BODY)
  188.                     break;
  189. -               srv = get_server_hh(s);
  190. +               srv = get_server_hh(s, prev_srv);
  191.                 break;
  192.  
  193.             case BE_LB_HASH_RDP:
  194.                 /* RDP Cookie hashing */
  195. -               srv = get_server_rch(s);
  196. +               srv = get_server_rch(s, prev_srv);
  197.                 break;
  198.  
  199.             default:
  200. diff --git a/src/lb_chash.c b/src/lb_chash.c
  201. index 7e188ac41..25ab25e69 100644
  202. --- a/src/lb_chash.c
  203. +++ b/src/lb_chash.c
  204. @@ -313,9 +313,10 @@ int chash_server_is_eligible(struct server *s)
  205.   * the closest distance from the value of <hash>. Doing so ensures that even
  206.   * with a well imbalanced hash, if some servers are close to each other, they
  207.   * will still both receive traffic. If any server is found, it will be returned.
  208. + * It will also skip server <avoid> if the hash result ends on this one.
  209.   * If no valid server is found, NULL is returned.
  210.   */
  211. -struct server *chash_get_server_hash(struct proxy *p, unsigned int hash)
  212. +struct server *chash_get_server_hash(struct proxy *p, unsigned int hash, const struct server *avoid)
  213.  {
  214.     struct eb32_node *next, *prev;
  215.     struct server *nsrv, *psrv;
  216. @@ -367,7 +368,7 @@ struct server *chash_get_server_hash(struct proxy *p, unsigned int hash)
  217.     }
  218.  
  219.     loop = 0;
  220. -   while (p->lbprm.chash.balance_factor && !chash_server_is_eligible(nsrv)) {
  221. +   while (p->lbprm.chash.balance_factor && (nsrv == avoid || !chash_server_is_eligible(nsrv))) {
  222.         next = eb32_next(next);
  223.         if (!next) {
  224.             next = eb32_first(root);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand