reftable/stack: allow locking of outdated stacks

In `reftable_stack_new_addition()` we first lock the stack and then
check whether it is still up-to-date. If it is not we return an error to
the caller indicating that the stack is outdated.

This is overly restrictive in our ref transaction interface though: we
lock the stack right before we start to verify the transaction, so we do
not really care whether it is outdated or not. What we really want is
that the stack is up-to-date after it has been locked so that we can
verify queued updates against its current state while we know that it is
locked for concurrent modification.

Introduce a new flag `REFTABLE_STACK_NEW_ADDITION_RELOAD` that alters
the behaviour of `reftable_stack_init_addition()` in this case: when we
notice that it is out-of-date we reload it instead of returning an error
to the caller.

This logic will be wired up in the reftable backend in the next commit.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-09-24 07:33:05 +02:00
committed by Junio C Hamano
parent bc39b6a796
commit 80e7342ea8
4 changed files with 91 additions and 13 deletions

View File

@@ -770,7 +770,7 @@ static int prepare_transaction_update(struct write_transaction_table_arg **out,
if (ret)
return ret;
ret = reftable_stack_new_addition(&addition, stack);
ret = reftable_stack_new_addition(&addition, stack, 0);
if (ret) {
if (ret == REFTABLE_LOCK_ERROR)
strbuf_addstr(err, "cannot lock references");
@@ -2207,7 +2207,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
if (ret < 0)
goto done;
ret = reftable_stack_new_addition(&add, stack);
ret = reftable_stack_new_addition(&add, stack, 0);
if (ret < 0)
goto done;