Más contenido relacionado Más de Michaël Figuière (19) ApacheCon NA 2013 - The New Face of Apache Cassandra2. Speaker
Michaël Figuière
@mfiguiere
©2012 DataStax 2
5. Linear Scalability
Client Writes/s by Node Count - Replication Factor = 3
©2012 DataStax 5
6. Client / Server Communication
Client ? Node Replica
Client
Node
Replica
Client
Node
Client Replica
©2012 DataStax 6
7. Client / Server Communication
Client Node Replica
Client
Node
Replica
Client
Node
Client Replica
Coordinator node:
Forwards all R/W requests
to corresponding replicas
©2012 DataStax 7
9. Tunable Consistency
Time
A A A
B A A
Write ‘B’
Write and wait for
acknowledge from one node
©2012 DataStax 9
10. Tunable Consistency
Time
R +W < N
A A A
B A A
B A A
Read waiting for one node Write and wait for
to answer acknowledge from one node
©2012 DataStax 10
11. Tunable Consistency
Time
R +W = N
A A A
B B A
B B A
Read waiting for one node Write and wait for
to answer acknowledges from two nodes
©2012 DataStax 11
12. Tunable Consistency
Time
R +W > N
A A A
B B A
B B A
Read waiting for two nodes Write and wait for
to answer acknowledges from two nodes
©2012 DataStax 12
13. Tunable Consistency
Time
R = W = QUORUM
A A A
B B A
B B A
QUORUM = (N / 2) + 1
©2012 DataStax 13
14. Request Path
1
Client Node Replica
2
3
Client
4 2
Node
Replica
3
Client
2
3
Node
Client Replica
Coordinator node
©2012 DataStax 14
15. Multi-Datacenter
Datacenter A
Node 1
Node Node Node 2
1 2
Datacenter B
Node 3
Node
6 Node
3 Node 4
Datacenter C
Node
Node
5 Node 5
4
Node 6
©2012 DataStax 15
16. Column Family Data Model
address email name state
jbellis
123 main jb@ds.com Jonathan TX
address email name state
dhutch
45 2nd st dh@ds.com Daria CA
email name
egilmore
eg@ds.com Eric
Row Key Columns = List of K/V pairs sorted by Key
©2012 DataStax 16
17. Column Family Data Model
datastax dhutch egilmore mzcassie
jbellis
egilmore
dhutch
datastax mzcassie
egilmore
Row Key Columns = List of K/V pairs sorted by Key
©2012 DataStax 17
18. Storage Engine
Memtable Memtable
Commit
SSTable
Log SSTable SSTable
SSTable
©2012 DataStax 18
19. CQL3 Denormalized Model
CQL3 Query Language comes with a new Data Model abstraction made of
denormalized, statically defined tables
Data duplicated over several tables
©2012 DataStax 19
20. CQL3 Data Model
Timeline Table
user_id tweet_id author body
gmason 1735 phenry Give me liberty or give me death
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
Partition Clustering
Key Key
©2012 DataStax 20
21. CQL3 Data Model
Timeline Table
user_id tweet_id author body
gmason 1735 phenry Give me liberty or give me death
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
CQL
CREATE TABLE timeline (
user_id varchar,
tweet_id timeuuid,
author varchar,
body varchar,
PRIMARY KEY (user_id, tweet_id));
©2012 DataStax 21
22. CQL3 Data Model
Timeline Table
user_id tweet_id author body
gmason 1735 phenry Give me liberty or give me death
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 Physical Layout
[1735, author] [1735, body] [1742, author] [1742, body]
gmason
gwashington I chopped down the... phenry Give me liberty or give...
[1767, author] [1767, body] [1794, author] [1794, body]
ahamilton
gwashington I chopped down the... jadams A government of laws...
©2012 DataStax 22
23. 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 23
24. 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 24
25. 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
•
©2012 DataStax
RetryPolicy
25
26. Connect and Write
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', 'john@doe.com')"
);
©2012 DataStax 26
27. Read
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 27
28. Asynchronous Read
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 28
29. Object Mapping
@Table(name = "user")
public class User { public enum Gender {
@PartitionKey @EnumValue("m")
@Column(name = "user_id") MALE,
private String userId;
@EnumValue("f")
private String name; FEMALE;
}
private String email;
private Gender gender;
}
©2012 DataStax 29
30. Inheritance
@Table(name = "catalog")
@Inheritance(
@InheritanceValue("tv")
subClasses = {Phone.class, TV.class},
public class TV
column = "product_type"
extends Product {
)
public abstract class Product {
private float size;
}
@Column(name = "product_id")
private String productId;
private float price;
private String vendor;
private String model;
}
©2012 DataStax 30