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

Re: [RFC PATCH 5/5] split-index: smudge and add racily clean cache entries to split index

From
Duy Nguyen <pclouds@gmail.com>
Date
Sep 8, 2018, 16:45 UTC
Message-ID
<CACsJy8CAPcD7pHgV-KWb39cFAvL1Yn+89y5znhcOgTG8O57w_A@mail.gmail.com>
In-Reply-To
<20180906024810.8074-6-szeder.dev@gmail.com>
On Thu, Sep 6, 2018 at 4:48 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:
Show 40 quoted lines
>
> Ever since the split index feature was introduced [1], refreshing a
> split index is prone to a variant of the classic racy git problem.
>
> Consider the following sequence of commands updating the split index
> when the shared index contains a racily clean cache entry, i.e. an
> entry whose cached stat data matches with the corresponding file in
> the worktree and the cached mtime matches that of the index:
>
>   echo "cached content" >file
>   git update-index --split-index --add file
>   echo "dirty worktree" >file    # size stays the same!
>   # ... wait ...
>   git update-index --add other-file
>
> Normally, when a non-split index is updated, then do_write_index()
> (the function responsible for writing all kinds of indexes, "regular",
> split, and shared) recognizes racily clean cache entries, and writes
> them with smudged stat data, i.e. with file size set to 0.  When
> subsequent git commands read the index, they will notice that the
> smudged stat data doesn't match with the file in the worktree, and
> then go on to check the file's content.
>
> In the above example, however, in the second 'git update-index'
> prepare_to_write_split_index() gathers all cache entries that should
> be written to the new split index.  Alas, this function never looks
> out for racily clean cache entries, and since the file's stat data in
> the worktree hasn't changed since the shared index was written, it
> won't be replaced in the new split index.  Consequently,
> do_write_index() doesn't even get this racily clean cache entry, and
> can't smudge its stat data.  Subsequent git commands will then see
> that the index has more recent mtime than the file and that the (not
> smudged) cached stat data still matches with the file in the worktree,
> and, ultimately, will erroneously consider the file clean.
>
> Modify prepare_to_write_split_index() to recognize racily clean cache
> entries, and mark them to be added to the split index.  This way
> do_write_index() will get these racily clean cache entries as well,
> and will then write them with smudged stat data to the new split
> index.

Ack. I was aware of the first half of of the racy solution but did not pay attention to this smudging business.

I wonder if untracked cache is also racy like this. It also only has half the racy solution because I only knew that much. I'll check this later.

Show 11 quoted lines
> Note that after this change if the index is split when it contains a
> racily clean cache entry, then a smudged cache entry will be written
> both to the new shared and to the new split indexes.  This doesn't
> affect regular git commands: as far as they are concerned this is just
> an entry in the split index replacing an outdated entry in the shared
> index.  It did affect a few tests in 't1700-split-index.sh', though,
> because they actually check which entries are stored in the split
> index; the previous patch made the necessary adjustments.  And racily
> clean cache entries and index splitting are rare enough to not worry
> about the resulting duplicated smudged cache entries, and the
> additional complexity required to prevent them is not worth it.

Yes. If we have to make updates (racy or not) we have to make updates, and the version in the shared index becomes obsolete by design.

-- 
Duy
Previous: Paul-Sebastian Ungureanu
Message 20 of 20 in “Fix the racy split index problem”
  1. 0/5 Fix the racy split index problemSZEDER Gábor, Sep 6, 2018
  2. 1/5 t1700-split-index: drop unnecessary 'grep'SZEDER Gábor, Sep 6, 2018
  3. Junio C HamanoSep 6, 2018
  4. Duy NguyenSep 8, 2018
  5. 2/5 t0090: disable GIT_TEST_SPLIT_INDEX for the test checking split indexSZEDER Gábor, Sep 6, 2018
  6. Ævar Arnfjörð BjarmasonSep 6, 2018
  7. 3/5 split index: add a test to demonstrate the racy split index problemSZEDER Gábor, Sep 6, 2018
  8. 4/5 t1700-split-index: date back files to avoid racy situationsSZEDER Gábor, Sep 6, 2018
  9. Ævar Arnfjörð BjarmasonSep 6, 2018
  10. SZEDER GáborSep 6, 2018
  11. Ævar Arnfjörð BjarmasonSep 6, 2018
  12. 5/5 split-index: smudge and add racily clean cache entries to split indexSZEDER Gábor, Sep 6, 2018
  13. Ævar Arnfjörð BjarmasonSep 6, 2018
  14. Ævar Arnfjörð BjarmasonSep 6, 2018
  15. SZEDER GáborSep 6, 2018
  16. Ævar Arnfjörð BjarmasonSep 6, 2018
  17. Ævar Arnfjörð BjarmasonSep 6, 2018
  18. SZEDER GáborSep 7, 2018
  19. Paul-Sebastian UngureanuSep 10, 2018
  20. Duy NguyenSep 8, 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.