Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

16
Hector v2 The Second Version of the Popular High-Level Java Client for Apache Cassandra [email protected] om

description

This presentation will provide a preview of our new high-level API designed around community feedback and built on the solid foundation of Hector client internals currently in use by a number of production systems. A brief introduction to the existing Hector client will be included to accomadate new users.

Transcript of Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Page 1: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Hector v2

The Second Version of the Popular High-Level Java Client for 

Apache Cassandra

[email protected]

Page 2: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Background

• Originated from abandoned Googlecode project• Made to fit immediate needs• Focus was on the plumbing • "First to market" advantage in adoption• Developers familiar with Apache Cassandra internals

Page 3: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Current Capabilities

• Solid set of features typically found in datastore connectorso Robust monitoring via JMXo Optional performance counters  o Configurable loggingo Failover o Reliable pooling geared towards a "cluster"o OSGi compatible bundle

• Client-side validation• Test-ability 

o Utility classes for testingo Base test class for easy setup

Page 4: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Current Status

• First in market means we have a lot of userso 47 closed issues on githubo helpful archive of user and developer mail list traffic

• Lots of experience with operational behavior over time

Page 5: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Initial Assumptions About API

•  Getting involved early meant you got comfortable with Thrift•  Several early threads asked directly for thrift encapsulation

o decided to focus on the plumbing • Thought we made the right choice given the number of

projects built on top

Page 6: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Pelops Released

• Pelops got popular for the very features we thought were less importanto Thrift encapsulationo High-level abstractions

• Competition is a good thing (choice validates a market)

Page 7: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Enter v2: Design Goals

• Familiar access patterns for for most common users (Spring Framework, Hibernate, etc) 

• Keep the simplest operations simple • Thrift encapsulation• API version hiding• Clear distinction between cluster and data operations• Support multiple clusters in same JVM• Type safety• Extractor interface • Exception Translation• Support method chaining • Properties on Result (op timers)

Page 8: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

v2 Continued: Misc Changes

• Examples become real o were being used as such anywayo actually had test coverage

• Removal of redundant operations• Few changes to current "low level" API as possible

o Direct Thrift access supported

Page 9: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Full Example// Create a cluster

Cluster c = HFactory.getOrCreateCluster("MyCluster", "cassandra1:9160");// Choose a keyspaceKeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", c);// create a string extractorStringExtractor se = StringExtractor.get();// insert valueMutator m = HFactory.createMutator(keyspaceOperator);m.insert("key1", "ColumnFamily1", HFactory.createColumn("column1", "value1", se, se)); // Now read a valueColumnQuery<String, String> q = HFactory.createColumnQuery(keyspaceOperator, se, se); 

// set key, name, cf and executeResult<HColumn<String, String>> r = q.setKey("key1").setName("column1").setColumnFamily("ColumnFamily1").execute();// read value from the resultHColumn<String, String> c = r.get();String value = c.getValue();

// information about result execution long executionTime = r.getExecutionTimeMicro();CassandraHost host = r.getHostUsed();

Page 10: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Full Example Part 1

Cluster c = HFactory.getOrCreateCluster("MyCluster", "cassandra1:9160"); 

 KeyspaceOperator ko = HFactory.createKeyspaceOperator("Keyspace1", c);

  StringExtractor se = StringExtractor.get();

Page 11: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Full Example Part 2

Mutator m = HFactory.createMutator(keyspaceOperator);

m.insert("key1",               "ColumnFamily1",               HFactory.createColumn("column1", "value1", se, se));    - OR - m.addInsertion("key1",                          "ColumnFamily1",                          HFactory.createColumn("column1", "value1", se, se));... m.execute(); 

Page 12: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Full Example Part 3

ColumnQuery<String, String> q =     HFactory.createColumnQuery(keyspaceOperator, se, se);  

Result<HColumn<String, String>> r = q.setKey("key1").setName("column1").setColumnFamily("ColumnFamily1").execute();

Page 13: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Full Example Part 4

HColumn<String, String> c = r.get(); 

String value = c.getValue();

long executionTime = r.getExecutionTimeMicro(); 

CassandraHost host = r.getHostUsed();

Page 14: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Simple Example (IoC Required)

simpleCassandraDao.insert("key1","column1", "value1");  String value = simpleCassandraDao.get("key1","column1"); 

     <bean id="cassandraHostConfigurator" class="me.prettyprint.cassandra.service.CassandraHostConfigurator">        <constructor-arg value="localhost:9170"/>

    </bean>

    <bean id="cluster" class="me.prettyprint.cassandra.service.Cluster">        <constructor-arg value="TestCluster"/>        <constructor-arg ref="cassandraHostConfigurator"/>    </bean>        <bean id="keyspaceOperator" class="me.prettyprint.cassandra.model.HFactory" factory-method="createKeyspaceOperator">        <constructor-arg value="Keyspace1"/>        <constructor-arg ref="cluster"/>    </bean>

    <bean id="simpleCassandraDao" class="me.prettyprint.cassandra.dao.SimpleCassandraDao">        <property name="keyspaceOperator" ref="keyspaceOperator"/>        <property name="keyspaceName" value="Keyspace1"/>        <property name="columnFamilyName" value="Standard1"/>    </bean>

 

Page 15: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Immediate(ish) Future

•  More refactoring on internalso unwind constructor complexity

•  v0.7 support o key changes o authenticationo new methods: column indexes, multi-get count

• Avro support(?) • Threshold-triggered per-thread monitoring (all the pieces in

place) • Back-off and retry for host pools marked dead• Configuarble client mediated selects• JPA Annotations • Load balancing

Page 16: Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra

Feedback Please

[email protected]

[email protected]

http://github.com/rantav/hector