Quantcast
Channel: Serverphorums.com - HAProxy
Viewing all articles
Browse latest Browse all 5112

[PATCH] Properly handle weight increase with consistent weight (1 reply)

$
0
0
Hi,

When consistent hash is used, when the weight of the server is increased
beyond the original one, it currently has no effect (well really it will
reset the weight to the original one, if it was decreased), to fix this,
the attached patch allocates more nodes, and add them to the ebtree as needed.

Regards,

Olivier
From a8d290e08d4820fe5058ba00fd4ef762e562cb69 Mon Sep 17 00:00:00 2001
From: Olivier Houchard <ohouchard@haproxy.com>
Date: Tue, 17 Oct 2017 15:52:59 +0200
Subject: [PATCH] MINOR: server: Handle weight increase in consistent hash.

When the server weight is rised using the CLI, extra nodes have to be
allocated, or the weight will be effectively the same as the original one.
---
src/lb_chash.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/src/lb_chash.c b/src/lb_chash.c
index 82124bc27..f368b684e 100644
--- a/src/lb_chash.c
+++ b/src/lb_chash.c
@@ -78,6 +78,25 @@ static inline void chash_queue_dequeue_srv(struct server *s)
eb32_delete(&s->lb_nodes[s->lb_nodes_now].node);
}

+ /* Attempt to increase the total number of nodes, if the user
+ * increased the weight beyond the original weight
+ */
+ if (s->lb_nodes_tot < s->next_eweight) {
+ struct tree_occ *new_nodes = realloc(s->lb_nodes, s->next_eweight);
+
+ if (new_nodes) {
+ unsigned int j;
+
+ s->lb_nodes = new_nodes;
+ memset(&s->lb_nodes[s->lb_nodes_tot], 0,
+ (s->next_eweight - s->lb_nodes_tot) * sizeof(*s->lb_nodes));
+ for (j = s->lb_nodes_tot; j < s->next_eweight; j++) {
+ s->lb_nodes[j].server = s;
+ s->lb_nodes[j].node.key = full_hash(s->puid * SRV_EWGHT_RANGE + j);
+ }
+ s->lb_nodes_tot = s->next_eweight;
+ }
+ }
while (s->lb_nodes_now < s->next_eweight) {
if (s->lb_nodes_now >= s->lb_nodes_tot) // should always be false anyway
break;
--
2.13.5

Viewing all articles
Browse latest Browse all 5112

Trending Articles