From 6241ce217046cc77d306bda06ad80ac1973b4932 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 24 Sep 2024 07:33:08 +0200 Subject: refs/reftable: reload locked stack when preparing transaction 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 Signed-off-by: Junio C Hamano --- refs/reftable-backend.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'refs') diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 6ca00627dd..efe2b0258c 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -770,7 +770,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"); -- cgit v1.2.3