Hector v2: The Second Version of the Popular High-Level Java Client for Apache Cassandra
-
Upload
zznate -
Category
Technology
-
view
5.724 -
download
4
description
Transcript of 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
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
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
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
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
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)
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)
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
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();
Full Example Part 1
Cluster c = HFactory.getOrCreateCluster("MyCluster", "cassandra1:9160");
KeyspaceOperator ko = HFactory.createKeyspaceOperator("Keyspace1", c);
StringExtractor se = StringExtractor.get();
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();
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();
Full Example Part 4
HColumn<String, String> c = r.get();
String value = c.getValue();
long executionTime = r.getExecutionTimeMicro();
CassandraHost host = r.getHostUsed();
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>
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