---
 include/types/queue.h |   2 +-
 src/hlua.c            |   5 --
 src/queue.c           | 144
+++++++++++---------------------------------------
 3 files changed, 33 insertions(+), 118 deletions(-)


diff --git a/include/types/queue.h b/include/types/queue.h
index 03377da69..5f4693942 100644
--- a/include/types/queue.h
+++ b/include/types/queue.h
@@ -35,7 +35,7 @@ struct pendconn {
 	struct stream *strm;
 	struct proxy  *px;
 	struct server *srv;        /* the server we are waiting for, may be NULL */
-	struct eb32_node node;
+	struct eb64_node node;
 	__decl_hathreads(HA_SPINLOCK_T lock);
 };
 
diff --git a/src/hlua.c b/src/hlua.c
index 6e727648d..dd7311ff8 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -5351,11 +5351,6 @@ __LJMP static int hlua_txn_set_priority_offset(lua_State *L)
 	htxn = MAY_LJMP(hlua_checktxn(L, 1));
 	offset = MAY_LJMP(luaL_checkinteger(L, 2));
 
-	if (offset < -0x7ffff)
-		offset = -0x7ffff;
-	else if (offset > 0x7ffff)
-		offset = 0x7ffff;
-
 	htxn->s->priority_offset = offset;
 
 	return 0;
diff --git a/src/queue.c b/src/queue.c
index cf445f97d..0f86fdb36 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -14,7 +14,7 @@
 #include <common/memory.h>
 #include <common/time.h>
 #include <common/hathreads.h>
-#include <eb32tree.h>
+#include <eb64tree.h>
 
 #include <proto/proto_http.h>
 #include <proto/queue.h>
@@ -26,23 +26,6 @@
 #include <proto/tcp_rules.h>
 
 
-#define NOW_OFFSET_BOUNDARY() (now_ms - (TIMER_LOOK_BACK >> 12) & 0xfffff)
-#define KEY_CLASS(key) (key & 0xfff00000)
-#define KEY_OFFSET(key) (key & 0xfffff)
-#define KEY_CLASS_BOUNDARY(key) (KEY_CLASS(key) | NOW_OFFSET_BOUNDARY())
-
-static u32 key_incr(u32 key) {
-	u32 key_next = key + 1;
-
-	if (KEY_CLASS(key_next) != KEY_CLASS(key))
-		key_next = KEY_CLASS(key_next);
-	else if (key_next == KEY_CLASS_BOUNDARY(key))
-		key_next += 0x100000;
-
-	return key_next;
-}
-
-
 struct pool_head *pool_head_pendconn;
 
 /* perform minimal intializations, report 0 in case of error, 1 if OK. */
@@ -100,57 +83,7 @@ static void pendconn_unlink(struct pendconn *p)
 		p->px->nbpend--;
 	}
 	HA_ATOMIC_SUB(&p->px->totpend, 1);
-	eb32_delete(&p->node);
-}
-
-/* Retrieve the next pending connection from the given pendconns ebtree with
- * key >= min.
- *
- * See pendconn_add for an explanation of the key & queue behavior.
- *
- * This function handles all the cases where due to the timestamp wrapping
- * the first node in the tree is not the highest priority.
- */
-static struct pendconn *pendconn_next(struct eb_root *pendconns, u32 min) {
-	struct eb32_node *node, *node2 = NULL;
-	u32 max;
-
-	// min is inclusive
-	// max is exclusive
-	max = KEY_CLASS_BOUNDARY(min);
-
-	node = eb32_lookup_ge(pendconns, min);
-
-	if (node) {
-		if (node->key < max || (max <= min && KEY_CLASS(node->key) == KEY_CLASS(min)))
-			return eb32_entry(node, struct pendconn, node);
-		if (KEY_CLASS(node->key) != KEY_CLASS(min))
-			node2 = node;
-		if (max > min)
-			goto class_next;
-	}
-
-	if (max <= min)
-		node = eb32_lookup_ge(pendconns, KEY_CLASS(min));
-	if (!node)
-		return NULL;
-	if (node->key < max && node->key < min)
-		return eb32_entry(node, struct pendconn, node);
-
-class_next:
-	if (node2) {
-		min = KEY_CLASS_BOUNDARY(node2->key);
-		if (node2->key >= min)
-			return eb32_entry(node2, struct pendconn, node);
-	} else
-		min = KEY_CLASS_BOUNDARY(min) + 0x100000;
-	node = eb32_lookup_ge(pendconns, min);
-	if (node && KEY_CLASS(node->key) == KEY_CLASS(min))
-		return eb32_entry(node, struct pendconn, node);
-	if (node2)
-		return eb32_entry(node2, struct pendconn, node);
-
-	return NULL;
+	eb64_delete(&p->node);
 }
 
 /* Process the next pending connection from either a server or a proxy, and
@@ -174,8 +107,8 @@ class_next:
 static int pendconn_process_next_strm(struct server *srv, struct proxy *px)
 {
 	struct pendconn *p = NULL, *pp = NULL;
+	struct eb64_node *node;
 	struct server   *rsrv;
-	u32 pkey, ppkey;
 	int remote;
 
 	rsrv = srv->track;
@@ -183,18 +116,26 @@ static int pendconn_process_next_strm(struct server *srv, struct proxy *px)
 		rsrv = srv;
 
 	if (srv->nbpend) {
-		for (p = pendconn_next(&srv->pendconns, NOW_OFFSET_BOUNDARY());
-		     p;
-		     p = pendconn_next(&srv->pendconns, key_incr(p->node.key)))
+		for (node = eb64_first(&srv->pendconns);
+		     node;
+				 node = eb64_lookup_ge(&srv->pendconns, node->key + 1)) {
+			p = eb64_entry(node, struct pendconn, node);
 			if (!HA_SPIN_TRYLOCK(PENDCONN_LOCK, &p->lock))
 				break;
+		}
+		if (!node)
+			p = NULL;
 	}
 	if (px->nbpend) {
-		for (pp = pendconn_next(&px->pendconns, NOW_OFFSET_BOUNDARY());
-		     pp;
-		     pp = pendconn_next(&px->pendconns, key_incr(pp->node.key)))
+		for (node = eb64_first(&px->pendconns);
+		     node;
+		     node = eb64_lookup_ge(&px->pendconns, node->key + 1)) {
+			pp = eb64_entry(node, struct pendconn, node);
 			if (!HA_SPIN_TRYLOCK(PENDCONN_LOCK, &pp->lock))
 				break;
+		}
+		if (!node)
+			pp = NULL;
 	}
 
 	if (!p && !pp)
@@ -206,23 +147,7 @@ static int pendconn_process_next_strm(struct server *srv, struct proxy *px)
 		p = pp;
 		goto pendconn_found;
 	}
-	if (KEY_CLASS(p->node.key) < KEY_CLASS(pp->node.key)) {
-		HA_SPIN_UNLOCK(PENDCONN_LOCK, &pp->lock);
-		goto pendconn_found;
-	}
-	if (KEY_CLASS(pp->node.key) < KEY_CLASS(p->node.key)) {
-		HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
-		p = pp;
-		goto pendconn_found;
-	}
-
-	pkey = KEY_OFFSET(p->node.key);
-	ppkey = KEY_OFFSET(pp->node.key);
-	if (pkey < NOW_OFFSET_BOUNDARY())
-		pkey += 0x100000;
-	if (ppkey < NOW_OFFSET_BOUNDARY())
-		ppkey += 0x100000;
-	if (pkey <= ppkey) {
+	if (p->node.key <= pp->node.key) {
 		HA_SPIN_UNLOCK(PENDCONN_LOCK, &pp->lock);
 	} else {
 		HA_SPIN_UNLOCK(PENDCONN_LOCK, &p->lock);
@@ -307,8 +232,8 @@ struct pendconn *pendconn_add(struct stream *strm)
 	srv = objt_server(strm->target);
 	px  = strm->be;
 
-	p->node.key = ((u32)(strm->priority_class + 0x7ff) << 20) |
-		      ((u32)(now_ms + strm->priority_offset) & 0xfffff);
+	p->node.key = ((u64)(strm->priority_class + 0x7ff) << 52) | 
+		      (((u64)(now.tv_sec) * 1000) + (now.tv_usec / 1000) + strm->priority_offset);
 	p->srv        = NULL;
 	p->px         = px;
 	p->strm       = strm;
@@ -322,7 +247,7 @@ struct pendconn *pendconn_add(struct stream *strm)
 		strm->cntdepend = srv->cntdepend;
 		if (srv->nbpend > srv->counters.nbpend_max)
 			srv->counters.nbpend_max = srv->nbpend;
-		eb32_insert(&srv->pendconns, &p->node);
+		eb64_insert(&srv->pendconns, &p->node);
 		HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
 	}
 	else {
@@ -331,7 +256,7 @@ struct pendconn *pendconn_add(struct stream *strm)
 		strm->cntdepend = px->cntdepend;
 		if (px->nbpend > px->be_counters.nbpend_max)
 			px->be_counters.nbpend_max = px->nbpend;
-		eb32_insert(&px->pendconns, &p->node);
+		eb64_insert(&px->pendconns, &p->node);
 		HA_SPIN_UNLOCK(PROXY_LOCK, &px->lock);
 	}
 	HA_ATOMIC_ADD(&px->totpend, 1);
@@ -345,7 +270,7 @@ struct pendconn *pendconn_add(struct stream *strm)
 int pendconn_redistribute(struct server *s)
 {
 	struct pendconn *p;
-	struct eb32_node *node;
+	struct eb64_node *node;
 	int xferred = 0;
 	int remote = 0;
 
@@ -355,10 +280,10 @@ int pendconn_redistribute(struct server *s)
 		return 0;
 
 	HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
-	for (node = eb32_first(&s->pendconns);
+	for (node = eb64_first(&s->pendconns);
 	     node;
-	     node = eb32_lookup_ge(&s->pendconns, key_incr(node->key))) {
-		p = eb32_entry(&node, struct pendconn, node);
+	     node = eb64_lookup_ge(&s->pendconns, node->key + 1)) {
+		p = eb64_entry(&node, struct pendconn, node);
 		if (p->strm_flags & SF_FORCE_PRST)
 			continue;
 
@@ -388,7 +313,7 @@ int pendconn_redistribute(struct server *s)
 int pendconn_grab_from_px(struct server *s)
 {
 	struct pendconn *p;
-	struct eb32_node *node;
+	struct eb64_node *node;
 	int maxconn, xferred = 0;
 	int remote = 0;
 
@@ -397,10 +322,10 @@ int pendconn_grab_from_px(struct server *s)
 
 	HA_SPIN_LOCK(PROXY_LOCK, &s->proxy->lock);
 	maxconn = srv_dynamic_maxconn(s);
-	for (node = eb32_first(&s->proxy->pendconns);
+	for (node = eb64_first(&s->proxy->pendconns);
 	     node;
-	     node = eb32_lookup_ge(&s->proxy->pendconns, key_incr(node->key))) {
-		p = eb32_entry(&node, struct pendconn, node);
+	     node = eb64_lookup_ge(&s->proxy->pendconns, node->key + 1)) {
+		p = eb64_entry(&node, struct pendconn, node);
 		if (s->maxconn && s->served + xferred >= maxconn)
 			break;
 
@@ -487,14 +412,14 @@ void pendconn_free(struct pendconn *p)
 		HA_SPIN_LOCK(SERVER_LOCK, &p->srv->lock);
 		p->strm->logs.srv_queue_pos += p->srv->cntdepend - p->strm->cntdepend;
 		p->srv->nbpend--;
-		eb32_delete(&p->node);
+		eb64_delete(&p->node);
 		HA_SPIN_UNLOCK(SERVER_LOCK, &p->srv->lock);
 	}
 	else {
 		HA_SPIN_LOCK(PROXY_LOCK, &p->px->lock);
 		p->strm->logs.prx_queue_pos += p->px->cntdepend - p->strm->cntdepend;
 		p->px->nbpend--;
-		eb32_delete(&p->node);
+		eb64_delete(&p->node);
 		HA_SPIN_UNLOCK(PROXY_LOCK, &p->px->lock);
 	}
 	HA_ATOMIC_SUB(&p->px->totpend, 1);
@@ -532,11 +457,6 @@ static enum act_return action_set_priority_offset(struct act_rule *rule, struct
 	if (!smp)
 		return ACT_RET_CONT;
 
-	if (smp->data.u.sint < -0x7ffff)
-		smp->data.u.sint = -0x7ffff;
-	else if (smp->data.u.sint > 0x7ffff)
-		smp->data.u.sint = 0x7ffff;
-
 	s->priority_offset = smp->data.u.sint;
 
 	return ACT_RET_CONT;

Reply via email to