Patchwork [1,of,3] chgserver: truncate base address at "." for hash address

login
register
mail settings
Submitter Jun Wu
Date Dec. 17, 2016, 1:49 a.m.
Message ID <69d25b06467d65bf6d1e.1481939389@x1c>
Download mbox | patch
Permalink /patch/17942/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - Dec. 17, 2016, 1:49 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1481934180 0
#      Sat Dec 17 00:23:00 2016 +0000
# Node ID 69d25b06467d65bf6d1e85d34d8fc57ec321b51d
# Parent  935092e525b0ee5656d0830162a1c2adf8248de3
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 69d25b06467d
chgserver: truncate base address at "." for hash address

Previously, the hash address is just appending "-$HASH" to base address.
This patch makes it truncate base address at "." before appending "-$HASH".

This makes it possible to spwan new servers without locks.

The lock is used to make sure the connect will connect to a server it just
created:

  1. start server --address foo
  2. connect to foo # wish "foo" is the server just started

With this change, the client could do:

  1. start server --address foo.tmp$PID
  2. connect to foo.tmp$PID # must be the serer just started
  3. rename foo.tmp$PID to foo

Thus it does not require locking any more.
Jun Wu - Dec. 17, 2016, 1:55 a.m.
Excerpts from Jun Wu's message of 2016-12-17 01:49:49 +0000:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1481934180 0
> #      Sat Dec 17 00:23:00 2016 +0000
> # Node ID 69d25b06467d65bf6d1e85d34d8fc57ec321b51d
> # Parent  935092e525b0ee5656d0830162a1c2adf8248de3
> # Available At https://bitbucket.org/quark-zju/hg-draft 
> #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r 69d25b06467d
> chgserver: truncate base address at "." for hash address
> 
> Previously, the hash address is just appending "-$HASH" to base address.
> This patch makes it truncate base address at "." before appending "-$HASH".
> 
> This makes it possible to spwan new servers without locks.
> 
> The lock is used to make sure the connect will connect to a server it just
> created:
> 
>   1. start server --address foo
>   2. connect to foo # wish "foo" is the server just started
> 
> With this change, the client could do:
> 
>   1. start server --address foo.tmp$PID
>   2. connect to foo.tmp$PID # must be the serer just started
>   3. rename foo.tmp$PID to foo
> 
> Thus it does not require locking any more.
> 
> diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
> --- a/mercurial/chgserver.py
> +++ b/mercurial/chgserver.py
> @@ -530,5 +530,9 @@ def _tempaddress(address):
>  
>  def _hashaddress(address, hashstr):
> -    return '%s-%s' % (address, hashstr)
> +    # if address contains '.', use only the left part. this makes it possible
> +    # for the client to pass 'server.tmp$PID' and follow by an atomic rename
> +    # to avoid locking when spawning new servers.
> +    base = address.split('.', 1)[0]

I just realized "address" could be an absolute full address, so this will
have trouble with a directory name having ".". I'll send a V2 with other
comments addressed.

> +    return '%s-%s' % (base, hashstr)
>  
>  class chgunixservicehandler(object):

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -530,5 +530,9 @@  def _tempaddress(address):
 
 def _hashaddress(address, hashstr):
-    return '%s-%s' % (address, hashstr)
+    # if address contains '.', use only the left part. this makes it possible
+    # for the client to pass 'server.tmp$PID' and follow by an atomic rename
+    # to avoid locking when spawning new servers.
+    base = address.split('.', 1)[0]
+    return '%s-%s' % (base, hashstr)
 
 class chgunixservicehandler(object):