git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Barkalow <barkalow@iabervon.org>
To: Junio C Hamano <junkio@cox.net>
Cc: Christian Couder <chriscool@tuxfamily.org>,
	git@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: On ref locking
Date: Mon, 25 Sep 2006 13:05:42 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0609251140550.9789@iabervon.org> (raw)
In-Reply-To: <7vmz8o1em0.fsf_-_@assigned-by-dhcp.cox.net>

On Mon, 25 Sep 2006, Junio C Hamano wrote:

> The comments you added to the strawman I sent suggested use of
> rather heavyweight locks, which made me feel we were somehow
> going in a wrong direction.  Before going into the details of
> branch removing, let's first see if we can summarize what kind
> of guarantee we would want from ref updates.  The current
> locking scheme is very carefully and nicely done by Linus and
> Daniel Barkalow around June last year, and I do not want to lose
> good property of it.
> 
>  - When reading and/or listing refs you do not need to acquire
>    any lock.
> 
>  - When you are going to update an existing $ref, you create
>    $ref.lock, and do a compare-and-swap.
> 
> What the latter means is that an updater:
> 
>  (1) first learns the current value of the $ref, without
>      locking;
> 
>  (2) decides based on the knowledge from (1) what the next value
>      should be;
> 
>  (3) gets $ref.lock, makes sure $ref still is the value it
>      learned in (1), updates it to the desired value and
>      releases the lock.
> 
> The above 3-step sequence prevents updater-updater races with an
> extremely short critical section.  We only need to hold the lock
> while we do compare and swap.

I remember having a certain amount of disagreement over whether it's 
better to actually take the lock in (1), and hold it through (2), or only 
verify that it didn't change in (3) after taking the lock for real. If 
there's nothing substantial going on in (2), it doesn't matter. If users 
are producing content (e.g., git tag), they may want to make sure that 
nobody else is in the middle of writing something that would conflict.

I think I'd advocated getting the lock early if you're going to want it, 
and I don't remember what the convincing argument on the other side was 
for the cases under consideration at the time, beyond it not mattering 
significantly.

Note that we make sure to remove the lock when aborting due to signals 
(assuming we get a chance), so the size of the critical section doesn't 
matter too much to the chance of it getting left locked inappropriately. 
Of course, this is harder to do with the core code for a shell script than 
for C code.

	-Daniel
*This .sig left intentionally blank*

  reply	other threads:[~2006-09-25 17:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-18  4:54 [PATCH] Remove branch by putting a null sha1 into the ref file Christian Couder
2006-09-18  5:47 ` Junio C Hamano
2006-09-18 16:31 ` Linus Torvalds
2006-09-18 18:43   ` Junio C Hamano
2006-09-20  2:56   ` Christian Couder
2006-09-22 22:09   ` Junio C Hamano
2006-09-23  4:45     ` Christian Couder
2006-09-23  8:04       ` Junio C Hamano
2006-09-23 11:22         ` Christian Couder
2006-09-23 21:49           ` Junio C Hamano
2006-09-24  4:45             ` Christian Couder
2006-09-25  9:26               ` On ref locking Junio C Hamano
2006-09-25 17:05                 ` Daniel Barkalow [this message]
2006-09-26  4:11                   ` Junio C Hamano
2006-09-26  4:13                 ` [PATCH 1/3] Clean-up lock-ref implementation Junio C Hamano
2006-09-26  4:13                 ` [PATCH 2/3] update-ref: -d flag and ref creation safety Junio C Hamano
2006-09-26 18:05                 ` [PATCH 3/3] update a few Porcelain-ish for ref lock safety Junio C Hamano
2006-09-26 18:08                   ` Andy Whitcroft
2006-09-27  7:25                     ` Junio C Hamano

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=Pine.LNX.4.64.0609251140550.9789@iabervon.org \
    --to=barkalow@iabervon.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=torvalds@osdl.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).