paris cassandra meetup - overview of new cassandra drivers
DESCRIPTION
TRANSCRIPT
Overview of NewCassandra Drivers
Michaël FiguièreEngineer & Developer Advocate, DataStax@mfiguiere
©2012 DataStax
Past Drivers Architecture
2
Thrift API
Thrift RPC
* This is a simplified view of drivers architecture. Details vary from one language to another.
OO API
Client Library
©2012 DataStax
Current Drivers Architecture
3
Thrift API
Thrift RPC
CQL API
Thrift RPC
DB API
* This is a simplified view of drivers architecture. Details vary from one language to another.
OO API
Client Library CQL Driver
©2012 DataStax
CQL: the new face of Cassandra
• CQL 3• Simpler Data Model using denormalized Tables• SQL-like query language• Schema definition
• CQL Binary Protocol• To be introduced in Cassandra 1.2 (CASSANDRA-2478)• Designed for CQL 3• Opens doors for Streaming, Notifications, ...• Thrift will keep being supported by Cassandra
4
©2012 DataStax
New Drivers Architecture
5
DB API
CQL Native Protocol
CQL API OO API
* This is a simplified view of drivers architecture. Details vary from one language to another.
Next Generation Driver
©2012 DataStax
Request Pipelining
6
Client
WithoutRequest Pipelining
Cassandra
Client CassandraWith
Request Pipelining
©2012 DataStax
Notifications
7
Client
WithoutNotifications
WithNotifications
NodeNode
Node
Client
NodeNode
Node
©2012 DataStax
Java Driver• Reference Implementation
• Asynchronous architecture based on Netty
• Prepared Statements Support
• Automatic Fail-over
• Node Discovery
• Cassandra Tracing Support
• Tunable policies• LoadBalancingPolicy• ReconnectionPolicy• RetryPolicy
8
©2012 DataStax
Connect and Write
9
Cluster cluster = new Cluster.Builder() .addContactPoints("127.0.0.1", "127.0.0.2") .build();
Session session = cluster.connect();
session.execute( "INSERT INTO user (user_id, name, email) VALUES (12345, 'johndoe', '[email protected]')");
©2012 DataStax
Read
10
ResultSet rs = session.execute("SELECT * FROM test");
List<CQLRow> rows = rs.fetchAll(); for (CQLRow row : rows) {
String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email");}
©2012 DataStax
Asynchronous Read
11
ResultSet.Future future = session.executeAsync("SELECT * FROM test");
ResultSet rs = future.get();
List<CQLRow> rows = rs.fetchAll(); for (CQLRow row : rows) {
String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email");}
©2012 DataStax
Mapping in Java
• JPA• Standard and very popular API• Very relational oriented• Hard for developers to figure out which part is usable
• JPA-ish• A mapping API designed for Cassandra• Most annotations borrowed and modified from JPA• Get rid of non relevant components• Add some Cassandra-specific concepts
12
©2012 DataStax
Object Mapping
13
public enum Gender {
@EnumValue("m") MALE, @EnumValue("f") FEMALE;}
@Table("user_and_messages")public class User { @Column("user_id") private String userId; private String name; private String email; private Gender gender;}
©2012 DataStax
Sample Data Model
14
user_and_messages Table
CREATE TABLE user_and_messages ( user_id varchar, msg_id int, title varchar, body varchar, PRIMARY KEY (user_id, msg_id));
CQL
gmason
user_id
Hello!
title
Give me liberty or give me death
body
gmason Bonjour ! I chopped down the cherry tree
ahamilton Hallo ! A government of laws, not men
ahamilton ¡Hola I chopped down the cherry tree
msg_id
4
5
7
9
©2012 DataStax
Aggregation
15
@Table("user_and_messages")public class User { @Column("user_id") private String userId; @GroupBy("user_id") private List<Message> messages;}
public class Message {
private String title; private String body; }
gmason
user_id
Hello!
title
Give me liberty or give me death
body
gmason Bonjour ! I chopped down the cherry tree
ahamilton Hallo ! A government of laws, not men
ahamilton ¡Hola I chopped down the cherry tree
msg_id
4
5
7
9
©2012 DataStax
Inheritance
16
@InheritanceValue("tv")public class TV extends Product {
private float size;}
@Table("catalog")@Inheritance({Phone.class, TV.class})@InheritanceColumn("product_type")public abstract class Product {
@Column("product_id") private String productId; private float price; private String vendor; private String model;
}
https://github.com/datastax/java-driver
Now Available!
@mfiguiere
blog.datastax.com
Stay Tuned!