Cherry pick the bug fix from upstream for retrying the deadlocked transaction - https://review.openstack.org/122147. Closes-Bug: #1384072

Change-Id: Id83ff6dd71a16dd4d704ebc2f68096edf4ab42fe