@michaelcahill, would you please review this pair of changes? I don't like the way this is structured, much, but I couldn't think of anything cleaner
I think the commit comments explain what's going on, and I'm going to add a few specific review notes to the code as well.