This lock was used to avoid errors due to list contents changing
during iteration, but is causing issues with pymysql. This patch
proposes an alternative approach which makes the use of a lock
unnecessary.
With this change a copy of the dirty_tenants set is made before
setting the dirty bit on resources, and then the mark_dirty routine
operates on this copy. This still guaranteses operations
correctness, as all the tenants that should be marked dirty are
marked dirty before the completion of the relevant API request.