]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: stick-table: provide a function to estimate on-wire data size
authorWilly Tarreau <w@1wt.eu>
Tue, 29 Sep 2026 14:19:07 +0000 (16:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 29 Sep 2026 15:06:36 +0000 (17:06 +0200)
We'll need to estimate the on-wire size of the stored data as a majorant
to adjust key sizes, so let's provide a new function for this. It
considers all varint at their maximum size.

include/haproxy/stick_table.h

index 37d85faf3194212c35b9aa53e46e6bfd894bb074..72bdc9558383b19437c08a7382c498f4e93ccb62 100644 (file)
@@ -141,6 +141,25 @@ static inline int stktable_type_size(int type)
        return 0;
 }
 
+/* return upper protocol size for standard data type <type> when transported
+ * over the peers protocol.
+ */
+static inline int stktable_type_proto_size(int type)
+{
+       switch(type) {
+       case STD_T_SINT:
+       case STD_T_UINT:
+               return 5;  // 32-bit varint
+       case STD_T_ULL:
+               return 9;  // 64-bit varint
+       case STD_T_FRQP:
+               return 15; // 3*32-bit varint
+       case STD_T_DICT:
+               return 5;  // 32-bit varint
+       }
+       return 0;
+}
+
 int stktable_alloc_data_type(struct stktable *t, int type, const char *sa, const char *sa2);
 
 /* return pointer for data type <type> in sticky session <ts> of table <t>, all