Skip to content

Avoid commit-graph lock contention #2198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dscho
Copy link
Member

@dscho dscho commented May 18, 2019

This PR is a backport of gitgitgadget#208, which avoids a lock contention in git gc --auto where the git gc process holds a read lock to the commit-graph file (if core.commitgraph=true) and the spawned git commit-graph write (if gc.writecommitgraph=true) tries to overwrite it.

cc @derrickstolee

derrickstolee and others added 4 commits May 18, 2019 21:33
The close_commit_graph() method took a repository struct, but then
only uses the raw_object_store within. Change the function prototype
to make the method more flexible.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
The close_all_packs() method is used to close all read handles to
pack-files and the multi-pack-index before running 'git gc --auto'.
This is particularly important on the Windows platform, where read
handles block any writes to those files. Replacing one of these
files with a rename() will fail in this situation.

The commit-graph also performs a rename, so is susceptable to this
problem. We are careful to close the commit-graph before writing,
but that doesn't work when a 'git fetch' (or similar) process runs
'git gc --auto' which may write a commit-graph.

Here, close the commit-graph as part of close_all_packs().

Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
The close_all_packs() method is now responsible for more than just pack-files.
It also closes the commit-graph and the multi-pack-index. Rename the function
to be more descriptive of its larger role. The name also fits because the
input parameter is a raw_object_store.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
This topic branch is a backport of
gitgitgadget#208, which avoids a lock
contention in `git gc --auto` where the `git gc` process holds a read
lock to the `commit-graph` file (if `core.commitgraph=true`) and the
spawned `git commit-graph write` (if `gc.writecommitgraph=true`) tries
to overwrite it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho dscho force-pushed the avoid-commit-graph-lock-contention branch from 1953afc to 441bb2d Compare May 18, 2019 19:34
@dscho dscho added this to the v2.21.0(2) milestone May 19, 2019
@dscho dscho merged commit 69e7a4c into git-for-windows:master May 19, 2019
@dscho dscho deleted the avoid-commit-graph-lock-contention branch May 19, 2019 17:09
dscho added a commit to git-for-windows/build-extra that referenced this pull request May 19, 2019
We [now avoid problems updating the commit
graph](git-for-windows/git#2198) when
`gc.writeCommitGraph=true`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit that referenced this pull request May 19, 2019
dscho added a commit that referenced this pull request May 19, 2019
dscho added a commit that referenced this pull request May 21, 2019
dscho added a commit that referenced this pull request May 21, 2019
dscho added a commit that referenced this pull request May 21, 2019
dscho added a commit that referenced this pull request May 22, 2019
dscho added a commit that referenced this pull request May 22, 2019
dscho added a commit that referenced this pull request May 22, 2019
dscho added a commit that referenced this pull request May 25, 2019
dscho added a commit that referenced this pull request May 25, 2019
dscho added a commit that referenced this pull request May 25, 2019
dscho added a commit that referenced this pull request May 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants