[MERGE][0.15] Better errors when locks contend

John Arbash Meinel john at arbash-meinel.com
Wed Mar 28 21:17:23 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Right now we have a small problem when you have a read-only command
running in the background (bzr diff | less), and you try to do a
write-command (bzr add, bzr rm). We have the same problem if you are
doing a write-command ('bzr merge') and you run a read-only one (bzr
status).

These all used to work, because the read lock was a no-op. Now that it
is grabbing an OS lock these are failing.

It would be nice if they didn't fail, but that is something in the
future. (It would mean grabbing the lock only while we are using/reading
the dirstate, and then releasing it afterwards). I'm pretty sure Robert
would like to close the file if we read the whole thing, and then just
check the header to make sure that nothing has changed.

Anyway, the biggest thing with this patch is that it LockContention does
not raise a traceback. So that if you have a read lock and you do a
write operation you get:

% ./bzr add foo
bzr: ERROR: Could not acquire lock [Errno 11] Resource temporarily
unavailable

Rather than:

% bzr add foo
bzr: ERROR: bzrlib.errors.LockError: Lock error: [Errno 11] Resource
temporarily unavailable

Traceback (most recent call last):
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/commands.py", line 650, in
run_bzr_catch_errors
    return run_bzr(argv)
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/commands.py", line 612, in
run_bzr
    ret = run(*run_argv)
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/commands.py", line 304, in
run_argv_aliases
    return self.run(**all_cmd_args)
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/builtins.py", line 372, in run
    action=action, save=not dry_run)
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/add.py", line 148, in
smart_add
    return smart_add_tree(tree, file_list, recurse, action=action,
save=save)
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/add.py", line 172, in
smart_add_tree
    tree.lock_tree_write()
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/workingtree_4.py", line
598, in lock_tree_write
    self._lock_self_write()
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/workingtree_4.py", line
582, in _lock_self_write
    state.lock_write()
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/dirstate.py", line 2229,
in lock_write
    self._lock_token = lock.WriteLock(self._filename)
  File "/home/jameinel/dev/bzr/bzr.dev/bzrlib/lock.py", line 146, in
__init__
    raise errors.LockError(e)
LockError: Lock error: [Errno 11] Resource temporarily unavailable

bzr 0.16.0dev0 on python 2.4.4.candidate.1 (linux2)
arguments: ['/home/jameinel/bin/bzr', 'add', 'foo']


Since it is a small fix, I think we can put it in for 0.15 final,
without needing another rc. (LockContention is a child of LockError, so
no api changes are effected).

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGCs1TJdeBCYSNAAMRAlJXAKC1X+gi40V1a31668UzCQXABoCCSgCfWs+O
X37pChGvH/hmG+TUsDwZEYU=
=vfL/
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: locking_errors.patch
Type: text/x-patch
Size: 3350 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070328/07a86ea9/attachment-0001.bin 


More information about the bazaar mailing list