This works by adding a RW lock on the row of the latest visit,
which should block other transactions until the insertion
is committed; so other transactions will generate a different
(larger) visit id
This commit also slightly rewrites how the max visit id is
computed, as we need to actually select a row to lock it,
instead of using the `max()` aggregate function.
Resolves T4444.