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

Re: [PATCH 12/17] Documentation: describe split commit-graphs

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
May 8, 2019, 17:20 UTC
Message-ID
<20190508172029.GP14763@szeder.dev>
In-Reply-To
<7bbe8d9150a623ea684c94d129eda1607dd32a79.1557330827.git.gitgitgadget@gmail.com>
On Wed, May 08, 2019 at 08:53:57AM -0700, Derrick Stolee via GitGitGadget wrote:
Show 131 quoted lines
> From: Derrick Stolee <dstolee@microsoft.com>
> 
> The design for the split commit-graphs uses file names to force
> a "stack" of commit-graph files. This allows incremental writes
> without updating the file format.
> 
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  Documentation/technical/commit-graph.txt | 142 +++++++++++++++++++++++
>  1 file changed, 142 insertions(+)
> 
> diff --git a/Documentation/technical/commit-graph.txt b/Documentation/technical/commit-graph.txt
> index fb53341d5e..ca1661d2d8 100644
> --- a/Documentation/technical/commit-graph.txt
> +++ b/Documentation/technical/commit-graph.txt
> @@ -127,6 +127,148 @@ Design Details
>    helpful for these clones, anyway. The commit-graph will not be read or
>    written when shallow commits are present.
>  
> +Split Commit Graphs
> +-------------------
> +
> +Typically, repos grow with near-constant velocity (commits per day). Over
> +time, the number of commits added by a fetch operation is much smaller than
> +the number of commits in the full history. The split commit-graph feature
> +allows for fast writes of new commit data without rewriting the entire
> +commit history -- at least, most of the time.
> +
> +## File Layout
> +
> +A split commit-graph uses multiple files, and we use a fixed naming
> +convention to organize these files. The base commit-graph file is the
> +same: `$OBJDIR/info/commit-graph`. The rest of the commit-graph files have
> +the format `$OBJDIR/info/commit-graphs/commit-graph-<N>` where N is a
> +positive integer. The integers must start at 1 and grow sequentially
> +to form a stack of files.
> +
> +Each `commit-graph-<N>` file has the same format as the `commit-graph`
> +file, including a lexicographic list of commit ids. The only difference
> +is that this list is considered to be concatenated to the list from
> +the lower commit-graphs. As an example, consider this diagram of three
> +files:
> +
> + +-----------------------+
> + |  commit-graph-2       |
> + +-----------------------+
> +	  |
> + +-----------------------+
> + |                       |
> + |  commit-graph-1       |
> + |                       |
> + +-----------------------+
> +	  |
> + +-----------------------+
> + |                       |
> + |                       |
> + |                       |
> + |  commit-graph         |
> + |                       |
> + |                       |
> + |                       |
> + +-----------------------+
> +
> +Let X0 be the number of commits in `commit-graph`, X1 be the number
> +of commits in commit-graph-1, and X2 be the number of commits in
> +commit-graph-2. If a commit appears in position i in `commit-graph-2`,
> +then we interpret this as being the commit in position (X0 + X1 + i),
> +and that will be used as its "graph position". The commits in
> +commit-graph-2 use these positions to refer to their parents, which
> +may be in commit-graph-1 or commit-graph. We can navigate to an
> +arbitrary commit in position j by checking its containment in the
> +intervals [0, X0), [X0, X0 + X1), [X0 + X1, X0 + X1 + X2).
> +
> +When Git reads from these files, it starts by acquiring a read handle
> +on the `commit-graph` file. On success, it continues acquiring read
> +handles on the `commit-graph-<N>` files in increasing order. This
> +order is important for how we replace the files.
> +
> +## Merging commit-graph files
> +
> +If we only added a `commit-graph-<N>` file on every write, we would
> +run into a linear search problem through many commit-graph files.
> +Instead, we use a merge strategy to decide when the stack should
> +collapse some number of levels.
> +
> +The diagram below shows such a collapse. As a set of new commits
> +are added, it is determined by the merge strategy that the files
> +should collapse to `commit-graph-1`. Thus, the new commits, the
> +commits in `commit-graph-2` and the commits in `commit-graph-1`
> +should be combined into a new `commit-graph-1` file.
> +
> +			    +---------------------+
> +			    |                     |
> +			    |    (new commits)    |
> +			    |                     |
> +			    +---------------------+
> +			    |                     |
> + +-----------------------+  +---------------------+
> + |  commit-graph-2       |->|                     |
> + +-----------------------+  +---------------------+
> +	  |                 |                     |
> + +-----------------------+  +---------------------+
> + |                       |  |                     |
> + |  commit-graph-1       |->|                     |
> + |                       |  |                     |
> + +-----------------------+  +---------------------+
> +	  |                   commit-graph-1.lock
> + +-----------------------+
> + |                       |
> + |                       |
> + |                       |
> + |  commit-graph         |
> + |                       |
> + |                       |
> + |                       |
> + +-----------------------+
> +
> +During this process, the commits to write are combined, sorted
> +and we write the contents to the `commit-graph-1.lock` file.
> +When the file is flushed and ready to swap to `commit-graph-1`,
> +we first unlink the files above our target file. This unlinking
> +is done from the top of the stack, the reverse direction that
> +another process would use to read the stack.
> +
> +During this time window, another process trying to read the
> +commit-graph stack could read `commit-graph-1` before the swap
> +but try to read `commit-graph-2` after it is unlinked. That
> +process would then believe that this stack is complete, but
> +will miss out on the performance benefits of the commits in
> +`commit-graph-2`. For this reason, the stack above the
> +`commit-graph` file should be small.
Consider the following sequence of events:
  1. There are three commit-graph files in the repository.
  2. A git process opens the base commit-graph and commit-graph-1 for
     reading.  It doesn't yet open commit-graph-2, because the (for
     arguments sake not very fair) scheduler takes the CPU away.
  3. Meanwhile, a 'git fetch', well, fetches from a remote, and
     upon noticing that it got a lot of commits it decides to collapse
     commit-graph-1 and -2 and the new commits, writing a brand new
     commit-graph-1.
  4. A second fetch fetches from a second remote, and writes
     commit-graph-2 (no collapsing this time).
  5. Now the crappy scheduler finally decides that it's time to wake
     up the waiting git process from step 2, which then finds the new
     commit-graph-2 file and opens it for reading.
  6. At this point this poor git process has file handles for:
  
     - the base commit-graph file, which is unchanged.
     - the old commit-graph-1 which has since been replaced, and does
       not yet contain info about the old commit-graph-2 or the
       commits received in the first fetch.
     - the new commit-graph-2, containing info only about commits
       received in the second fetch, and whose parents' graph
       positions point either to the base commitg-graph (good, since
       unchanged) or to the new commit-graph-1 (uh-oh).

What happens next? If this process tries to access the parent of a commit from commit-graph-2, and the metadata about this parent is in the new commit-graph-1, then I expect all kinds of weird bugs.

But will a git process ever try to access a commit that didn't yet existed in the repository when it started opening the commit-graph files?

Show 35 quoted lines
> +## Merge Strategy
> +
> +When writing a set of commits that do not exist in the
> +commit-graph stack of height N, we default to creating
> +a new file at level N + 1. We then decide to merge
> +with the Nth level if one of two conditions hold:
> +
> +  1. The expected file size for level N + 1 is at
> +     least half the file size for level N.
> +
> +  2. Level N + 1 contains more than MAX_SPLIT_COMMITS
> +     commits (64,0000 commits).
> +
> +This decision cascades down the levels: when we
> +merge a level we create a new set of commits that
> +then compares to the next level.
> +
> +The first condition bounds the number of levels
> +to be logarithmic in the total number of commits.
> +The second condition bounds the total number of
> +commits in a `commit-graph-N` file and not in
> +the `commit-graph` file, preventing significant
> +performance issues when the stack merges and another
> +process only partially reads the previous stack.
> +
> +The merge strategy values (2 for the size multiple,
> +64,000 for the maximum number of commits) could be
> +extracted into config settings for full flexibility.
> +
>  Related Links
>  -------------
>  [0] https://bugs.chromium.org/p/git/issues/detail?id=8
> -- 
> gitgitgadget
> 
Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee
Message 16 of 136 in “[RFC] Commit-graph: Write incremental files”
  1. 00/17 [RFC] Commit-graph: Write incremental filesDerrick Stolee via GitGitGadget, May 8, 2019
  2. 01/17 commit-graph: fix the_repository referenceDerrick Stolee via GitGitGadget, May 8, 2019
  3. 02/17 commit-graph: return with errors during writeDerrick Stolee via GitGitGadget, May 8, 2019
  4. 03/17 commit-graph: collapse parameters into flagsDerrick Stolee via GitGitGadget, May 8, 2019
  5. 04/17 commit-graph: remove Future Work sectionDerrick Stolee via GitGitGadget, May 8, 2019
  6. 06/17 commit-graph: extract fill_oids_from_packs()Derrick Stolee via GitGitGadget, May 8, 2019
  7. 08/17 commit-graph: extract fill_oids_from_all_packs()Derrick Stolee via GitGitGadget, May 8, 2019
  8. 10/17 commit-graph: extract copy_oids_to_commits()Derrick Stolee via GitGitGadget, May 8, 2019
  9. 09/17 commit-graph: extract count_distinct_commits()Derrick Stolee via GitGitGadget, May 8, 2019
  10. 07/17 commit-graph: extract fill_oids_from_commit_hex()Derrick Stolee via GitGitGadget, May 8, 2019
  11. 05/17 commit-graph: create write_commit_graph_contextDerrick Stolee via GitGitGadget, May 8, 2019
  12. 14/17 commit-graph: load split commit-graph filesDerrick Stolee via GitGitGadget, May 8, 2019
  13. 11/17 commit-graph: extract write_commit_graph_file()Derrick Stolee via GitGitGadget, May 8, 2019
  14. 13/17 commit-graph: lay groundwork for incremental filesDerrick Stolee via GitGitGadget, May 8, 2019
  15. 12/17 Documentation: describe split commit-graphsDerrick Stolee via GitGitGadget, May 8, 2019
  16. SZEDER GáborMay 8, 2019
  17. Derrick StoleeMay 8, 2019
  18. Ævar Arnfjörð BjarmasonMay 8, 2019
  19. Junio C HamanoMay 9, 2019
  20. Derrick StoleeMay 9, 2019
  21. Derrick StoleeMay 9, 2019
  22. Ævar Arnfjörð BjarmasonMay 9, 2019
  23. Derrick StoleeMay 9, 2019
  24. Ævar Arnfjörð BjarmasonMay 9, 2019
  25. Derrick StoleeMay 10, 2019
  26. 16/17 commit-graph: add --split optionDerrick Stolee via GitGitGadget, May 8, 2019
  27. 15/17 commit-graph: write split commit-graph filesDerrick Stolee via GitGitGadget, May 8, 2019
  28. 17/17 fetch: add fetch.writeCommitGraph config settingDerrick Stolee via GitGitGadget, May 8, 2019
  29. Ævar Arnfjörð BjarmasonMay 9, 2019
  30. Derrick StoleeMay 9, 2019
  31. Ævar Arnfjörð BjarmasonMay 8, 2019
  32. 00/11 [RFC] Commit-graph: Write incremental filesDerrick Stolee via GitGitGadget, May 22, 2019
  33. 01/11 commit-graph: document commit-graph chainsDerrick Stolee via GitGitGadget, May 22, 2019
  34. 02/11 commit-graph: prepare for commit-graph chainsDerrick Stolee via GitGitGadget, May 22, 2019
  35. 03/11 commit-graph: rename commit_compare to oid_compareDerrick Stolee via GitGitGadget, May 22, 2019
  36. 04/11 commit-graph: load commit-graph chainsDerrick Stolee via GitGitGadget, May 22, 2019
  37. 05/11 commit-graph: add base graphs chunkDerrick Stolee via GitGitGadget, May 22, 2019
  38. 06/11 commit-graph: rearrange chunk count logicDerrick Stolee via GitGitGadget, May 22, 2019
  39. 08/11 commit-graph: add --split option to builtinDerrick Stolee via GitGitGadget, May 22, 2019
  40. SZEDER GáborMay 27, 2019
  41. 07/11 commit-graph: write commit-graph chainsDerrick Stolee via GitGitGadget, May 22, 2019
  42. 10/11 commit-graph: allow cross-alternate chainsDerrick Stolee via GitGitGadget, May 22, 2019
  43. 09/11 commit-graph: merge commit-graph chainsDerrick Stolee via GitGitGadget, May 22, 2019
  44. Ævar Arnfjörð BjarmasonMay 23, 2019
  45. Derrick StoleeMay 23, 2019
  46. 11/11 commit-graph: expire commit-graph filesDerrick Stolee via GitGitGadget, May 22, 2019
  47. 00/14 Commit-graph: Write incremental filesDerrick Stolee via GitGitGadget, Jun 3, 2019
  48. 01/14 commit-graph: document commit-graph chainsDerrick Stolee via GitGitGadget, Jun 3, 2019
  49. Junio C HamanoJun 5, 2019
  50. Derrick StoleeJun 5, 2019
  51. Philip OakleyJun 6, 2019
  52. Derrick StoleeJun 6, 2019
  53. Philip OakleyJun 6, 2019
  54. 02/14 commit-graph: prepare for commit-graph chainsDerrick Stolee via GitGitGadget, Jun 3, 2019
  55. 04/14 commit-graph: load commit-graph chainsDerrick Stolee via GitGitGadget, Jun 3, 2019
  56. 03/14 commit-graph: rename commit_compare to oid_compareDerrick Stolee via GitGitGadget, Jun 3, 2019
  57. 08/14 commit-graph: add --split option to builtinDerrick Stolee via GitGitGadget, Jun 3, 2019
  58. 06/14 commit-graph: rearrange chunk count logicDerrick Stolee via GitGitGadget, Jun 3, 2019
  59. 05/14 commit-graph: add base graphs chunkDerrick Stolee via GitGitGadget, Jun 3, 2019
  60. 07/14 commit-graph: write commit-graph chainsDerrick Stolee via GitGitGadget, Jun 3, 2019
  61. 10/14 commit-graph: allow cross-alternate chainsDerrick Stolee via GitGitGadget, Jun 3, 2019
  62. 11/14 commit-graph: expire commit-graph filesDerrick Stolee via GitGitGadget, Jun 3, 2019
  63. 09/14 commit-graph: merge commit-graph chainsDerrick Stolee via GitGitGadget, Jun 3, 2019
  64. 14/14 commit-graph: clean up chains after flattened writeDerrick Stolee via GitGitGadget, Jun 3, 2019
  65. 13/14 commit-graph: verify chains with --shallow modeDerrick Stolee via GitGitGadget, Jun 3, 2019
  66. 12/14 commit-graph: create options for split filesDerrick Stolee via GitGitGadget, Jun 3, 2019
  67. 00/14 Commit-graph: Write incremental filesDerrick Stolee via GitGitGadget, Jun 6, 2019
  68. 02/14 commit-graph: prepare for commit-graph chainsDerrick Stolee via GitGitGadget, Jun 6, 2019
  69. Philip OakleyJun 6, 2019
  70. Junio C HamanoJun 6, 2019
  71. Derrick StoleeJun 7, 2019
  72. 03/14 commit-graph: rename commit_compare to oid_compareDerrick Stolee via GitGitGadget, Jun 6, 2019
  73. 01/14 commit-graph: document commit-graph chainsDerrick Stolee via GitGitGadget, Jun 6, 2019
  74. 06/14 commit-graph: rearrange chunk count logicDerrick Stolee via GitGitGadget, Jun 6, 2019
  75. Junio C HamanoJun 7, 2019
  76. 04/14 commit-graph: load commit-graph chainsDerrick Stolee via GitGitGadget, Jun 6, 2019
  77. Junio C HamanoJun 6, 2019
  78. Derrick StoleeJun 7, 2019
  79. 07/14 commit-graph: write commit-graph chainsDerrick Stolee via GitGitGadget, Jun 6, 2019
  80. 05/14 commit-graph: add base graphs chunkDerrick Stolee via GitGitGadget, Jun 6, 2019
  81. Junio C HamanoJun 7, 2019
  82. 09/14 commit-graph: merge commit-graph chainsDerrick Stolee via GitGitGadget, Jun 6, 2019
  83. 11/14 commit-graph: expire commit-graph filesDerrick Stolee via GitGitGadget, Jun 6, 2019
  84. 10/14 commit-graph: allow cross-alternate chainsDerrick Stolee via GitGitGadget, Jun 6, 2019
  85. Philip OakleyJun 6, 2019
  86. 08/14 commit-graph: add --split option to builtinDerrick Stolee via GitGitGadget, Jun 6, 2019
  87. Junio C HamanoJun 7, 2019
  88. Derrick StoleeJun 11, 2019
  89. Junio C HamanoJun 11, 2019
  90. 12/14 commit-graph: create options for split filesDerrick Stolee via GitGitGadget, Jun 6, 2019
  91. Ramsay JonesJun 6, 2019
  92. 13/14 commit-graph: verify chains with --shallow modeDerrick Stolee via GitGitGadget, Jun 6, 2019
  93. 14/14 commit-graph: clean up chains after flattened writeDerrick Stolee via GitGitGadget, Jun 6, 2019
  94. Junio C HamanoJun 6, 2019
  95. Derrick StoleeJun 7, 2019
  96. 00/16 Commit-graph: Write incremental filesDerrick Stolee via GitGitGadget, Jun 7, 2019
  97. 01/16 commit-graph: document commit-graph chainsDerrick Stolee via GitGitGadget, Jun 7, 2019
  98. 02/16 commit-graph: prepare for commit-graph chainsDerrick Stolee via GitGitGadget, Jun 7, 2019
  99. 07/16 commit-graph: write commit-graph chainsDerrick Stolee via GitGitGadget, Jun 7, 2019
  100. 08/16 commit-graph: add --split option to builtinDerrick Stolee via GitGitGadget, Jun 7, 2019
  101. 05/16 commit-graph: add base graphs chunkDerrick Stolee via GitGitGadget, Jun 7, 2019
  102. 04/16 commit-graph: load commit-graph chainsDerrick Stolee via GitGitGadget, Jun 7, 2019
  103. Junio C HamanoJun 10, 2019
  104. Derrick StoleeJun 10, 2019
  105. 03/16 commit-graph: rename commit_compare to oid_compareDerrick Stolee via GitGitGadget, Jun 7, 2019
  106. 10/16 commit-graph: allow cross-alternate chainsDerrick Stolee via GitGitGadget, Jun 7, 2019
  107. 09/16 commit-graph: merge commit-graph chainsDerrick Stolee via GitGitGadget, Jun 7, 2019
  108. 13/16 commit-graph: verify chains with --shallow modeDerrick Stolee via GitGitGadget, Jun 7, 2019
  109. 15/16 commit-graph: test octopus merges with --splitDerrick Stolee via GitGitGadget, Jun 7, 2019
  110. 16/16 commit-graph: test --split across alternate without --splitDerrick Stolee via GitGitGadget, Jun 7, 2019
  111. 14/16 commit-graph: clean up chains after flattened writeDerrick Stolee via GitGitGadget, Jun 7, 2019
  112. 12/16 commit-graph: create options for split filesDerrick Stolee via GitGitGadget, Jun 7, 2019
  113. 06/16 commit-graph: rearrange chunk count logicDerrick Stolee via GitGitGadget, Jun 7, 2019
  114. 11/16 commit-graph: expire commit-graph filesDerrick Stolee via GitGitGadget, Jun 7, 2019
  115. commit-graph: normalize commit-graph filenamesDerrick Stolee, Jun 17, 2019
  116. Derrick StoleeJun 17, 2019
  117. commit-graph: normalize commit-graph filenamesDerrick Stolee, Jun 17, 2019
  118. 00/18 Commit-graph: Write incremental filesDerrick Stolee via GitGitGadget, Jun 18, 2019
  119. 01/18 commit-graph: document commit-graph chainsDerrick Stolee via GitGitGadget, Jun 18, 2019
  120. 04/18 commit-graph: load commit-graph chainsDerrick Stolee via GitGitGadget, Jun 18, 2019
  121. 05/18 commit-graph: add base graphs chunkDerrick Stolee via GitGitGadget, Jun 18, 2019
  122. 03/18 commit-graph: rename commit_compare to oid_compareDerrick Stolee via GitGitGadget, Jun 18, 2019
  123. 08/18 commit-graph: add --split option to builtinDerrick Stolee via GitGitGadget, Jun 18, 2019
  124. 09/18 commit-graph: merge commit-graph chainsDerrick Stolee via GitGitGadget, Jun 18, 2019
  125. 06/18 commit-graph: rearrange chunk count logicDerrick Stolee via GitGitGadget, Jun 18, 2019
  126. 07/18 commit-graph: write commit-graph chainsDerrick Stolee via GitGitGadget, Jun 18, 2019
  127. 10/18 commit-graph: allow cross-alternate chainsDerrick Stolee via GitGitGadget, Jun 18, 2019
  128. 02/18 commit-graph: prepare for commit-graph chainsDerrick Stolee via GitGitGadget, Jun 18, 2019
  129. 14/18 commit-graph: clean up chains after flattened writeDerrick Stolee via GitGitGadget, Jun 18, 2019
  130. 15/18 commit-graph: test octopus merges with --splitDerrick Stolee via GitGitGadget, Jun 18, 2019
  131. 18/18 commit-graph: test verify across alternatesDerrick Stolee via GitGitGadget, Jun 18, 2019
  132. 11/18 commit-graph: expire commit-graph filesDerrick Stolee via GitGitGadget, Jun 18, 2019
  133. 13/18 commit-graph: verify chains with --shallow modeDerrick Stolee via GitGitGadget, Jun 18, 2019
  134. 12/18 commit-graph: create options for split filesDerrick Stolee via GitGitGadget, Jun 18, 2019
  135. 16/18 commit-graph: test --split across alternate without --splitDerrick Stolee via GitGitGadget, Jun 18, 2019
  136. 17/18 commit-graph: normalize commit-graph filenamesDerrick Stolee via GitGitGadget, Jun 18, 2019

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.