Message ID | 20230812000011.1227371-1-christian.couder@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | Repack objects into separate packfiles based on a filter | expand |
Christian Couder <christian.couder@gmail.com> writes: > # Changes since version 4 > > Thanks to Junio who reviewed versions 1, 2, 3 and 4, and to Taylor who > reviewed version 1, 3 and 4! Thanks also to Robert Coup who > participated in the discussions related to version 2 and Peff who > participated in the discussions related to version 4. The changes are > the following: > > - In patch 2/8, which introduces `test-tool find-pack`, a spurious > space character has been removed between 'die' and '(', as suggested > by Taylor. > > - In patch 4/8, which refactors code into a find_pack_prefix() > function, this function has been changed so that the `packdir` and > `packtmp` arguments are now 'const', as suggested by Taylor. > > - In patch 5/8, which introduces `--filter=<filter-spec>` option, the > `filter_options` member of the 'cruft_po_args' variable is not > initialized and freed anymore, as this member is actually unused. > > - Also in patch 5/8, the '--filter fails with --write-bitmap-index' > test has been changed to use `test_must_fail env` to fix failures > with the 'test-lint' Makefile target, as suggested by Junio and > Taylor. (Junio's 'SQUASH???' patch was squashed into that patch.) Thanks. I do not recall if the previous version with SQUASH??? passed the tests or not, but this round seems to be breaking the exact test we had trouble with with the previous round: https://github.com/git/git/actions/runs/5850998716/job/15861158252#step:4:1822 The symptom looks like that "test_must_fail env" test is not failing. Ring a bell? Thanks.
On Mon, Aug 14, 2023 at 05:51:05PM -0700, Junio C Hamano wrote: > Thanks. I do not recall if the previous version with SQUASH??? passed > the tests or not, but this round seems to be breaking the exact test > we had trouble with with the previous round: > > https://github.com/git/git/actions/runs/5850998716/job/15861158252#step:4:1822 > > The symptom looks like that "test_must_fail env" test is not > failing. Ring a bell? That does ring a bell for me, but this is a different failure than before, IIRC. This time we're expecting to fail writing a bitmap during a filtered repack, but we succeed. I was wondering in [1] whether or not we should be catching this bad combination of options more eagerly than relying on the pack-bitmap machinery to notice that we're missing a reachability closure. I think the reason that this succeeds is that we already have a bitmap, and it likely reuses all of the existing bitmaps before discovering that the pack we wrote doesn't contain all objects. So doing this "fixes" the immediate issue: --- 8< --- diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 48e92aa6f7..e5134d3451 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -342,6 +342,7 @@ test_expect_success 'repacking with a filter works' ' ' test_expect_success '--filter fails with --write-bitmap-index' ' + rm -f bare.git/objects/pack/*.bitmap && test_must_fail \ env GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \ git -C bare.git repack -a -d --write-bitmap-index --filter=blob:none --- >8 --- but I wonder if a more complete fix would be something like: --- 8< --- diff --git a/builtin/repack.c b/builtin/repack.c index c396029ec9..f021349c4e 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -48,6 +48,11 @@ static const char incremental_bitmap_conflict_error[] = N_( "--no-write-bitmap-index or disable the pack.writeBitmaps configuration." ); +static const char filtered_bitmap_conflict_error[] = N_( +"Filtered repacks are incompatible with bitmap indexes. Use\n" +"--no-write-bitmap-index or disable the pack.writeBitmaps configuration." +); + struct pack_objects_args { const char *window; const char *window_memory; @@ -953,7 +958,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix) if (write_bitmaps < 0) { if (!write_midx && - (!(pack_everything & ALL_INTO_ONE) || !is_bare_repository())) + (!(pack_everything & ALL_INTO_ONE) || !is_bare_repository()) && + !po_args.filter_options.choice) write_bitmaps = 0; } else if (write_bitmaps && git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0) && @@ -966,6 +972,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix) if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx) die(_(incremental_bitmap_conflict_error)); + if (write_bitmaps && po_args.filter_options.choice) + die(_(filtered_bitmap_conflict_error)); + if (write_bitmaps && po_args.local && has_alt_odb(the_repository)) { /* * When asked to do a local repack, but we have --- >8 --- would be preferable. Thanks, Taylor [1]: https://lore.kernel.org/git/ZNQH6EMKqbuUzEhs@nand.local/
Taylor Blau <me@ttaylorr.com> writes: > I think the reason that this succeeds is that we already have a bitmap, > and it likely reuses all of the existing bitmaps before discovering that > the pack we wrote doesn't contain all objects. Now I am confused. We were asked to write bitmap index when we are going to create an incomplete pack, and the packfile we generate with the filter will not have full set of objects, and generating a bitmap with such an incomplete knowledge of what objects are reachable from what would be a disaster, so we should turn it off. But the posted patch lacked such a "we should abort when bitmap is asked to be written while filtering" logic. Then what were we expecting for the test to fail for? > but I wonder if a more complete fix would be something like: > ... > @@ -966,6 +972,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix) > if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx) > die(_(incremental_bitmap_conflict_error)); > > + if (write_bitmaps && po_args.filter_options.choice) > + die(_(filtered_bitmap_conflict_error)); > + It sounds like the most direct fix.
On Tue, Aug 15, 2023 at 03:32:23PM -0700, Junio C Hamano wrote: > Taylor Blau <me@ttaylorr.com> writes: > > > I think the reason that this succeeds is that we already have a bitmap, > > and it likely reuses all of the existing bitmaps before discovering that > > the pack we wrote doesn't contain all objects. > > Now I am confused. > > We were asked to write bitmap index when we are going to create an > incomplete pack, and the packfile we generate with the filter will > not have full set of objects, and generating a bitmap with such an > incomplete knowledge of what objects are reachable from what would > be a disaster, so we should turn it off. But the posted patch > lacked such a "we should abort when bitmap is asked to be written > while filtering" logic. I was similarly confused, and started writing a patch to detect when we see objects in one bitmap but not the other when remapping. But we already handle that case, see the call to `rebuild_bitmap()` from `fill_bitmap_commit()` in pack-bitmap-write.c. So I don't think we'd ever end up reusing an existing bitmap that refers to objects that we don't have. But something is definitely strange here. The bitmap generated by this test claims to have three commits: $ ~/src/git/t/helper/test-tool bitmap list-commits 95a9e53327b06212dcf98bd44794b0e2b913deab 3677360288c631b6b2e1f0e1f081b1e518605e9f 6f105e6234717c52e9b117b08840926910a68314 ...but none of them actually appear to exist in the bitmap: $ git rev-list --test-bitmap 95a9e53327b06212dcf98bd44794b0e2b913deab Bitmap v1 test (3 entries loaded) Found bitmap for '95a9e53327b06212dcf98bd44794b0e2b913deab'. 64 bits / 8b3b6ee7 checksum fatal: object not in bitmap: 'ac3e272b72bbf89def8657766b855d0656630ed4' I think what's going on here is that we attempt to create bitmaps for all three of those commits. We then try and reuse the existing bitmaps, but fail, because we are missing some objects. So then we try and generate the bitmap from scratch, and when we get down to fill_bitmap_tree() we look up the bit position of the tree itself, and find a non-zero answer, indicating that we have already marked that tree. And fill_bitmap_tree() correctly assumes that if we have marked the bit corresponding to the tree, that everything reachable from that tree has also been marked. So we never try and locate the bit position for the blob, since we already think that we have a blob marked in the resulting bitmap! But why is that tree marked in the first place? It's because we attempt to rebuild the bitmap from the existing .bitmap file, but fail part of the way through (when we look up the first blob object in the reposition table). But that happens *after* we see the tree object, so its bit position is marked, even though we didn't rebuild a complete bitmap. I don't think this matters outside of filtered repacks, but it would be a serious bug to not catch this earlier up like suggested in the (quoted) patch below. > > but I wonder if a more complete fix would be something like: > > ... > > @@ -966,6 +972,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix) > > if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx) > > die(_(incremental_bitmap_conflict_error)); > > > > + if (write_bitmaps && po_args.filter_options.choice) > > + die(_(filtered_bitmap_conflict_error)); > > + > > It sounds like the most direct fix. I agree. I think that we would be OK to not change the implementation of rebuild_bitmap(), or its caller in fill_bitmap_commit(), since this only bites us when bitmapping a filtered pack, and we should catch that case well before getting this deep into the bitmap code. But it does seem suspect that we rebuild right into ent->bitmap, so we may want to consider doing something like: --- >8 --- diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index f6757c3cbf..f4ecdf8b0e 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -413,15 +413,19 @@ static int fill_bitmap_commit(struct bb_commit *ent, if (old_bitmap && mapping) { struct ewah_bitmap *old = bitmap_for_commit(old_bitmap, c); + struct bitmap *remapped = bitmap_new(); /* * If this commit has an old bitmap, then translate that * bitmap and add its bits to this one. No need to walk * parents or the tree for this commit. */ - if (old && !rebuild_bitmap(mapping, old, ent->bitmap)) { + if (old && !rebuild_bitmap(mapping, old, remapped)) { + bitmap_or(ent->bitmap, remapped); + bitmap_free(remapped); reused_bitmaps_nr++; continue; } + bitmap_free(remapped); } /* --- 8< --- on top. Applying that patch and then rerunning the tests with the appropriate TEST variables causes the 'git repack' to fail as expected, ensuring that the containing test passes. Thanks, Taylor
Taylor Blau <me@ttaylorr.com> writes: > But why is that tree marked in the first place? It's because we attempt > to rebuild the bitmap from the existing .bitmap file, but fail part of > the way through (when we look up the first blob object in the reposition > table). But that happens *after* we see the tree object, so its bit > position is marked, even though we didn't rebuild a complete bitmap. So, there is another bug lurking, other than the lack of "combining filtered repack and bitmaps are explicitly forbidden" logic? We see the tree object, we immediately mark it as "done" even we are not, then we finish in failure and the "done" mark is left behind? Do we need two bits, "under review" and "done", or something then? > But it does seem suspect that we rebuild right into ent->bitmap, so we > may want to consider doing something like: > > --- >8 --- > diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c > index f6757c3cbf..f4ecdf8b0e 100644 > --- a/pack-bitmap-write.c > +++ b/pack-bitmap-write.c > @@ -413,15 +413,19 @@ static int fill_bitmap_commit(struct bb_commit *ent, > > if (old_bitmap && mapping) { > struct ewah_bitmap *old = bitmap_for_commit(old_bitmap, c); > + struct bitmap *remapped = bitmap_new(); > /* > * If this commit has an old bitmap, then translate that > * bitmap and add its bits to this one. No need to walk > * parents or the tree for this commit. > */ > - if (old && !rebuild_bitmap(mapping, old, ent->bitmap)) { > + if (old && !rebuild_bitmap(mapping, old, remapped)) { > + bitmap_or(ent->bitmap, remapped); > + bitmap_free(remapped); > reused_bitmaps_nr++; > continue; > } > + bitmap_free(remapped); > } > > /* > --- 8< --- > > on top. > > Applying that patch and then rerunning the tests with the appropriate > TEST variables causes the 'git repack' to fail as expected, ensuring > that the containing test passes. Interesting.
On Tue, Aug 15, 2023 at 04:18:02PM -0700, Junio C Hamano wrote: > Taylor Blau <me@ttaylorr.com> writes: > > > But why is that tree marked in the first place? It's because we attempt > > to rebuild the bitmap from the existing .bitmap file, but fail part of > > the way through (when we look up the first blob object in the reposition > > table). But that happens *after* we see the tree object, so its bit > > position is marked, even though we didn't rebuild a complete bitmap. > > So, there is another bug lurking, other than the lack of "combining > filtered repack and bitmaps are explicitly forbidden" logic? I think that there is a bug lurking in the sense of trying to reuse bitmaps when covering a pack that doesn't have reachability closure in this particular scenario. But there are no "blessed" use-cases for doing this. So I think that we should indeed fix this, but I am not immediately concerned here. > We see the tree object, we immediately mark it as "done" even we are > not, then we finish in failure and the "done" mark is left behind? Do > we need two bits, "under review" and "done", or something then? No; we can either reuse a complete bitmap or not. So it's fine to OR all of the (permuted) bits into ent->bitmap, but it's not OK to fill in just part of them. Thanks, Taylor
Taylor Blau <me@ttaylorr.com> writes: > I think that there is a bug lurking in the sense of trying to reuse > bitmaps when covering a pack that doesn't have reachability closure in > this particular scenario. > > But there are no "blessed" use-cases for doing this. So I think that we > should indeed fix this, but I am not immediately concerned here. OK. > No; we can either reuse a complete bitmap or not. So it's fine to OR > all of the (permuted) bits into ent->bitmap, but it's not OK to fill in > just part of them. Sounds sane.
On Wed, Aug 16, 2023 at 1:09 AM Taylor Blau <me@ttaylorr.com> wrote: > > On Tue, Aug 15, 2023 at 03:32:23PM -0700, Junio C Hamano wrote: > > Taylor Blau <me@ttaylorr.com> writes: > > > but I wonder if a more complete fix would be something like: > > > ... > > > @@ -966,6 +972,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix) > > > if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx) > > > die(_(incremental_bitmap_conflict_error)); > > > > > > + if (write_bitmaps && po_args.filter_options.choice) > > > + die(_(filtered_bitmap_conflict_error)); > > > + > > > > It sounds like the most direct fix. I would be Ok with such a fix, if we think that we don't want to fix the underlying issue, or if we think that fixing the underlying issue is not enough... > I agree. > > I think that we would be OK to not change the implementation of > rebuild_bitmap(), or its caller in fill_bitmap_commit(), since this only > bites us when bitmapping a filtered pack, and we should catch that case > well before getting this deep into the bitmap code. > > But it does seem suspect that we rebuild right into ent->bitmap, so we > may want to consider doing something like: > > --- >8 --- > diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c > index f6757c3cbf..f4ecdf8b0e 100644 > --- a/pack-bitmap-write.c > +++ b/pack-bitmap-write.c > @@ -413,15 +413,19 @@ static int fill_bitmap_commit(struct bb_commit *ent, > > if (old_bitmap && mapping) { > struct ewah_bitmap *old = bitmap_for_commit(old_bitmap, c); > + struct bitmap *remapped = bitmap_new(); > /* > * If this commit has an old bitmap, then translate that > * bitmap and add its bits to this one. No need to walk > * parents or the tree for this commit. > */ > - if (old && !rebuild_bitmap(mapping, old, ent->bitmap)) { > + if (old && !rebuild_bitmap(mapping, old, remapped)) { > + bitmap_or(ent->bitmap, remapped); > + bitmap_free(remapped); > reused_bitmaps_nr++; > continue; > } > + bitmap_free(remapped); > } > > /* > --- 8< --- > > on top. > > Applying that patch and then rerunning the tests with the appropriate > TEST variables causes the 'git repack' to fail as expected, ensuring > that the containing test passes. ...however I think that fixing this underlying issue is important, as it might cause other tricky issues in the future, for example if other bitmap code is copying or reusing this code. So I just sent a version 6 of this series with this change in a new patch. I hope my explanations in the commit message are good enough. Thanks for finding the cause of the CI test failures and suggesting this fix, Christian.