From 9a4115efc146dcb64a2f51211222baa6e0cc9519 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 01:32:51 -0500 Subject: [PATCH 01/22] Making a few tweaks and cleanups as well as moving the connection manager to a gevent queue --- riak/client.py | 16 ++-- riak/transports/connection.py | 154 +++++++++++----------------------- 2 files changed, 57 insertions(+), 113 deletions(-) diff --git a/riak/client.py b/riak/client.py index 7bb5e8dc..0d2c2ba4 100644 --- a/riak/client.py +++ b/riak/client.py @@ -36,7 +36,7 @@ class RiakClient(object): Riak. The Riak API uses HTTP, so there is no persistent connection, and the ``RiakClient`` object is extremely lightweight. """ - def __init__(self, host='127.0.0.1', port=8098, prefix='riak', + def __init__(self, host=('127.0.0.1', 8098), prefix='riak', mapred_prefix='mapred', transport_class=None, client_id=None, solr_transport_class=None, transport_options=None): @@ -63,8 +63,7 @@ def __init__(self, host='127.0.0.1', port=8098, prefix='riak', api = getattr(transport_class, 'api', 1) if api >= 2: - hostports = [ (host, port), ] - self._cm = transport_class.default_cm(hostports) + self._cm = transport_class.default_cm(host) # If no transport options are provided, then default to the # empty dict, otherwise just pass through what we are provided. @@ -77,10 +76,8 @@ def __init__(self, host='127.0.0.1', port=8098, prefix='riak', client_id=client_id, **transport_options) else: - deprecated('please upgrade the transport to the new API') - self._cm = None - self._transport = transport_class(host, port, client_id=client_id) - + raise Exception('please upgrade the transport to the new API') + self._r = "default" self._w = "default" self._dw = "default" @@ -93,8 +90,7 @@ def __init__(self, host='127.0.0.1', port=8098, prefix='riak', 'text/json': json.loads} self._solr = None self._host = host - self._port = port - + def get_transport(self): """ Get the transport instance the client is using for it's connection. @@ -380,6 +376,6 @@ def get_index(self, bucket, index, startkey, endkey=None): def solr(self): if self._solr is None: - self._solr = RiakSearch(self, host=self._host, port=self._port) + self._solr = RiakSearch(self, host=self._host[0], port=self._host[1]) return self._solr diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 12172df4..fc3ca71d 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -21,6 +21,8 @@ import contextlib import functools +from gevent.queue import Queue + class ConnectionManager(object): # Must be constructable with: connection_class(host, port) @@ -28,76 +30,45 @@ class ConnectionManager(object): # Must have a close() method connection_class = None - def __init__(self, hostports=[]): + def __init__(self, hostports, pool_size=10): # We want a private copy of this list: either to detach the argument # default, or to detach from the caller's list. - self.hostports = hostports[:] - - # Open a connection to each specified host/port. On single-threaded - # systems, this will create a round-robin across all specified servers. - # When multi-threaded, this will give us an initial set for all the - # threads to work with (and more will be created, according to demand). - self.conns = [self.connection_class(host, port) - for host, port in hostports] - - def add_hostport(self, host, port): - self.hostports.append((host, port)) - - # Open an initial connection. For single-threaded, this adds to the - # round-robin pool. On multi-threaded, it simply gives us an extra - # connectiong for the load-balancing across the servers. - self.conns.append(self.connection_class(host, port)) - - def remove_host(self, host, port=None): - if port is None: - self.hostports = [(h, p) for h, p in self.hostports - if h != host] + if type(hostports) is list: + if len(hostports) > pool_size: + raise Exception("pool_size cannot be larger than hostports") + + self.pool_size = pool_size + self.hostports = hostports + + self.queue = Queue(pool_size) + + if type(self.hostports) is list: + for host, port in self.hostports: + self.queue.put(self.connection_class(host, port)) else: - self.hostports.remove((host, port)) - - # Now that the host/port pair has been removed from self.hostports, - # no connections on this pair will be added in .giveback(). Thus, the - # existing connections are all that may exist at this time. We'll - # snapshot the list, and look for offending connections, then try and - # remove them, being wary that race conditions may remove them before - # we can remove it. - for conn in self.conns[:]: - if conn.host == host and (port is None or conn.port == port): - try: - self.conns.remove(conn) - except ValueError: - # Another thread removed the connection. It won't be coming back, - # so we have nothing to do here. - pass - else: - # If the connection was still present (no ValueError), then we - # should go ahead and close it down. - conn.close() - - # Just in case somebody uses a host/port combo and typos... - remove_hostport = remove_host - - def take(self): - if len(self.conns) == 0: - # RACE: in a multi-threaded environment, a conn might arrive in - # self.conns, but... no biggy. If we're bouncing up against - # needing a new connection, then we'll just create one. - return self._new_connection() - - # RACE: self.conns might empty out right now, so we need to protect - # our access to it. - try: - # round-robin: take from the front, we'll append when it comes back - return self.conns.pop(0) - except IndexError: - return self._new_connection() - - def giveback(self, conn): - # Connections using a host/port pair that is NOT in self.hostports - # should be ignored. Likely, remove_host() was called while this - # connection was borrowed for some work. - if (conn.host, conn.port) in self.hostports: - self.conns.append(conn) + for i in range(0, pool_size): + self.queue.put(self.connection_class(hostports[0], hostports[1])) + + def checkout(self): + """Checkout a connection from the queue - block if we have + none in the queue till one arrives.""" + + return self.queue.get() + + def checkin(self, conn): + """Checkin a connection back into the queue. + + If it doesn't exist in the hostports list then + close it. + """ + + # If we are tring to checkin a connection and the pool has + # already been re-filled, throw away the connection silently + if self.queue.qsize() >= self.pool_size: + conn.close() + + if ((type(self.hostports) is list) and (conn.host, conn.port) in self.hostports) or (conn.host, conn.port) == self.hostports: + self.queue.put(conn) else: # Proactively close the connection. The caller won't know whether # we put it into our list, or left the connection for the caller @@ -106,45 +77,22 @@ def giveback(self, conn): @contextlib.contextmanager def withconn(self): - conn = self.take() + """Context managaer method.""" + conn = self.checkout() try: yield conn finally: - self.giveback(conn) - - def _new_connection(self): - if len(self.hostports) == 0: - raise NoHostsDefined() - - # Grab the first host/port combo. We'll put this at the end, so that - # we do a round-robin on the host/port pairs. - host, port = self.hostports[0] - conn = self.connection_class(host, port) - - if len(self.hostports) == 1: - # No rotation needed. - return conn - - # Be careful about rotating. We want to append before removing, so that - # we never hit a len==0 race condition (which could prevent the creation - # of needed connections). - self.hostports.append((host, port)) - - # RACE: another thread may have appended the same host/port pair. We - # will add another pair. Each thread will remove one (either [0], or - # one that had been appened), resulting in a correct state of a single - # pair in the list. - # RACE: another thread may get the host/port pair from hostports[0] - # before we have a chance to remove it. We don't need precision - # round-robin behavior; just something close. - # RACE: another thread may have removed hostports[0] (which we are - # also trying to remove), but it will have placed another copy at - # the end before doing so. We have also added a host/port pair, and - # will remove one, leaving the list in a correct state. - self.hostports.remove((host, port)) - - return conn - + self.checkin(conn) + + def new(self): + """Create a new connection if we have room for it.""" + + if self.queue.qsize() >= self.pool_size: + raise Exception("the queue is already full") + + host, port = self.hostports[0] if type(self.hostports) is list else self.hostports + + self.queue.put(self.connection_class(host, port)) class Socket(object): From 5e743fb6c9d19731e0f889d46c2012ad80b3a59e Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 01:34:18 -0500 Subject: [PATCH 02/22] Adding gevent dependency --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d6a1d020..3524b4af 100755 --- a/setup.py +++ b/setup.py @@ -13,7 +13,8 @@ def make_docs(): os.rename(name, 'docs/%s' % name) install_requires = ["riak_pb >=1.2.0, < 1.3.0"] -requires = ["riak_pb(>=1.2.0,<1.3.0)"] +requires = ["riak_pb(>=1.2.0,<1.3.0)", + "gevent"] tests_require = [] if platform.python_version() < '2.7': tests_require.append("unittest2") From c772cf69eb3f373f7ef3e8307e9551ca7ceb89c1 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 01:49:49 -0500 Subject: [PATCH 03/22] Adding in the pool_size argument --- riak/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/riak/client.py b/riak/client.py index 0d2c2ba4..7e910d1d 100644 --- a/riak/client.py +++ b/riak/client.py @@ -36,7 +36,7 @@ class RiakClient(object): Riak. The Riak API uses HTTP, so there is no persistent connection, and the ``RiakClient`` object is extremely lightweight. """ - def __init__(self, host=('127.0.0.1', 8098), prefix='riak', + def __init__(self, host=('127.0.0.1', 8098), pool_size=10, prefix='riak', mapred_prefix='mapred', transport_class=None, client_id=None, solr_transport_class=None, transport_options=None): @@ -63,7 +63,7 @@ def __init__(self, host=('127.0.0.1', 8098), prefix='riak', api = getattr(transport_class, 'api', 1) if api >= 2: - self._cm = transport_class.default_cm(host) + self._cm = transport_class.default_cm(host, pool_size) # If no transport options are provided, then default to the # empty dict, otherwise just pass through what we are provided. From 7397117d71a908c826020e023c175a3fb6d68b90 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 01:50:18 -0500 Subject: [PATCH 04/22] Fixing the factory connection manager to accept the pool_size arg --- riak/transports/connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index fc3ca71d..c1ad621f 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -30,7 +30,7 @@ class ConnectionManager(object): # Must have a close() method connection_class = None - def __init__(self, hostports, pool_size=10): + def __init__(self, hostports, pool_size): # We want a private copy of this list: either to detach the argument # default, or to detach from the caller's list. if type(hostports) is list: @@ -120,9 +120,9 @@ def close(self): class FactoryConnectionManager(ConnectionManager): - def __init__(self, connection_class, hostports=[]): + def __init__(self, connection_class, hostports, pool_size=10): self.connection_class = connection_class - ConnectionManager.__init__(self, hostports) + ConnectionManager.__init__(self, hostports, pool_size) def cm_using(connection_class): From d04cc25dfda445adbbcab4b1a778eba2f6e68286 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 02:53:17 -0500 Subject: [PATCH 05/22] Replacing the vanilla socket lib with gevent socket replacement --- riak/transports/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index c1ad621f..3a7cf9e7 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -17,11 +17,11 @@ """ import httplib -import socket import contextlib import functools from gevent.queue import Queue +from gevent import socket class ConnectionManager(object): From 41a7c257b407b3ce93d3efa8ee6c89cfdbf5c961 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 02:55:24 -0500 Subject: [PATCH 06/22] Upping the version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3524b4af..a1bbd86f 100755 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def make_docs(): setup( name='riak', - version='1.5.0', + version='1.5.2', packages = find_packages(), requires = requires, install_requires = install_requires, From 4889eaef92fb7040075737eefbf67480581e59fa Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 03:08:05 -0500 Subject: [PATCH 07/22] Little change? --- riak/transports/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 3a7cf9e7..a8389eb4 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -20,8 +20,8 @@ import contextlib import functools -from gevent.queue import Queue from gevent import socket +from gevent.queue import Queue class ConnectionManager(object): From d52dfc4978d2137b193fb44d82c6814b7a671997 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 03:18:11 -0500 Subject: [PATCH 08/22] Trying monkey patching --- riak/transports/connection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index a8389eb4..0bd20bab 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -20,9 +20,11 @@ import contextlib import functools -from gevent import socket +from gevent import monkey from gevent.queue import Queue +monkey.patch_socket() + class ConnectionManager(object): # Must be constructable with: connection_class(host, port) From 2c03f18c80137bd856a1e0fc0bd0dc88e3c3e7d7 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 03:31:07 -0500 Subject: [PATCH 09/22] Huh? --- riak/transports/connection.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 0bd20bab..b8c7e920 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -20,11 +20,9 @@ import contextlib import functools -from gevent import monkey +#from gevent import socket from gevent.queue import Queue -monkey.patch_socket() - class ConnectionManager(object): # Must be constructable with: connection_class(host, port) @@ -106,6 +104,7 @@ def __init__(self, host, port): def maybe_connect(self): if self.sock is None: + from gevent import socket self.sock = s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: From 8e2f40f7e20c3653af3c4a8ce44358c480f6ff0f Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 03:32:25 -0500 Subject: [PATCH 10/22] Fixing the imports --- riak/transports/connection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index b8c7e920..dce50f1b 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -20,7 +20,6 @@ import contextlib import functools -#from gevent import socket from gevent.queue import Queue class ConnectionManager(object): @@ -104,7 +103,9 @@ def __init__(self, host, port): def maybe_connect(self): if self.sock is None: + # I have no idea why, but it will only work with the import...here from gevent import socket + self.sock = s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: From 2e301e19e78458e9fc06046ac37e7ffb5b51523c Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 14:59:59 -0500 Subject: [PATCH 11/22] Fixing the version in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a1bbd86f..3524b4af 100755 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def make_docs(): setup( name='riak', - version='1.5.2', + version='1.5.0', packages = find_packages(), requires = requires, install_requires = install_requires, From b21a63148f32b8ac560e35a5c48994e8ca445ef3 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 15:39:54 -0500 Subject: [PATCH 12/22] Moving to monkey patching instead --- riak/transports/connection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index dce50f1b..d351f2fa 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -19,6 +19,8 @@ import httplib import contextlib import functools +import socket +import gevent.monkey from gevent.queue import Queue @@ -41,6 +43,9 @@ def __init__(self, hostports, pool_size): self.queue = Queue(pool_size) + # Patch httplib if we are using that, also patch the sockets + gevent.monkey.patch_all(httplib=True) + if type(self.hostports) is list: for host, port in self.hostports: self.queue.put(self.connection_class(host, port)) @@ -103,9 +108,6 @@ def __init__(self, host, port): def maybe_connect(self): if self.sock is None: - # I have no idea why, but it will only work with the import...here - from gevent import socket - self.sock = s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: From 15ef8fc19ef2f8f5ee8f18e1ad482c5bd019a6ff Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 15:42:01 -0500 Subject: [PATCH 13/22] Fixing import --- riak/transports/connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index d351f2fa..44535989 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -20,7 +20,7 @@ import contextlib import functools import socket -import gevent.monkey +from gevent import monkey from gevent.queue import Queue @@ -44,7 +44,7 @@ def __init__(self, hostports, pool_size): self.queue = Queue(pool_size) # Patch httplib if we are using that, also patch the sockets - gevent.monkey.patch_all(httplib=True) + monkey.patch_all(httplib=True) if type(self.hostports) is list: for host, port in self.hostports: From b9018441326cd9a33d28842f0f53a4d2e6747d41 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 15:43:27 -0500 Subject: [PATCH 14/22] Fixing --- riak/transports/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 44535989..55dff835 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -44,7 +44,7 @@ def __init__(self, hostports, pool_size): self.queue = Queue(pool_size) # Patch httplib if we are using that, also patch the sockets - monkey.patch_all(httplib=True) + monkey.patch_all() if type(self.hostports) is list: for host, port in self.hostports: From 4f4eaa8a40f3520dcab5b99d8c87c4b363e272fb Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 15:57:54 -0500 Subject: [PATCH 15/22] Now will build x number of connections per host --- riak/transports/connection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 55dff835..3f17a1aa 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -48,7 +48,9 @@ def __init__(self, hostports, pool_size): if type(self.hostports) is list: for host, port in self.hostports: - self.queue.put(self.connection_class(host, port)) + # Build x number connections per host + for i in range(0, pool_size): + self.queue.put(self.connection_class(host, port)) else: for i in range(0, pool_size): self.queue.put(self.connection_class(hostports[0], hostports[1])) From 9c2e5f10cb29fd1623365f771f76fbbb298d2412 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 16:05:50 -0500 Subject: [PATCH 16/22] Bleh --- riak/transports/connection.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 3f17a1aa..55dff835 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -48,9 +48,7 @@ def __init__(self, hostports, pool_size): if type(self.hostports) is list: for host, port in self.hostports: - # Build x number connections per host - for i in range(0, pool_size): - self.queue.put(self.connection_class(host, port)) + self.queue.put(self.connection_class(host, port)) else: for i in range(0, pool_size): self.queue.put(self.connection_class(hostports[0], hostports[1])) From b249d58a890f82069cf67aafc983d38df9098092 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 16:13:00 -0500 Subject: [PATCH 17/22] Using put_nowait --- riak/transports/connection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 55dff835..40023da0 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -48,7 +48,8 @@ def __init__(self, hostports, pool_size): if type(self.hostports) is list: for host, port in self.hostports: - self.queue.put(self.connection_class(host, port)) + for i in range(0, pool_size): + self.queue.put_nowait(self.connection_class(host, port)) else: for i in range(0, pool_size): self.queue.put(self.connection_class(hostports[0], hostports[1])) From f6367c1bffd5c820e45dc60eb80e8ecb30493d91 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 16:14:28 -0500 Subject: [PATCH 18/22] Fixing the queue limit --- riak/transports/connection.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 40023da0..7c7b6b33 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -41,7 +41,8 @@ def __init__(self, hostports, pool_size): self.pool_size = pool_size self.hostports = hostports - self.queue = Queue(pool_size) + queue_limit = pool_size * len(hostports) if type(hostports) is list else pool_size + self.queue = Queue(queue_limit) # Patch httplib if we are using that, also patch the sockets monkey.patch_all() @@ -49,7 +50,7 @@ def __init__(self, hostports, pool_size): if type(self.hostports) is list: for host, port in self.hostports: for i in range(0, pool_size): - self.queue.put_nowait(self.connection_class(host, port)) + self.queue.put(self.connection_class(host, port)) else: for i in range(0, pool_size): self.queue.put(self.connection_class(hostports[0], hostports[1])) From a6cb9a7a6f5a826f9b27deaa70ff9c3e2657fb52 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 16:20:20 -0500 Subject: [PATCH 19/22] Fixing the default pool_size arg --- riak/transports/connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 7c7b6b33..83fa37c1 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -31,7 +31,7 @@ class ConnectionManager(object): # Must have a close() method connection_class = None - def __init__(self, hostports, pool_size): + def __init__(self, hostports, pool_size=10): # We want a private copy of this list: either to detach the argument # default, or to detach from the caller's list. if type(hostports) is list: @@ -126,7 +126,7 @@ def close(self): class FactoryConnectionManager(ConnectionManager): - def __init__(self, connection_class, hostports, pool_size=10): + def __init__(self, connection_class, hostports, pool_size): self.connection_class = connection_class ConnectionManager.__init__(self, hostports, pool_size) From d16dac192f92fb307fc9f219c2a14064a98b8ca1 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Thu, 9 Aug 2012 16:24:00 -0500 Subject: [PATCH 20/22] No need for this I suppose... Dev should set it themselves --- riak/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/riak/client.py b/riak/client.py index 7e910d1d..e66c754c 100644 --- a/riak/client.py +++ b/riak/client.py @@ -60,7 +60,7 @@ def __init__(self, host=('127.0.0.1', 8098), pool_size=10, prefix='riak', """ if transport_class is None: transport_class = RiakHttpTransport - + api = getattr(transport_class, 'api', 1) if api >= 2: self._cm = transport_class.default_cm(host, pool_size) @@ -76,7 +76,9 @@ def __init__(self, host=('127.0.0.1', 8098), pool_size=10, prefix='riak', client_id=client_id, **transport_options) else: - raise Exception('please upgrade the transport to the new API') + deprecated('please upgrade the transport to the new API') + self._cm = None + self._transport = transport_class(host[0], host[1], client_id=client_id) self._r = "default" self._w = "default" From 5af6457f6fd138b1c64172b4e1ea3ff920042933 Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Wed, 29 Aug 2012 13:59:52 -0500 Subject: [PATCH 21/22] Only monkey patching specific pieces --- riak/transports/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index 83fa37c1..b6962c48 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -45,7 +45,7 @@ def __init__(self, hostports, pool_size=10): self.queue = Queue(queue_limit) # Patch httplib if we are using that, also patch the sockets - monkey.patch_all() + monkey.patch_all(socket=True, dns=True, thread=True) if type(self.hostports) is list: for host, port in self.hostports: From a10df14889a890327c91b4a3d5f0394c74feb66f Mon Sep 17 00:00:00 2001 From: Parnell Springmeyer Date: Wed, 29 Aug 2012 14:25:37 -0500 Subject: [PATCH 22/22] Fixing a few more of those monkey patching calls --- riak/transports/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riak/transports/connection.py b/riak/transports/connection.py index b6962c48..6ce947d2 100644 --- a/riak/transports/connection.py +++ b/riak/transports/connection.py @@ -45,7 +45,7 @@ def __init__(self, hostports, pool_size=10): self.queue = Queue(queue_limit) # Patch httplib if we are using that, also patch the sockets - monkey.patch_all(socket=True, dns=True, thread=True) + monkey.patch_all(select=False, os=False, ssl=False, subprocess=False) if type(self.hostports) is list: for host, port in self.hostports: