Rev 4734: (andrew) Add -Drelock debug flag that makes noise about wasteful in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Oct 9 00:44:42 BST 2009


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

------------------------------------------------------------
revno: 4734 [merge]
revision-id: pqm at pqm.ubuntu.com-20091008234440-e0thgiawplpcqomd
parent: pqm at pqm.ubuntu.com-20091008172636-tygnfi5hsnn9203g
parent: andrew.bennetts at canonical.com-20091008225313-qd6w1gt7mmfe5q9e
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2009-10-09 00:44:40 +0100
message:
  (andrew) Add -Drelock debug flag that makes noise about wasteful
  	unlocking and relocking.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/help_topics/en/debug-flags.txt debugflags.txt-20090312050229-rdspqbqq4fzbjtpe-1
  bzrlib/lock.py                 lock.py-20050527050856-ec090bb51bc03349
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
=== modified file 'NEWS'
--- a/NEWS	2009-10-08 16:15:00 +0000
+++ b/NEWS	2009-10-08 23:44:40 +0000
@@ -202,6 +202,10 @@
 Internals
 *********
 
+* Added ``-Drelock`` debug flag.  It will ``note`` a message every time a
+  repository or branch object is unlocked then relocked the same way.
+  (Andrew Bennetts)
+  
 * ``BTreeLeafParser.extract_key`` has been tweaked slightly to reduce
   mallocs while parsing the index (approx 3=>1 mallocs per key read).
   This results in a 10% speedup while reading an index.

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-09-30 07:02:41 +0000
+++ b/bzrlib/branch.py	2009-10-08 08:16:35 +0000
@@ -49,6 +49,7 @@
 from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
 from bzrlib.hooks import HookPoint, Hooks
 from bzrlib.inter import InterObject
+from bzrlib.lock import _RelockDebugMixin
 from bzrlib import registry
 from bzrlib.symbol_versioning import (
     deprecated_in,
@@ -2079,7 +2080,7 @@
     _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
 
 
-class BzrBranch(Branch):
+class BzrBranch(Branch, _RelockDebugMixin):
     """A branch stored in the actual filesystem.
 
     Note that it's "local" in the context of the filesystem; it doesn't
@@ -2131,6 +2132,8 @@
         return self.control_files.is_locked()
 
     def lock_write(self, token=None):
+        if not self.is_locked():
+            self._note_lock('w')
         # All-in-one needs to always unlock/lock.
         repo_control = getattr(self.repository, 'control_files', None)
         if self.control_files == repo_control or not self.is_locked():
@@ -2146,6 +2149,8 @@
             raise
 
     def lock_read(self):
+        if not self.is_locked():
+            self._note_lock('r')
         # All-in-one needs to always unlock/lock.
         repo_control = getattr(self.repository, 'control_files', None)
         if self.control_files == repo_control or not self.is_locked():

=== modified file 'bzrlib/help_topics/en/debug-flags.txt'
--- a/bzrlib/help_topics/en/debug-flags.txt	2009-08-20 05:02:45 +0000
+++ b/bzrlib/help_topics/en/debug-flags.txt	2009-10-07 08:19:19 +0000
@@ -22,16 +22,18 @@
 -Dhttp            Trace http connections, requests and responses.
 -Dindex           Trace major index operations.
 -Dknit            Trace knit operations.
--Dstrict_locks    Trace when OS locks are potentially used in a non-portable
-                  manner.
 -Dlock            Trace when lockdir locks are taken or released.
 -Dprogress        Trace progress bar operations.
 -Dmerge           Emit information for debugging merges.
 -Dno_apport       Don't use apport to report crashes.
--Dunlock          Some errors during unlock are treated as warnings.
 -Dpack            Emit information about pack operations.
+-Drelock          Emit a message every time a branch or repository object is
+                  unlocked then relocked the same way.
 -Dsftp            Trace SFTP internals.
 -Dstream          Trace fetch streams.
+-Dstrict_locks    Trace when OS locks are potentially used in a non-portable
+                  manner.
+-Dunlock          Some errors during unlock are treated as warnings.
 -DIDS_never       Never use InterDifferingSerializer when fetching.
 -DIDS_always      Always use InterDifferingSerializer to fetch if appropriate
                   for the format, even for non-local fetches.

=== modified file 'bzrlib/lock.py'
--- a/bzrlib/lock.py	2009-07-31 16:51:48 +0000
+++ b/bzrlib/lock.py	2009-10-07 08:17:25 +0000
@@ -518,3 +518,24 @@
 # We default to using the first available lock class.
 _lock_type, WriteLock, ReadLock = _lock_classes[0]
 
+
+class _RelockDebugMixin(object):
+    """Mixin support for -Drelock flag.
+
+    Add this as a base class then call self._note_lock with 'r' or 'w' when
+    acquiring a read- or write-lock.  If this object was previously locked (and
+    locked the same way), and -Drelock is set, then this will trace.note a
+    message about it.
+    """
+    
+    _prev_lock = None
+
+    def _note_lock(self, lock_type):
+        if 'relock' in debug.debug_flags and self._prev_lock == lock_type:
+            if lock_type == 'r':
+                type_name = 'read'
+            else:
+                type_name = 'write'
+            trace.note('%r was %s locked again', self, type_name)
+        self._prev_lock = lock_type
+

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2009-10-08 01:50:30 +0000
+++ b/bzrlib/remote.py	2009-10-08 08:16:35 +0000
@@ -619,7 +619,7 @@
         return self._custom_format._serializer
 
 
-class RemoteRepository(_RpcHelper):
+class RemoteRepository(_RpcHelper, lock._RelockDebugMixin):
     """Repository accessed over rpc.
 
     For the moment most operations are performed using local transport-backed
@@ -949,6 +949,7 @@
     def lock_read(self):
         # wrong eventually - want a local lock cache context
         if not self._lock_mode:
+            self._note_lock('r')
             self._lock_mode = 'r'
             self._lock_count = 1
             self._unstacked_provider.enable_cache(cache_misses=True)
@@ -974,6 +975,7 @@
 
     def lock_write(self, token=None, _skip_rpc=False):
         if not self._lock_mode:
+            self._note_lock('w')
             if _skip_rpc:
                 if self._lock_token is not None:
                     if token != self._lock_token:
@@ -2082,7 +2084,7 @@
         return self._custom_format.supports_set_append_revisions_only()
 
 
-class RemoteBranch(branch.Branch, _RpcHelper):
+class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
     """Branch stored on a server accessed by HPSS RPC.
 
     At the moment most operations are mapped down to simple file operations.
@@ -2319,6 +2321,7 @@
     def lock_read(self):
         self.repository.lock_read()
         if not self._lock_mode:
+            self._note_lock('r')
             self._lock_mode = 'r'
             self._lock_count = 1
             if self._real_branch is not None:
@@ -2344,6 +2347,7 @@
 
     def lock_write(self, token=None):
         if not self._lock_mode:
+            self._note_lock('w')
             # Lock the branch and repo in one remote call.
             remote_tokens = self._remote_lock_write(token)
             self._lock_token, self._repo_lock_token = remote_tokens

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2009-09-30 07:02:41 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2009-10-08 08:16:35 +0000
@@ -73,6 +73,7 @@
     )
 from bzrlib.trace import (
     mutter,
+    note,
     warning,
     )
 
@@ -2300,6 +2301,9 @@
         if self._write_lock_count == 1:
             self._transaction = transactions.WriteTransaction()
         if not locked:
+            if 'relock' in debug.debug_flags and self._prev_lock == 'w':
+                note('%r was write locked again', self)
+            self._prev_lock = 'w'
             for repo in self._fallback_repositories:
                 # Writes don't affect fallback repos
                 repo.lock_read()
@@ -2312,6 +2316,9 @@
         else:
             self.control_files.lock_read()
         if not locked:
+            if 'relock' in debug.debug_flags and self._prev_lock == 'r':
+                note('%r was read locked again', self)
+            self._prev_lock = 'r'
             for repo in self._fallback_repositories:
                 repo.lock_read()
             self._refresh_data()

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2009-10-08 01:50:30 +0000
+++ b/bzrlib/repository.py	2009-10-08 22:53:13 +0000
@@ -50,6 +50,7 @@
 """)
 
 from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
+from bzrlib.lock import _RelockDebugMixin
 from bzrlib.inter import InterObject
 from bzrlib.inventory import (
     Inventory,
@@ -856,7 +857,7 @@
 # Repositories
 
 
-class Repository(object):
+class Repository(_RelockDebugMixin):
     """Repository holding history for one or more branches.
 
     The repository holds and retrieves historical information including
@@ -1381,6 +1382,7 @@
         locked = self.is_locked()
         result = self.control_files.lock_write(token=token)
         if not locked:
+            self._note_lock('w')
             for repo in self._fallback_repositories:
                 # Writes don't affect fallback repos
                 repo.lock_read()
@@ -1391,6 +1393,7 @@
         locked = self.is_locked()
         self.control_files.lock_read()
         if not locked:
+            self._note_lock('r')
             for repo in self._fallback_repositories:
                 repo.lock_read()
             self._refresh_data()




More information about the bazaar-commits mailing list