of 30 /30
©2014 DataStax @AlTobey Open Source Mechanic | Datastax Apache Cassandra のオーペンソースエバンジェセト Tunable Consistency 1

Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Embed Size (px)

DESCRIPTION

Al Tobey presenting on Tunable Consistency at the Tokyo Cassandra Summit 2014.

Citation preview

Page 1: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

©2014 DataStax

@AlTobey Open Source Mechanic | Datastax Apache Cassandra のオーペンソースエバンジェセト

Tunable Consistency

!1

Page 2: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

アルトビー

Leo Rufus

Page 3: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

!日本で1.4億携帯電話理由Cassandraを選ぶのか

Page 4: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

理由Cassandraを選ぶのか!妥協のない

Page 5: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

!日本で億のインターネットユーザー理由Cassandraを選ぶのか

Page 6: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

!インターネットは眠らない。理由Cassandraを選ぶのか

Page 7: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

オンラインシステムの概要

Client/ServerClassic 3-tier

3-tier + read scaled DB + cache

Page 8: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

オンラインシステムの概要

Page 9: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

オンラインシステムの概要

Page 10: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

オンラインシステムの概要

master slaveslave

Page 11: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

オンラインシステムの概要

master slaveslave

cache

Page 12: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

オンラインシステムの概要

Page 13: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

オンラインシステムの概要

Page 14: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Read-Modify-WriteUPDATE  Employees  SET  Rank=4,  Promoted=2014-­‐01-­‐24  WHERE  EmployeeID=1337;

EmployeeID**1337Name********アルトビーStartDate***2013510501Rank********3Promoted****null

EmployeeID**1337Name********アルトビーStartDate***2013510501Rank********4Promoted****2014501524

Page 15: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Read-Modify-WriteUPDATE  Employees  SET  Rank=4,  Promoted=2014-­‐01-­‐24  WHERE  EmployeeID=1337;

無償の昼食なんてものはありません

EmployeeID**1337Name********アルトビーStartDate***2013510501Rank********4Promoted****2014501524

EmployeeID**1337Name********アルトビーStartDate***2013510501Rank********3Promoted****null

RDBMS

Page 16: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Eventual Consistency

EmployeeID**1337Name********アルトビーStartDate***2013510501Rank********4Promoted****2014501524

EmployeeID**1337Name********アルトビーStartDate***2013510501Rank********3Promoted****null

Coordinator

Cassandra

UPDATE  Employees  SET  Rank=4,  Promoted=2014-­‐01-­‐24  WHERE  EmployeeID=1337;

Page 17: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Eventual Consistency

EmployeeID**1337Name********アルトビーStartDate***2013510501Rank********4Promoted****2014501524

EmployeeID**1337Name********アルトビーStartDate***2013510501Rank********3Promoted****null

Coordinator

Cassandra

UPDATE  Employees  SET  Rank=4,  Promoted=2014-­‐01-­‐24  WHERE  EmployeeID=1337;

Page 18: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Avoiding Read-Modify-Write•Overwrites •Key / Value •Journal / Logging / Time-series •Content-addressable-storage •Cassandra Collection Types •Cassandra Lightweight Transactions

Page 19: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

OverwritingCREATE TABLE host_lookup ( name varchar, id uuid, PRIMARY KEY(name) ); !INSERT INTO host_uuid (name,id) VALUES (“www.tobert.org”, “463b03ec-fcc1-4428-bac8-80ccee1c2f77”); !INSERT INTO host_uuid (name,id) VALUES (“tobert.org”, “463b03ec-fcc1-4428-bac8-80ccee1c2f77”); !INSERT INTO host_uuid (name,id) VALUES (“www.tobert.org”, “463b03ec-fcc1-4428-bac8-80ccee1c2f77”); !SELECT id FROM host_lookup WHERE name=“tobert.org”;

Page 20: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Key/ValueCREATE TABLE keyval ( key VARCHAR, value blob, PRIMARY KEY(key) ); !INSERT INTO keyval (key,value) VALUES (?, ?); !SELECT value FROM keyval WHERE key=?;

Page 21: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Journaling / Logging / Time-seriesCREATE TABLE tsdb ( time_bucket timestamp, time timestamp, value blob, PRIMARY KEY(time_bucket, time) ); !INSERT INTO tsdb (time_bucket, time, value) VALUES ( “2014-10-24”, -- 1-day bucket (UTC) “2014-10-24T12:12:12Z”, -- ALWAYS USE UTC ‘{“foo”: “bar”}’ );

Page 22: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Journaling / Logging / Time-series

{"“2014(01(24”"=>"{""""“2014(01(24T12:12:12Z”"=>"{""""""""‘{“foo”:"“bar”}’""""}}

2014(01(24 2014(01(24T12:12:12Z{“key”:"“value”}

2014(01(25 2014(01(25T13:13:13Z{“key”:"“value”}

2014(01(24T21:21:21Z{“key”:"“value”}

Page 23: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Content Addressable StorageCREATE TABLE objects ( cid varchar, content blob, PRIMARY KEY(cid) ); !INSERT INTO objects (cid,content) VALUES (?, ?); !SELECT content FROM objects WHERE cid=?;

Page 24: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Content Addressable Storagerequire  'cql'  require  ‘digest/sha1'  !dbh  =  Cql::Client.connect(hosts:  ['127.0.0.1'])  dbh.use('cas')  !data  =  {  :timestamp  =>  1390436043,  :value  =>  1234  }  !cid  =  Digest::SHA1.new.digest(data.to_s).unpack(‘H*’)  !sth  =  client.prepare(     'SELECT  content  FROM  objects  WHERE  cid=?')  !sth.execute(root_cid).first[‘content’]

Page 25: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

In Practice• In practice, RMW is sometimes unavoidable

• Recent versions of Cassandra support RMW

• Use them only when necessary

• Or when performance hit is mitigated elsewhere or irrelevant

Page 26: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Cassandra CollectionsCREATE TABLE posts ( id uuid, body varchar, created timestamp, authors set<varchar>, tags set<varchar>, PRIMARY KEY(id) ); !INSERT INTO posts (id,body,created,authors,tags) VALUES ( ea4aba7d-9344-4d08-8ca5-873aa1214068, ‘アルトビーの犬はばかね’, ‘now', [‘アルトビー’, ’ィオートビー’], [‘dog’, ‘silly’, ’犬’, ‘ばか’] );

Page 27: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Cassandra CollectionsCREATE TABLE metrics ( bucket timestamp, time timestamp, value blob, labels map<varchar,varchar>, PRIMARY KEY(bucket) );

Page 28: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Lightweight Transactions• Cassandra 2.0 and on support LWT based on PAXOS

• PAXOS is a distributed consensus protocol

• Given a constraint, Cassandra ensure correct ordering

Page 29: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Lightweight TransactionsUPDATE  users          SET  username=‘tobert’    WHERE  id=68021e8a-­‐9eb0-­‐436c-­‐8cdd-­‐aac629788383          IF  username=‘renice’;  !INSERT  INTO  users  (id,  username)  VALUES  (68021e8a-­‐9eb0-­‐436c-­‐8cdd-­‐aac629788383,  ‘renice’)  IF  NOT  EXISTS;  !!

Page 30: Tokyo Cassandra Summit 2014: Tunable Consistency by Al Tobey

Conclusion• Businesses are scaling further and faster than ever

• Data models and application architectures need to change to keep up

• Avoiding Read/Modify/Write makes high-performance easier

• Cassandra excels at time-series and other write-mostly workloads

• Cassandra provides tools for safe RMW when you need it

!

• Questions?