Permalink
Browse files

Let the pool retry TTransportException instead of the general TException

With the c11 thrift API update, all exceptions in ttypes inherit from
TException instead of Exception. This change restores the old behavior and
does not retry any of: NotFoundException, InvalidRequestException,
AuthenticationException, AuthorizationException, SchemaDisagreementException

Compared to pycassa 1.6.0 TProtocolException is no longer retried either.
  • Loading branch information...
1 parent 1adde9c commit 9591f719d4cd64dbc1de6e0cd5b45ddfbcc84c8f @hannosch hannosch committed Jul 18, 2012
Showing with 19 additions and 1 deletion.
  1. +3 −1 pycassa/pool.py
  2. +16 −0 tests/test_connection_pooling.py
View
4 pycassa/pool.py
@@ -12,6 +12,7 @@
import Queue
from thrift import Thrift
+from thrift.transport.TTransport import TTransportException
from connection import Connection
from logging.pool_logger import PoolLogger
from util import as_interface
@@ -128,7 +129,8 @@ def new_f(self, *args, **kwargs):
self._pool._decrement_overflow()
self._pool._clear_current()
raise app_exc
- except (TimedOutException, UnavailableException, Thrift.TException,
+ except (TimedOutException, UnavailableException,
+ TTransportException,
socket.error, IOError, EOFError), exc:
self._pool._notify_on_failure(exc, server=self.server, connection=self)
View
16 tests/test_connection_pooling.py
@@ -6,6 +6,8 @@
from pycassa import ColumnFamily, ConnectionPool, PoolListener, InvalidRequestError,\
NoConnectionAvailable, MaximumRetryException, AllServersUnavailable
from pycassa.cassandra.ttypes import ColumnPath
+from pycassa.cassandra.ttypes import InvalidRequestException
+
_credentials = {'username':'jsmith', 'password':'havebadpass'}
@@ -486,6 +488,20 @@ def test_failure_connection_info(self):
assert_equal(request['args'], ('greunt', ColumnPath('Counter1', None, 'col'), 1))
assert_equal(request['kwargs'], {})
+ def test_pool_invalid_request(self):
+ listener = _TestListener()
+ pool = ConnectionPool(pool_size=1, max_overflow=0, recycle=10000,
+ prefill=True, max_retries=3,
+ keyspace='PycassaTestKeyspace',
+ credentials=_credentials,
+ listeners=[listener], use_threadlocal=False,
+ server_list=['localhost:9160'])
+ cf = ColumnFamily(pool, 'Standard1')
+ # Make sure the pool doesn't hide and retries invalid requests
+ assert_raises(InvalidRequestException, cf.add, 'key', 'col')
+ pool.dispose()
+
+
class _TestListener(PoolListener):
def __init__(self):

0 comments on commit 9591f71

Please sign in to comment.