Add locking to WiredTiger metadata and some cleanup.