]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MEDIUM: server: set the macro for server's max weight SRV_UWGHT_MAX to SRV_UWGHT_...
authorGodbach <nylzhaowei@gmail.com>
Sun, 21 Jul 2013 23:44:53 +0000 (07:44 +0800)
committerWilly Tarreau <w@1wt.eu>
Mon, 22 Jul 2013 07:29:34 +0000 (09:29 +0200)
commita34bdc0ea402ea5be1e9d7f80eaddec772b94393
treeef1eb62aecd88d8305fd1aa84a2e5fb61b68b2fa
parent506d050600ffa767345766bdc19752284c971a9f
BUG/MEDIUM: server: set the macro for server's max weight SRV_UWGHT_MAX to SRV_UWGHT_RANGE

The max weight of server is 256 now, but SRV_UWGHT_MAX is still 255. As a result,
FWRR will not work well when server's weight is 256. The description is as below:

There are some macros related to server's weight in include/types/server.h:
    #define SRV_UWGHT_RANGE 256
    #define SRV_UWGHT_MAX   (SRV_UWGHT_RANGE - 1)
    #define SRV_EWGHT_MAX   (SRV_UWGHT_MAX   * BE_WEIGHT_SCALE)

Since weight of server can be reach to 256 and BE_WEIGHT_SCALE equals to 16,
the max eweight of server should be 256*16 = 4096, it will exceed SRV_EWGHT_MAX
which equals to SRV_UWGHT_MAX*BE_WEIGHT_SCALE = 255*16 = 4080. When a server
with weight 256 is insterted into FWRR tree during initialization, the key value
of this server should be SRV_EWGHT_MAX - s->eweight = 4080 - 4096 = -16 which
is closed to UINT_MAX in unsigned type, so the server with highest weight will
be not elected as the first server to process request.

In addition, it is a better choice to compare with SRV_UWGHT_MAX than a magic
number 256 while doing check for the weight. The max number of servers for
round-robin algorithm is also updated.

Signed-off-by: Godbach <nylzhaowei@gmail.com>
doc/configuration.txt
include/types/backend.h
include/types/server.h
src/cfgparse.c
src/lb_fwrr.c