bill_event() charges atomically: sql = dsql = switch_mprintf("UPDATE %s SET %s=%s-%f WHERE %s='%s'", globals.db_table, globals.db_column_cash, globals.db_column_cash, billamount, globals.db_column_account, billaccount); That UPDATE query won't conflict with any other queries running at the same time, they'll lock on each other so one updates the row at a time. The balance fetched by get_balance isn't used to update the balance so it shouldn't matter if there are multiple calls. Both will use UPDATE and overlapping calls will update the balance correctly. They'll then both spot if the balance drops below the minimum. On 6 September 2016 at 05:50, Mohd Kamal Mustafa <kamal@xoxzo.com> wrote:
If not, is there a possibilities of reach condition where updates from multiple channels override each other. For example, 2 incoming calls at the same time to 2 different numbers, but owned by single user - that mean nibble will be updating the same record in database.
I'm planning to add "FOR UPDATE" clause to the custom_sql_lookup:-
SELECT cash AS nibble_balance FROM accounts WHERE account_code='${nibble_account} FOR UPDATE
But if each query run inside their own transaction, that would be no use.
Thank you.
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
Official FreeSWITCH Sites http://www.freeswitch.org http://confluence.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org