From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH 3/3] refs/reftable: reload locked stack when preparing transaction
Date: Tue, 17 Sep 2024 15:43:25 +0200 [thread overview]
Message-ID: <37ec3acbff00564ecf3b63d1635aad5da0c54b19.1726578382.git.ps@pks.im> (raw)
In-Reply-To: <cover.1726578382.git.ps@pks.im>
When starting a reftable transaction we lock all stacks we are about to
modify. While it may happen that the stack is out-of-date at this point
in time we don't really care: transactional updates encode the expected
state of a certain reference, so all that we really want to verify is
that the _current_ value matches that expected state.
Pass `REFTABLE_STACK_NEW_ADDITION_RELOAD` when locking the stack such
that an out-of-date stack will be reloaded after having been locked.
This change is safe because all verifications of the expected state
happen after this step anyway.
Add a testcase that verifies that many writers are now able to write to
the stack concurrently without failures and with a deterministic end
result.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
refs/reftable-backend.c | 3 ++-
t/t0610-reftable-basics.sh | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index c500fb820a7..d4b383ca179 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -766,7 +766,8 @@ static int prepare_transaction_update(struct write_transaction_table_arg **out,
if (ret)
return ret;
- ret = reftable_stack_new_addition(&addition, stack, 0);
+ ret = reftable_stack_new_addition(&addition, stack,
+ REFTABLE_STACK_NEW_ADDITION_RELOAD);
if (ret) {
if (ret == REFTABLE_LOCK_ERROR)
strbuf_addstr(err, "cannot lock references");
diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh
index 62da3e37823..2d951c8ceb6 100755
--- a/t/t0610-reftable-basics.sh
+++ b/t/t0610-reftable-basics.sh
@@ -450,6 +450,37 @@ test_expect_success 'ref transaction: retry acquiring tables.list lock' '
)
'
+test_expect_success 'ref transaction: many concurrent writers' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ # Set a high timeout such that a busy CI machine will not abort
+ # early. 10 seconds should hopefully be ample of time to make
+ # this non-flaky.
+ git config set reftable.lockTimeout 10000 &&
+ test_commit --no-tag initial &&
+
+ head=$(git rev-parse HEAD) &&
+ for i in $(test_seq 100)
+ do
+ printf "%s commit\trefs/heads/branch-%s\n" "$head" "$i" ||
+ return 1
+ done >expect &&
+ printf "%s commit\trefs/heads/main\n" "$head" >>expect &&
+
+ for i in $(test_seq 100)
+ do
+ { git update-ref refs/heads/branch-$i HEAD& } ||
+ return 1
+ done &&
+
+ wait &&
+ git for-each-ref --sort=v:refname >actual &&
+ test_cmp expect actual
+ )
+'
+
test_expect_success 'pack-refs: compacts tables' '
test_when_finished "rm -rf repo" &&
git init repo &&
--
2.46.0.551.gc5ee8f2d1c.dirty
next prev parent reply other threads:[~2024-09-17 13:43 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-17 13:43 [PATCH 0/3] reftable: graceful concurrent writes Patrick Steinhardt
2024-09-17 13:43 ` [PATCH 1/3] refs/reftable: introduce "reftable.lockTimeout" Patrick Steinhardt
2024-09-17 17:46 ` karthik nayak
2024-09-17 17:50 ` Eric Sunshine
2024-09-18 4:31 ` Patrick Steinhardt
2024-09-18 4:31 ` Patrick Steinhardt
2024-09-17 13:43 ` [PATCH 2/3] reftable/stack: allow locking of outdated stacks Patrick Steinhardt
2024-09-17 13:43 ` Patrick Steinhardt [this message]
2024-09-17 18:26 ` [PATCH 0/3] reftable: graceful concurrent writes karthik nayak
2024-09-18 4:31 ` Patrick Steinhardt
2024-09-18 4:32 ` [PATCH v2 " Patrick Steinhardt
2024-09-18 4:32 ` [PATCH v2 1/3] refs/reftable: introduce "reftable.lockTimeout" Patrick Steinhardt
2024-09-18 9:22 ` James Liu
2024-09-18 9:39 ` Patrick Steinhardt
2024-09-18 4:32 ` [PATCH v2 2/3] reftable/stack: allow locking of outdated stacks Patrick Steinhardt
2024-09-18 9:26 ` James Liu
2024-09-18 9:39 ` Patrick Steinhardt
2024-09-18 4:32 ` [PATCH v2 3/3] refs/reftable: reload locked stack when preparing transaction Patrick Steinhardt
2024-09-18 9:33 ` [PATCH v2 0/3] reftable: graceful concurrent writes James Liu
2024-09-18 9:59 ` [PATCH v3 " Patrick Steinhardt
2024-09-18 9:59 ` [PATCH v3 1/3] refs/reftable: introduce "reftable.lockTimeout" Patrick Steinhardt
2024-09-19 21:34 ` Junio C Hamano
2024-09-18 9:59 ` [PATCH v3 2/3] reftable/stack: allow locking of outdated stacks Patrick Steinhardt
2024-09-20 18:10 ` Junio C Hamano
2024-09-24 5:33 ` Patrick Steinhardt
2024-09-18 9:59 ` [PATCH v3 3/3] refs/reftable: reload locked stack when preparing transaction Patrick Steinhardt
2024-09-18 23:23 ` [PATCH v3 0/3] reftable: graceful concurrent writes James Liu
2024-09-24 5:33 ` Patrick Steinhardt
2024-09-24 5:32 ` [PATCH v4 " Patrick Steinhardt
2024-09-24 5:33 ` [PATCH v4 1/3] refs/reftable: introduce "reftable.lockTimeout" Patrick Steinhardt
2024-09-24 5:33 ` [PATCH v4 2/3] reftable/stack: allow locking of outdated stacks Patrick Steinhardt
2024-09-24 5:33 ` [PATCH v4 3/3] refs/reftable: reload locked stack when preparing transaction Patrick Steinhardt
2024-09-27 4:07 ` Jeff King
2024-09-30 6:49 ` Patrick Steinhardt
2024-09-30 22:19 ` Josh Steadmon
2024-10-01 4:27 ` Patrick Steinhardt
2024-10-01 22:54 ` Jeff King
2024-10-01 23:24 ` Junio C Hamano
2024-10-02 10:58 ` Patrick Steinhardt
2024-10-01 7:34 ` Junio C Hamano
2024-10-01 18:53 ` Josh Steadmon
2024-10-01 19:08 ` Jeff King
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=37ec3acbff00564ecf3b63d1635aad5da0c54b19.1726578382.git.ps@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
/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).