git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Han-Wen Nienhuys <hanwen@google.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	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: Reftable locking on Windows (Re: [PATCH 1/6] fixup! reftable: rest of library)
Date: Thu, 3 Dec 2020 14:56:43 +0100	[thread overview]
Message-ID: <CAFQ2z_PBk+fHLQ_hP5Lo1qJEX+eHnfWV_pbzkijajdMJDauW-A@mail.gmail.com> (raw)
In-Reply-To: <87k0tzulf1.fsf@evledraar.gmail.com>

On Thu, Dec 3, 2020 at 1:24 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> >> 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).
> >
> > So, how does this sound:
> >
> > * add a void
> >
> >   set_warn_handler(void(*handler)(char const*))
> >
> > The handler is called for non-fatal errors (eg. deleting an in-use
> > .ref file during compaction), and can provide the warning.
> >
> > * all .ref files will be prefixed with an 8-byte random string, to
> > avoid that new *.ref files collide with unreferenced, stale *.ref
> > files.
>
> Just trying to follow along here. Do you mean prefix the file name or
> the content of those *.ref files? In any case isn't this synonymous with
> proposing moving beyond reftable v1 (to the WIP v2, or a v1.1 with just
> this change?). The current spec seems to preclude prefixing either the
> file content or filename, but maybe I'm misreading it:

This is about prefixing the filename with an uniquifying prefix. This
is because the range of timestamps encompassed by the table doesn't
uniquely identify the table.

Consider the following case:
  State: 1 table "00001.ref"
  Transaction 1: add ref xyz at timestamp 2
     add ref abc at timestamp 2
     => 00002.ref
  Transaction 2: add delete ref xyz at timestamp 3
     => 00003.ref

On compacting 00002 and 00003 together, you'll end up with a table for
only  "ref abc at timestamp 2". If you call that result 00002.ref
again, there are two versions 00002.ref.

In the current spec with unix semantics, that's not a problem, because
out of date tables are removed, and disappear once the last reader closes
the file, but if we have to cater for a system
where removal that doesn't always work, we'd have to fix up things
afterwards. That means we have to be able to tell apart these two
versions of 00002.ref, and this is where a random prefix would help.

The exact naming of the tables is not central to the spec, as the
table names to read are listed in tables.list, and systems can write
filenames as they please. Maybe recommendations around filenames
should be phrased as a "SHOULD" clause, with a "MUST" that each table
has a globally unique name.

> https://googlers.googlesource.com/sop/jgit/+/reftable/Documentation/technical/reftable.md#update-transactions
> https://googlers.googlesource.com/sop/jgit/+/reftable/Documentation/technical/reftable.md#header
>
> When the reftable format was initially being discussed I suggested
> somewhat flippantly (why not SQLite?). Partially because in trying to
> invent what's essentially a portable and concurrently updated database
> format we'd be likely to reinvent much of the same wheel.
>
> So not to drag that whole thing up again as a proposal for a format
> replacement, but I wonder what SQLite would do in this scenario & others
> where desired DB semantics / transactions and FS/portability semantics
> clash. AFAIK the reftable has only been battle-tested in production
> under JGit so far (presumably Linux-only). Whereas SQLite has been
> ported to and widely used on Windows, HP/UX and probably other systems
> where Linux-specific assumptions don't apply.

I think it would be an interesting exercise to build a ref database on
SQLite, and I wish it had been done before, because large part of the
work of getting reftable to work with git proper, is disentangling
the code with assumptions about the underlying ref storage system.

I agree that some of this is reinventing the wheel, and I wish that
reftable had been based on another format (say, LevelDB) to get away
from bit mangling, but I think SQlite is a tricky proposition, because
SQLite is a system with considerable complexity of its own. You'd
force all the other Git implementations (libgit2, Microsoft's C#,
go-git, JGit, Dulwhich etc.) to find a way to implement SQLite
support. That will be a difficult proposition for the implementations that
try to avoid FFI.

You could also look at this from the positive side, which is that the
transaction semantics of reftable are much easier to understand and
verify than those of the files backend.

--
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
--

Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
--

Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

  reply	other threads:[~2020-12-03 13:57 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
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 [this message]
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

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

  git send-email \
    --in-reply-to=CAFQ2z_PBk+fHLQ_hP5Lo1qJEX+eHnfWV_pbzkijajdMJDauW-A@mail.gmail.com \
    --to=hanwen@google.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.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.
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 NNTP newsgroup(s).