Improve robustness of cluster version bookkeeping
Summary:
Ref T4292. Small fixes:
- There was a bug with the first write, where we'd write 1 but expect 0. Fix this.
- Narrow the window where we hold the isWriting lock: we don't need to wait for the client to finish.
- Release the lock even if something throws.
- Use a more useful variable name.
Test Plan:
- Made new writes to a fresh cluster repository.
- Made sequential writes.
- Made concurrent writes.
- Made good writes and bad writes.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4292
Differential Revision: https://secure.phabricator.com/D15747