git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Han-Wen Nienhuys <hanwen@google.com>
Cc: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
	git <git@vger.kernel.org>, Han-Wen Nienhuys <hanwenn@gmail.com>,
	Jeff King <peff@peff.net>
Subject: Re: [PATCH 1/6] fixup! reftable: rest of library
Date: Wed, 2 Dec 2020 11:57:22 +0100 (CET)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.2012021149030.25979@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <CAFQ2z_N=sZuYorZxNLn-OoWjb6y=1zrc7sCPuKzZHQODi08s+Q@mail.gmail.com>

Hi Han-Wen,

On Tue, 1 Dec 2020, Han-Wen Nienhuys wrote:

> On Sat, Nov 28, 2020 at 7:44 AM Johannes Schindelin via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> >
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> >
> > Close the file descriptors to obsolete files before trying to delete or
> > rename them. This is actually required on Windows.
> >
> > Note: this patch is just a band-aid to get the tests pass on Windows.
> > The fact that it is needed raises concerns about the overall resource
> > handling: are file descriptors closed properly whenever appropriate, or
> > are they closed much later (which can lead to rename() problems on
> > Windows, and risks running into ulimits)?
> >
> > Also, a `reftable_stack_destroy()` call had to be moved in
> > `test_reftable_stack_uptodate()` to avoid the prompt complaining that a
> > `.ref` file could not be deleted on Windows. This raises the question
> > whether the code does the right thing when two concurrent processes want
> > to access the reftable, and one wants to compact it. At the moment, it
> > does not appear to fail gracefully.
>
> Thanks for the report; I have to look more closely at these fixes; I
> fear they might be incorrect.

They might be incorrect, but less so than the previous state, as testified
by the previously failing PR build.

> The reftable spec doesn't treat this case in depth, and I think it was
> rather written for Unix-like semantics. In the Unix flavor, a process
> that wants to read can keep file descriptors open to keep reading from
> the ref DB at a consistent snapshot.

Thanks for the explanation. I actually knew that.

> What is the approach that the rest of Git on Windows takes in these
> circumstances?

The rest of Git (whether on Windows or not) treats this as a no-no. You
cannot keep a handle open to a file that is deleted.

> Consider processes P1 and P2, and the following sequence of actions
>
> P1 opens ref DB (ie. opens a set of *.ref files for read)
> P2 opens ref DB, executes a transaction. Post-transaction, it compacts
> the reftable stack.
> P2 exits
> P1 exits
>
> Currently, the compaction in P2 tries to delete the files obviated by
> the compaction. On Windows this currently fails, because you can't
> delete open files.

Indeed. So the design needs to be fixed, if it fails.

> There are several options:
>
> 1) P2 should fail the compaction. This is bad because it will lead to
> degraded performance over time, and it's not obvious if you can
> anticipate that the deletion doesn't work.
> 2) P2 should retry deleting until it succeeds. This is bad, because a
> reader can starve writers.
> 3) on exit, P1 should check if its *.ref files are still in use, and
> delete them. This smells bad, because P1 is a read-only process, yet
> it executes writes. Also, do we have good on-exit hooks in Git?
> 4) On exit, P1 does nothing. Stale *.ref files are left behind. Some
> sort of GC process cleans things up asynchronously.
> 5) The ref DB should not keep files open, and should rather open and
> close files as needed; this means P1 doesn't keep files open for long,
> and P2 can retry safely.
>
> I think 3) seems the cleanest to me (even though deleting in read
> process feels weird), but perhaps we could fallback to 5) on windows
> as well.

Traditionally, Git would fail gracefully (i.e. with a warning) to delete
the stale files, and try again at a later stage (during `git gc --auto`,
for example, or after the next compaction step).

> What errno code does deleting an in-use file on Windows produce?

I believe it would be `EACCES`. See
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/unlink-wunlink?view=msvc-160
for the documented behavior (I believe that an in-use file is treated the
same way as a read-only file in this instance).

Ciao,
Dscho

  reply	other threads:[~2020-12-02 12:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-28  6:44 [PATCH 0/6] Minimal patches to let reftable pass the CI builds Johannes Schindelin via GitGitGadget
2020-11-28  6:44 ` [PATCH 1/6] fixup! reftable: rest of library Johannes Schindelin via GitGitGadget
2020-12-01 14:32   ` Han-Wen Nienhuys
2020-12-02 10:57     ` Johannes Schindelin [this message]
2020-12-02 18:31       ` Reftable locking on Windows (Re: [PATCH 1/6] fixup! reftable: rest of library) Han-Wen Nienhuys
2020-12-03 12:24         ` Ævar Arnfjörð Bjarmason
2020-12-03 13:56           ` Han-Wen Nienhuys
2020-11-28  6:44 ` [PATCH 2/6] fixup! reftable: utility functions Johannes Schindelin via GitGitGadget
2020-11-28  6:44 ` [PATCH 3/6] fixup! reftable: rest of library Johannes Schindelin via GitGitGadget
2020-12-01 10:26   ` Jeff King
2020-12-01 11:10     ` Han-Wen Nienhuys
2020-12-01 11:57       ` Jeff King
2020-11-28  6:44 ` [PATCH 4/6] " Johannes Schindelin via GitGitGadget
2020-11-28  6:44 ` [PATCH 5/6] " Johannes Schindelin via GitGitGadget
2020-11-28  6:44 ` [PATCH 6/6] " Johannes Schindelin via GitGitGadget
2020-12-01 10:28   ` Jeff King
2020-12-01 14:24     ` Johannes Schindelin
2020-12-02  1:50       ` Jeff King
2020-12-02 11:01         ` Han-Wen Nienhuys
2020-12-02 12:43           ` Jeff King
2020-11-30 14:26 ` [PATCH 0/6] Minimal patches to let reftable pass the CI builds Han-Wen Nienhuys
2020-12-01 14:18   ` Johannes Schindelin

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.2012021149030.25979@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=hanwen@google.com \
    --cc=hanwenn@gmail.com \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).