From: Jun Wu <quark.zju@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, peff@peff.net, ps@pks.im, Jun Wu <quark@meta.com>
Subject: Re: [PATCH 1/2] repository: add core.indexLockTimeout
Date: Wed, 14 Oct 2026 15:12:32 -0700 [thread overview]
Message-ID: <20261014221233.1694344-1-quark.zju@gmail.com> (raw)
In-Reply-To: <xmqqbj8xuugv.fsf@gitster.g>
On Tue, 13 Oct 2026 15:05:52 -0700, Junio C Hamano wrote:
> > Default timeout is 1s, effective but not too long to avoid breaking potential
> > user expectation (e.g. "an index.lock error means I should check whether a
> > commit message editor is open somewhere"). Tests that are slowed down by the
> > default timeout now set the timeout to 0.
>
> Need to change the existing tests is a sign that end-user workflows
> that are emulated by them will be impacted, and we'd need to be
> careful.
Yes. I'm aware of end-user behavior change. The test changes aren't strictly
necessary - without the changes tests still pass, although run a bit slower.
> I am not sure if the change is making the right trade-off between
> background tasks and end-user action that expects immediate
> response.
It seems the trade-off is between command success rate and command duration.
I suspect that end-users want commands to work (not fail) first, performance
comes next. In my experience, high command failure rate escalates to oncall
incidents, occasional slightly slower commands often get unnoticed unless we
look at the metrics explicitly.
Mercurial has been using 10-minute timeout by default. I picked 1 second as a
middle ground, limit the "slowness". I'm open to setting it to 10 minutes
(matches hg), or 0 (preserves the old behavior), or another value.
> A few comments and/or questions..
>
> (1) In the unhappy case where the index was read already and then
> we try to take the lock, what should happen when we notice that
> the index is locked and better yet if we notice that the index
> has been updated before we write the in-core index we wanted to
> write out? The question is what "should" happen, not "what
> happens with the current code".
I think the lock infrastructure might want to force dropping outdated in-memory
index once lock gets acquired. The users of the lock APIs need to handle this
new cache invalidation situation. Locks in hg work this way.
How each command treats the "cache gets dropped by locking" can vary by case.
For example,
- status: read -> refresh -> lock(timeout=0) -> invalidated ? skip : write
- add -i: read -> lock(timeout>0) -> invalidated ? re-apply "add" : write
> (2) Are there cases where we take lock only to make sure nobody
> will update the index without any intention to write out the
> contents of our in-core index? IOW, we are holding the lock
> only to have a consistent world view while performing a
> read-only operation? How would this change affect it?
There are commands (e.g. rm --dry-run) that lock without writing, but these
might be for convenience, not consistency. This change will make them wait.
Since a single read of the index is already consistent (it is replaced
atomically), I assume by "view" you also mean the working tree files.
Then, there is a question about the intended scope of the index lock:
a. only covers the index
b. covers both the index and working copy files
The answer probably does not matter that much, since commands that write
working copy files likely also want to update stat, therefore take the index
lock. The only exception seems to be "clean", since index has no stat for
untracked files. Today, "clean" does not lock. So this change doesn't affect
it.
> (3) When 'repo->index->initialized' is true, does it always mean we
> have read the on-disk index already, or are there cases where
> we created the in-core index from scratch and called this
> function with the intention to write over it? For such a use
> case, what, if any, are the implications of this change?
## Does initialized=1 mean reading from disk already?
Not always.
initialized=1 is set by either 'do_read_index' or 'unpack_trees'.
'do_read_index' is the regular path. 'unpack_trees' sets result->initialized=1
so it depends on the input of 'unpack_trees'. Some callers (e.g. read-tree)
call unpack_trees when repo->index is empty, not initialized. So in this case,
initialized=1 does not mean "read from disk".
## Cases we created index from scratch, then call repo_hold_locked_index
I didn't find any.
There are commands that create index from scratch, intend to write: clone and
read-tree. But they all take the index lock (when initialized=0) before calling
'unpack_trees' (sets initialized=1).
next prev parent reply other threads:[~2026-10-14 22:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 17:23 [PATCH 0/2] Add a way to wait for index lock Jun Wu
2026-10-13 17:23 ` [PATCH 1/2] repository: add core.indexLockTimeout Jun Wu
2026-10-13 21:40 ` D. Ben Knoble
2026-10-14 2:38 ` Jun Wu
2026-10-14 16:29 ` D. Ben Knoble
2026-10-13 22:05 ` Junio C Hamano
2026-10-14 22:12 ` Jun Wu [this message]
2026-10-13 17:23 ` [PATCH 2/2] commit: lock index before reading Jun Wu
2026-10-14 10:04 ` Jeff King
2026-10-15 0:19 ` Jun Wu
2026-10-13 22:05 ` [PATCH 0/2] Add a way to wait for index lock Junio C Hamano
2026-10-14 22:12 ` Jun Wu
2026-10-14 10:14 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261014221233.1694344-1-quark.zju@gmail.com \
--to=quark.zju@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
--cc=quark@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox