The server ID is currently stored as a 32-bit int using an eb32 tree.
It's used essentially to find holes in order to automatically assign IDs,
and to detect duplicates. Let's change this to use compact trees instead
in order to save 24 bytes in struct server for this node, plus 8 bytes in
struct proxy. The server struct is still 3904 bytes large (due to
alignment) and the proxy struct is 3072.
struct ceb_node uuid_node; /* place in the tree of used IDs, indexes <uuid> above */
int line; /* line where the section appears */
struct ceb_root *used_listener_id; /* list of listener IDs in use */
- struct eb_root used_server_id; /* list of server IDs in use */
+ struct ceb_root *used_server_id; /* list of server IDs in use */
struct ceb_root *used_server_name; /* list of server names in use */
struct list bind; /* list of bind settings */
struct list listeners; /* list of listeners belonging to this frontend */
unsigned int svc_port; /* the port to connect to (for relevant families) */
unsigned down_time; /* total time the server was down */
- int puid; /* proxy-unique server ID, used for SNMP, and "first" LB algo */
+ int puid; /* proxy-unique server ID, used for SNMP, and "first" LB algo, indexed via puid_node below */
int tcp_ut; /* for TCP, user timeout */
char *tcp_md5sig; /* TCP MD5 signature password (RFC2385) */
struct task *srvrq_check; /* Task testing SRV record expiration date for this server */
struct {
const char *file; /* file where the section appears */
- struct eb32_node id; /* place in the tree of used IDs */
+ struct ceb_node puid_node; /* place in the tree of used IDs, indexes <puid> above */
struct ceb_node name_node; /* place in the tree of used names, indexes <id> above, not unique, indexed in px->used_server_name */
int line; /* line where the section appears */
} conf; /* config information */
#include <unistd.h>
+#include <import/ceb32_tree.h>
+
#include <haproxy/api.h>
#include <haproxy/applet-t.h>
#include <haproxy/arg-t.h>
/* index server <srv>'s id into proxy <px>'s used_server_id */
static inline void server_index_id(struct proxy *px, struct server *srv)
{
- eb32_insert(&px->conf.used_server_id, &srv->conf.id);
+ ceb32_item_insert(&px->conf.used_server_id, conf.puid_node, puid, srv);
}
/* increase the number of cumulated streams on the designated server */
*/
static inline struct server *server_find_by_id(struct proxy *bk, int id)
{
- struct eb32_node *eb32;
-
- eb32 = eb32_lookup(&bk->conf.used_server_id, id);
- return eb32 ? container_of(eb32, struct server, conf.id) : NULL;
+ return ceb32_item_lookup(&bk->conf.used_server_id, conf.puid_node, puid, id, struct server);
}
* spare entry starting with next_svid.
*/
next_id = server_get_next_id(curproxy, next_id);
- newsrv->conf.id.key = newsrv->puid = next_id;
+ newsrv->puid = next_id;
server_index_id(curproxy, newsrv);
}
MT_LIST_INIT(&p->lbprm.lb_free_list);
p->conf.used_listener_id = NULL;
- p->conf.used_server_id = EB_ROOT;
+ p->conf.used_server_id = NULL;
p->used_server_addr = NULL;
/* Timeouts are defined as -1 */
*/
uint server_get_next_id(const struct proxy *px, uint from)
{
- const struct eb32_node *used;
+ const struct server *sv;
do {
- used = eb32_lookup_ge((struct eb_root *)&px->conf.used_server_id, from);
- if (!used || used->key > from)
+ sv = ceb32_item_lookup_ge(&px->conf.used_server_id, conf.puid_node, puid, from, struct server);
+ if (!sv || sv->puid > from)
return from; /* available */
from++;
} while (from);
}
newsrv->puid = atol(args[*cur_arg + 1]);
- newsrv->conf.id.key = newsrv->puid;
if (newsrv->puid <= 0) {
memprintf(err, "'%s' : custom id has to be > 0", args[*cur_arg]);
goto out;
}
- srv->conf.id.key = srv->puid = next_id;
+ srv->puid = next_id;
}
/* insert the server in the backend trees */
srv_detach(srv);
/* remove srv from addr_node tree */
- eb32_delete(&srv->conf.id);
+ ceb32_item_delete(&be->conf.used_server_id, conf.puid_node, puid, srv);
cebis_item_delete(&be->conf.used_server_name, conf.name_node, id, srv);
cebuis_item_delete(&be->used_server_addr, addr_node, addr_key, srv);