CASSANDRA COMMUNITY WEBINARS APRIL 2013INTRODUCTION TOAPACHE CASSANDRA 1.2Aaron MortonApache Cassandra Committer, Data Sta...
Cassandra Summit 2013June 11 & 12San FranciscoUse SFSummit25 for 25% off
Cassandra Summit 2013DataStax Ac*ademyFree certification during thesummit.
OverviewThe ClusterThe NodeThe Data Model
Cassandra- Started at Facebook- Open sourced in 2008- Top Level Apache projectsince 2010.
Used by...Netflix,Twitter, Reddit,Rackspace...
Inspiration- Google Big Table (2006)- Amazon Dynamo (2007)
Why Cassandra?- Scale- Operations- Data Model
OverviewThe ClusterThe NodeThe Data Model
Store ‘foo’ key with Replication Factor 3.Node 1 - fooNode 2 - fooNode 4Node 3 - foo
Consistent Hashing.- Evenly map keys to nodes- Minimise key movementswhen nodes join or leave
Partitioner.RandomPartitionertransforms Keys to Tokensusing MD5.(Default pre version 1.2.)
Partitioner.Murmur3Partitionertransforms Keys to Tokensusing Murmur3.(Default in version 1.2.)
Keys andTokens?token 0 99key fop foo10 90
Token Ring.footoken: 90foptoken: 1099 0
Token Ranges pre v1.2.Node 1token: 0Node 2token: 25Node 4token: 75Node 3token: 501-2576-0
Token Ranges withVirtual Nodes in v1.2.Node 1Node 2Node 3Node 4
LocateToken Range.Node 1Node 2Node 3Node 4footoken: 90
Replication Strategy selectsReplication Factor number ofnodes for a row.
SimpleStrategy with RF 3.Node 1Node 2Node 3Node 4footoken: 90
NetworkTopologyStrategy usesa Replication Factor per DataCentre.(Default.)
Multi DC Replication with RF 3 and RF 2.Node 1Node 2Node 3Node 4footoken: 90Node 1Node 2Node 3Node 4West DC East DC
The Snitch knows which DataCentre and Rack the Node isin.
SimpleSnitch.Places all nodes in the sameDC and Rack.(Default, there are others.)
EC2Snitch.DC is set to AWS Region anda Rack to Availability Zone.
The Client and the Coordinator.Node 1Node 2Node 3Node 4footoken: 90Client
Multi DC Client and the Coordinator.Node 1Node 2Node 3Node 4footoken: 90ClientNode 10Node 20Node 30Node 40
Gossip.Nodes share information witha small number of neighbours.Who share information with asmall number of neigh..
Consistency Level (CL).- Specified for each request- Number of nodes to waitfor.
Consistency Level (CL)- Any*- One,Two Three- QUORUM- LOCAL_QUORUM, EACH_QUOURM*
QUOURM at Replication Factor...ReplicationFactorQUOURM2 or 3 4 or 5 6 or 72 3 4
Write ‘foo’ at QUOURM with Hinted Handoff.Node 1Node 2Node 3Node 4foo for #3footoken: 90Client
Read ‘foo’ at QUOURM.Node 1Node 2Node 3Node 4footoken: 90Client
Column Timestampsused to resolvedifferences.
Resolving differences.Column Node 1 Node 2 Node 3purplecromulent(timestamp 10)cromulent(timestamp 10)<missing>monkeyembigg...
Consistent read for ‘foo’ at QUOURM.Node 1Node 2Node 3Node 4Clientcromulentcromulent<empty>Node 1Node 2Node 3Node 4Clientc...
Strong ConsistencyW + R > N(#Write Nodes + #Read Nodes> Replication Factor)
Achieving Strong Consistency.- QUOURM Read + QUORUM Write- ALL Read + ONE Write- ONE Read + ALL Write
Achieving Consistency- Consistency Level- Hinted Handoff- Read Repair- Anti Entropy
OverviewThe ClusterThe NodeThe Data Model
Optimised forWrites.
Write pathAppend to WriteAhead Log.(fsync every 10s by default, other options available)
Write path...Merge Columnsinto Memtable.(Lock free, always in memory.)
(Later.)Asynchronously flushMemtable to new files.(May be 10’s or 100’s of MB in size.)
Data is stored inimmutable SSTables.(Sorted String table.)
SSTable files.*-Data.db*-Index.db*-Filter.db(And others)
SSTables.SSTable 1foo:dishwasher (ts 10):tomatopurple (ts 10):cromulentSSTable 2foo:frink (ts 20):flayvenmonkey (ts 10):emb...
Read purple, monkey, dishwasher.SSTable 1-Data.dbfoo:dishwasher (ts 10):tomatopurple (ts 10):cromulentSSTable 2-Data.dbfoo...
Key Cache caches row keyposition in *-Data.db file.(Removes up to1disk seek per SSTable.)
Read with Key Cache.SSTable 1-Data.dbfoo:dishwasher (ts 10):tomatopurple (ts 10):cromulentSSTable 2-Data.dbfoo:frink (ts 2...
Row Cache caches entire row.(Removes all disk IO.)
Read with Row Cache.Row CacheSSTable 1-Data.dbfoo:dishwasher (ts 10):tomatopurple (ts 10):cromulentSSTable 2-Data.dbfoo:fr...
Compaction merges truth frommultiple SSTables into oneSSTable with the same truth.(Manual and continuous background proces...
Compaction.Column SSTable 1 SSTable 2 SSTable 4 Newpurplecromulent(timestamp 10)<tombstone>(timestamp 15)<tombstone>(times...
OverviewThe ClusterThe NodeThe Data Model
Cassandra is good atreading data from a row in theorder it is stored.
Typically an efficient data model willdenormalize data and use thestorage engine order.
To create a good data modelunderstand the queries yourapplication requires.
API ChoiceThriftOriginal and still fullysupported API.
API ChoiceCQL3New and fully supported API.
CQL 3A Table Orientated, SchemaDriven, Data Model andQuery language similar toSQL.
CQL 3A Table Orientated, SchemaDriven, Data Model andQuery language similar toSQL.
Twitter cloneusing CQL 3 via the cqlshtool.bin/cqlsh
Queries?- Post Tweet to Followers- Get Tweet by ID- List Tweets by User- List Tweets in User Timeline- List Followers
KeyspaceA Namespace container.
Our KeyspaceCREATE KEYSPACEcass_communityWITH replication ={class:NetworkTopologyStrategy,datacenter1:1};
TableA sparse collection of wellknown, ordered columns.
FirstTableCREATE TABLE User(user_name text,password text,real_name text,PRIMARY KEY (user_name));
Some userscqlsh:cass_community> INSERT INTO User... (user_name, password, real_name)... VALUES... (fred, sekr8t, Mr Foo);c...
Some userscqlsh:cass_community> INSERT INTO User... (user_name, password)... VALUES... (bob, pwd);cqlsh:cass_community> se...
Data Model (so far)Table /ValueUseruser_name Primary Key
TweetTableCREATE TABLE Tweet(tweet_id bigint,body text,user_name text,timestamp timestamp,PRIMARY KEY (tweet_id));
TweetTable...cqlsh:cass_community> INSERT INTO Tweet... (tweet_id, body, user_name, timestamp)... VALUES... (1, The Tweet,...
Data Model (so far)Table /ValueUser Tweetuser_name Primary Key Fieldtweet_id Primary Key
UserTweetsTableCREATE TABLE UserTweets(tweet_id bigint,user_name text,body text,timestamp timestamp,PRIMARY KEY (user_name...
UserTweetsTable...cqlsh:cass_community> INSERT INTO UserTweets... (tweet_id, body, user_name, timestamp)... VALUES... (1, ...
UserTweetsTable...cqlsh:cass_community> select * from UserTweets whereuser_name=fred and tweet_id=1;user_name | tweet_id |...
UserTweetsTable...cqlsh:cass_community> INSERT INTO UserTweets... (tweet_id, body, user_name, timestamp)... VALUES... (2, ...
UserTweetsTable...cqlsh:cass_community> select * from UserTweets where user_name = fred order bytweet_id desc;user_name | ...
UserTimelineCREATE TABLE UserTimeline(user_name text,tweet_id bigint,tweet_user text,body text,timestamp timestamp,PRIMARY...
UserTimelinecqlsh:cass_community> INSERT INTO UserTimeline... (user_name, tweet_id, tweet_user, body, timestamp)... VALUES...
UserTimelinecqlsh:cass_community> select * from UserTimeline where user_name = fred;user_name | tweet_id | body | timestam...
Data Model (so far)Table /ValueUser TweetUserTweetsUserTimelineuser_name Primary Key Field Primary Key Primary Keytweet_id...
UserMetricsTableCREATE TABLE UserMetrics(user_name text,tweets counter,followers counter,following counter,PRIMARY KEY (us...
UserMetricsTable...cqlsh:cass_community> UPDATE... UserMetrics... SET... tweets = tweets + 1... WHERE... user_name = fred;...
Data Model (so far)Table /ValueUser TweetUserTweetsUserTimelineUser Metricsuser_namePrimaryKeyFieldPrimaryKeyPrimaryKeyPri...
RelationshipsCREATE TABLE Followers(user_name text,follower text,timestamp timestamp,PRIMARY KEY (user_name, follower));CR...
Relationshipscqlsh:cass_community> INSERT INTO... Following... (user_name, following, timestamp)... VALUES... (bob, fred, ...
Relationshipscqlsh:cass_community> select * from Following;user_name | following | timestamp-----------+-----------+------...
Data ModelTable /ValueUser TweetUserTweetsUserTimelineUserMetricsFollowsFollowersuser_namePrimaryKeyFieldPrimaryKeyPrimary...
Cassandra Summit 2013June 11 & 12San FranciscoUse SFSummit25 for 25% off
Thanks.
Aaron Morton@aaronmortonwww.thelastpickle.comLicensed under a Creative Commons Attribution-NonCommercial 3.0 New Zealand L...
Upcoming SlideShare
Loading in...5
×

Cassandra Community Webinar | Introduction to Apache Cassandra 1.2

1,859

Published on

Title: Introduction to Apache Cassandra 1.2

Details: Join Aaron Morton, DataStax MVP for Apache Cassandra and learn the basics of the massively scalable NoSQL database. This webinar is will examine C*’s architecture and its strengths for powering mission-critical applications. Aaron will introduce you to core concepts such as Cassandra’s data model, multi-datacenter replication, and tunable consistency. He’ll also cover new features in Cassandra version 1.2 including virtual nodes, CQL 3 language and query tracing.

Speaker: Aaron Morton, Apache Cassandra Committer

Aaron Morton is a Freelance Developer based in New Zealand, and a Committer on the Apache Cassandra project. In 2010, he gave up the RDBMS world for the scale and reliability of Cassandra. He now spends his time advancing the Cassandra project and helping others get the best out of it.

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,859
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

Cassandra Community Webinar | Introduction to Apache Cassandra 1.2

  1. 1. CASSANDRA COMMUNITY WEBINARS APRIL 2013INTRODUCTION TOAPACHE CASSANDRA 1.2Aaron MortonApache Cassandra Committer, Data Stax MVP for Apache Cassandra@aaronmortonwww.thelastpickle.comLicensed under a Creative Commons Attribution-NonCommercial 3.0 New Zealand License
  2. 2. Cassandra Summit 2013June 11 & 12San FranciscoUse SFSummit25 for 25% off
  3. 3. Cassandra Summit 2013DataStax Ac*ademyFree certification during thesummit.
  4. 4. OverviewThe ClusterThe NodeThe Data Model
  5. 5. Cassandra- Started at Facebook- Open sourced in 2008- Top Level Apache projectsince 2010.
  6. 6. Used by...Netflix,Twitter, Reddit,Rackspace...
  7. 7. Inspiration- Google Big Table (2006)- Amazon Dynamo (2007)
  8. 8. Why Cassandra?- Scale- Operations- Data Model
  9. 9. OverviewThe ClusterThe NodeThe Data Model
  10. 10. Store ‘foo’ key with Replication Factor 3.Node 1 - fooNode 2 - fooNode 4Node 3 - foo
  11. 11. Consistent Hashing.- Evenly map keys to nodes- Minimise key movementswhen nodes join or leave
  12. 12. Partitioner.RandomPartitionertransforms Keys to Tokensusing MD5.(Default pre version 1.2.)
  13. 13. Partitioner.Murmur3Partitionertransforms Keys to Tokensusing Murmur3.(Default in version 1.2.)
  14. 14. Keys andTokens?token 0 99key fop foo10 90
  15. 15. Token Ring.footoken: 90foptoken: 1099 0
  16. 16. Token Ranges pre v1.2.Node 1token: 0Node 2token: 25Node 4token: 75Node 3token: 501-2576-0
  17. 17. Token Ranges withVirtual Nodes in v1.2.Node 1Node 2Node 3Node 4
  18. 18. LocateToken Range.Node 1Node 2Node 3Node 4footoken: 90
  19. 19. Replication Strategy selectsReplication Factor number ofnodes for a row.
  20. 20. SimpleStrategy with RF 3.Node 1Node 2Node 3Node 4footoken: 90
  21. 21. NetworkTopologyStrategy usesa Replication Factor per DataCentre.(Default.)
  22. 22. Multi DC Replication with RF 3 and RF 2.Node 1Node 2Node 3Node 4footoken: 90Node 1Node 2Node 3Node 4West DC East DC
  23. 23. The Snitch knows which DataCentre and Rack the Node isin.
  24. 24. SimpleSnitch.Places all nodes in the sameDC and Rack.(Default, there are others.)
  25. 25. EC2Snitch.DC is set to AWS Region anda Rack to Availability Zone.
  26. 26. The Client and the Coordinator.Node 1Node 2Node 3Node 4footoken: 90Client
  27. 27. Multi DC Client and the Coordinator.Node 1Node 2Node 3Node 4footoken: 90ClientNode 10Node 20Node 30Node 40
  28. 28. Gossip.Nodes share information witha small number of neighbours.Who share information with asmall number of neigh..
  29. 29. Consistency Level (CL).- Specified for each request- Number of nodes to waitfor.
  30. 30. Consistency Level (CL)- Any*- One,Two Three- QUORUM- LOCAL_QUORUM, EACH_QUOURM*
  31. 31. QUOURM at Replication Factor...ReplicationFactorQUOURM2 or 3 4 or 5 6 or 72 3 4
  32. 32. Write ‘foo’ at QUOURM with Hinted Handoff.Node 1Node 2Node 3Node 4foo for #3footoken: 90Client
  33. 33. Read ‘foo’ at QUOURM.Node 1Node 2Node 3Node 4footoken: 90Client
  34. 34. Column Timestampsused to resolvedifferences.
  35. 35. Resolving differences.Column Node 1 Node 2 Node 3purplecromulent(timestamp 10)cromulent(timestamp 10)<missing>monkeyembiggens(timestamp 10)embiggens(timestamp 10)debigulator(timestamp 5)dishwashertomato(timestamp 10)tomato(timestamp 10)tomacco(timestamp 15)
  36. 36. Consistent read for ‘foo’ at QUOURM.Node 1Node 2Node 3Node 4Clientcromulentcromulent<empty>Node 1Node 2Node 3Node 4Clientcromulent cromulent
  37. 37. Strong ConsistencyW + R > N(#Write Nodes + #Read Nodes> Replication Factor)
  38. 38. Achieving Strong Consistency.- QUOURM Read + QUORUM Write- ALL Read + ONE Write- ONE Read + ALL Write
  39. 39. Achieving Consistency- Consistency Level- Hinted Handoff- Read Repair- Anti Entropy
  40. 40. OverviewThe ClusterThe NodeThe Data Model
  41. 41. Optimised forWrites.
  42. 42. Write pathAppend to WriteAhead Log.(fsync every 10s by default, other options available)
  43. 43. Write path...Merge Columnsinto Memtable.(Lock free, always in memory.)
  44. 44. (Later.)Asynchronously flushMemtable to new files.(May be 10’s or 100’s of MB in size.)
  45. 45. Data is stored inimmutable SSTables.(Sorted String table.)
  46. 46. SSTable files.*-Data.db*-Index.db*-Filter.db(And others)
  47. 47. SSTables.SSTable 1foo:dishwasher (ts 10):tomatopurple (ts 10):cromulentSSTable 2foo:frink (ts 20):flayvenmonkey (ts 10):embigginsSSTable 3 SSTable 4foo:dishwasher (ts 15):tomaccoSSTable 5
  48. 48. Read purple, monkey, dishwasher.SSTable 1-Data.dbfoo:dishwasher (ts 10):tomatopurple (ts 10):cromulentSSTable 2-Data.dbfoo:frink (ts 20):flayvenmonkey (ts 10):embigginsSSTable 3-Data.db SSTable 4-Data.dbfoo:dishwasher (ts 15):tomaccoSSTable 5-Data.dbBloom FilterIndex SampleSSTable 1-Index.dbBloom FilterIndex SampleSSTable 2-Index.dbBloom FilterIndex SampleSSTable 3-Index.dbBloom FilterIndex SampleSSTable 4-Index.dbBloom FilterIndex SampleSSTable 5-Index.dbMemoryDisk
  49. 49. Key Cache caches row keyposition in *-Data.db file.(Removes up to1disk seek per SSTable.)
  50. 50. Read with Key Cache.SSTable 1-Data.dbfoo:dishwasher (ts 10):tomatopurple (ts 10):cromulentSSTable 2-Data.dbfoo:frink (ts 20):flayvenmonkey (ts 10):embigginsSSTable 3-Data.db SSTable 4-Data.dbfoo:dishwasher (ts 15):tomaccoSSTable 5-Data.dbKey CacheIndex SampleSSTable 1-Index.dbKey CacheIndex SampleSSTable 2-Index.dbKey CacheIndex SampleSSTable 3-Index.dbKey CacheIndex SampleSSTable 4-Index.dbKey CacheIndex SampleSSTable 5-Index.dbMemoryDiskBloom Filter Bloom Filter Bloom Filter Bloom Filter Bloom Filter
  51. 51. Row Cache caches entire row.(Removes all disk IO.)
  52. 52. Read with Row Cache.Row CacheSSTable 1-Data.dbfoo:dishwasher (ts 10):tomatopurple (ts 10):cromulentSSTable 2-Data.dbfoo:frink (ts 20):flayvenmonkey (ts 10):embigginsSSTable 3-Data.db SSTable 4-Data.dbfoo:dishwasher (ts 15):tomaccoSSTable 5-Data.dbKey CacheIndex SampleSSTable 1-Index.dbKey CacheIndex SampleSSTable 2-Index.dbKey CacheIndex SampleSSTable 3-Index.dbKey CacheIndex SampleSSTable 4-Index.dbKey CacheIndex SampleSSTable 5-Index.dbMemoryDiskBloom Filter Bloom Filter Bloom Filter Bloom Filter Bloom Filter
  53. 53. Compaction merges truth frommultiple SSTables into oneSSTable with the same truth.(Manual and continuous background process.)
  54. 54. Compaction.Column SSTable 1 SSTable 2 SSTable 4 Newpurplecromulent(timestamp 10)<tombstone>(timestamp 15)<tombstone>(timestamp 15)monkeyembiggens(timestamp 10)embiggens(timestamp 10)dishwashertomato(timestamp 10)tomacco(timestamp 15)tomacco(timestamp 15)
  55. 55. OverviewThe ClusterThe NodeThe Data Model
  56. 56. Cassandra is good atreading data from a row in theorder it is stored.
  57. 57. Typically an efficient data model willdenormalize data and use thestorage engine order.
  58. 58. To create a good data modelunderstand the queries yourapplication requires.
  59. 59. API ChoiceThriftOriginal and still fullysupported API.
  60. 60. API ChoiceCQL3New and fully supported API.
  61. 61. CQL 3A Table Orientated, SchemaDriven, Data Model andQuery language similar toSQL.
  62. 62. CQL 3A Table Orientated, SchemaDriven, Data Model andQuery language similar toSQL.
  63. 63. Twitter cloneusing CQL 3 via the cqlshtool.bin/cqlsh
  64. 64. Queries?- Post Tweet to Followers- Get Tweet by ID- List Tweets by User- List Tweets in User Timeline- List Followers
  65. 65. KeyspaceA Namespace container.
  66. 66. Our KeyspaceCREATE KEYSPACEcass_communityWITH replication ={class:NetworkTopologyStrategy,datacenter1:1};
  67. 67. TableA sparse collection of wellknown, ordered columns.
  68. 68. FirstTableCREATE TABLE User(user_name text,password text,real_name text,PRIMARY KEY (user_name));
  69. 69. Some userscqlsh:cass_community> INSERT INTO User... (user_name, password, real_name)... VALUES... (fred, sekr8t, Mr Foo);cqlsh:cass_community> select * from User;user_name | password | real_name-----------+----------+-----------fred | sekr8t | Mr Foo
  70. 70. Some userscqlsh:cass_community> INSERT INTO User... (user_name, password)... VALUES... (bob, pwd);cqlsh:cass_community> select * from User where user_name =bob;user_name | password | real_name-----------+----------+-----------bob | pwd | null
  71. 71. Data Model (so far)Table /ValueUseruser_name Primary Key
  72. 72. TweetTableCREATE TABLE Tweet(tweet_id bigint,body text,user_name text,timestamp timestamp,PRIMARY KEY (tweet_id));
  73. 73. TweetTable...cqlsh:cass_community> INSERT INTO Tweet... (tweet_id, body, user_name, timestamp)... VALUES... (1, The Tweet,fred,1352150816917);cqlsh:cass_community> select * from Tweet where tweet_id = 1;tweet_id | body | timestamp | user_name----------+-----------+--------------------------+-----------1 | The Tweet | 2012-11-06 10:26:56+1300 | fred
  74. 74. Data Model (so far)Table /ValueUser Tweetuser_name Primary Key Fieldtweet_id Primary Key
  75. 75. UserTweetsTableCREATE TABLE UserTweets(tweet_id bigint,user_name text,body text,timestamp timestamp,PRIMARY KEY (user_name, tweet_id));
  76. 76. UserTweetsTable...cqlsh:cass_community> INSERT INTO UserTweets... (tweet_id, body, user_name, timestamp)... VALUES... (1, The Tweet,fred,1352150816917);cqlsh:cass_community> select * from UserTweets whereuser_name=fred;user_name | tweet_id | body | timestamp-----------+----------+-----------+--------------------------fred | 1 | The Tweet | 2012-11-06 10:26:56+1300
  77. 77. UserTweetsTable...cqlsh:cass_community> select * from UserTweets whereuser_name=fred and tweet_id=1;user_name | tweet_id | body | timestamp-----------+----------+-----------+--------------------------fred | 1 | The Tweet | 2012-11-06 10:26:56+1300
  78. 78. UserTweetsTable...cqlsh:cass_community> INSERT INTO UserTweets... (tweet_id, body, user_name, timestamp)... VALUES... (2, Second Tweet, fred, 1352150816918);cqlsh:cass_community> select * from UserTweets where user_name = fred;user_name | tweet_id | body | timestamp-----------+----------+--------------+--------------------------fred | 1 | The Tweet | 2012-11-06 10:26:56+1300fred | 2 | Second Tweet | 2012-11-06 10:26:56+1300
  79. 79. UserTweetsTable...cqlsh:cass_community> select * from UserTweets where user_name = fred order bytweet_id desc;user_name | tweet_id | body | timestamp-----------+----------+--------------+--------------------------fred | 2 | Second Tweet | 2012-11-06 10:26:56+1300fred | 1 | The Tweet | 2012-11-06 10:26:56+1300
  80. 80. UserTimelineCREATE TABLE UserTimeline(user_name text,tweet_id bigint,tweet_user text,body text,timestamp timestamp,PRIMARY KEY (user_name, tweet_id))WITH CLUSTERING ORDER BY (tweet_id DESC);
  81. 81. UserTimelinecqlsh:cass_community> INSERT INTO UserTimeline... (user_name, tweet_id, tweet_user, body, timestamp)... VALUES... (fred, 1, fred, The Tweet,1352150816917);cqlsh:cass_community> INSERT INTO UserTimeline... (user_name, tweet_id, tweet_user, body, timestamp)... VALUES... (fred, 100, bob, My Tweet,1352150846917);
  82. 82. UserTimelinecqlsh:cass_community> select * from UserTimeline where user_name = fred;user_name | tweet_id | body | timestamp | tweet_user-----------+----------+-----------+--------------------------+------------fred | 100 | My Tweet | 2012-11-06 10:27:26+1300 | bobfred | 1 | The Tweet | 2012-11-06 10:26:56+1300 | fred
  83. 83. Data Model (so far)Table /ValueUser TweetUserTweetsUserTimelineuser_name Primary Key Field Primary Key Primary Keytweet_id Primary KeyPrimary KeyComponentPrimary KeyComponent
  84. 84. UserMetricsTableCREATE TABLE UserMetrics(user_name text,tweets counter,followers counter,following counter,PRIMARY KEY (user_name));
  85. 85. UserMetricsTable...cqlsh:cass_community> UPDATE... UserMetrics... SET... tweets = tweets + 1... WHERE... user_name = fred;cqlsh:cass_community> select * from UserMetrics whereuser_name = fred;user_name | followers | following | tweets-----------+-----------+-----------+--------fred | null | null | 1
  86. 86. Data Model (so far)Table /ValueUser TweetUserTweetsUserTimelineUser Metricsuser_namePrimaryKeyFieldPrimaryKeyPrimaryKeyPrimaryKeytweet_idPrimaryKeyPrimary KeyComponentPrimary KeyComponent
  87. 87. RelationshipsCREATE TABLE Followers(user_name text,follower text,timestamp timestamp,PRIMARY KEY (user_name, follower));CREATE TABLE Following(user_name text,following text,timestamp timestamp,PRIMARY KEY (user_name, following));
  88. 88. Relationshipscqlsh:cass_community> INSERT INTO... Following... (user_name, following, timestamp)... VALUES... (bob, fred, 1352247749161);cqlsh:cass_community> INSERT INTO... Followers... (user_name, follower, timestamp)... VALUES... (fred, bob, 1352247749161);
  89. 89. Relationshipscqlsh:cass_community> select * from Following;user_name | following | timestamp-----------+-----------+--------------------------bob | fred | 2012-11-07 13:22:29+1300cqlsh:cass_community> select * from Followers;user_name | follower | timestamp-----------+----------+--------------------------fred | bob | 2012-11-07 13:22:29+1300
  90. 90. Data ModelTable /ValueUser TweetUserTweetsUserTimelineUserMetricsFollowsFollowersuser_namePrimaryKeyFieldPrimaryKeyPrimaryKeyPrimaryKeyPrimaryKeytweet_idPrimaryKeyPrimary KeyComponentPrimary KeyComponent
  91. 91. Cassandra Summit 2013June 11 & 12San FranciscoUse SFSummit25 for 25% off
  92. 92. Thanks.
  93. 93. Aaron Morton@aaronmortonwww.thelastpickle.comLicensed under a Creative Commons Attribution-NonCommercial 3.0 New Zealand License

×