[MERGE] Move protocol version querying logic into the medium
Andrew Bennetts
andrew at canonical.com
Thu Feb 28 14:42:29 GMT 2008
Hi all,
This is a small change towards implementing the next revision of the smart
server protocol, but it is worthwhile on its own. It moves the discovery of the
protocol version to use into the medium. Previously this was done by
RemoteBzrDirFormat. An immediate improvement is that it now avoids redundant
round-trips caused by reissuing 'hello' queries for each remote bzrdir that is
opened. This should shave up to a couple of seconds off typical sessions on
high-latency (e.g. intercontinental) links.
Additionally, it uses the new API to allow the bzrlib.smart.client module to
dynamically use the best protocol version. This is helpful for my protocol v3
work.
-Andrew.
-------------- next part --------------
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: andrew.bennetts at canonical.com-20080228144108-\
# sabjein0zz3k031d
# target_branch: http://bazaar-vcs.org/bzr/bzr.dev
# testament_sha1: e374f5b2f4751be9d70dc2d6bd0d65dcc75d558c
# timestamp: 2008-02-29 01:41:32 +1100
# source_branch: http://people.ubuntu.com/~andrew/bzr/protocol-\
# versioning-api
# base_revision_id: pqm at pqm.ubuntu.com-20080228032258-4mdmqlx603ak6x2w
#
# Begin patch
=== modified file 'bzrlib/bzrdir.py'
--- bzrlib/bzrdir.py 2008-02-24 16:42:13 +0000
+++ bzrlib/bzrdir.py 2008-02-28 14:21:20 +0000
@@ -2393,18 +2393,15 @@
def probe_transport(klass, transport):
"""Return a RemoteBzrDirFormat object if it looks possible."""
try:
- client = transport.get_smart_client()
+ medium = transport.get_smart_client()
except (NotImplementedError, AttributeError,
errors.TransportNotPossible):
# no smart server, so not a branch for this format type.
raise errors.NotBranchError(path=transport.base)
else:
- # Send a 'hello' request in protocol version one, and decline to
- # open it if the server doesn't support our required version (2) so
- # that the VFS-based transport will do it.
- request = client.get_request()
- smart_protocol = protocol.SmartClientRequestProtocolOne(request)
- server_version = smart_protocol.query_version()
+ # Decline to open it if the server doesn't support our required
+ # version (2) so that the VFS-based transport will do it.
+ server_version = medium.protocol_version()
if server_version != 2:
raise errors.NotBranchError(path=transport.base)
return klass()
=== modified file 'bzrlib/smart/client.py'
--- bzrlib/smart/client.py 2008-01-24 03:21:43 +0000
+++ bzrlib/smart/client.py 2008-02-28 14:41:08 +0000
@@ -33,6 +33,16 @@
def get_smart_medium(self):
return self._shared_connection.connection
+ def _build_client_protocol(self):
+ medium = self.get_smart_medium()
+ version = medium.protocol_version()
+ request = medium.get_request()
+ if version == 2:
+ smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
+ else:
+ smart_protocol = protocol.SmartClientRequestProtocolOne(request)
+ return smart_protocol
+
def call(self, method, *args):
"""Call a method on the remote server."""
result, protocol = self.call_expecting_body(method, *args)
@@ -47,8 +57,7 @@
result, smart_protocol = smart_client.call_expecting_body(...)
body = smart_protocol.read_body_bytes()
"""
- request = self.get_smart_medium().get_request()
- smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
+ smart_protocol = self._build_client_protocol()
smart_protocol.call(method, *args)
return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
@@ -61,8 +70,7 @@
raise TypeError('args must be byte strings, not %r' % (args,))
if type(body) is not str:
raise TypeError('body must be byte string, not %r' % (body,))
- request = self.get_smart_medium().get_request()
- smart_protocol = protocol.SmartClientRequestProtocolOne(request)
+ smart_protocol = self._build_client_protocol()
smart_protocol.call_with_body_bytes((method, ) + args, body)
return smart_protocol.read_response_tuple()
@@ -75,8 +83,7 @@
raise TypeError('args must be byte strings, not %r' % (args,))
if type(body) is not str:
raise TypeError('body must be byte string, not %r' % (body,))
- request = self.get_smart_medium().get_request()
- smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
+ smart_protocol = self._build_client_protocol()
smart_protocol.call_with_body_bytes((method, ) + args, body)
return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
=== modified file 'bzrlib/smart/medium.py'
--- bzrlib/smart/medium.py 2008-02-06 03:52:25 +0000
+++ bzrlib/smart/medium.py 2008-02-28 14:21:20 +0000
@@ -35,6 +35,7 @@
)
from bzrlib.smart.protocol import (
REQUEST_VERSION_TWO,
+ SmartClientRequestProtocolOne,
SmartServerRequestProtocolOne,
SmartServerRequestProtocolTwo,
)
@@ -368,6 +369,20 @@
class SmartClientMedium(object):
"""Smart client is a medium for sending smart protocol requests over."""
+ def __init__(self):
+ super(SmartClientMedium, self).__init__()
+ self._protocol_version = None
+
+ def protocol_version(self):
+ """Find out the best protocol version to use."""
+ if self._protocol_version is None:
+ medium_request = self.get_request()
+ # Send a 'hello' request in protocol version one, for maximum
+ # backwards compatibility.
+ client_protocol = SmartClientRequestProtocolOne(medium_request)
+ self._protocol_version = client_protocol.query_version()
+ return self._protocol_version
+
def disconnect(self):
"""If this medium maintains a persistent connection, close it.
@@ -385,6 +400,7 @@
"""
def __init__(self):
+ SmartClientMedium.__init__(self)
self._current_request = None
# Be optimistic: we assume the remote end can accept new remote
# requests until we get an error saying otherwise. (1.2 adds some
=== modified file 'bzrlib/tests/test_remote.py'
--- bzrlib/tests/test_remote.py 2008-02-12 05:17:25 +0000
+++ bzrlib/tests/test_remote.py 2008-02-28 14:06:05 +0000
@@ -301,6 +301,9 @@
input_file, output_file)
return medium.SmartClientStreamMediumRequest(client_medium)
+ def protocol_version(self):
+ return 1
+
class OldServerTransport(object):
"""A fake transport for test_old_server that reports it's smart server
# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWVyXYT0ACIJfgGRQWe//////
//C////wYA3c99j5e28j0lUBQADaeV3S7AFVK6DpVDoNB0G1Ummp+oYiNlMmTaJhGBMjJkGmQDEG
gaA5hNAaA0aMI0GI0xMmJoMI0DIBkwGU0myJpJ5IAGgAAAAAAAAAEiIFE2kp+Q2oyTUzUyNHqGJo
0NGg0aBkZABFJCZBqYBMTTIp7BCp+U9MTTSm8qeJmimm9SPSaZBJIEZAmE00CU8pkZGyhPyoHk1D
Q9TygaNGnlKo1iBpJbf0/b8JW/fnK5zop026xZ73yG9zNGMfp84cWo/NTHoWvXbCrlx5X9ytt7lt
qVEGDj9MaibWtEGDX9bj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