Improve lava-master SQL atomicity
Database accesses done by the dispatcher-master are partially atomic as we are using:
- transaction: the full block is executed. If an exception is raised, changes are rollbacked
- select_for_update: lock a row that will be updated in the block.
The select_for_update() is the right way to make calls atomic. However, PostgreSQL does not allow to use select_for_update() with JOIN. So for the moment, we are only locking the Job table and not the Device one.
Doing two calls:
- Job.objects.select_for_update(). ... then
- Device.objects.select_for_update().get(jop_id=...) should be enough to make the calls fully atomic.
But, if their is a path somewhere in lava that does the reverse we will have a deadlock.
So this task is to:
- make the dispatcher-master fully atomic (two select_for_update)
- check that lava-server is always blocking in the same order (job then device).
Migrated from https://projects.linaro.org/browse/LAVA-83