Re: [PATCH v2 08/24] midx: respect 'core.multiPackIndex' when writing
From: Taylor Blau <hidden>
Date: 2021-07-27 17:47:43
On Tue, Jul 27, 2021 at 01:42:35PM -0400, Jeff King wrote:
On Tue, Jul 27, 2021 at 01:36:34PM -0400, Taylor Blau wrote:quoted
quoted
But now the internal midx writing code can never call close_midx() on that, because it does not own it to close. Can we simply drop the close_midx() call there? This would all make much more sense to me if write_midx_internal() simply took a conceptually read-only midx as a parameter, and the caller passed in the appropriate one (probably even using prepare_multi_pack_index_one() to get it).No, we can't drop the close_midx() call there because we must close the MIDX file on Windows before moving a new one into place. My feeling is we should always be working on the r->objects->multi_pack_index pointer, and calling close_object_store() there instead of close_midx(). Does that seem like a reasonable approach to you?Yes, though I'd have said that it is the responsibility of the caller (who knows we are operating with r->objects->multi_pack_index) to do that closing. But maybe it's not possible if the rename-into-place happens at too low a level.
Right; write_midx_internal() needs to access the MIDX right up until the point that we write the new one into place, so the only place to close it is in write_midx_internal().
BTW, yet another weirdness: close_object_store() will call close_midx() on the outermost midx struct, ignoring o->multi_pack_index->next entirely. So that's a leak, but also means we may not be closing the midx we're interested in (since write_midx_internal() takes an object-dir parameter, and we could be pointing to some other object-dir's midx).
Yuck, this is a mess. I'm tempted to say that we should be closing the MIDX that we're operating on inside of write_midx_internal() so we can write, but then declaring the whole object store to be bunk and calling close_object_store() before leaving the function. Of course, one of those steps should be closing the inner-most MIDX before closing the next one and so on.
-Peff
Thanks, Taylor