Fix yet another deadlock bug in the lock manager.

We cannot process the readsets and writesets in isolation. They have to be
merged in sorted order and then latched. Implemented a merge-sort like merge
function to funnel latch acquisitions in sorted order spanning both read and
write sets.