Permalink
Browse files

Merge pull request #608 from weizhu-us/master

 issue #594, handle SocketTimeoutException differently
  • Loading branch information...
zznate committed Mar 28, 2013
2 parents 1eb113d + a53ee63 commit d862e955a134495609685bfc0011ea7f39e90323
@@ -6,6 +6,8 @@
import java.util.concurrent.atomic.AtomicLong;
import me.prettyprint.cassandra.service.CassandraHost;
+import me.prettyprint.cassandra.service.ExceptionsTranslator;
+import me.prettyprint.cassandra.service.ExceptionsTranslatorImpl;
import me.prettyprint.cassandra.service.SystemProperties;
import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
import me.prettyprint.hector.api.exceptions.HectorTransportException;
@@ -45,6 +47,7 @@
private static final AtomicLong serial = new AtomicLong(0);
final CassandraHost cassandraHost;
+ final ExceptionsTranslator exceptionsTranslator;
private final long mySerial;
protected final int timeout;
@@ -67,6 +70,7 @@ public HThriftClient(CassandraHost cassandraHost) {
this.cassandraHost = cassandraHost;
this.timeout = getTimeout(cassandraHost);
mySerial = serial.incrementAndGet();
+ exceptionsTranslator = new ExceptionsTranslatorImpl();
}
/**
@@ -79,6 +83,7 @@ public HThriftClient(CassandraHost cassandraHost, TSSLTransportParameters params
this.timeout = getTimeout(cassandraHost);
this.params = params;
mySerial = serial.incrementAndGet();
+ exceptionsTranslator = new ExceptionsTranslatorImpl();
}
/**
* {@inheritDoc}
@@ -106,7 +111,7 @@ public HThriftClient(CassandraHost cassandraHost, TSSLTransportParameters params
} catch (InvalidRequestException ire) {
throw new HInvalidRequestException(ire);
} catch (TException e) {
- throw new HectorTransportException(e);
+ throw exceptionsTranslator.translate(e);
}
keyspaceName = keyspaceNameArg;
}
@@ -30,7 +30,14 @@ public HectorException translate(Throwable original) {
} else if (original instanceof TApplicationException) {
return new HCassandraInternalException(((TApplicationException)original).getType(), original.getMessage());
} else if (original instanceof TTransportException) {
- return new HectorTransportException(original);
+ // if the underlying cause is a scoket timeout, reflect that directly
+ // TODO this may be an issue on the Cassandra side which warrants investigation.
+ // I seem to remember these coming back as TimedOutException previously
+ if (((TTransportException) original).getCause() instanceof SocketTimeoutException) {
+ return new HTimedOutException(original);
+ } else {
+ return new HectorTransportException(original);
+ }
} else if (original instanceof org.apache.cassandra.thrift.TimedOutException) {
return new HTimedOutException(original);
} else if (original instanceof org.apache.cassandra.thrift.InvalidRequestException) {

0 comments on commit d862e95

Please sign in to comment.