From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
Justin Tobler <jltobler@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Carlo Arenas <carenas@gmail.com>
Subject: [PATCH v4 8/8] refs/reftable: always reload stacks when creating lock
Date: Wed, 13 Aug 2025 08:25:32 +0200 [thread overview]
Message-ID: <20250813-pks-reftable-fixes-for-libgit2-v4-8-42b5544c8e2a@pks.im> (raw)
In-Reply-To: <20250813-pks-reftable-fixes-for-libgit2-v4-0-42b5544c8e2a@pks.im>
When creating a new addition via either `reftable_stack_new_addition()`
or its convenince wrapper `reftable_stack_add()` we:
1. Create the "tables.list.lock" file.
2. Verify that the current version of the "tables.list" file is
up-to-date.
3. Write the new table records if so.
By default, the second step would cause us to bail out if we see that
there has been a concurrent write to the stack that made our in-memory
copy of the stack out-of-date. This is a safety mechanism to not write
records to the stack based on outdated information.
The downside though is that concurrent writes may now cause us to bail
out, which is not a good user experience. In addition, this isn't even
necessary for us, as Git knows to perform all checks for the old state
of references under the lock. (Well, in all except one case: when we
expire the reflog we first create the log iterator before we create the
lock, but this ordering is fixed as part of this commit.)
Consequently, most writers pass the `REFTABLE_STACK_NEW_ADDITION_RELOAD`
flag. The effect of this flag is that we reload the stack after having
acquired the lock in case the stack is out-of-date. This plugs the race
with concurrent writers, but we continue performing the verifications of
the expected old state to catch actual conflicts in the references we
are about to write.
Adapt the remaining callsites that don't yet pass this flag to do so.
While at it, drop a needless manual reload.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
refs/reftable-backend.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 3f0deab338..66d25411f1 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1006,10 +1006,6 @@ static int prepare_transaction_update(struct write_transaction_table_arg **out,
if (!arg) {
struct reftable_addition *addition;
- ret = reftable_stack_reload(be->stack);
- if (ret)
- return ret;
-
ret = reftable_stack_new_addition(&addition, be->stack,
REFTABLE_STACK_NEW_ADDITION_RELOAD);
if (ret) {
@@ -1960,7 +1956,8 @@ static int reftable_be_rename_ref(struct ref_store *ref_store,
ret = backend_for(&arg.be, refs, newrefname, &newrefname, 1);
if (ret)
goto done;
- ret = reftable_stack_add(arg.be->stack, &write_copy_table, &arg, 0);
+ ret = reftable_stack_add(arg.be->stack, &write_copy_table, &arg,
+ REFTABLE_STACK_NEW_ADDITION_RELOAD);
done:
assert(ret != REFTABLE_API_ERROR);
@@ -1989,7 +1986,8 @@ static int reftable_be_copy_ref(struct ref_store *ref_store,
ret = backend_for(&arg.be, refs, newrefname, &newrefname, 1);
if (ret)
goto done;
- ret = reftable_stack_add(arg.be->stack, &write_copy_table, &arg, 0);
+ ret = reftable_stack_add(arg.be->stack, &write_copy_table, &arg,
+ REFTABLE_STACK_NEW_ADDITION_RELOAD);
done:
assert(ret != REFTABLE_API_ERROR);
@@ -2360,7 +2358,8 @@ static int reftable_be_create_reflog(struct ref_store *ref_store,
goto done;
arg.stack = be->stack;
- ret = reftable_stack_add(be->stack, &write_reflog_existence_table, &arg, 0);
+ ret = reftable_stack_add(be->stack, &write_reflog_existence_table, &arg,
+ REFTABLE_STACK_NEW_ADDITION_RELOAD);
done:
return ret;
@@ -2431,7 +2430,8 @@ static int reftable_be_delete_reflog(struct ref_store *ref_store,
return ret;
arg.stack = be->stack;
- ret = reftable_stack_add(be->stack, &write_reflog_delete_table, &arg, 0);
+ ret = reftable_stack_add(be->stack, &write_reflog_delete_table, &arg,
+ REFTABLE_STACK_NEW_ADDITION_RELOAD);
assert(ret != REFTABLE_API_ERROR);
return ret;
@@ -2552,15 +2552,16 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
if (ret < 0)
goto done;
- ret = reftable_stack_init_log_iterator(be->stack, &it);
+ ret = reftable_stack_new_addition(&add, be->stack,
+ REFTABLE_STACK_NEW_ADDITION_RELOAD);
if (ret < 0)
goto done;
- ret = reftable_iterator_seek_log(&it, refname);
+ ret = reftable_stack_init_log_iterator(be->stack, &it);
if (ret < 0)
goto done;
- ret = reftable_stack_new_addition(&add, be->stack, 0);
+ ret = reftable_iterator_seek_log(&it, refname);
if (ret < 0)
goto done;
--
2.51.0.rc1.215.g0f929dcec7.dirty
next prev parent reply other threads:[~2025-08-13 6:26 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 14:47 [PATCH 0/5] reftable: a couple of improvements for libgit2 Patrick Steinhardt
2025-08-01 14:47 ` [PATCH 1/5] reftable/writer: fix type used for number of records Patrick Steinhardt
2025-08-01 14:47 ` [PATCH 2/5] reftable/writer: drop Git-specific `QSORT()` macro Patrick Steinhardt
2025-08-01 14:47 ` [PATCH 3/5] reftable/stack: fix compiler warning due to missing braces Patrick Steinhardt
2025-08-01 19:19 ` Eric Sunshine
2025-08-04 6:03 ` Patrick Steinhardt
2025-08-04 19:14 ` Junio C Hamano
2025-08-05 4:49 ` Patrick Steinhardt
2025-08-12 4:18 ` Carlo Arenas
2025-08-12 9:27 ` Patrick Steinhardt
2025-08-12 14:37 ` Junio C Hamano
2025-08-01 14:47 ` [PATCH 4/5] reftable/stack: reorder code to avoid forward declarations Patrick Steinhardt
2025-08-01 14:47 ` [PATCH 5/5] reftable/stack: allow passing flags to `reftable_stack_add()` Patrick Steinhardt
2025-08-04 9:40 ` [PATCH v2 0/6] reftable: a couple of improvements for libgit2 Patrick Steinhardt
2025-08-04 9:40 ` [PATCH v2 1/6] reftable/writer: fix type used for number of records Patrick Steinhardt
2025-08-04 9:40 ` [PATCH v2 2/6] reftable/writer: drop Git-specific `QSORT()` macro Patrick Steinhardt
2025-08-04 9:40 ` [PATCH v2 3/6] reftable/stack: fix compiler warning due to missing braces Patrick Steinhardt
2025-08-04 9:40 ` [PATCH v2 4/6] reftable/stack: reorder code to avoid forward declarations Patrick Steinhardt
2025-08-11 19:10 ` Justin Tobler
2025-08-04 9:40 ` [PATCH v2 5/6] reftable/stack: allow passing flags to `reftable_stack_add()` Patrick Steinhardt
2025-08-11 19:34 ` Justin Tobler
2025-08-12 9:27 ` Patrick Steinhardt
2025-08-04 9:40 ` [PATCH v2 6/6] reftable/stack: handle outdated stacks when compacting Patrick Steinhardt
2025-08-11 20:04 ` Justin Tobler
2025-08-12 9:28 ` Patrick Steinhardt
2025-08-12 9:54 ` [PATCH v3 0/8] reftable: a couple of improvements for libgit2 Patrick Steinhardt
2025-08-12 9:54 ` [PATCH v3 1/8] reftable/writer: fix type used for number of records Patrick Steinhardt
2025-08-12 9:54 ` [PATCH v3 2/8] reftable/writer: drop Git-specific `QSORT()` macro Patrick Steinhardt
2025-08-12 9:54 ` [PATCH v3 3/8] reftable/stack: reorder code to avoid forward declarations Patrick Steinhardt
2025-08-12 9:54 ` [PATCH v3 4/8] reftable/stack: fix compiler warning due to missing braces Patrick Steinhardt
2025-08-12 16:51 ` Justin Tobler
2025-08-12 9:54 ` [PATCH v3 5/8] reftable/stack: allow passing flags to `reftable_stack_add()` Patrick Steinhardt
2025-08-12 16:59 ` Justin Tobler
2025-08-13 6:12 ` Patrick Steinhardt
2025-08-12 9:54 ` [PATCH v3 6/8] reftable/stack: handle outdated stacks when compacting Patrick Steinhardt
2025-08-12 9:54 ` [PATCH v3 7/8] reftable: don't second-guess errors from flock interface Patrick Steinhardt
2025-08-12 17:05 ` Justin Tobler
2025-08-12 9:54 ` [PATCH v3 8/8] refs/reftable: always reload stacks when creating lock Patrick Steinhardt
2025-08-12 17:12 ` Justin Tobler
2025-08-12 19:00 ` [PATCH v3 0/8] reftable: a couple of improvements for libgit2 Carlo Arenas
2025-08-13 6:11 ` Patrick Steinhardt
2025-08-13 14:23 ` Junio C Hamano
2025-08-13 6:25 ` [PATCH v4 " Patrick Steinhardt
2025-08-13 6:25 ` [PATCH v4 1/8] reftable/writer: fix type used for number of records Patrick Steinhardt
2025-08-13 6:25 ` [PATCH v4 2/8] reftable/writer: drop Git-specific `QSORT()` macro Patrick Steinhardt
2025-08-13 6:25 ` [PATCH v4 3/8] reftable/stack: reorder code to avoid forward declarations Patrick Steinhardt
2025-08-13 6:25 ` [PATCH v4 4/8] reftable/stack: fix compiler warning due to missing braces Patrick Steinhardt
2025-08-13 6:25 ` [PATCH v4 5/8] reftable/stack: allow passing flags to `reftable_stack_add()` Patrick Steinhardt
2025-08-13 6:25 ` [PATCH v4 6/8] reftable/stack: handle outdated stacks when compacting Patrick Steinhardt
2025-08-13 6:25 ` [PATCH v4 7/8] reftable: don't second-guess errors from flock interface Patrick Steinhardt
2025-08-13 6:25 ` Patrick Steinhardt [this message]
2025-08-13 14:38 ` [PATCH v4 0/8] reftable: a couple of improvements for libgit2 Justin Tobler
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=20250813-pks-reftable-fixes-for-libgit2-v4-8-42b5544c8e2a@pks.im \
--to=ps@pks.im \
--cc=carenas@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jltobler@gmail.com \
--cc=sunshine@sunshineco.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).