Permalink
Browse files

Merge branch '0.8.0' of github.com:rantav/hector into 0.8.0

  • Loading branch information...
2 parents 1220950 + 1939eca commit dcd0a3f2be4de0bcf2d2ab674314898879c8fa3e zznate committed Oct 13, 2011
View
@@ -18,6 +18,7 @@ Fixed speed4j setup - modified hector so it only uses speed4j.properties to conf
name must be of the form "hector-<cluster-name>". Updating wiki page as well.
Fix issue https://github.com/rantav/hector/issues/294.
Fix issue with non-rentrant mutators on ColumnFamilyTemplate hierarchy. See https://github.com/rantav/hector/issues/286
+Close client on HInvalidRequestException and on HCassandraInternalException (issue-299)
0.8.0-2
=======
@@ -237,23 +237,23 @@ public void operateWithFailover(Operation<?> op) throws HectorException {
} catch (Exception ex) {
HectorException he = exceptionsTranslator.translate(ex);
- if ( he instanceof HInvalidRequestException || he instanceof HCassandraInternalException || he instanceof HUnavailableException) {
+ if ( he instanceof HUnavailableException) {
// break out on HUnavailableException as well since we can no longer satisfy the CL
throw he;
- } else if ( he instanceof HectorTransportException) {
- // client can be null in this situation
- if ( client != null ) {
- client.close();
- }
+ } else if (he instanceof HInvalidRequestException || he instanceof HCassandraInternalException) {
+ closeClient(client);
+ throw he;
+ } else if (he instanceof HectorTransportException) {
+ closeClient(client);
markHostAsDown(pool.getCassandraHost());
excludeHosts.add(pool.getCassandraHost());
retryable = true;
-
+
monitor.incCounter(Counter.RECOVERABLE_TRANSPORT_EXCEPTIONS);
-
+
} else if (he instanceof HTimedOutException ) {
// DO NOT drecrement retries, we will be keep retrying on timeouts until it comes back
- // if HLT.checkTimeout(cassandraHost): suspendHost(cassandraHost);
+ // if HLT.checkTimeout(cassandraHost): suspendHost(cassandraHost);
doTimeoutCheck(pool.getCassandraHost());
retryable = true;
@@ -275,8 +275,9 @@ public void operateWithFailover(Operation<?> op) throws HectorException {
// that we don't add in time.
retryable = false;
}
- if ( retries <= 0 || retryable == false) throw he;
-
+ if ( retries <= 0 || retryable == false)
+ throw he;
+
log.warn("Could not fullfill request on this host {}", client);
log.warn("Exception: ", he);
monitor.incCounter(Counter.SKIP_HOST_SUCCESS);
@@ -291,15 +292,21 @@ public void operateWithFailover(Operation<?> op) throws HectorException {
}
}
}
-
+
+ private void closeClient(HThriftClient client) {
+ if ( client != null ) {
+ client.close();
+ }
+ }
+
public HOpTimer getTimer() {
- return timer;
+ return timer;
}
public void setTimer(HOpTimer timer) {
- this.timer = timer;
+ this.timer = timer;
}
-
+
/**
* Use the HostTimeoutCheck and initiate a suspend if and only if
* we are configured for such AND there is more than one operating host pool
@@ -0,0 +1,68 @@
+package me.prettyprint.cassandra.model;
+
+import static me.prettyprint.hector.api.factory.HFactory.createColumn;
+import static me.prettyprint.hector.api.factory.HFactory.createKeyspace;
+import static me.prettyprint.hector.api.factory.HFactory.createMutator;
+import static me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
+import me.prettyprint.cassandra.serializers.LongSerializer;
+import me.prettyprint.cassandra.serializers.StringSerializer;
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.ColumnSlice;
+import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.query.QueryResult;
+import me.prettyprint.hector.api.query.SliceQuery;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class GetSliceQueryTest extends BaseEmbededServerSetupTest {
+
+ private final static String KEYSPACE = "Keyspace1";
+ private static final StringSerializer se = new StringSerializer();
+ private static final LongSerializer le = new LongSerializer();
+ private Cluster cluster;
+ private Keyspace keyspace;
+ private String cf = "Standard1";
+
+ @Before
+ public void setupCase() {
+ CassandraHostConfigurator chc = new CassandraHostConfigurator("127.0.0.1:9170");
+ chc.setMaxActive(2);
+ cluster = getOrCreateCluster("MyCluster", chc);
+ keyspace = createKeyspace(KEYSPACE, cluster);
+
+ createMutator(keyspace, se)
+ .addInsertion("getSliceTest_key3", cf, createColumn("birthyear1", 1974L, se, le))
+ .addInsertion("getSliceTest_key3", cf, createColumn("birthyear2", 1975L, se, le))
+ .addInsertion("getSliceTest_key3", cf, createColumn("birthyear3", 1976L, se, le))
+ .addInsertion("getSliceTest_key3", cf, createColumn("birthyear4", 1977L, se, le))
+ .addInsertion("getSliceTest_key3", cf, createColumn("birthyear5", 1978L, se, le))
+ .addInsertion("getSliceTest_key3", cf, createColumn("birthyear6", 1979L, se, le))
+ .execute();
+ }
+
+ @Test
+ public void testNullKeyInvalidQuery() {
+ SliceQuery<String, String, Long> sq = HFactory.createSliceQuery(keyspace, se, se, le);
+ sq.setColumnFamily(cf);
+ sq.setRange("birthyear1", "birthyear4", false, 100);
+ // we are missing sq.setKey(...);
+
+ try {
+ sq.execute();
+ fail();
+ } catch (HInvalidRequestException he) {
+ // ok!
+ }
+
+ sq.setKey("getSliceTest_key3");
+ QueryResult<ColumnSlice<String, Long>> result = sq.execute();
+ assertEquals(4,result.get().getColumns().size());
+ }
+}

0 comments on commit dcd0a3f

Please sign in to comment.