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

Re: [RFC PATCH v1 0/6] stash: drop usage of a second index

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Jun 16, 2020, 07:06 UTC
Message-ID
<20200616070645.GF2898@szeder.dev>
In-Reply-To
<20200615215020.GE2898@szeder.dev>
On Mon, Jun 15, 2020 at 11:50:20PM +0200, SZEDER Gábor wrote:
Show 38 quoted lines
> On Mon, Jun 15, 2020 at 05:27:15PM +0200, SZEDER Gábor wrote:
> >       - Should we even allow 'splitIndex.sharedIndexExpire=now'?
> >     
> >         I believe, though haven't confirmed, that it can cause trouble
> >         even without using an alternate index.  Consider the following
> >         sequence of events:
> >     
> >           - Git process A reads '.git/index', finds the 'link' extension,
> >             and reads the SHA1 recorded there that determines the filename
> >             of its shared index.
> >     
> >           - The scheduler steps in, and puts process A to sleep.
> >     
> >           - Git process B updates the index, decides that it's time to
> >             write a new shared index, does so, and then because of
> >             'splitIndex.sharedIndexExpire=now' it removes all other shared
> >             index files.
> >     
> >           - The scheduler wakes process A, which now tries to open the
> >             shared index file it just learned about, but fails because
> >             that file has just been removed by process B.
> 
> Confirmed.
> 
> To help reproduce the issue, this diff adds a strategically-placed
> controllable delay between reading '.git/index' and reading its
> shared/base index:
> 
> diff --git a/read-cache.c b/read-cache.c
> index b888c5df44..5a66e9bf4b 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2319,6 +2319,9 @@ int read_index_from(struct index_state *istate, const char *path,
>  	else
>  		split_index->base = xcalloc(1, sizeof(*split_index->base));
>  
> +	if (git_env_bool("GIT_TEST_WAIT", 0))
> +		sleep(3);
We don't even need this sleep() call ...
Show 14 quoted lines
>  	base_oid_hex = oid_to_hex(&split_index->base_oid);
>  	base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
>  	trace2_region_enter_printf("index", "shared/do_read_index",
> 
> 
> Then this test creates the above described sequence of events:
> 
> test_expect_failure 'splitIndex.sharedIndexExpire=now can be harmful' '
> 	>file1 &&
> 	>file2 &&
> 	git update-index --split-index --add file1 &&
> 
> 	{
> 		sleep 1 &&
... and this 'sleep 1' command.
Show 15 quoted lines
> 		# "process B"
> 		git -c splitIndex.sharedIndexExpire=now \
> 		    update-index --split-index --add file2 &
> 	} &&
> 
> 	# "process A"
> 	GIT_TEST_WAIT=1 git diff --cached --name-only
> '
> 
> ... and fails reliably with:
> 
>   [...]
>   + GIT_TEST_WAIT=1 git diff --cached --name-only
>   [ ... trace from background commands removed ...]
>   fatal: .git/sharedindex.818f65852e7402f236aeaadd32efdbb62291aa75: index file open failed: No such file or directory

Flipping the test to 'test_expect_success' and running it with '--stress' almost always fails within 2 seconds.

Show 9 quoted lines
> >         This is similar to the issue we have with 'git gc --prune=now',
> >         except that 'git gc's documentation explicitly warns about the
> >         risks of using '--prune=now', while the description of
> >         'splitIndex.sharedIndexExpire' doesn't have any such warning.
> >     
> >         I think that 'splitIndex.sharedIndexExpire=now' should be allowed,
> >         for those who hopefully know what they are doing, just as we allow
> >         'git gc --prune=now', but the documentation should clearly warn
> >         against its potential pitfalls.
Previous: SZEDER GáborNext: Junio C Hamano
Message 21 of 44 in “stash: drop usage of a second index”
  1. 0/6 stash: drop usage of a second indexAlban Gruin, May 5, 2020
  2. 2/6 stash: remove the second index in stash_working_tree()Alban Gruin, May 5, 2020
  3. Christian CouderJun 13, 2020
  4. Alban GruinJun 13, 2020
  5. Christian CouderJun 15, 2020
  6. 1/6 stash: mark `i_tree' in reset_tree() constAlban Gruin, May 5, 2020
  7. Christian CouderJun 13, 2020
  8. 4/6 stash: remove the second index in save_untracked_files()Alban Gruin, May 5, 2020
  9. Christian CouderJun 13, 2020
  10. 5/6 stash: remove the second index in restore_untracked()Alban Gruin, May 5, 2020
  11. Christian CouderJun 13, 2020
  12. 3/6 stash: remove the second index in stash_patch()Alban Gruin, May 5, 2020
  13. Christian CouderJun 13, 2020
  14. Christian CouderJun 13, 2020
  15. 6/6 stash: remove `stash_index_path'Alban Gruin, May 5, 2020
  16. Alban GruinJun 4, 2020
  17. Christian CouderJun 13, 2020
  18. Alban GruinJun 25, 2020
  19. SZEDER GáborJun 15, 2020
  20. SZEDER GáborJun 15, 2020
  21. SZEDER GáborJun 16, 2020
  22. Junio C HamanoJun 17, 2020
  23. Alban GruinJun 17, 2020
  24. 0/6 stash: drop usage of a second indexAlban Gruin, Jun 30, 2020
  25. 1/6 stash: mark `i_tree' in reset_tree() constAlban Gruin, Jun 30, 2020
  26. 2/6 stash: remove the second index in stash_working_tree()Alban Gruin, Jun 30, 2020
  27. 4/6 stash: remove the second index in save_untracked_files()Alban Gruin, Jun 30, 2020
  28. 3/6 stash: remove the second index in stash_patch()Alban Gruin, Jun 30, 2020
  29. 5/6 stash: remove the second index in restore_untracked()Alban Gruin, Jun 30, 2020
  30. Christian CouderJul 31, 2020
  31. Alban GruinJul 31, 2020
  32. 6/6 stash: remove `stash_index_path'Alban Gruin, Jun 30, 2020
  33. Christian CouderJul 31, 2020
  34. 0/6 stash: drop usage of a second indexAlban Gruin, Jul 31, 2020
  35. 1/6 stash: mark `i_tree' in reset_tree() constAlban Gruin, Jul 31, 2020
  36. Junio C HamanoJul 31, 2020
  37. 2/6 stash: remove the second index in stash_working_tree()Alban Gruin, Jul 31, 2020
  38. Junio C HamanoJul 31, 2020
  39. Junio C HamanoAug 2, 2020
  40. 4/6 stash: remove the second index in save_untracked_files()Alban Gruin, Jul 31, 2020
  41. 5/6 stash: remove the second index in restore_untracked()Alban Gruin, Jul 31, 2020
  42. 3/6 stash: remove the second index in stash_patch()Alban Gruin, Jul 31, 2020
  43. 6/6 stash: remove `stash_index_path'Alban Gruin, Jul 31, 2020
  44. Junio C HamanoJul 31, 2020

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.