[merge] LockDir: use put_file_non_atomic instead of append_file

John Arbash Meinel john at arbash-meinel.com
Sat Sep 9 01:53:28 BST 2006


Martin Pool wrote:
> On  8 Sep 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
>> The attached bundle just changes LockDir to use the new
>> 'put_file_non_atomic()' since it saves an extra round trip with sftp.
>>
>> When locking a remote directory, this saves a round trip for each lock.
>> So in the common case, this saves 2 round trips. (For me, this is 200+ms
>> when committing or pushing to Launchpad).
> 
> Because we don't need to stat the file to tell how long it will be?

Exactly.

> 
> +1
>> === modified file bzrlib/lockdir.py
>> --- bzrlib/lockdir.py
>> +++ bzrlib/lockdir.py
>> @@ -203,11 +203,11 @@
>>              sio = StringIO()
>>              self._prepare_info(sio)
>>              sio.seek(0)
>> -            # append will create a new file; we use append rather than put
>> -            # because we don't want to write to a temporary file and rename
>> -            # into place, because that's going to happen to the whole
>> -            # directory
>> -            self.transport.append_file(tmpname + self.__INFO_NAME, sio)
>> +            # We use put_file_non_atomic because we just created a new unique
>> +            # directory so we don't have to worry about files existing there.
>> +            # We'll rename the whole directory into place to get atomic
>> +            # properties
>> +            self.transport.put_file_non_atomic(tmpname + self.__INFO_NAME, sio)
>>  
>>              self.transport.rename(tmpname, self._held_dir)
>>              self._lock_held = True
> 
> Presumably this could use put_bytes_non_atomic to be a bit simpler?

Well, in _prepare_info(), you create a Stanza object, and then use
RioWriter to write into it, which expects a file-like object.

So one alternative would be to use Stanza.to_string() instead of a
RioWriter().

Attached is an add-on patch to do just that if you prefer it.
(_prepare_info() is private, so it doesn't matter if we change it).

John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: avoid_rio_writer.diff
Type: text/x-patch
Size: 1923 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060908/3b0c24bf/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060908/3b0c24bf/attachment.pgp 


More information about the bazaar mailing list