Ditto improvements

Summary:
Refactored some more, improved error handling for queries, changed
the ditto lock mechanism to one that relies on triggering a dup key
error to block other processes

Test Plan: ad-hoc, ran tests in testing directory

Reviewers: ankur, nikita, adam, pieguy, carl

CC: engineering

Differential Revision: http://grizzly.memsql.com/D2957