Contenu connexe
Similaire à Paris Cassandra Meetup - Overview of New Cassandra Drivers
Similaire à Paris Cassandra Meetup - Overview of New Cassandra Drivers (20)
Plus de Michaël Figuière (20)
Paris Cassandra Meetup - Overview of New Cassandra Drivers
- 2. Past Drivers Architecture
Thrift API OO API
Thrift RPC
Client Library
* This is a simplified view of drivers architecture. Details vary from one language to another.
©2012 DataStax 2
- 3. Current Drivers Architecture
CQL API Thrift API OO API DB API
Thrift RPC Thrift RPC
Client Library CQL Driver
* This is a simplified view of drivers architecture. Details vary from one language to another.
©2012 DataStax 3
- 4. 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
©2012 DataStax 4
- 5. New Drivers Architecture
DB API CQL API OO API
CQL Native Protocol
Next Generation Driver
* This is a simplified view of drivers architecture. Details vary from one language to another.
©2012 DataStax 5
- 6. Request Pipelining
Client Cassandra
Without
Request Pipelining
With
Client Cassandra Request Pipelining
©2012 DataStax 6
- 7. Notifications
Node
Client
Node
Node
Without
Notifications
With
Notifications
Node
Client
Node
Node
©2012 DataStax 7
- 8. Java Driver
• Reference Implementation
• Asynchronous architecture based on Netty
• Prepared Statements Support
• Automatic Fail-over
• Node Discovery
• Cassandra Tracing Support
• Tunable policies
• LoadBalancingPolicy
• ReconnectionPolicy
•
©2012 DataStax
RetryPolicy
8
- 9. Connect and Write
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', 'john@doe.com')"
);
©2012 DataStax 9
- 10. Read
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 10
- 11. Asynchronous Read
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 11
- 12. 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
©2012 DataStax 12
- 13. Object Mapping
@Table("user_and_messages") public enum Gender {
public class User {
@EnumValue("m")
@Column("user_id") MALE,
private String userId;
@EnumValue("f")
private String name; FEMALE;
}
private String email;
private Gender gender;
}
©2012 DataStax 13
- 14. Sample Data Model
user_and_messages Table
user_id msg_id title body
gmason 4 Hello! Give me liberty or give me death
gmason 5 Bonjour ! I chopped down the cherry tree
ahamilton 7 Hallo ! A government of laws, not men
ahamilton 9 ¡Hola I chopped down the cherry tree
CQL
CREATE TABLE user_and_messages (
user_id varchar,
msg_id int,
title varchar,
body varchar,
PRIMARY KEY (user_id, msg_id));
©2012 DataStax 14
- 15. Aggregation
user_id msg_id title body
gmason 4 Hello! Give me liberty or give me death
gmason 5 Bonjour ! I chopped down the cherry tree
ahamilton 7 Hallo ! A government of laws, not men
ahamilton 9 ¡Hola I chopped down the cherry tree
@Table("user_and_messages") public class Message {
public class User {
private String title;
@Column("user_id")
private String userId; private String body;
}
@GroupBy("user_id")
private List<Message> messages;
}
©2012 DataStax 15
- 16. Inheritance
@Table("catalog")
@InheritanceValue("tv")
@Inheritance({Phone.class, TV.class})
public class TV
@InheritanceColumn("product_type")
extends Product {
public abstract class Product {
private float size;
@Column("product_id")
}
private String productId;
private float price;
private String vendor;
private String model;
}
©2012 DataStax 16