git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Han-Wen Nienhuys <hanwen@google.com>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
	"Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Subject: Re: [PATCH v4 27/28] reftable: fixup for new base topic 2/3
Date: Mon, 30 Aug 2021 15:01:50 +0200	[thread overview]
Message-ID: <87r1ebxe2y.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <CAFQ2z_MnJr58Cu970Be7SXE1jFkgOGThQ0Geq2+kNihJE3_BvQ@mail.gmail.com>


On Mon, Aug 30 2021, Han-Wen Nienhuys wrote:

> On Mon, Aug 23, 2021 at 2:13 PM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>>
>> Since my "refs API: remove OID argument to reflog_expire()" we don't
>> have the "oid" as part of the reflog_expire() signature. Instead the
>> reflog_expire() should pass the OID of the tip of the "locked" ref to
>> the prepare_fn().
>>
>> In files_reflog_expire() we do that by getting the OID from
>> lock_ref_oid_basic(). I'm assuming (but am not familiar enough with
>> reftable...) that by the time we get here we've got a locked ref
>> already in some way, so let's just use
>> refs_resolve_ref_unsafe_with_errno() to lookup the current OID of that
>> presumably-locked ref.
>
> I quickly looked at the files code, but I don't understand why the OID
> needs to be passed-in (before your refactoring): in builtin/reflog.c
> (before), the current OID is read, with any protection. This means
> that its value can't be trusted.
>
> After your refactoring, you lock the ref. I guess in the files backend
> this protects against non-atomic update of (ref, reflog) racing with a
> concurrent reflog expiry? In reftable, the (ref,reflog) update is
> atomic, so there is no need for locking to properly sequence
> operations.

Before my [1] we'd do:

 1. Read the OID for the branch in builtin/reflog.c
 2. Pass it to refs/files-backend.c, it would lock at that OID (or fail if it changed)
 3. Pass the OID with the now-locked OID to the builtin/reflog.c code

After that [1] we do:

 1. Lock the branch in refs/files-backend.c
 2. Pass the OID with the now-locked OID to the builtin/reflog.c code
    (ditto #3 above)

Whatever reftable itself does with updates doesn't change that we need
to do that 2nd step of passing the OID to builtin/reflog.c, as it makes
use of it.

That code is a bit confusing, if you want to understand it I recommend
reading it at the tip of my yet-unsubmitted
avar/cleanup-refs-api-and-reflog-expire-post-no-eisdir, it makes the
control flow a lot cleaner.

So as far as what we do here is concerned, we're stuck with the refs
files backend inherently wanting to pass "I locked this for you, here's
the OID".

I guess it could also pass "OK, now go ahead and expire" and pass no
OID. We'd then in builtin/reflog.c lookup the current OID for the logic
there, but just having the reftable backend appease the common API by
looking up the OID and passing it seemed like the most straightforward
thing to do.

I haven't tested this or thought it through, but I don't understand how
reftable isn't going to race in reflog expiry then. Sure, the ref/reflog
update itself is atomic, so it won't suffer from the needing-a-lock
problem of two concurrent file backend writers doing the equivalent of:

    echo $NEW_SHA1 >.git/refs/heads/some-branch

But we will need at least the optimistic locking of code like
builtin/reflog.c wanting to do an expiry, and deciding whether to do
that expiry based on a given state of the ref/reflog. I.e. we don't
want:

    1. Start reflog expiry
    2. Code in builtin/reflog.c looks up the OID
    3. Code in builtin/reflog.c decides whether expire the reflog
    4. Concurrent with #4, another writer updates the ref/reflog pair
    5. Code in builtin/reflog.c says "OK, expire it!"
    6. Reftable queues a delete/prune of the reflog per #5.

This would be a sequente of updates to the ref/reflog, none of whom were
racy as far as the reftable semantics itself are concerneb, but where
we'd do the wrong thing because the writer thought we had A when we
really had B. So we need the equivalent of an "git update-ref" with the
"<oldvalue>".

Is there a better way to do that in this case that I'm missing?

1. https://lore.kernel.org/git/patch-v5-09.13-aba12606cea-20210823T113115Z-avarab@gmail.com/
2. https://github.com/avar/git/compare/avar/files-backend-remove-dead-errno-eisdir-6...avar:avar/cleanup-refs-api-and-reflog-expire-post-no-eisdir

  reply	other threads:[~2021-08-30 13:22 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-20 17:04 [PATCH 00/26] Support reftable ref backend for Git Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 01/26] hash.h: provide constants for the hash IDs Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 02/26] init-db: set the_repository->hash_algo early on Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 03/26] reftable: RFC: add LICENSE Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 04/26] reftable: add error related functionality Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 05/26] reftable: utility functions Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 06/26] reftable: add blocksource, an abstraction for random access reads Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 07/26] reftable: (de)serialization for the polymorphic record type Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 08/26] Provide zlib's uncompress2 from compat/zlib-compat.c Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 09/26] reftable: reading/writing blocks Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 10/26] reftable: a generic binary tree implementation Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 11/26] reftable: write reftable files Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 12/26] reftable: generic interface to tables Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 13/26] reftable: read reftable files Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 14/26] reftable: reftable file level tests Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 15/26] reftable: add a heap-based priority queue for reftable records Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 16/26] reftable: add merged table view Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 17/26] reftable: implement refname validation Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 18/26] reftable: implement stack, a mutable database of reftable files Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 19/26] reftable: add dump utility Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 20/26] refs: RFC: Reftable support for git-core Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 21/26] git-prompt: prepare for reftable refs backend SZEDER Gábor via GitGitGadget
2021-07-20 17:04 ` [PATCH 22/26] Add "test-tool dump-reftable" command Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 23/26] t1301: document what needs to be done for reftable Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 24/26] t1401,t2011: parameterize HEAD.lock for REFFILES Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 25/26] t1404: annotate test cases with REFFILES Han-Wen Nienhuys via GitGitGadget
2021-07-20 17:04 ` [PATCH 26/26] t7004: avoid direct filesystem access Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:16 ` [PATCH v2 00/25] Support reftable ref backend for Git Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:16   ` [PATCH v2 01/25] hash.h: provide constants for the hash IDs Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:16   ` [PATCH v2 02/25] init-db: set the_repository->hash_algo early on Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:16   ` [PATCH v2 03/25] reftable: RFC: add LICENSE Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:16   ` [PATCH v2 04/25] reftable: add error related functionality Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:16   ` [PATCH v2 05/25] reftable: utility functions Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:16   ` [PATCH v2 06/25] reftable: add blocksource, an abstraction for random access reads Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:16   ` [PATCH v2 07/25] reftable: (de)serialization for the polymorphic record type Han-Wen Nienhuys via GitGitGadget
2021-08-16 21:54     ` Carlo Marcelo Arenas Belón
2021-08-17 13:44       ` Han-Wen Nienhuys
2021-08-16 20:16   ` [PATCH v2 08/25] Provide zlib's uncompress2 from compat/zlib-compat.c Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 09/25] reftable: reading/writing blocks Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 10/25] reftable: a generic binary tree implementation Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 11/25] reftable: write reftable files Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 12/25] reftable: generic interface to tables Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 13/25] reftable: read reftable files Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 14/25] reftable: reftable file level tests Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 15/25] reftable: add a heap-based priority queue for reftable records Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 16/25] reftable: add merged table view Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 17/25] reftable: implement refname validation Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 18/25] reftable: implement stack, a mutable database of reftable files Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 19/25] reftable: add dump utility Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 20/25] refs: RFC: Reftable support for git-core Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 21/25] git-prompt: prepare for reftable refs backend SZEDER Gábor via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 22/25] Add "test-tool dump-reftable" command Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 23/25] t1301: document what needs to be done for reftable Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 24/25] t1401,t2011: parameterize HEAD.lock for REFFILES Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:17   ` [PATCH v2 25/25] t1404: annotate test cases with REFFILES Han-Wen Nienhuys via GitGitGadget
2021-08-16 20:48   ` [PATCH v2 00/25] Support reftable ref backend for Git Junio C Hamano
2021-08-17 16:38     ` Han-Wen Nienhuys
2021-08-17 13:39   ` [PATCH v3 " Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 01/25] hash.h: provide constants for the hash IDs Han-Wen Nienhuys via GitGitGadget
2021-08-23  9:47       ` Ævar Arnfjörð Bjarmason
2021-08-17 13:39     ` [PATCH v3 02/25] init-db: set the_repository->hash_algo early on Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 03/25] reftable: RFC: add LICENSE Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 04/25] reftable: add error related functionality Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 05/25] reftable: utility functions Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 06/25] reftable: add blocksource, an abstraction for random access reads Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 07/25] reftable: (de)serialization for the polymorphic record type Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 08/25] Provide zlib's uncompress2 from compat/zlib-compat.c Han-Wen Nienhuys via GitGitGadget
2021-08-18 10:14       ` Philip Oakley
2021-08-18 10:39         ` Han-Wen Nienhuys
2021-08-18 11:53           ` Philip Oakley
2021-08-17 13:39     ` [PATCH v3 09/25] reftable: reading/writing blocks Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 10/25] reftable: a generic binary tree implementation Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 11/25] reftable: write reftable files Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 12/25] reftable: generic interface to tables Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 13/25] reftable: read reftable files Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 14/25] reftable: reftable file level tests Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 15/25] reftable: add a heap-based priority queue for reftable records Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 16/25] reftable: add merged table view Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:39     ` [PATCH v3 17/25] reftable: implement refname validation Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:40     ` [PATCH v3 18/25] reftable: implement stack, a mutable database of reftable files Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:40     ` [PATCH v3 19/25] reftable: add dump utility Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:40     ` [PATCH v3 20/25] refs: RFC: Reftable support for git-core Han-Wen Nienhuys via GitGitGadget
2021-08-23  9:50       ` Ævar Arnfjörð Bjarmason
2021-08-30 13:31         ` Han-Wen Nienhuys
2021-08-30 14:10           ` Ævar Arnfjörð Bjarmason
2021-08-17 13:40     ` [PATCH v3 21/25] git-prompt: prepare for reftable refs backend SZEDER Gábor via GitGitGadget
2021-08-17 13:40     ` [PATCH v3 22/25] Add "test-tool dump-reftable" command Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:40     ` [PATCH v3 23/25] t1301: document what needs to be done for reftable Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:40     ` [PATCH v3 24/25] t1401,t2011: parameterize HEAD.lock for REFFILES Han-Wen Nienhuys via GitGitGadget
2021-08-17 13:40     ` [PATCH v3 25/25] t1404: annotate test cases with REFFILES Han-Wen Nienhuys via GitGitGadget
2021-08-23  9:08     ` [PATCH v3 00/25] Support reftable ref backend for Git Ævar Arnfjörð Bjarmason
2021-08-26 16:02       ` Ævar Arnfjörð Bjarmason
2021-08-23 12:12     ` [PATCH v4 00/28] " Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 01/28] hash.h: provide constants for the hash IDs Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 02/28] init-db: set the_repository->hash_algo early on Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 03/28] reftable: RFC: add LICENSE Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 04/28] reftable: add error related functionality Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 05/28] reftable: utility functions Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 06/28] reftable: add blocksource, an abstraction for random access reads Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 07/28] reftable: (de)serialization for the polymorphic record type Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 08/28] Provide zlib's uncompress2 from compat/zlib-compat.c Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 09/28] reftable: reading/writing blocks Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 10/28] reftable: a generic binary tree implementation Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 11/28] reftable: write reftable files Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 12/28] reftable: generic interface to tables Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 13/28] reftable: read reftable files Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 14/28] reftable: reftable file level tests Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 15/28] reftable: add a heap-based priority queue for reftable records Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 16/28] reftable: add merged table view Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 17/28] reftable: implement refname validation Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 18/28] reftable: implement stack, a mutable database of reftable files Ævar Arnfjörð Bjarmason
2021-08-27  5:33         ` Junio C Hamano
2021-08-27  6:01           ` [RFC PATCH] reftable: fixup for broken __FUNCTION__ use Ævar Arnfjörð Bjarmason
2021-08-27  7:00             ` Carlo Arenas
2021-08-30 12:11             ` Han-Wen Nienhuys
2021-08-23 12:12       ` [PATCH v4 19/28] reftable: add dump utility Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 20/28] refs: RFC: Reftable support for git-core Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 21/28] git-prompt: prepare for reftable refs backend Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 22/28] Add "test-tool dump-reftable" command Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 23/28] t1301: document what needs to be done for reftable Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 24/28] t1401,t2011: parameterize HEAD.lock for REFFILES Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 25/28] t1404: annotate test cases with REFFILES Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 26/28] reftable: fixup for new base topic 1/3 Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 27/28] reftable: fixup for new base topic 2/3 Ævar Arnfjörð Bjarmason
2021-08-30 12:32         ` Han-Wen Nienhuys
2021-08-30 13:01           ` Ævar Arnfjörð Bjarmason [this message]
2021-08-30 13:48             ` Han-Wen Nienhuys
2021-08-30 14:03               ` Ævar Arnfjörð Bjarmason
2021-08-23 12:12       ` [PATCH v4 28/28] reftable: fixup for new base topic 3/3 Ævar Arnfjörð Bjarmason
2021-08-26  8:39       ` [PATCH v4 00/28] Support reftable ref backend for Git Junio C Hamano
2021-08-26  8:56         ` Han-Wen Nienhuys
2021-08-26 15:05           ` Junio C Hamano

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=87r1ebxe2y.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hanwen@google.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;
as well as URLs for NNTP newsgroup(s).