If someone runs more than 1 openser host with shared `location` table in DB_ONLY mode, there's a possibility that one host will delete expired record/contact while another host retrieves it and tries to update (resulting in 0 rows updated). This patch adds 'db_atomic' option to usrloc module, which switches to using update_ucontact_atomic (and because of that, insert/update function instead of standard insert) in ul_mi and registrar/save.
It works only when db_mode==3 (DB_ONLY) and db_atomic==1. It needs a database schema change - making username+domain+contact (+callid if matching mode includes callid) a unique key, instead of standard index.
In mysql it results in running:
INSERT INTO location ... ON DUPLICATE KEY UPDATE ...
instead of normal SELECT FROM + INSERT/UPDATE
Patch is for an older version of 1.3, but seems to be trivially portable to trunk. Unfortunately I don't have proper environment to test that.
One issue I know of is that ul callbacks are not supported properly. Before db update it's not known if event was UL_CONTACT_INSERT, or UL_CONTACT_UPDATE, so I left it as ..._INSERT
As far as I can tell, patch worked reliably for couple of days without issues.
Stanisław Pitucha
atomic db update patch