]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua_fcn: add server->get_rid() method
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 10 Mar 2023 14:11:27 +0000 (15:11 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Apr 2023 06:58:17 +0000 (08:58 +0200)
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.

doc/lua-api/index.rst
src/hlua_fcn.c

index e20042ddae38b4544e84baa7caf1c19b613e9d95..146c05047342bfecdf89ede3bdd85ab66529ca58 100644 (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.
index ff90321815d1c8f8100ef399cc11a437af110cf2..5f96f5cfe7fb58eeb39ade15d60d9b8f6bb3d007 100644 (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);