ChtiJUG - Cassandra 2.0
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,498
On Slideshare
1,464
From Embeds
34
Number of Embeds
1

Actions

Shares
Downloads
23
Comments
0
Likes
2

Embeds 34

https://twitter.com 34

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Cassandra 2.0 Michaël Figuière @mfiguiere
  • 2. Speaker Michaël Figuière @mfiguiere ©2012 DataStax 2
  • 3. Ring Architecture Node Node Cassandra Node ©2012 DataStax Node Node Node 3
  • 4. Ring Architecture Node Replica Node Replica Node ©2012 DataStax Replica 4
  • 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 Client ©2012 DataStax Node Replica 6
  • 7. Client / Server Communication Client Node Replica Client Node Replica Client Client Node Replica Coordinator node: Forwards all R/W requests to corresponding replicas ©2012 DataStax 7
  • 8. Tunable Consistency Time A A A 3 replicas ©2012 DataStax 8
  • 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 to answer ©2012 DataStax Write and wait for acknowledge from one node 10
  • 11. Tunable Consistency Time R +W = N A A A B B A B B A Read waiting for one node to answer ©2012 DataStax Write and wait for acknowledges from two nodes 11
  • 12. Tunable Consistency Time R +W > N A A A B B A B B A Read waiting for two nodes to answer ©2012 DataStax Write and wait for acknowledges from two nodes 12
  • 13. Tunable Consistency R = W = QUORUM A A A B B A B B Time A QUORUM = (N / 2) + 1 ©2012 DataStax 13
  • 14. Request Path 1 Client Client Node 2 Replica 3 4 2 Node 3 Client Replica 2 Client Node 3 Replica Coordinator node ©2012 DataStax 14
  • 15. Multi-Datacenter Datacenter A Node 1 Node 1 Node 2 Node 2 Datacenter B Node 3 Node 6 Node 3 Node 4 Datacenter C Node 5 Node 4 Node 5 Node 6 ©2012 DataStax 15
  • 16. Storage Engine Memtable Commit Log ©2012 DataStax Memtable SSTable SSTable SSTable SSTable 16
  • 17. CQL Denormalized Model Cassandra comes with a Data Model abstraction made of denormalized, statically defined tables Data duplicated over several tables ©2012 DataStax 17
  • 18. Cassandra Data Model Timeline Table user_id tweet_id author 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 Key Clustering Key ©2012 DataStax body 18
  • 19. Cassandra 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 19
  • 20. Cassandra 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 gmason ahamilton ©2012 DataStax [1735, author] [1735, body] [1742, author] [1742, body] gwashington I chopped down the... phenry Give me liberty or give... [1767, author] [1767, body] [1794, author] [1794, body] gwashington I chopped down the... jadams A government of laws... 20
  • 21. Example: Video DB Application CREATE TABLE users ( username varchar, firstname varchar, lastname varchar, email list<varchar>, password varchar, created_date timestamp, PRIMARY KEY (username) ); ©2012 DataStax 21
  • 22. Example: Video DB Application CREATE TABLE videos ( videoid uuid, videoname varchar, username varchar, description varchar, location map<varchar,varchar>, tags set<varchar>, upload_date timestamp, PRIMARY KEY (videoid) ); ©2012 DataStax 22
  • 23. Example: Video DB Application CREATE TABLE comments_by_video ( videoid uuid, username varchar, comment_ts timeuuid, comment varchar, PRIMARY KEY (videoid,comment_ts,username) ) WITH CLUSTERING ORDER BY (comment_ts DESC, username ASC); ©2012 DataStax 23
  • 24. Example: Video DB Application CREATE TABLE comments_by_user ( username varchar, videoid uuid, comment_ts timeuuid, comment varchar, PRIMARY KEY (username,comment_ts,videoid) ) WITH CLUSTERING ORDER BY (comment_ts DESC, videoid ASC); ©2012 DataStax 24
  • 25. Example: Video DB Application CREATE TABLE video_rating ( videoid uuid, rating_counter counter, rating_total counter, PRIMARY KEY (videoid) ); ©2012 DataStax 25
  • 26. New Driver Architecture DB API CQL API OO API CQL Native Protocol Next Generation Driver ©2012 DataStax 26
  • 27. DataStax Java Driver • Reference Implementation • Asynchronous architecture based on Netty • Prepared Statements Support • Automatic Fail-over • Node Discovery • Cassandra Tracing Support • Tunable policies • • • ©2012 DataStax LoadBalancingPolicy ReconnectionPolicy RetryPolicy 27
  • 28. 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 28
  • 29. Read ResultSet rs = session.execute("SELECT * FROM test"); List<Row> rows = rs.all(); for (Row row : rows) { String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email"); } ©2012 DataStax 29
  • 30. Asynchronous Read ResultSetFuture 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 30
  • 31. Read with Callback final ResultSetFuture future = session.executeAsync("SELECT * FROM test"); future.addListener(new Runnable() { public run() { for (Row row : future.get()) { String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email"); } } }, executor); ©2012 DataStax 31
  • 32. Lightweight Transactions Session 1 SELECT * FROM users WHERE username = ’jbellis’ [empty resultset] INSERT INTO users (...) VALUES (’jbellis’, ...) ©2012 DataStax Session 2 SELECT * FROM users WHERE username = ’jbellis’ [empty resultset] INSERT INTO users (...) VALUES (’jbellis’, ...) 32
  • 33. Lightweight Transactions • Based on Paxos • Fault tolerant • Quorum based • 4 round trips vs. 1 for normal updates • State is durable ©2012 DataStax 33
  • 34. Lightweight Transactions INSERT INTO USERS (username, email, ...) VALUES (‘jbellis’, ‘jbellis@datastax.com’, ... ) IF NOT EXISTS; UPDATE USERS SET email = ’jonathan@datastax.com’, ... WHERE username = ’jbellis’ IF email = ’jbellis@datastax.com’; ©2012 DataStax 34
  • 35. Paging with Cassandra 1.2 CREATE TABLE timeline ( user_id uuid, tweet_id timeuuid, tweet_author uuid, tweet_body text, PRIMARY KEY (user_id, tweet_id) ); ©2012 DataStax SELECT * FROM timeline WHERE (user_id = :last_key AND tweet_id > :last_tweet) OR token(user_id) > token(:last_key) LIMIT 100 35
  • 36. Automatic Paging 1st Request Node Query Client Page 1 + Paging State 1 Node Replica Node ©2012 DataStax Replica Replica 36
  • 37. Automatic Paging 2nd Request Node Replica Query + Paging State 1 Node Client Replica Page 2 + Paging State 2 Node ©2012 DataStax Replica 37
  • 38. Stay Tuned! blog.datastax.com @mfiguiere