Rev 5303: (parthm) Lock URL shown in case of failure to acquire lock (for smart server in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jun 17 12:52:18 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5303 [merge]
revision-id: pqm at pqm.ubuntu.com-20100617115213-prepapy1lnxdb2w2
parent: pqm at pqm.ubuntu.com-20100617103338-k4kkjx9fkt5qv33e
parent: parth.malwankar at gmail.com-20100615095342-d35to11xkra9xxs1
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-06-17 12:52:13 +0100
message:
  (parthm) Lock URL shown in case of failure to acquire lock (for smart server
   access) is now valid. Default timeout for lock contention is now 30s.
   (Parth Malwankar)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/lockdir.py              lockdir.py-20060220222025-98258adf27fbdda3
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/tests/test_lockdir.py   test_lockdir.py-20060220222025-33d4221569a3d600
=== modified file 'NEWS'
--- a/NEWS	2010-06-17 10:33:38 +0000
+++ b/NEWS	2010-06-17 11:52:13 +0000
@@ -69,6 +69,11 @@
 * ``walkdirs`` now raises a useful message when the filenames are not using
   the filesystem encoding. (Eric Moritz, #488519)
 
+* URL displayed for use with ``break-lock`` when smart server sees lock
+  contention are now valid. Default timeout for lock contention retry is
+  now 30 seconds instead of 300 seconds.
+  (Parth Malwankar, #250451)
+
 Improvements
 ************
 

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2010-06-11 01:43:18 +0000
+++ b/bzrlib/errors.py	2010-06-17 11:52:13 +0000
@@ -1041,8 +1041,6 @@
 class LockContention(LockError):
 
     _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
-    # TODO: show full url for lock, combining the transport and relative
-    # bits?
 
     internal_error = False
 

=== modified file 'bzrlib/lockdir.py'
--- a/bzrlib/lockdir.py	2010-05-25 17:27:52 +0000
+++ b/bzrlib/lockdir.py	2010-06-15 09:53:42 +0000
@@ -151,7 +151,7 @@
 # files/dirs created.
 
 
-_DEFAULT_TIMEOUT_SECONDS = 300
+_DEFAULT_TIMEOUT_SECONDS = 30
 _DEFAULT_POLL_SECONDS = 1.0
 
 
@@ -539,24 +539,27 @@
                 if deadline_str is None:
                     deadline_str = time.strftime('%H:%M:%S',
                                                  time.localtime(deadline))
+                # As local lock urls are correct we display them.
+                # We avoid displaying remote lock urls.
                 lock_url = self.transport.abspath(self.path)
-                # See <https://bugs.launchpad.net/bzr/+bug/250451>
-                # the URL here is sometimes not one that is useful to the
-                # user, perhaps being wrapped in a lp-%d or chroot decorator,
-                # especially if this error is issued from the server.
-                self._report_function('%s %s\n'
-                    '%s\n' # held by
-                    '%s\n' # locked ... ago
-                    'Will continue to try until %s, unless '
-                    'you press Ctrl-C.\n'
-                    'See "bzr help break-lock" for more.',
-                    start,
-                    formatted_info[0],
-                    formatted_info[1],
-                    formatted_info[2],
-                    deadline_str,
-                    )
-
+                if lock_url.startswith('file://'):
+                    lock_url = lock_url.split('.bzr/')[0]
+                else:
+                    lock_url = ''
+                user, hostname, pid, time_ago = formatted_info
+                msg = ('%s lock %s '        # lock_url
+                    'held by '              # start
+                    '%s\n'                  # user
+                    'at %s '                # hostname
+                    '[process #%s], '       # pid
+                    'acquired %s.')         # time ago
+                msg_args = [start, lock_url, user, hostname, pid, time_ago]
+                if timeout > 0:
+                    msg += ('\nWill continue to try until %s, unless '
+                        'you press Ctrl-C.')
+                    msg_args.append(deadline_str)
+                msg += '\nSee "bzr help break-lock" for more.'
+                self._report_function(msg, *msg_args)
             if (max_attempts is not None) and (attempt_count >= max_attempts):
                 self._trace("exceeded %d attempts")
                 raise LockContention(self)
@@ -564,8 +567,11 @@
                 self._trace("waiting %ss", poll)
                 time.sleep(poll)
             else:
+                # As timeout is always 0 for remote locks
+                # this block is applicable only for local
+                # lock contention
                 self._trace("timeout after waiting %ss", timeout)
-                raise LockContention(self)
+                raise LockContention('(local)', lock_url)
 
     def leave_in_place(self):
         self._locked_via_token = True
@@ -616,17 +622,19 @@
 
     def _format_lock_info(self, info):
         """Turn the contents of peek() into something for the user"""
-        lock_url = self.transport.abspath(self.path)
         start_time = info.get('start_time')
         if start_time is None:
             time_ago = '(unknown)'
         else:
             time_ago = format_delta(time.time() - int(info['start_time']))
+        user = info.get('user', '<unknown>')
+        hostname = info.get('hostname', '<unknown>')
+        pid = info.get('pid', '<unknown>')
         return [
-            'lock %s' % (lock_url,),
-            'held by %s on host %s [process #%s]' %
-                tuple([info.get(x, '<unknown>') for x in ['user', 'hostname', 'pid']]),
-            'locked %s' % (time_ago,),
+            user,
+            hostname,
+            pid,
+            time_ago,
             ]
 
     def validate_token(self, token):

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2010-05-20 18:23:17 +0000
+++ b/bzrlib/remote.py	2010-06-11 07:56:46 +0000
@@ -2420,9 +2420,16 @@
             repo_token = self.repository.lock_write().repository_token
             self.repository.unlock()
         err_context = {'token': token}
-        response = self._call(
-            'Branch.lock_write', self._remote_path(), branch_token,
-            repo_token or '', **err_context)
+        try:
+            response = self._call(
+                'Branch.lock_write', self._remote_path(), branch_token,
+                repo_token or '', **err_context)
+        except errors.LockContention, e:
+            # The LockContention from the server doesn't have any
+            # information about the lock_url. We re-raise LockContention
+            # with valid lock_url.
+            raise errors.LockContention('(remote lock)',
+                self.repository.base.split('.bzr/')[0])
         if response[0] != 'ok':
             raise errors.UnexpectedSmartServerResponse(response)
         ok, branch_token, repo_token = response

=== modified file 'bzrlib/tests/test_lockdir.py'
--- a/bzrlib/tests/test_lockdir.py	2010-05-20 18:23:17 +0000
+++ b/bzrlib/tests/test_lockdir.py	2010-06-15 09:53:42 +0000
@@ -191,22 +191,21 @@
                     "took %f seconds to detect lock contention" % (after - before))
         finally:
             lf1.unlock()
-        lock_base = lf2.transport.abspath(lf2.path)
         self.assertEqual(1, len(self._logged_reports))
-        lock_url = lf2.transport.abspath(lf2.path)
-        self.assertEqual('%s %s\n'
-                         '%s\n%s\n'
-                         'Will continue to try until %s, unless '
-                         'you press Ctrl-C.\n'
-                         'See "bzr help break-lock" for more.',
-                         self._logged_reports[0][0])
-        args = self._logged_reports[0][1]
-        self.assertEqual('Unable to obtain', args[0])
-        self.assertEqual('lock %s' % (lock_base,), args[1])
-        self.assertStartsWith(args[2], 'held by ')
-        self.assertStartsWith(args[3], 'locked ')
-        self.assertEndsWith(args[3], ' ago')
-        self.assertContainsRe(args[4], r'\d\d:\d\d:\d\d')
+        self.assertEqual(self._logged_reports[0][0],
+            '%s lock %s held by %s\n'
+            'at %s [process #%s], acquired %s.\n'
+            'Will continue to try until %s, unless '
+            'you press Ctrl-C.\n'
+            'See "bzr help break-lock" for more.')
+        start, lock_url, user, hostname, pid, time_ago, deadline_str = \
+            self._logged_reports[0][1]
+        self.assertEqual(start, u'Unable to obtain')
+        self.assertEqual(user, u'jrandom at example.com')
+        # skip hostname
+        self.assertContainsRe(pid, r'\d+')
+        self.assertContainsRe(time_ago, r'.* ago')
+        self.assertContainsRe(deadline_str, r'\d{2}:\d{2}:\d{2}')
 
     def test_31_lock_wait_easy(self):
         """Succeed when waiting on a lock with no contention.
@@ -597,11 +596,10 @@
             info_list = ld1._format_lock_info(ld1.peek())
         finally:
             ld1.unlock()
-        self.assertEqual('lock %s' % (ld1.transport.abspath(ld1.path),),
-                         info_list[0])
-        self.assertContainsRe(info_list[1],
-                              r'^held by .* on host .* \[process #\d*\]$')
-        self.assertContainsRe(info_list[2], r'locked \d+ seconds? ago$')
+        self.assertEqual(info_list[0], u'jrandom at example.com')
+        # info_list[1] is hostname. we skip this.
+        self.assertContainsRe(info_list[2], '^\d+$') # pid
+        self.assertContainsRe(info_list[3], r'^\d+ seconds? ago$') # time_ago
 
     def test_lock_without_email(self):
         global_config = config.GlobalConfig()
@@ -680,9 +678,7 @@
         info = lf.peek()
         formatted_info = lf._format_lock_info(info)
         self.assertEquals(
-            ['lock %s' % t.abspath('test_lock'),
-             'held by <unknown> on host <unknown> [process #<unknown>]',
-             'locked (unknown)'],
+            ['<unknown>', '<unknown>', '<unknown>', '(unknown)'],
             formatted_info)
 
 




More information about the bazaar-commits mailing list