paris cassandra meetup - overview of new cassandra drivers

18
Overview of New Cassandra Drivers Michaël Figuière Engineer & Developer Advocate, DataStax @mfiguiere

Upload: michael-figuiere

Post on 15-Jan-2015

1.183 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Paris Cassandra Meetup - Overview of New Cassandra Drivers

Overview of NewCassandra Drivers

Michaël FiguièreEngineer & Developer Advocate, DataStax@mfiguiere

Page 2: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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

Page 3: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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

Page 4: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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

Page 5: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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

Page 6: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©2012 DataStax

Request Pipelining

6

Client

WithoutRequest Pipelining

Cassandra

Client CassandraWith

Request Pipelining

Page 7: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©2012 DataStax

Notifications

7

Client

WithoutNotifications

WithNotifications

NodeNode

Node

Client

NodeNode

Node

Page 8: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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

Page 9: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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]')");

Page 10: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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");}

Page 11: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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");}

Page 12: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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

Page 13: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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;}

Page 14: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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

Page 15: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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

Page 16: Paris Cassandra Meetup - Overview of New Cassandra Drivers

©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;

}

Page 17: Paris Cassandra Meetup - Overview of New Cassandra Drivers

https://github.com/datastax/java-driver

Now Available!

Page 18: Paris Cassandra Meetup - Overview of New Cassandra Drivers

@mfiguiere

blog.datastax.com

Stay Tuned!