Cassandra   A short Intro                   Vitaly Kushner                    astrails.com
• Distributed• Non-relational• Linearly scalable• Multi data-center aware
BigTablehttp://labs.google.com/papers/bigtable.html
Terminology Sucks      big time
my_cluster: {  demo_app: {    accounts: {       "1": {         "attributes": {            "name": "astrails"         },   ...
my_cluster: {	 	 	 	 	 	 	 	              <<= Cluster Name  demo_app: {    accounts: {       "1": {         "attributes": ...
my_cluster: {  demo_app: {	 	 	 	 	 	 	 	              <== Keyspace    accounts: {       "1": {         "attributes": {   ...
my_cluster: {  demo_app: {    accounts: {	 	 	 	 	 	 	              <<= super column family       "1": {         "attribut...
my_cluster: {  demo_app: {    accounts: {       "1": {         "attributes": {            "name": "astrails"         },   ...
my_cluster: {  demo_app: {    accounts: {       "1": {	 	 	 	 	 	 	 	              <<= key         "attributes": {        ...
my_cluster: {  demo_app: {    accounts: {       "1": {         "attributes": {	 	 	 	 	         << super column           ...
my_cluster: {  demo_app: {    accounts: {       "1": {         "attributes": {            "name": "astrails"	 	 	       <<...
my_cluster: {  demo_app: {    accounts: {       "1": {         "attributes": {            "name": "astrails"	 	 	       <<...
my_cluster: {  demo_app: {    accounts: {       "1": {         "attributes": {            "name": "astrails"         },   ...
my_cluster: {	 	 	 	 	 	 	 	              <<=   cluster  demo_app: {	 	 	 	 	 	 	 	              <<=   keyspace    account...
my_cluster: {	 	 	 	 	 	 	 	              <<=   cluster  demo_app: {	 	 	 	 	 	 	 	              <<=   database    account...
my_cluster: {	 	 	 	 	 	 	 	              <<=   cluster  demo_app: {	 	 	 	 	 	 	 	              <<=   database    account...
my_cluster: {	 	 	 	 	 	 	 	              <<=   cluster  demo_app: {	 	 	 	 	 	 	 	              <<=   database    account...
my_cluster: {	 	 	 	 	 	 	 	              <<=   cluster  demo_app: {	 	 	 	 	 	 	 	              <<=   database    account...
my_cluster: {	 	 	 	 	 	 	 	              <<=   cluster  demo_app: {	 	 	 	 	 	 	 	              <<=   database    account...
Indexing
"my_cluster": {  "demo_app": {    "users": {       "b2c75e99-e079-449d-b562-293dfdbf006e": {         "attributes": {      ...
"my_cluster": {  "demo_app": {    "users": {       "b2c75e99-e079-449d-b562-293dfdbf006e": {         "attributes": {      ...
"my_cluster": {  "demo_app": {    "users": {       "b2c75e99-e079-449d-b562-293dfdbf006e": {         "attributes": {      ...
"my_cluster": {  "demo_app": {    "users": {       "b2c75e99-e079-449d-b562-293dfdbf006e": {         "attributes": {      ...
"my_cluster": {  "demo_app": {    "users": {       "b2c75e99-e079-449d-b562-293dfdbf006e": {         "attributes": {      ...
"my_cluster": {  "demo_app": {    "users": {       "b2c75e99-e079-449d-b562-293dfdbf006e": {         "attributes": {      ...
Playtime
> gem install cassandra...> cassandra_helper cassandra...
<ClusterName>my_cluster</ClusterName><Keyspaces>  <Keyspace Name="demo_app">    <ColumnFamily CompareWith="UTF8Type" Name=...
require rubygemsrequire cassandrainclude Cassandra::Constantsclient = Cassandra.new(demo_app)client.insert(:users, "1", {"...
Rails?
YES!
SmallRecordWARNING: waporware :)
http://github.com/astrails/small_record
ActiveModel
class Account < SmallRecord::Base  attribute :name  attribute :created_at, :type => :datetime  has_many :users  validates_...
production: adapter: cassandra host: 127.0.0.1 port: 9160 keyspace: chronosdevelopment: adapter: mocktest: adapter: mock
production: adapter: cassandra host: 127.0.0.1 port: 9160 keyspace: chronosdevelopment: adapter: mocktest: adapter: mock
Some Links•   http://incubator.apache.org/cassandra•   http://labs.google.com/papers/bigtable.html•   http://blog.evanweav...
Upcoming SlideShare
Loading in...5
×

Cassandra intro

221

Published on

A short introduction to Cassandra, as in NoSQL DB. At least the state it was in back in 2010. By Vitaly Kushner.

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

  • Be the first to like this

No Downloads
Views
Total Views
221
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cassandra intro

  1. 1. Cassandra A short Intro Vitaly Kushner astrails.com
  2. 2. • Distributed• Non-relational• Linearly scalable• Multi data-center aware
  3. 3. BigTablehttp://labs.google.com/papers/bigtable.html
  4. 4. Terminology Sucks big time
  5. 5. my_cluster: { demo_app: { accounts: { "1": { "attributes": { "name": "astrails" }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  6. 6. my_cluster: { <<= Cluster Name demo_app: { accounts: { "1": { "attributes": { "name": "astrails" }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  7. 7. my_cluster: { demo_app: { <== Keyspace accounts: { "1": { "attributes": { "name": "astrails" }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  8. 8. my_cluster: { demo_app: { accounts: { <<= super column family "1": { "attributes": { "name": "astrails" }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  9. 9. my_cluster: { demo_app: { accounts: { "1": { "attributes": { "name": "astrails" }, "users": { "1" => "", "3" => "", } } }, users: { <<= column family "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  10. 10. my_cluster: { demo_app: { accounts: { "1": { <<= key "attributes": { "name": "astrails" }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  11. 11. my_cluster: { demo_app: { accounts: { "1": { "attributes": { << super column "name": "astrails" }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  12. 12. my_cluster: { demo_app: { accounts: { "1": { "attributes": { "name": "astrails" <<= column }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  13. 13. my_cluster: { demo_app: { accounts: { "1": { "attributes": { "name": "astrails" <<= value }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", "email": "vitaly@astrails.com" } } }}
  14. 14. my_cluster: { demo_app: { accounts: { "1": { "attributes": { "name": "astrails" }, "users": { "1" => "", "3" => "", } } }, users: { "1": { "name": "vitaly", <<= column "email": "vitaly@astrails.com" } } }}
  15. 15. my_cluster: { <<= cluster demo_app: { <<= keyspace accounts: { <<= super column family "1": { <<= key "attributes": { <<= supercolumn "name": "astrails" <<= column }, "users": { "1" => "", "3" => "", } } }, users: { <<= column family "1": { <<= key "name": "vitaly", <<= column "email": "vitaly@astrails.com" } } }}
  16. 16. my_cluster: { <<= cluster demo_app: { <<= database accounts: { <<= super column family "1": { <<= key "attributes": { <<= supercolumn "name": "astrails" <<= column }, "users": { "1" => "", "3" => "", } } }, users: { <<= column family "1": { <<= key "name": "vitaly", <<= column "email": "vitaly@astrails.com" } } }}
  17. 17. my_cluster: { <<= cluster demo_app: { <<= database accounts: { <<= table "1": { <<= key "attributes": { <<= supercolumn "name": "astrails" <<= column }, "users": { "1" => "", "3" => "", } } }, users: { <<= column family "1": { <<= key "name": "vitaly", <<= column "email": "vitaly@astrails.com" } } }}
  18. 18. my_cluster: { <<= cluster demo_app: { <<= database accounts: { <<= table "1": { <<= key "attributes": { <<= supercolumn "name": "astrails" <<= column }, "users": { "1" => "", "3" => "", } } }, users: { <<= table "1": { <<= key "name": "vitaly", <<= column "email": "vitaly@astrails.com" } } }}
  19. 19. my_cluster: { <<= cluster demo_app: { <<= database accounts: { <<= table "1": { <<= key "attributes": { <<= collection "name": "astrails" <<= column }, "users": { "1" => "", "3" => "", } } }, users: { <<= table "1": { <<= key "name": "vitaly", <<= column "email": "vitaly@astrails.com" } } }}
  20. 20. my_cluster: { <<= cluster demo_app: { <<= database accounts: { <<= table "1": { <<= key "attributes": { <<= collection "name": "astrails" <<= attribute }, "users": { "1" => "", "3" => "", } } }, users: { <<= table "1": { <<= key "name": "vitaly", <<= attribute "email": "vitaly@astrails.com" } } }}
  21. 21. Indexing
  22. 22. "my_cluster": { "demo_app": { "users": { "b2c75e99-e079-449d-b562-293dfdbf006e": { "attributes": { "name": "Vitaly", "email": "vitaly@astrails.com", "remember_me": "74c4f3a2c85b66f216211edd5245d25ba251d83e" } } }, "emails": { "vitaly@astrails.com": "b2c75e99-e079-449d-b562-293dfdbf006e", } "remember_me": { "74c4f3a2c85b66f216211edd5245d25ba251d83e": "b2c75e99-e079-449d-b562-293dfdbf006e", } }}
  23. 23. "my_cluster": { "demo_app": { "users": { "b2c75e99-e079-449d-b562-293dfdbf006e": { "attributes": { "name": "Vitaly", "email": "vitaly@astrails.com", "remember_me": "74c4f3a2c85b66f216211edd5245d25ba251d83e" } } }, "emails": { "vitaly@astrails.com": "b2c75e99-e079-449d-b562-293dfdbf006e", } "remember_me": { "74c4f3a2c85b66f216211edd5245d25ba251d83e": "b2c75e99-e079-449d-b562-293dfdbf006e", } }}
  24. 24. "my_cluster": { "demo_app": { "users": { "b2c75e99-e079-449d-b562-293dfdbf006e": { "attributes": { "name": "Vitaly", "email": "vitaly@astrails.com", "remember_me": "74c4f3a2c85b66f216211edd5245d25ba251d83e" } } }, "emails": { "vitaly@astrails.com": "b2c75e99-e079-449d-b562-293dfdbf006e", } "remember_me": { "74c4f3a2c85b66f216211edd5245d25ba251d83e": "b2c75e99-e079-449d-b562-293dfdbf006e", } }}
  25. 25. "my_cluster": { "demo_app": { "users": { "b2c75e99-e079-449d-b562-293dfdbf006e": { "attributes": { "name": "Vitaly", "email": "vitaly@astrails.com", "remember_me": "74c4f3a2c85b66f216211edd5245d25ba251d83e" } } }, "emails": { "vitaly@astrails.com": "b2c75e99-e079-449d-b562-293dfdbf006e", } "remember_me": { "74c4f3a2c85b66f216211edd5245d25ba251d83e": "b2c75e99-e079-449d-b562-293dfdbf006e", } }}
  26. 26. "my_cluster": { "demo_app": { "users": { "b2c75e99-e079-449d-b562-293dfdbf006e": { "attributes": { "name": "Vitaly", "email": "vitaly@astrails.com", "remember_me": "74c4f3a2c85b66f216211edd5245d25ba251d83e" } } }, "emails": { "vitaly@astrails.com": "b2c75e99-e079-449d-b562-293dfdbf006e", } "remember_me": { "74c4f3a2c85b66f216211edd5245d25ba251d83e": "b2c75e99-e079-449d-b562-293dfdbf006e", } }}
  27. 27. "my_cluster": { "demo_app": { "users": { "b2c75e99-e079-449d-b562-293dfdbf006e": { "attributes": { "name": "Vitaly", "email": "vitaly@astrails.com", "remember_me": "74c4f3a2c85b66f216211edd5245d25ba251d83e" } } }, "emails": { "vitaly@astrails.com": "b2c75e99-e079-449d-b562-293dfdbf006e", } "remember_me": { "74c4f3a2c85b66f216211edd5245d25ba251d83e": "b2c75e99-e079-449d-b562-293dfdbf006e", } }}
  28. 28. Playtime
  29. 29. > gem install cassandra...> cassandra_helper cassandra...
  30. 30. <ClusterName>my_cluster</ClusterName><Keyspaces> <Keyspace Name="demo_app"> <ColumnFamily CompareWith="UTF8Type" Name="users" ColumnType="Super" CompareSubcolumnsWith="UTF8Type" /> <ColumnFamily CompareWith="UTF8Type" Name="emails" ColumnType="Super" CompareSubcolumnsWith="UTF8Type" /> <ColumnFamily CompareWith="UTF8Type" Name="tokens" /> </Keyspace></Keyspaces>
  31. 31. require rubygemsrequire cassandrainclude Cassandra::Constantsclient = Cassandra.new(demo_app)client.insert(:users, "1", {"name" => "vitaly", "email" => "vitaly@astrails.com"})client.insert(:accounts, "1", {"attributes" => {"name" => "astrails"}, "users" => {"1" => ""}})client.insert(:users, "2", {"name" => "boris"})client.insert(:accounts, "1", {"users" => {"2" => ""}})client.get(:users, "1")
  32. 32. Rails?
  33. 33. YES!
  34. 34. SmallRecordWARNING: waporware :)
  35. 35. http://github.com/astrails/small_record
  36. 36. ActiveModel
  37. 37. class Account < SmallRecord::Base attribute :name attribute :created_at, :type => :datetime has_many :users validates_presence_of :nameendclass User < SmallRecord::Base attribute :name attribute :email attribute :created_at, :type => :datetime attribute :account_id def account @account ||= Account.find(:account_id) end validates_presence_of :name validates_presence_of :emailendAccount.find(params[:account]).users.first.name
  38. 38. production: adapter: cassandra host: 127.0.0.1 port: 9160 keyspace: chronosdevelopment: adapter: mocktest: adapter: mock
  39. 39. production: adapter: cassandra host: 127.0.0.1 port: 9160 keyspace: chronosdevelopment: adapter: mocktest: adapter: mock
  40. 40. Some Links• http://incubator.apache.org/cassandra• http://labs.google.com/papers/bigtable.html• http://blog.evanweaver.com/articles/2009/07/06/up-and-running-with-cassandra/• http://arin.me/blog/wtf-is-a-supercolumn-cassandra-data-model• http://github.com/astrails/small_record
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×