diff options
author | Ryan Williams <rdw@lindenlab.com> | 2008-05-13 21:07:14 +0000 |
---|---|---|
committer | Ryan Williams <rdw@lindenlab.com> | 2008-05-13 21:07:14 +0000 |
commit | 52333fc8307b13fa83683d239305765aa48dc35b (patch) | |
tree | 0caa64f54195584f3344ef9bb845d51cb05a2134 /indra/lib/python/indra/ipc | |
parent | 875606a04d656ef6e5600a3a7fb6e8b52feb1945 (diff) |
svn merge -r87349:87423 svn+ssh://svn.lindenlab.com/svn/linden/branches/escrow/liquid-banjo-03-merge release dataserver-is-deprecated
Diffstat (limited to 'indra/lib/python/indra/ipc')
-rw-r--r-- | indra/lib/python/indra/ipc/llsdhttp.py | 7 | ||||
-rw-r--r-- | indra/lib/python/indra/ipc/mysql_pool.py | 88 |
2 files changed, 35 insertions, 60 deletions
diff --git a/indra/lib/python/indra/ipc/llsdhttp.py b/indra/lib/python/indra/ipc/llsdhttp.py index 0561cfd520..12d759d3a0 100644 --- a/indra/lib/python/indra/ipc/llsdhttp.py +++ b/indra/lib/python/indra/ipc/llsdhttp.py @@ -60,21 +60,22 @@ def postFile(url, filename): return post_(url, llsd_body) +# deprecated in favor of get_ def getStatus(url, use_proxy=False): status, _headers, _body = get_(url, use_proxy=use_proxy) return status - +# deprecated in favor of put_ def putStatus(url, data): status, _headers, _body = put_(url, data) return status - +# deprecated in favor of delete_ def deleteStatus(url): status, _headers, _body = delete_(url) return status - +# deprecated in favor of post_ def postStatus(url, data): status, _headers, _body = post_(url, data) return status diff --git a/indra/lib/python/indra/ipc/mysql_pool.py b/indra/lib/python/indra/ipc/mysql_pool.py index 827b6d42e9..2a5a916e74 100644 --- a/indra/lib/python/indra/ipc/mysql_pool.py +++ b/indra/lib/python/indra/ipc/mysql_pool.py @@ -1,6 +1,6 @@ """\ @file mysql_pool.py -@brief Uses saranwrap to implement a pool of nonblocking database connections to a mysql server. +@brief Thin wrapper around eventlet.db_pool that chooses MySQLdb and Tpool. $LicenseInfo:firstyear=2007&license=mit$ @@ -26,44 +26,14 @@ THE SOFTWARE. $/LicenseInfo$ """ -import os - -from eventlet.pools import Pool -from eventlet.processes import DeadProcess -from indra.ipc import saranwrap - import MySQLdb +from eventlet import db_pool -# method 2: better -- admits the existence of the pool -# dbp = my_db_connector.get() -# dbh = dbp.get() -# dbc = dbh.cursor() -# dbc.execute(named_query) -# dbc.close() -# dbp.put(dbh) - -class DatabaseConnector(object): - """\ -@brief This is an object which will maintain a collection of database -connection pools keyed on host,databasename""" +class DatabaseConnector(db_pool.DatabaseConnector): def __init__(self, credentials, min_size = 0, max_size = 4, *args, **kwargs): - """\ - @brief constructor - @param min_size the minimum size of a child pool. - @param max_size the maximum size of a child pool.""" - self._min_size = min_size - self._max_size = max_size - self._args = args - self._kwargs = kwargs - self._credentials = credentials # this is a map of hostname to username/password - self._databases = {} - - def credentials_for(self, host): - if host in self._credentials: - return self._credentials[host] - else: - return self._credentials.get('default', None) + super(DatabaseConnector, self).__init__(MySQLdb, credentials, min_size, max_size, conn_pool=db_pool.ConnectionPool, *args, **kwargs) + # get is extended relative to eventlet.db_pool to accept a port argument def get(self, host, dbname, port=3306): key = (host, dbname, port) if key not in self._databases: @@ -77,28 +47,32 @@ connection pools keyed on host,databasename""" return self._databases[key] - -class ConnectionPool(Pool): +class ConnectionPool(db_pool.TpooledConnectionPool): """A pool which gives out saranwrapped MySQLdb connections from a pool """ - def __init__(self, min_size = 0, max_size = 4, *args, **kwargs): - self._args = args - self._kwargs = kwargs - Pool.__init__(self, min_size, max_size) - def create(self): - return saranwrap.wrap(MySQLdb).connect(*self._args, **self._kwargs) - - def put(self, conn): - # rollback any uncommitted changes, so that the next process - # has a clean slate. This also pokes the process to see if - # it's dead or None - try: - conn.rollback() - except (AttributeError, DeadProcess), e: - conn = self.create() - # TODO figure out if we're still connected to the database - if conn is not None: - Pool.put(self, conn) - else: - self.current_size -= 1 + def __init__(self, min_size = 0, max_size = 4, *args, **kwargs): + super(ConnectionPool, self).__init__(MySQLdb, min_size, max_size, *args, **kwargs) + + def get(self): + conn = super(ConnectionPool, self).get() + # annotate the connection object with the details on the + # connection; this is used elsewhere to check that you haven't + # suddenly changed databases in midstream while making a + # series of queries on a connection. + arg_names = ['host','user','passwd','db','port','unix_socket','conv','connect_timeout', + 'compress', 'named_pipe', 'init_command', 'read_default_file', 'read_default_group', + 'cursorclass', 'use_unicode', 'charset', 'sql_mode', 'client_flag', 'ssl', + 'local_infile'] + # you could have constructed this connectionpool with a mix of + # keyword and non-keyword arguments, but we want to annotate + # the connection object with a dict so it's easy to check + # against so here we are converting the list of non-keyword + # arguments (in self._args) into a dict of keyword arguments, + # and merging that with the actual keyword arguments + # (self._kwargs). The arg_names variable lists the + # constructor arguments for MySQLdb Connection objects. + converted_kwargs = dict([ (arg_names[i], arg) for i, arg in enumerate(self._args) ]) + converted_kwargs.update(self._kwargs) + conn.connection_parameters = converted_kwargs + return conn |