[xs64bit] CA-134765: Fix race condition in database layer

Backport of https://github.com/xapi-project/xen-api/pull/1745.