git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 1/9] t5326: demonstrate bitmap corruption after permutation

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Jan 20, 2022, 17:55 UTC
Message-ID
<20220120175541.3099054-1-jonathantanmy@google.com>
In-Reply-To
<babce7d29a85df0da54cb651433111bc33097a4e.1641320129.git.me@ttaylorr.com>
Taylor Blau <me@ttaylorr.com> writes:
Show 20 quoted lines
> This patch demonstrates a cause of bitmap corruption that can occur when
> the contents of the multi-pack index does not change, but the underlying
> object order does.
> 
> In this example, we have a MIDX containing two packs, each with a
> distinct set of objects (pack A corresponds to the tree, blob, and
> commit from the first patch, and pack B corresponds to the second
> patch).
> 
> First, a MIDX is written where the 'A' pack is preferred. As expected,
> the bitmaps generated there are in-tact. But then, we generate an
> identical MIDX with a different object order: this time preferring pack
> 'B'.
> 
> Due to a bug which will be explained and fixed in the following commit,
> the MIDX is updated, but the .rev file is not, causing the .bitmap file
> to be read incorrectly. Specifically, the .bitmap file will contain
> correct data, but the auxiliary object order in the .rev file is stale,
> causing readers to get confused by reading the new bitmaps using the old
> object order.
Thanks - overall, this looks like a bug that needs to be fixed.

For the benefit of other reviewers, here's my summary of the problem: the .midx, .rev, and .bitmap files are almost always generated together, and it is possible for two different invocations of Git to generate the same .midx but a different .rev and .bitmap. For example, when generating a .midx+.rev+.bitmap for 2 disjoint packfiles, the 1st time with one packfile as preferred and the 2nd time with the other packfile as preferred. In .midx, packfiles are always ordered by lexicographical order of their names, and the preferred status only matters when an object is in multiple packfiles (which never happens in this case, since the packfiles are disjoint). But the preferred status affects .rev and .bitmap, because they use a concept called "pseudo-pack order" (see pack-format.txt for more details) in which the preferred pack comes first.

As an effort to ensure that Git reads coherent .midx, .rev, and .bitmap files, both the .rev and .bitmap files are keyed on the checksum of the .midx file. But the issue here is that a .rev and a .bitmap could both refer to the same .midx checksum when the .rev and .bitmap files are not coherent with respect to each other (e.g. when a Git process has written the .rev, but not the .bitmap yet - but this would appear perfectly ordinary to another concurrently running Git process, since the .midx checksum in the .rev and .bitmap files match).

This problem is exacerbated by the fact that the .rev has its .midx checksum in its filename, whereas the .bitmap has its .midx checksum in its file contents. When generating .midx+.rev+.bitmap, it would write the .bitmap but not the .rev, since a .rev of the same filename already exists.

The solution is to embed the .rev in the .midx. This means that the checksum stored in .bitmap takes into account the contents of what would have been in .rev, solving the coherency issue. (There are other solutions like storing the name of the preferred pack in .midx, but I think that putting the contents of .rev in the .midx is best.)

Previous: Taylor BlauNext: Taylor Blau
Message 35 of 87 in “midx: prevent bitmap corruption when permuting pack order”
  1. 0/2 midx: prevent bitmap corruption when permuting pack orderTaylor Blau, Dec 8, 2021
  2. 1/2 t5326: demonstrate bitmap corruption after permutationTaylor Blau, Dec 8, 2021
  3. 2/2 midx.c: make changing the preferred pack safeTaylor Blau, Dec 8, 2021
  4. Derrick StoleeDec 8, 2021
  5. Jeff KingDec 8, 2021
  6. Taylor BlauDec 10, 2021
  7. Taylor BlauDec 10, 2021
  8. Taylor BlauDec 11, 2021
  9. Derrick StoleeDec 13, 2021
  10. Taylor BlauDec 13, 2021
  11. 0/8 midx: prevent bitmap corruption when permuting pack orderTaylor Blau, Dec 14, 2021
  12. 1/8 t5326: demonstrate bitmap corruption after permutationTaylor Blau, Dec 14, 2021
  13. 2/8 midx.c: make changing the preferred pack safeTaylor Blau, Dec 14, 2021
  14. 3/8 pack-revindex.c: instrument loading on-disk reverse indexTaylor Blau, Dec 14, 2021
  15. 4/8 t5326: drop unnecessary setupTaylor Blau, Dec 14, 2021
  16. 5/8 t5326: extract `test_rev_exists`Taylor Blau, Dec 14, 2021
  17. Derrick StoleeDec 20, 2021
  18. Taylor BlauJan 4, 2022
  19. 6/8 t5326: move tests to t/lib-bitmap.shTaylor Blau, Dec 14, 2021
  20. 7/8 t/lib-bitmap.sh: parameterize tests over reverse index sourceTaylor Blau, Dec 14, 2021
  21. 8/8 midx: read `RIDX` chunk when presentTaylor Blau, Dec 14, 2021
  22. Derrick StoleeDec 20, 2021
  23. Taylor BlauJan 4, 2022
  24. Junio C HamanoDec 15, 2021
  25. Taylor BlauDec 15, 2021
  26. Junio C HamanoDec 15, 2021
  27. Junio C HamanoDec 15, 2021
  28. Derrick StoleeDec 20, 2021
  29. Taylor BlauDec 20, 2021
  30. Derrick StoleeDec 20, 2021
  31. Junio C HamanoDec 15, 2021
  32. Taylor BlauDec 15, 2021
  33. 0/9 midx: prevent bitmap corruption when permuting pack orderTaylor Blau, Jan 4, 2022
  34. 1/9 t5326: demonstrate bitmap corruption after permutationTaylor Blau, Jan 4, 2022
  35. Jonathan TanJan 20, 2022
  36. Taylor BlauJan 20, 2022
  37. Junio C HamanoJan 20, 2022
  38. Taylor BlauJan 20, 2022
  39. Jonathan TanJan 24, 2022
  40. 2/9 midx.c: make changing the preferred pack safeTaylor Blau, Jan 4, 2022
  41. Junio C HamanoJan 14, 2022
  42. Junio C HamanoJan 14, 2022
  43. Taylor BlauJan 15, 2022
  44. Junio C HamanoJan 15, 2022
  45. Jonathan TanJan 20, 2022
  46. Taylor BlauJan 20, 2022
  47. 3/9 pack-revindex.c: instrument loading on-disk reverse indexTaylor Blau, Jan 4, 2022
  48. Jonathan TanJan 20, 2022
  49. Taylor BlauJan 20, 2022
  50. Jonathan TanJan 24, 2022
  51. 4/9 t5326: drop unnecessary setupTaylor Blau, Jan 4, 2022
  52. 5/9 t5326: extract `test_rev_exists`Taylor Blau, Jan 4, 2022
  53. 6/9 t5326: move tests to t/lib-bitmap.shTaylor Blau, Jan 4, 2022
  54. 7/9 t/lib-bitmap.sh: parameterize tests over reverse index sourceTaylor Blau, Jan 4, 2022
  55. Jonathan TanJan 24, 2022
  56. Taylor BlauJan 25, 2022
  57. Jonathan TanJan 26, 2022
  58. 8/9 midx: read `RIDX` chunk when presentTaylor Blau, Jan 4, 2022
  59. Jonathan TanJan 24, 2022
  60. Taylor BlauJan 25, 2022
  61. Jonathan TanJan 26, 2022
  62. 9/9 pack-bitmap.c: gracefully fallback after opening pack/MIDXTaylor Blau, Jan 4, 2022
  63. Jonathan TanJan 24, 2022
  64. Taylor BlauJan 25, 2022
  65. 0/9 midx: prevent bitmap corruption when permuting pack orderTaylor Blau, Jan 25, 2022
  66. 1/9 t5326: demonstrate bitmap corruption after permutationTaylor Blau, Jan 25, 2022
  67. Ævar Arnfjörð BjarmasonJan 26, 2022
  68. Taylor BlauJan 26, 2022
  69. 2/9 midx.c: make changing the preferred pack safeTaylor Blau, Jan 25, 2022
  70. 3/9 pack-revindex.c: instrument loading on-disk reverse indexTaylor Blau, Jan 25, 2022
  71. Ævar Arnfjörð BjarmasonJan 26, 2022
  72. 4/9 t5326: drop unnecessary setupTaylor Blau, Jan 25, 2022
  73. 5/9 t5326: extract `test_rev_exists`Taylor Blau, Jan 25, 2022
  74. Ævar Arnfjörð BjarmasonJan 26, 2022
  75. Taylor BlauJan 26, 2022
  76. 6/9 t5326: move tests to t/lib-bitmap.shTaylor Blau, Jan 25, 2022
  77. 7/9 t/lib-bitmap.sh: parameterize tests over reverse index sourceTaylor Blau, Jan 25, 2022
  78. 8/9 midx: read `RIDX` chunk when presentTaylor Blau, Jan 25, 2022
  79. Ævar Arnfjörð BjarmasonJan 26, 2022
  80. Taylor BlauJan 26, 2022
  81. 9/9 pack-bitmap.c: gracefully fallback after opening pack/MIDXTaylor Blau, Jan 25, 2022
  82. Ævar Arnfjörð BjarmasonJan 26, 2022
  83. Ævar Arnfjörð BjarmasonJan 26, 2022
  84. Taylor BlauJan 26, 2022
  85. Jonathan TanJan 27, 2022
  86. Taylor BlauFeb 24, 2022
  87. Derrick StoleeJan 27, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.