ApacheCon NA 2013 - The New Face of Apache Cassandra
-
Upload
michael-figuiere -
Category
Technology
-
view
4.543 -
download
1
description
Transcript of ApacheCon NA 2013 - The New Face of Apache Cassandra
The new face of Cassandra
Michaël Figuière@mfiguiere
©2012 DataStax
Speaker
Michaël Figuière
@mfiguiere
2
©2012 DataStax
Ring Architecture
CassandraNode
Node
NodeNode
Node
Node
3
©2012 DataStax
Ring Architecture
4
Node
Node Replica
Replica
NodeReplica
©2012 DataStax
Linear Scalability
5
Client Writes/s by Node Count - Replication Factor = 3
©2012 DataStax
Client / Server Communication
Client
Client
Client
Client
Node?
Node
6
Replica
Replica
Replica
Node
©2012 DataStax
Client / Server Communication
Client
Client
Client
Client
Node
Node
Coordinator node:Forwards all R/W requeststo corresponding replicas
7
Replica
Replica
ReplicaNode
©2012 DataStax
3 replicas
A A A
Time
8
Tunable Consistency
©2012 DataStax
Write and wait for acknowledge from one node
Write ‘B’
B A A
9
Time
A A A
Tunable Consistency
©2012 DataStax
R + W < N
Read waiting for one node to answer
B A A
10
B A A
A A A
Write and wait for acknowledge from one node
Time
Tunable Consistency
©2012 DataStax
R + W = N
11
B B A
B A
A A A
B
Write and wait for acknowledges from two nodes
Read waiting for one node to answer
Tunable ConsistencyTime
©2012 DataStax
Tunable Consistency
R + W > N
12
B A
B A
A A A
B
B
Write and wait for acknowledges from two nodes
Read waiting for two nodes to answer
Time
©2012 DataStax
Tunable Consistency
R = W = QUORUM
13
B A
B A
A A A
B
B
Time
QUORUM = (N / 2) + 1
©2012 DataStax
Request Path
1
2
2
2
3
3
3
4
14
Client
Client
Client
Client
Node
Node
Node
Replica
Replica
Replica
Coordinator node
©2012 DataStax
Multi-Datacenter
Node6
Node1
Node4
Node5
Node2
Node3
15
Node 1
Node 2
Datacenter A
Node 3
Node 4
Datacenter B
Node 5
Node 6
Datacenter C
©2012 DataStax
Column Family Data Model
16
123 main
address
Jonathan
name
TX
statejbellis
45 2nd st
address
Daria
name
CA
statedhutch
Eric
nameegilmore
Row Key Columns = List of K/V pairs sorted by Key
©2012 DataStax
Column Family Data Model
17
datastax dhutch egilmore mzcassiejbellis
egilmoredhutch
datastax mzcassieegilmore
Row Key Columns = List of K/V pairs sorted by Key
©2012 DataStax
Storage Engine
18
Memtable
CommitLog SSTable SSTableSSTableSSTable
Memtable
©2012 DataStax
CQL3 Denormalized Model
19
Data duplicated over several tables
CQL3 Query Language comes with a new Data Model abstraction made of denormalized, statically defined tables
©2012 DataStax
CQL3 Data Model
20
gmason
user_id
1735
tweet_id
phenry
author
Give me liberty or give me death
body
PartitionKey
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
ClusteringKey
Timeline Table
©2012 DataStax
CQL3 Data Model
21
gmason
user_id
1735
tweet_id
phenry
author
Give me liberty or give me death
body
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
Timeline Table
CREATE TABLE timeline ( user_id varchar, tweet_id timeuuid, author varchar, body varchar, PRIMARY KEY (user_id, tweet_id));
CQL
©2012 DataStax
CQL3 Data Model
22
gmason
user_id tweet_id
phenry
author
Give me liberty or give me death
body
gmason gwashington I chopped down the cherry tree
ahamilton jadams A government of laws, not men
ahamilton gwashington I chopped down the cherry tree
gwashington
[1735, author]
I chopped down the...
[1735, body]
phenry
[1742, author]
Give me liberty or give...
[1742, body]gmason
gwashington
[1767, author]
I chopped down the...
[1767, body]
jadams
[1794, author]
A government of laws...
[1794, body]ahamilton
Timeline Table
Timeline Physical Layout
1735
1742
1767
1794
©2012 DataStax
Current Drivers Architecture
23
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
New Drivers Architecture
24
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
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
25
©2012 DataStax
Connect and Write
26
Cluster cluster = new Cluster.Builder() .addContactPoints("10.0.0.1", "10.0.0.2") .build();
Session session = cluster.connect("myKeyspace");
session.execute( "INSERT INTO user (user_id, name, email) VALUES (12345, 'johndoe', '[email protected]')");
©2012 DataStax
Read
27
ResultSet rs = session.execute("SELECT * FROM test");
List<Row> rows = rs.fetchAll(); for (Row row : rows) {
String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email");}
©2012 DataStax
Asynchronous Read
28
ResultSet.Future future = session.executeAsync("SELECT * FROM test");
for (Row row : future.get()) {
String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email");}
©2012 DataStax
Object Mapping
29
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;}
©2012 DataStax
Inheritance
30
@InheritanceValue("tv")public class TV extends Product {
private float size;}
@Table(name = "catalog")@Inheritance( subClasses = {Phone.class, TV.class}, column = "product_type")public abstract class Product {
@Column(name = "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!