[RFC] Implement bzrlib.lock with CreateFile rather than LockFileEx on win32

Martin Pool mbp at sourcefrog.net
Tue Jun 16 05:13:35 BST 2009


2009/6/10 Martin (gzlist) <gzlist at googlemail.com>:
> Having had cause to look at the workings of bzrlib.lock the other day,
> it seems that the desired semantics would be better implemented on
> windows with a lock at file creation, rather than one bolted on
> afterwards.
>
> Attached (lock_on_create_rev2.patch) is an example of how this can be
> done, that fits with the current design. I can trivially write the
> same code using ctypes as well. The only slight ugliness is having to
> deal with three sets of file-opening-flags, for the win32 kernel, for
> C, and for python. The win is slightly simpler code, and better
> compatability, see <https://bugs.launchpad.net/bzr/+bug/103731> and
> attached (bzrlib.tests.per_lock.log) results of selftest.
>
> Questions:
> # Would a change along these lines be acceptable?

I think these a change along these lines would be fine, assuming it
pases tests (or doesn't cause any new failures.)  We should also
manually check interoperation with old versions, to make sure they
correctly exclude each other.

> # Are there any expectations of the lock classes that aren't exercised in tests?

Possibly.  The main limitations seem to me to be:

1. We don't have very good code for testing locking across different
unrelated processes, different threads, etc -- and the behaviour of
the locks we use there varies, which is bad.  Eventually we want to
get away from using OS file locks.

> # Should the existing win32 classes be left in place for the moment at least?

I don't think so.  Do you?  If it turns out to be a problem we can
revert the change or (in the short term) people can downgrade.

> # Would altering the design to avoid all the code duplication be warrented?

Feel free too, but maybe as a separate patch.

> # Are locks only taken on byte string filenames, or is unicode used as well?

I'm not sure tbh.  It can probably be either.

> # How *are* you meant to do unicode exceptions in bazaar...

What do you mean?

-- 
Martin <http://launchpad.net/~mbp/>



More information about the bazaar mailing list