Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
some cleanup of exception logging in retry scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
zznate committed Dec 3, 2010
1 parent 8670d9b commit 8215dd1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
Expand Up @@ -8,7 +8,12 @@

import me.prettyprint.cassandra.service.CassandraHost;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ExceptionsTranslator;
import me.prettyprint.hector.api.exceptions.HCassandraInternalException;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.exceptions.HectorTransportException;

import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -19,10 +24,12 @@ public class CassandraHostRetryService extends BackgroundCassandraHostService {
public static final int DEF_QUEUE_SIZE = 3;
public static final int DEF_RETRY_DELAY = 10;
private final LinkedBlockingQueue<CassandraHost> downedHostQueue;
private final ExceptionsTranslator exceptionsTranslator;

public CassandraHostRetryService(HConnectionManager connectionManager,
CassandraHostConfigurator cassandraHostConfigurator) {
super(connectionManager, cassandraHostConfigurator);
this.exceptionsTranslator = connectionManager.exceptionsTranslator;
this.retryDelayInSeconds = cassandraHostConfigurator.getRetryDownedHostsDelayInSeconds();
downedHostQueue = new LinkedBlockingQueue<CassandraHost>(cassandraHostConfigurator.getRetryDownedHostsQueueSize());
sf = executor.scheduleWithFixedDelay(new RetryRunner(), this.retryDelayInSeconds,this.retryDelayInSeconds, TimeUnit.SECONDS);
Expand Down Expand Up @@ -99,16 +106,24 @@ private boolean verifyConnection(CassandraHost cassandraHost) {
if ( cassandraHost == null ) {
return false;
}
boolean found = false;
HThriftClient client = new HThriftClient(cassandraHost);
try {
client.open();
return client.getCassandra().describe_cluster_name() != null;
found = client.getCassandra().describe_cluster_name() != null;
client.close();
} catch (Exception e) {
log.error("Downed Host retry failed attempt to verify CassandraHost", e);
} finally {
client.close();
}
return false;
HectorException he = exceptionsTranslator.translate(e);
if ( he instanceof HectorTransportException ) {
log.error("Downed {} host still appears to be down: {}", cassandraHost, he.getMessage());
}
if ( he instanceof HCassandraInternalException ) {
log.error("Downed host retry service got a server-side error for {} - you should look into this on that node", cassandraHost);
} else {
log.error("Downed Host retry failed attempt to verify CassandraHost", e);
}
}
return found;
}

}
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class HConnectionManager {

private final ClockResolution clock;

private final ExceptionsTranslator exceptionsTranslator;
final ExceptionsTranslator exceptionsTranslator;
private CassandraClientMonitor monitor;


Expand All @@ -56,7 +56,8 @@ public HConnectionManager(CassandraHostConfigurator cassandraHostConfigurator) {
}
for ( CassandraHost host : cassandraHostConfigurator.buildCassandraHosts() ) {
try {
hostPools.put(host,new ConcurrentHClientPool(host));
ConcurrentHClientPool chcp = new ConcurrentHClientPool(host);
hostPools.put(host,chcp);
} catch (HectorTransportException hte) {
log.error("Could not start connection pool for host {}", host);
if ( cassandraHostRetryService != null ) {
Expand Down Expand Up @@ -246,10 +247,3 @@ public void shutdown() {


}

/*
- Make failoverPolicy a class
~ add max time skipping parameter
~ configurable and passed in via setter with default
*/
Expand Up @@ -50,10 +50,9 @@ HThriftClient close() {
if ( log.isDebugEnabled() ) {
log.debug("Closing client {}", this);
}
if (transport != null) {
if ( isOpen() ) {
try {
transport.flush();

} catch (Exception e) {
log.error("Could not flush transport (to be expected if the pool is shutting down) in close for client: " + toString(), e);
} finally {
Expand Down

0 comments on commit 8215dd1

Please sign in to comment.