2. CQL The new face of Cassandra
* CQL3
* Simpler Data Model using Denormalized Tables
* SQL-like Query Language
* Schema Definition
* CQL Native Protocol
* Introduced in Cassandra 1.2
* Designed for CQL3
* Thrift will keep being supported by Cassandra
3. * Cassandra lives closer to users and application
* Data model expresses your application intent
* Not made for generalizable queries
* Key to a successful project
CQL Data Model Overview
4. CQL3 Data Model
Data duplicated over several tables
CQL3 Query Language
comes with a new Data
Model abstraction
made of denormalized,
statically defined tables
5. CQL3 Data Model
gmason
user_id
1735
tweet_id
phenry
author
Give me liberty or give me death
body
Partition
Key
gmason 1742 gwashington I chopped down the cherry tree
ahamilton 1767 jadams A government of laws, not men
ahamilton 1794 gwashington I chopped down the cherry tree
Clustering
Key
Timeline Table
6. CQL3 Data Model
gmason
user_id
1735
tweet_id
phenry
author
Give me liberty or give me death
body
Partition
Key
gmason 1742 gwashington I chopped down the cherry tree
ahamilton 1767 jadams A government of laws, not men
ahamilton 1794 gwashington I chopped down the cherry tree
Clustering
Key
Timeline Table
CREATE TABLE timeline (
user_id varchar,
tweet_id timeuuid,
author varchar,
body varchar,
PRIMARY KEY (user_id, tweet_id));
CQL
7. DB API
CQL Native Protocol
CQL API OO API
Next Generation Driver
New Driver Architecture
8. * Reference Implementation
* Asynchronous architecture based on Netty
* Prepared Statements Support
* Automatic Fail-over
* Node Discovery
* Cassandra Tracing Support
* Tunable Policies
Java Driver Overview
22. Multi Datacenter Load Balancing
Node
Node
Replica
Node
Client Node
NodeReplica
Replica
Nodes that own a
Replica of the data
being read or written
by the query will be
contacted first.
23. contactPoints = {“10.0.0.1”,”10.0.0.2”}
keyspace = “videodb”
public VideoDbBasicImpl(List<String> contactPoints, String keyspace) {
cluster = Cluster
.builder()
.addContactPoints(
! contactPoints.toArray(new String[contactPoints.size()]))
.withLoadBalancingPolicy(Policies.defaultLoadBalancingPolicy())
.build();
session = cluster.connect(keyspace);
}
Create your own policy!
Add a Load Balancing Policy
24. Client
If the requested
Consistency Level
cannot be reached
(QUORUM here), a
second request with a
lower CL is sent
automatically.
Node
Node Replica
Replica
Node
Replica
Downgrading Retry Policy
25. contactPoints = {“10.0.0.1”,”10.0.0.2”}
keyspace = “videodb”
public VideoDbBasicImpl(List<String> contactPoints, String keyspace) {
cluster = Cluster
.builder()
.addContactPoints(
! contactPoints.toArray(new String[contactPoints.size()]))
.withLoadBalancingPolicy(Policies.defaultLoadBalancingPolicy())
.withRetryPolicy(Policies.defaultRetryPolicy())
.build();
session = cluster.connect(keyspace);
}
Create your own policy!
Specify a Retry Policy
26. public enum Gender {
@EnumValue("m")
MALE,
@EnumValue("f")
FEMALE;
}
@Table(name = "user")
public class User {
@PartitionKey
@Column(name = "user_id")
private String userId;
private String name;
private String email;
private Gender gender;
}
Object Mapping