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

Re: [PATCH v4 27/28] reftable: fixup for new base topic 2/3

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 30, 2021, 13:01 UTC
Message-ID
<87r1ebxe2y.fsf@evledraar.gmail.com>
In-Reply-To
<CAFQ2z_MnJr58Cu970Be7SXE1jFkgOGThQ0Geq2+kNihJE3_BvQ@mail.gmail.com>
On Mon, Aug 30 2021, Han-Wen Nienhuys wrote:
Show 25 quoted lines
> 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
Previous: Han-Wen NienhuysNext: Han-Wen Nienhuys
Message 125 of 132 in “Support reftable ref backend for Git”
  1. 00/26 Support reftable ref backend for GitHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  2. 01/26 hash.h: provide constants for the hash IDsHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  3. 02/26 init-db: set the_repository->hash_algo early onHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  4. 03/26 reftable: RFC: add LICENSEHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  5. 06/26 reftable: add blocksource, an abstraction for random access readsHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  6. 04/26 reftable: add error related functionalityHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  7. 05/26 reftable: utility functionsHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  8. 08/26 Provide zlib's uncompress2 from compat/zlib-compat.cHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  9. 07/26 reftable: (de)serialization for the polymorphic record type.Han-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  10. 10/26 reftable: a generic binary tree implementationHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  11. 13/26 reftable: read reftable filesHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  12. 15/26 reftable: add a heap-based priority queue for reftable recordsHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  13. 09/26 reftable: reading/writing blocksHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  14. 12/26 reftable: generic interface to tablesHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  15. 14/26 reftable: reftable file level testsHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  16. 11/26 reftable: write reftable filesHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  17. 19/26 reftable: add dump utilityHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  18. 17/26 reftable: implement refname validationHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  19. 16/26 reftable: add merged table viewHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  20. 20/26 refs: RFC: Reftable support for git-coreHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  21. 24/26 t1401,t2011: parameterize HEAD.lock for REFFILESHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  22. 23/26 t1301: document what needs to be done for reftableHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  23. 26/26 t7004: avoid direct filesystem accessHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  24. 25/26 t1404: annotate test cases with REFFILESHan-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  25. 21/26 git-prompt: prepare for reftable refs backendSZEDER Gábor via GitGitGadget, Jul 20, 2021
  26. 18/26 reftable: implement stack, a mutable database of reftable files.Han-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  27. 22/26 Add "test-tool dump-reftable" command.Han-Wen Nienhuys via GitGitGadget, Jul 20, 2021
  28. 00/25 Support reftable ref backend for GitHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  29. 01/25 hash.h: provide constants for the hash IDsHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  30. 02/25 init-db: set the_repository->hash_algo early onHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  31. 03/25 reftable: RFC: add LICENSEHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  32. 04/25 reftable: add error related functionalityHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  33. 05/25 reftable: utility functionsHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  34. 06/25 reftable: add blocksource, an abstraction for random access readsHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  35. 08/25 Provide zlib's uncompress2 from compat/zlib-compat.cHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  36. 07/25 reftable: (de)serialization for the polymorphic record type.Han-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  37. Carlo Marcelo Arenas BelónAug 16, 2021
  38. Han-Wen NienhuysAug 17, 2021
  39. 09/25 reftable: reading/writing blocksHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  40. 10/25 reftable: a generic binary tree implementationHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  41. 11/25 reftable: write reftable filesHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  42. 12/25 reftable: generic interface to tablesHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  43. 13/25 reftable: read reftable filesHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  44. 14/25 reftable: reftable file level testsHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  45. 15/25 reftable: add a heap-based priority queue for reftable recordsHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  46. 16/25 reftable: add merged table viewHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  47. 17/25 reftable: implement refname validationHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  48. 18/25 reftable: implement stack, a mutable database of reftable files.Han-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  49. 19/25 reftable: add dump utilityHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  50. 21/25 git-prompt: prepare for reftable refs backendSZEDER Gábor via GitGitGadget, Aug 16, 2021
  51. 20/25 refs: RFC: Reftable support for git-coreHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  52. 22/25 Add "test-tool dump-reftable" command.Han-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  53. 23/25 t1301: document what needs to be done for reftableHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  54. 24/25 t1401,t2011: parameterize HEAD.lock for REFFILESHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  55. 25/25 t1404: annotate test cases with REFFILESHan-Wen Nienhuys via GitGitGadget, Aug 16, 2021
  56. Junio C HamanoAug 16, 2021
  57. Han-Wen NienhuysAug 17, 2021
  58. 00/25 Support reftable ref backend for GitHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  59. 01/25 hash.h: provide constants for the hash IDsHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  60. Ævar Arnfjörð BjarmasonAug 23, 2021
  61. 06/25 reftable: add blocksource, an abstraction for random access readsHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  62. 08/25 Provide zlib's uncompress2 from compat/zlib-compat.cHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  63. Philip OakleyAug 18, 2021
  64. Han-Wen NienhuysAug 18, 2021
  65. Philip OakleyAug 18, 2021
  66. 09/25 reftable: reading/writing blocksHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  67. 05/25 reftable: utility functionsHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  68. 03/25 reftable: RFC: add LICENSEHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  69. 04/25 reftable: add error related functionalityHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  70. 12/25 reftable: generic interface to tablesHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  71. 07/25 reftable: (de)serialization for the polymorphic record type.Han-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  72. 11/25 reftable: write reftable filesHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  73. 10/25 reftable: a generic binary tree implementationHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  74. 21/25 git-prompt: prepare for reftable refs backendSZEDER Gábor via GitGitGadget, Aug 17, 2021
  75. 20/25 refs: RFC: Reftable support for git-coreHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  76. Ævar Arnfjörð BjarmasonAug 23, 2021
  77. Han-Wen NienhuysAug 30, 2021
  78. Ævar Arnfjörð BjarmasonAug 30, 2021
  79. 19/25 reftable: add dump utilityHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  80. 15/25 reftable: add a heap-based priority queue for reftable recordsHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  81. 13/25 reftable: read reftable filesHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  82. 25/25 t1404: annotate test cases with REFFILESHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  83. 16/25 reftable: add merged table viewHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  84. 18/25 reftable: implement stack, a mutable database of reftable files.Han-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  85. 24/25 t1401,t2011: parameterize HEAD.lock for REFFILESHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  86. 22/25 Add "test-tool dump-reftable" command.Han-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  87. 17/25 reftable: implement refname validationHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  88. 23/25 t1301: document what needs to be done for reftableHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  89. 14/25 reftable: reftable file level testsHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  90. 02/25 init-db: set the_repository->hash_algo early onHan-Wen Nienhuys via GitGitGadget, Aug 17, 2021
  91. Ævar Arnfjörð BjarmasonAug 23, 2021
  92. Ævar Arnfjörð BjarmasonAug 26, 2021
  93. 00/28 Support reftable ref backend for GitÆvar Arnfjörð Bjarmason, Aug 23, 2021
  94. 01/28 hash.h: provide constants for the hash IDsÆvar Arnfjörð Bjarmason, Aug 23, 2021
  95. 02/28 init-db: set the_repository->hash_algo early onÆvar Arnfjörð Bjarmason, Aug 23, 2021
  96. 03/28 reftable: RFC: add LICENSEÆvar Arnfjörð Bjarmason, Aug 23, 2021
  97. 04/28 reftable: add error related functionalityÆvar Arnfjörð Bjarmason, Aug 23, 2021
  98. 05/28 reftable: utility functionsÆvar Arnfjörð Bjarmason, Aug 23, 2021
  99. 06/28 reftable: add blocksource, an abstraction for random access readsÆvar Arnfjörð Bjarmason, Aug 23, 2021
  100. 07/28 reftable: (de)serialization for the polymorphic record type.Ævar Arnfjörð Bjarmason, Aug 23, 2021
  101. 08/28 Provide zlib's uncompress2 from compat/zlib-compat.cÆvar Arnfjörð Bjarmason, Aug 23, 2021
  102. 09/28 reftable: reading/writing blocksÆvar Arnfjörð Bjarmason, Aug 23, 2021
  103. 10/28 reftable: a generic binary tree implementationÆvar Arnfjörð Bjarmason, Aug 23, 2021
  104. 12/28 reftable: generic interface to tablesÆvar Arnfjörð Bjarmason, Aug 23, 2021
  105. 13/28 reftable: read reftable filesÆvar Arnfjörð Bjarmason, Aug 23, 2021
  106. 14/28 reftable: reftable file level testsÆvar Arnfjörð Bjarmason, Aug 23, 2021
  107. 15/28 reftable: add a heap-based priority queue for reftable recordsÆvar Arnfjörð Bjarmason, Aug 23, 2021
  108. 16/28 reftable: add merged table viewÆvar Arnfjörð Bjarmason, Aug 23, 2021
  109. 17/28 reftable: implement refname validationÆvar Arnfjörð Bjarmason, Aug 23, 2021
  110. 19/28 reftable: add dump utilityÆvar Arnfjörð Bjarmason, Aug 23, 2021
  111. 18/28 reftable: implement stack, a mutable database of reftable files.Ævar Arnfjörð Bjarmason, Aug 23, 2021
  112. Junio C HamanoAug 27, 2021
  113. reftable: fixup for broken __FUNCTION__ useÆvar Arnfjörð Bjarmason, Aug 27, 2021
  114. Carlo ArenasAug 27, 2021
  115. Han-Wen NienhuysAug 30, 2021
  116. 21/28 git-prompt: prepare for reftable refs backendÆvar Arnfjörð Bjarmason, Aug 23, 2021
  117. 20/28 refs: RFC: Reftable support for git-coreÆvar Arnfjörð Bjarmason, Aug 23, 2021
  118. 22/28 Add "test-tool dump-reftable" command.Ævar Arnfjörð Bjarmason, Aug 23, 2021
  119. 23/28 t1301: document what needs to be done for reftableÆvar Arnfjörð Bjarmason, Aug 23, 2021
  120. 26/28 reftable: fixup for new base topic 1/3Ævar Arnfjörð Bjarmason, Aug 23, 2021
  121. 25/28 t1404: annotate test cases with REFFILESÆvar Arnfjörð Bjarmason, Aug 23, 2021
  122. 24/28 t1401,t2011: parameterize HEAD.lock for REFFILESÆvar Arnfjörð Bjarmason, Aug 23, 2021
  123. 27/28 reftable: fixup for new base topic 2/3Ævar Arnfjörð Bjarmason, Aug 23, 2021
  124. Han-Wen NienhuysAug 30, 2021
  125. Ævar Arnfjörð BjarmasonAug 30, 2021
  126. Han-Wen NienhuysAug 30, 2021
  127. Ævar Arnfjörð BjarmasonAug 30, 2021
  128. 28/28 reftable: fixup for new base topic 3/3Ævar Arnfjörð Bjarmason, Aug 23, 2021
  129. 11/28 reftable: write reftable filesÆvar Arnfjörð Bjarmason, Aug 23, 2021
  130. Junio C HamanoAug 26, 2021
  131. Han-Wen NienhuysAug 26, 2021
  132. Junio C HamanoAug 26, 2021

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.