]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log/balance: support for the "sticky" lb algorithm
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 21 Sep 2023 18:24:14 +0000 (20:24 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 13 Oct 2023 08:05:06 +0000 (10:05 +0200)
sticky algorithm always tries to send log messages to the first server in
the farm. The server will stay in front during queue and dequeue
operations (no other server can steal its place), unless it becomes
unavailable, in which case it will be replaced by another server from
the tree.

doc/configuration.txt
src/backend.c
src/log.c

index 584d604236dac700dc33a8141f21b3dfbd90b807..6c903fcd50192018bacc1181d5862961f6e29600 100644 (file)
@@ -8833,6 +8833,12 @@ log-balance <algorithm> [ <arguments> ]
                   fairest algorithm when the server's processing time remains
                   equally distributed.
 
+      sticky      The first server in the list of available servers receives all
+                  the log messages. When the server goes DOWN, the next server
+                  in the list takes its place. When a previously DOWN server
+                  goes back UP it is added at the end of the list so that the
+                  sticky server doesn't change until it becomes DOWN.
+
     <arguments> is an optional list of arguments which may be needed by some
                 algorithms.
 
index 190e95ee12186ec28ce2bcc616e4a905fa3f7a36..8b76a9343e0d62e1536508dcdb063940a65e33f6 100644 (file)
@@ -2844,8 +2844,13 @@ int backend_parse_log_balance(const char **args, char **err, struct proxy *curpr
                curproxy->lbprm.algo &= ~BE_LB_ALGO;
                curproxy->lbprm.algo |= BE_LB_ALGO_RR;
        }
+       else if (strcmp(args[0], "sticky") == 0) {
+               curproxy->lbprm.algo &= ~BE_LB_ALGO;
+               /* we use ALGO_FAS as "sticky" mode in log-balance context */
+               curproxy->lbprm.algo |= BE_LB_ALGO_FAS;
+       }
        else {
-               memprintf(err, "only supports 'roundrobin' option");
+               memprintf(err, "only supports 'roundrobin', 'sticky' options");
                return -1;
        }
        return 0;
index 7f01ddf93ae2f139f6b8dde37b98f46c47444966..6900407a41e46e6475be81fd3a3a28a1e1087df0 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2109,6 +2109,13 @@ static inline void __do_send_log_backend(struct proxy *be, struct log_header hdr
                 */
                targetid = HA_ATOMIC_FETCH_ADD(&be->lbprm.log.lastid, 1) % nb_srv;
        }
+       else if ((be->lbprm.algo & BE_LB_ALGO) == BE_LB_ALGO_FAS) {
+               /* sticky mode: use first server in the pool, which will always stay
+                * first during dequeuing and requeuing, unless it becomes unavailable
+                * and will be replaced by another one
+                */
+               targetid = 0;
+       }
 
  skip_lb: