MODE-2004 Update the logic that reads/writes the repository metadata document

Per code review, the method that does this work needed some improvements
to make it work correctly in a highly-concurrent scenario.