Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit dcd0a3f2be4de0bcf2d2ab674314898879c8fa3e 2 parents 1220950 + 1939eca
authored October 13, 2011
1  CHANGELOG
@@ -18,6 +18,7 @@ Fixed speed4j setup - modified hector so it only uses speed4j.properties to conf
18 18
   name must be of the form "hector-<cluster-name>".  Updating wiki page as well.
19 19
 Fix issue https://github.com/rantav/hector/issues/294. 
20 20
 Fix issue with non-rentrant mutators on ColumnFamilyTemplate hierarchy. See https://github.com/rantav/hector/issues/286
  21
+Close client on HInvalidRequestException and on HCassandraInternalException (issue-299)
21 22
 
22 23
 0.8.0-2
23 24
 =======
37  core/src/main/java/me/prettyprint/cassandra/connection/HConnectionManager.java
@@ -237,23 +237,23 @@ public void operateWithFailover(Operation<?> op) throws HectorException {
237 237
 
238 238
       } catch (Exception ex) {
239 239
         HectorException he = exceptionsTranslator.translate(ex);
240  
-        if ( he instanceof HInvalidRequestException || he instanceof HCassandraInternalException || he instanceof HUnavailableException) {
  240
+        if ( he instanceof HUnavailableException) {
241 241
           // break out on HUnavailableException as well since we can no longer satisfy the CL
242 242
           throw he;
243  
-        } else if ( he instanceof HectorTransportException) {
244  
-          // client can be null in this situation
245  
-          if ( client != null ) {            
246  
-            client.close();
247  
-          }
  243
+        } else if (he instanceof HInvalidRequestException || he instanceof HCassandraInternalException) {
  244
+          closeClient(client);
  245
+          throw he;
  246
+        } else if (he instanceof HectorTransportException) {
  247
+          closeClient(client);
248 248
           markHostAsDown(pool.getCassandraHost());
249 249
           excludeHosts.add(pool.getCassandraHost());
250 250
           retryable = true;
251  
-          
  251
+
252 252
           monitor.incCounter(Counter.RECOVERABLE_TRANSPORT_EXCEPTIONS);
253  
-                  
  253
+
254 254
         } else if (he instanceof HTimedOutException ) {
255 255
           // DO NOT drecrement retries, we will be keep retrying on timeouts until it comes back
256  
-          // if HLT.checkTimeout(cassandraHost): suspendHost(cassandraHost);          
  256
+          // if HLT.checkTimeout(cassandraHost): suspendHost(cassandraHost);
257 257
           doTimeoutCheck(pool.getCassandraHost());
258 258
 
259 259
           retryable = true;
@@ -275,8 +275,9 @@ public void operateWithFailover(Operation<?> op) throws HectorException {
275 275
           // that we don't add in time. 
276 276
           retryable = false;
277 277
         }
278  
-        if ( retries <= 0 || retryable == false) throw he;
279  
-        
  278
+        if ( retries <= 0 || retryable == false)
  279
+          throw he;
  280
+
280 281
         log.warn("Could not fullfill request on this host {}", client);
281 282
         log.warn("Exception: ", he);
282 283
         monitor.incCounter(Counter.SKIP_HOST_SUCCESS);
@@ -291,15 +292,21 @@ public void operateWithFailover(Operation<?> op) throws HectorException {
291 292
       }
292 293
     }
293 294
   }
294  
-  
  295
+
  296
+  private void closeClient(HThriftClient client) {
  297
+    if ( client != null ) {
  298
+      client.close();
  299
+    }
  300
+  }
  301
+
295 302
   public HOpTimer getTimer() {
296  
-	return timer;
  303
+    return timer;
297 304
   }
298 305
 
299 306
   public void setTimer(HOpTimer timer) {
300  
-	this.timer = timer;
  307
+    this.timer = timer;
301 308
   }
302  
-  
  309
+
303 310
   /**
304 311
    * Use the HostTimeoutCheck and initiate a suspend if and only if
305 312
    * we are configured for such AND there is more than one operating host pool
68  core/src/test/java/me/prettyprint/cassandra/model/GetSliceQueryTest.java
... ...
@@ -0,0 +1,68 @@
  1
+package me.prettyprint.cassandra.model;
  2
+
  3
+import static me.prettyprint.hector.api.factory.HFactory.createColumn;
  4
+import static me.prettyprint.hector.api.factory.HFactory.createKeyspace;
  5
+import static me.prettyprint.hector.api.factory.HFactory.createMutator;
  6
+import static me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster;
  7
+import static org.junit.Assert.assertEquals;
  8
+import static org.junit.Assert.fail;
  9
+import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
  10
+import me.prettyprint.cassandra.serializers.LongSerializer;
  11
+import me.prettyprint.cassandra.serializers.StringSerializer;
  12
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
  13
+import me.prettyprint.hector.api.Cluster;
  14
+import me.prettyprint.hector.api.Keyspace;
  15
+import me.prettyprint.hector.api.beans.ColumnSlice;
  16
+import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
  17
+import me.prettyprint.hector.api.factory.HFactory;
  18
+import me.prettyprint.hector.api.query.QueryResult;
  19
+import me.prettyprint.hector.api.query.SliceQuery;
  20
+
  21
+import org.junit.Before;
  22
+import org.junit.Test;
  23
+
  24
+public class GetSliceQueryTest extends BaseEmbededServerSetupTest {
  25
+  
  26
+  private final static String KEYSPACE = "Keyspace1";
  27
+  private static final StringSerializer se = new StringSerializer();
  28
+  private static final LongSerializer le = new LongSerializer();
  29
+  private Cluster cluster;
  30
+  private Keyspace keyspace;
  31
+  private String cf = "Standard1";
  32
+
  33
+  @Before
  34
+  public void setupCase() {
  35
+    CassandraHostConfigurator chc = new CassandraHostConfigurator("127.0.0.1:9170");
  36
+    chc.setMaxActive(2);
  37
+    cluster = getOrCreateCluster("MyCluster", chc);
  38
+    keyspace = createKeyspace(KEYSPACE, cluster);
  39
+
  40
+    createMutator(keyspace, se)
  41
+    .addInsertion("getSliceTest_key3", cf, createColumn("birthyear1", 1974L, se, le))
  42
+    .addInsertion("getSliceTest_key3", cf, createColumn("birthyear2", 1975L, se, le))
  43
+    .addInsertion("getSliceTest_key3", cf, createColumn("birthyear3", 1976L, se, le))
  44
+    .addInsertion("getSliceTest_key3", cf, createColumn("birthyear4", 1977L, se, le))
  45
+    .addInsertion("getSliceTest_key3", cf, createColumn("birthyear5", 1978L, se, le))
  46
+    .addInsertion("getSliceTest_key3", cf, createColumn("birthyear6", 1979L, se, le))
  47
+    .execute();
  48
+  }
  49
+
  50
+  @Test
  51
+  public void testNullKeyInvalidQuery() {
  52
+    SliceQuery<String, String, Long> sq = HFactory.createSliceQuery(keyspace, se, se, le);
  53
+    sq.setColumnFamily(cf);
  54
+    sq.setRange("birthyear1", "birthyear4", false, 100);
  55
+    // we are missing sq.setKey(...);
  56
+
  57
+    try {
  58
+      sq.execute();
  59
+      fail();
  60
+    } catch (HInvalidRequestException he) {
  61
+      // ok!
  62
+    }
  63
+
  64
+    sq.setKey("getSliceTest_key3");
  65
+    QueryResult<ColumnSlice<String, Long>> result = sq.execute();
  66
+    assertEquals(4,result.get().getColumns().size());
  67
+  }
  68
+}

0 notes on commit dcd0a3f

Please sign in to comment.
Something went wrong with that request. Please try again.