> Em 12 de mai. de 2021, à(s) 02:47, Willy Tarreau <w...@1wt.eu> escreveu:
> 
> On Tue, May 11, 2021 at 05:41:28PM -0300, Joao Morais wrote:
> 
>> Just to confirm how it works, I created the snippet below:
>> 
>>    http-request lua.auth ## assigning txn.core
>>    http-request return lf-string %[var(txn.code)] content-type text/plain
>> 
>> It worked since the first run and this is the only place I declared txn.code.
>> Does this mean that a var is created in the following conditions?
>> Any change in the sentences below?
>> 
>> - after the first read from a  Lua script
>> - after the first write from a Lua script provided that ifexists parameter 
>> is set to false
>> - always exists, if used anywhere in the configuration file
> 
> It's not a matter of first or second access. It's that the function
> you used initially resulted in always allocating an entry for the
> variable's name, causing some huge memory usage for those who were
> using them like maps and performing random lookups there. In order
> to avoid this, Tim added an extra argument saying that we're just
> performing an opportunistic lookup and that the variable must not
> be created if it does not exist.

Afaics this is only an option for set_var()? Here is the doc:

    TXN.set_var(TXN, var, value[, ifexist])
    TXN.get_var(TXN, var)
    http://www.arpalert.org/src/haproxy-lua-api/2.3/index.html
    (link is broken from haproxy site, is the source versioned
    somewhere so I can send a patch?)

So lookups would still create variables, hence the “in the second run it works” 
- my second script (which reads) create the entry and my first script (which 
writes with ifexists true) can find it and update in the second run and beyond.

> Other parts of the code (the native config parts I mean) which use
> variables always result in a creation because these names are static.
> So my understanding is that it can be simplified to this:
>  - a variable declared in the config always exists
>  - a variable accessed from Lua with ifexists set to true will not
>    be created but will be found if it exists
>  - a vraiable accessed from Lua with ifexists set to false or not
>    present will always be created during the lookup.

Taking the sentence above I’d update this to:

- s/variable accessed/variable updated, set_var(),/
- variable accessed from Lua, get_var(), will always be created

Does this make any sense?


Reply via email to