Hello,
From the documentation for t_lookup_request()[1], it is not clear whether it creates a new transaction if one does not exist:
"Checks if a transaction exists. Returns a positive value if so, negative otherwise. Most likely you will not want to use it, as a typical application of a look-up is to introduce a new transaction if none was found. However this is safely (atomically) done using t_newtran."
This language is quite unclear in the following respects:
1) Why would I not want to use it?
2) Does the "typical application" mean that t_lookup_request() _will_ create a new transaction if one does not exist?
3) Do I have some means of choosing whether to invoke t_lookup_request() in a "typical" or "atypical" application?
4) This statement "this is safely (atomically) done using t_newtran" implies that creating a new transaction using t_lookup_request() (which also implies that yes, it does create a new transaction) is "unsafe" and "non-atomic". Why is this?
5) Does this mean that the effect here would be to create two transactions?
if(!t_lookup_request()) t_newtran();
-- Alex
[1] http://kamailio.org/docs/modules/4.2.x/modules/tm.html#tm.f.t_lookup_request
Hello,
I haven't implemented the function, nor use it for my configs, but I expect that it doesn't create the transaction, it just searches to see if it exists.
More comments inline.
On 12/05/15 23:53, Alex Balashov wrote:
Hello,
From the documentation for t_lookup_request()[1], it is not clear whether it creates a new transaction if one does not exist:
"Checks if a transaction exists. Returns a positive value if so, negative otherwise. Most likely you will not want to use it, as a typical application of a look-up is to introduce a new transaction if none was found. However this is safely (atomically) done using t_newtran."
This language is quite unclear in the following respects:
- Why would I not want to use it?
What is the main role of knowing if the transaction exists for you in the config?
- Does the "typical application" mean that t_lookup_request() _will_
create a new transaction if one does not exist?
I expect to not to create the transaction. Perhaps this is visible by running with debug=3 and doing a small test -- could be faster than checking the code.
- Do I have some means of choosing whether to invoke
t_lookup_request() in a "typical" or "atypical" application?
Again, I never used it and can't imagine a need to use it right now. I care not to be a retransmission in my config, but I use the new mechanism with t_precheck_trans(), which is lightweight and does the job. Later is a just matter of the action is after t_relay() or not to know if it is a transaction active, but again, I don't really need to know the transaction is there as long as I filter out retransmissions.
- This statement "this is safely (atomically) done using t_newtran"
implies that creating a new transaction using t_lookup_request() (which also implies that yes, it does create a new transaction) is "unsafe" and "non-atomic". Why is this?
Again, rather old tm code that just work, so can't remember by heart and no much time to dig in. But t_newtran() is creating the transaction if doesn't exit. If it exists, it will stop execution of the config file (i.e., retransmission handling) if that transaction is not the active one for the config in that moment.
- Does this mean that the effect here would be to create two
transactions?
if(!t_lookup_request()) t_newtran();
Never will be two transactions for same request.
Cheers, Daniel