MINOR: hlua_fcn: add server->get_rid() method

Server revision ID was recently added to haproxy with 61e3894
("MINOR: server: add srv->rid (revision id) value")

Let's add it to the hlua server class.
This commit is contained in:
Aurelien DARRAGON 2023-03-10 15:11:27 +01:00 committed by Christopher Faulet
parent 6b0b9bd39f
commit 94ee6632ee
2 changed files with 28 additions and 0 deletions

View File

@ -1042,6 +1042,17 @@ Server class
Returns the proxy unique identifier of the server.
.. js:function:: Server.get_rid(sv)
Returns the rid (revision ID) of the server.
It is an unsigned integer that is set upon server creation. Value is derived
from a global counter that starts at 0 and is incremented each time one or
multiple server deletions are followed by a server addition (meaning that
old name/id reuse could occur).
Combining server name/id with server rid yields a process-wide unique
identifier.
.. js:function:: Server.is_draining(sv)
Return true if the server is currently draining sticky connections.

View File

@ -990,6 +990,22 @@ int hlua_server_get_puid(lua_State *L)
return 1;
}
int hlua_server_get_rid(lua_State *L)
{
struct server *srv;
char buffer[12];
srv = hlua_check_server(L, 1);
if (srv == NULL) {
lua_pushnil(L);
return 1;
}
snprintf(buffer, sizeof(buffer), "%d", srv->rid);
lua_pushstring(L, buffer);
return 1;
}
int hlua_server_get_name(lua_State *L)
{
struct server *srv;
@ -1373,6 +1389,7 @@ int hlua_fcn_new_server(lua_State *L, struct server *srv)
/* set public methods */
hlua_class_function(L, "get_name", hlua_server_get_name);
hlua_class_function(L, "get_puid", hlua_server_get_puid);
hlua_class_function(L, "get_rid", hlua_server_get_rid);
hlua_class_function(L, "is_draining", hlua_server_is_draining);
hlua_class_function(L, "set_maxconn", hlua_server_set_maxconn);
hlua_class_function(L, "get_maxconn", hlua_server_get_maxconn);