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

Re: [PATCH 0/1] Fix UX issue with commit-graph.lock

From
Derrick Stolee <stolee@gmail.com>
Date
May 10, 2018, 12:52 UTC
Message-ID
<3b8005c4-a43d-bd46-c7d9-d6490d500114@gmail.com>
In-Reply-To
<xmqqfu30j8q7.fsf@gitster-ct.c.googlers.com>
On 5/10/2018 3:00 AM, Junio C Hamano wrote:
Show 24 quoted lines
> Derrick Stolee <dstolee@microsoft.com> writes:
>
>> We use the lockfile API to avoid multiple Git processes from writing to
>> the commit-graph file in the .git/objects/info directory. In some cases,
>> this directory may not exist, so we check for its existence.
>>
>> The existing code does the following when acquiring the lock:
>>
>> 1. Try to acquire the lock.
>> 2. If it fails, try to create the .git/object/info directory.
>> 3. Try to acquire the lock, failing if necessary.
>>
>> The problem is that if the lockfile exists, then the mkdir fails, giving
>> an error that doesn't help the user:
>>
>>    "fatal: cannot mkdir .git/objects/info: File exists"
> Isn't a better immediate fix to make the second step pay attention
> to errno?  If mkdir() failed due to EEXIST, then we know we tried to
> aquire the lock already, so we can die with an appropriate message.
>
> That way, we can keep the "optimize for the normal case" that the
> approach to assume object/info/ directory is already there, instead
> of always checking its existence which is almost always true
> beforehand.

This "optimize for the normal case" is why the existing code is organized the way it is.

Since this code is only for writing a commit-graph file, this "check the directory first" option is a very small portion of the full time to write the file, so the "optimization" has very little effect, relatively. My personal opinion is to make the code cleaner when the performance difference is negligible.

I'm willing to concede this point and use the steps you suggest below, if we think this is the best way forward.

> Also, can't we tell why we failed to acquire the lock at step #1?
> Do we only get a NULL that says "I am not telling you why, but we
> failed to lock"?

To tell why we failed to acquire the lock, we could inspect "errno". However, this requires whitebox knowledge of both the lockfile API and the tempfile API to know that the last system call to set errno was an open() or adjust_shared_perm(). To cleanly make decisions based on the reason the lock failed to acquire, I think we would need to modify the lockfile and tempfile APIs to return a failure reason. This could be done by passing an `int *reason`, but the extra noise in these APIs is likely not worth the change.

Show 15 quoted lines
> What I am getting at is that the ideal sequence
> would be more like:
>      1. Try to acquire the lock.
>      2-a. if #1 succeeds, we are happy. ignore the rest and return
>           the lock.
>      2-b. if #1 failed because object/info/ did not exist,
>           mkdir() it, and die if we cannot, saying "cannot mkdir".
> 	 if mkdir() succeeds, jump t 3.
>      2-c. if #1 failed but that is not due to missing object/info/,
> 	 die saying "cannot lock".
>      3. Try to acquire the lock.
>      4-a. if #3 succeeds, we are happy.ignore the rest and return
>           the lock.
>      4-b. die saying "cannot lock".
>

Thanks, -Stolee

Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 11 in “Fix UX issue with commit-graph.lock”
  1. 0/1 Fix UX issue with commit-graph.lockDerrick Stolee, May 9, 2018
  2. 1/1 commit-graph: fix UX issue when .lock file existsDerrick Stolee, May 9, 2018
  3. Jeff KingMay 9, 2018
  4. Derrick StoleeMay 9, 2018
  5. Jeff KingMay 10, 2018
  6. Duy NguyenMay 9, 2018
  7. Junio C HamanoMay 10, 2018
  8. Derrick StoleeMay 10, 2018
  9. Junio C HamanoMay 11, 2018
  10. commit-graph: fix UX issue when .lock file existsDerrick Stolee, May 10, 2018
  11. Jeff KingMay 11, 2018

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.