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

Commit

Permalink
Merge branch '0.8.0' of github.com:rantav/hector into 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zznate committed Oct 13, 2011
2 parents 1220950 + 1939eca commit dcd0a3f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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. 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 https://github.com/rantav/hector/issues/294.
Fix issue with non-rentrant mutators on ColumnFamilyTemplate hierarchy. See https://github.com/rantav/hector/issues/286 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 0.8.0-2
======= =======
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -237,23 +237,23 @@ public void operateWithFailover(Operation<?> op) throws HectorException {


} catch (Exception ex) { } catch (Exception ex) {
HectorException he = exceptionsTranslator.translate(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 // break out on HUnavailableException as well since we can no longer satisfy the CL
throw he; throw he;
} else if ( he instanceof HectorTransportException) { } else if (he instanceof HInvalidRequestException || he instanceof HCassandraInternalException) {
// client can be null in this situation closeClient(client);
if ( client != null ) { throw he;
client.close(); } else if (he instanceof HectorTransportException) {
} closeClient(client);
markHostAsDown(pool.getCassandraHost()); markHostAsDown(pool.getCassandraHost());
excludeHosts.add(pool.getCassandraHost()); excludeHosts.add(pool.getCassandraHost());
retryable = true; retryable = true;

monitor.incCounter(Counter.RECOVERABLE_TRANSPORT_EXCEPTIONS); monitor.incCounter(Counter.RECOVERABLE_TRANSPORT_EXCEPTIONS);

} else if (he instanceof HTimedOutException ) { } else if (he instanceof HTimedOutException ) {
// DO NOT drecrement retries, we will be keep retrying on timeouts until it comes back // 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()); doTimeoutCheck(pool.getCassandraHost());


retryable = true; retryable = true;
Expand All @@ -275,8 +275,9 @@ public void operateWithFailover(Operation<?> op) throws HectorException {
// that we don't add in time. // that we don't add in time.
retryable = false; 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("Could not fullfill request on this host {}", client);
log.warn("Exception: ", he); log.warn("Exception: ", he);
monitor.incCounter(Counter.SKIP_HOST_SUCCESS); monitor.incCounter(Counter.SKIP_HOST_SUCCESS);
Expand All @@ -291,15 +292,21 @@ public void operateWithFailover(Operation<?> op) throws HectorException {
} }
} }
} }


private void closeClient(HThriftClient client) {
if ( client != null ) {
client.close();
}
}

public HOpTimer getTimer() { public HOpTimer getTimer() {
return timer; return timer;
} }


public void setTimer(HOpTimer timer) { public void setTimer(HOpTimer timer) {
this.timer = timer; this.timer = timer;
} }

/** /**
* Use the HostTimeoutCheck and initiate a suspend if and only if * 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 * we are configured for such AND there is more than one operating host pool
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -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.