Upload
amy-hanlon
View
162
Download
0
Embed Size (px)
Citation preview
DESCRIBE contact_book; +-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐+ | Field | Type | Null | Key | Default | Extra | +-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐+ | user_id | int(11) | NO | PRI | NULL | | | phone_number | varchar(15) | NO | PRI | NULL | | | name | varchar(60) | YES | | NULL | | +-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐+
SELECT * FROM contact_book; +-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+ | user_id | phone_number | name | +-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+ | 1 | 3453456789 | NULL | | 1 | 6786786789 | Amy Hanlon | +-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+
MySQL updates• append to log
• locate row(s)
• modify index and row(s) in memory
• acknowledge
• update index and row on disk
DESCRIBE TABLE contact_book; !
CREATE TABLE contact_book ( user_id int, phone_number text, name text, PRIMARY KEY ((user_id), phone_number) )
select * from contact_book; !
user_id | phone_number | name -‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐ 1 | 3453456789 | null 1 | 6786786789 | Amy Hanlon
select * from contact_book; !
user_id 1: !
3453456789:name | 6786786789:name -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐ null | Amy Hanlon
Cassandra updates
• append to log
• write update to memtable
• acknowledge
• (eventually) flush memtable to disk into sstable
INSERT INTO contact_book (user_id, phone_number, name) VALUES (1, '3453456789', 'cassidy'); !
# flush memtable !
UPDATE contact_book SET name='Cassidy Williams' WHERE user_id=1 AND phone_number='3453456789';
Cassandra reads
• read row(s) from sstables
• get updates to row(s) from memtable
• reduce any multiple values for columns
• respond to coordinator
Links• http://planetcassandra.org/blog/composite-keys-in-apache-cassandra/
• http://docs.datastax.com/en/cassandra/2.0/cassandra/dml/dml_write_path_c.html
• http://thelastpickle.com/blog/2011/04/28/Forces-of-Write-and-Read.html
• http://docs.datastax.com/en/cassandra/2.0/cassandra/dml/dml_about_reads_c.html
• http://docs.datastax.com/en/cassandra/2.0/cassandra/operations/ops_how_cache_works_c.html
• http://www.datastax.com/dev/blog/when-to-use-leveled-compaction
• http://www.datastax.com/dev/blog/leveled-compaction-in-apache-cassandra