comparison mercurial/chgserver.py @ 30619:88efb4fb1975

chgserver: truncate base address at "." for hash address Previously, the hash address is just appending "-$HASH" to base address. This patch makes it truncate the basename address at "." before appending "-$HASH". This makes it possible to spawn new servers in a racy situation and the client could be sure the server it connects is the new server just spawned. This is a step towards removing the lock. One of the functionalities of the lock is 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 # is the server just started (note: if it is not, it does not affect correctness - linux pid namespace is not a concern here) 3. rename foo.tmp$PID to foo Another functionality of the lock is to avoid starting multiple servers with a same confighash in parallel. But that also prevents starting multiple servers with different confighashes in parallel.
author Jun Wu <quark@fb.com>
date Mon, 19 Dec 2016 22:07:41 +0000
parents 201b44c8875c
children a150173da1c1
comparison
equal deleted inserted replaced
30618:201b44c8875c 30619:88efb4fb1975
524 524
525 def _tempaddress(address): 525 def _tempaddress(address):
526 return '%s.%d.tmp' % (address, os.getpid()) 526 return '%s.%d.tmp' % (address, os.getpid())
527 527
528 def _hashaddress(address, hashstr): 528 def _hashaddress(address, hashstr):
529 return '%s-%s' % (address, hashstr) 529 # if the basename of address contains '.', use only the left part. this
530 # makes it possible for the client to pass 'server.tmp$PID' and follow by
531 # an atomic rename to avoid locking when spawning new servers.
532 dirname, basename = os.path.split(address)
533 basename = basename.split('.', 1)[0]
534 return '%s-%s' % (os.path.join(dirname, basename), hashstr)
530 535
531 class chgunixservicehandler(object): 536 class chgunixservicehandler(object):
532 """Set of operations for chg services""" 537 """Set of operations for chg services"""
533 538
534 pollinterval = 1 # [sec] 539 pollinterval = 1 # [sec]