You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.2 KiB

  1. From 74ffd0cd0cecaeec3cfa848cbc03beb08999cc72 Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Thu, 3 Nov 2016 18:19:49 +0100
  4. Subject: [PATCH 28/31] BUG/MEDIUM: srv-state: properly restore the DRAIN state
  5. There were seveal reports about the DRAIN state not being properly
  6. restored upon reload.
  7. It happens that the condition in the code does exactly the opposite
  8. of what the comment says, and the comment is right so the code is
  9. wrong.
  10. It's worth noting that the conditions are complex here due to the 2
  11. available methods to set the drain state (CLI/agent, and config's
  12. weight). To paraphrase the updated comment in the code, there are
  13. two possible reasons for FDRAIN to have been present :
  14. - previous config weight was zero
  15. - "set server b/s drain" was sent to the CLI
  16. In the first case, we simply want to drop this drain state if the new
  17. weight is not zero anymore, meaning the administrator has intentionally
  18. turned the weight back to a positive value to enable the server again
  19. after an operation. In the second case, the drain state was forced on
  20. the CLI regardless of the config's weight so we don't want a change to
  21. the config weight to lose this status. What this means is :
  22. - if previous weight was 0 and new one is >0, drop the DRAIN state.
  23. - if the previous weight was >0, keep it.
  24. This fix must be backported to 1.6.
  25. (cherry picked from commit 22cace2f4c3cbeca27c1941c647e7ae38ec8c0c0)
  26. ---
  27. src/server.c | 22 +++++++++++++++-------
  28. 1 file changed, 15 insertions(+), 7 deletions(-)
  29. diff --git a/src/server.c b/src/server.c
  30. index 79b3cb2..b9e72b7 100644
  31. --- a/src/server.c
  32. +++ b/src/server.c
  33. @@ -2093,15 +2093,23 @@ static void srv_update_state(struct server *srv, int version, char **params)
  34. /* apply drain mode if server is currently enabled */
  35. if (!(srv->admin & SRV_ADMF_FMAINT) && (srv_admin_state & SRV_ADMF_FDRAIN)) {
  36. /* The SRV_ADMF_FDRAIN flag is inherited when srv->iweight is 0
  37. - * (srv->iweight is the weight set up in configuration)
  38. - * so we don't want to apply it when srv_iweight is 0 and
  39. - * srv->iweight is greater than 0. Purpose is to give the
  40. - * chance to the admin to re-enable this server from configuration
  41. - * file by setting a new weight > 0.
  42. + * (srv->iweight is the weight set up in configuration).
  43. + * There are two possible reasons for FDRAIN to have been present :
  44. + * - previous config weight was zero
  45. + * - "set server b/s drain" was sent to the CLI
  46. + *
  47. + * In the first case, we simply want to drop this drain state
  48. + * if the new weight is not zero anymore, meaning the administrator
  49. + * has intentionally turned the weight back to a positive value to
  50. + * enable the server again after an operation. In the second case,
  51. + * the drain state was forced on the CLI regardless of the config's
  52. + * weight so we don't want a change to the config weight to lose this
  53. + * status. What this means is :
  54. + * - if previous weight was 0 and new one is >0, drop the DRAIN state.
  55. + * - if the previous weight was >0, keep it.
  56. */
  57. - if ((srv_iweight == 0) && (srv->iweight > 0)) {
  58. + if (srv_iweight > 0 || srv->iweight == 0)
  59. srv_adm_set_drain(srv);
  60. - }
  61. }
  62. srv->last_change = date.tv_sec - srv_last_time_change;
  63. --
  64. 2.7.3