• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
NYC* Tech Day - New Cassandra Drivers in Depth
 

NYC* Tech Day - New Cassandra Drivers in Depth

on

  • 2,391 views

 

Statistics

Views

Total Views
2,391
Views on SlideShare
2,047
Embed Views
344

Actions

Likes
3
Downloads
16
Comments
0

4 Embeds 344

http://iwlwi.blog.fc2.com 203
https://twitter.com 137
http://webcache.googleusercontent.com 3
http://admin.blog.fc2.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    NYC* Tech Day - New Cassandra Drivers in Depth NYC* Tech Day - New Cassandra Drivers in Depth Presentation Transcript

    • New Cassandra Drivers inDepthMichaël Figuière@mfiguiere
    • Speaker Michaël Figuière @mfiguiere©2012 DataStax 2
    • CQL: the new face of Cassandra • CQL 3 • Simpler Data Model using denormalized Tables • SQL-like query language • Schema definition • CQL Binary Protocol • Introduced in Cassandra 1.2 (CASSANDRA-2478) • Designed for CQL 3 • Opens doors for Streaming, Notifications, ... • Thrift will keep being supported by Cassandra©2012 DataStax 3
    • CQL3 Denormalized Model CQL3 Query Language comes with a new Data Model abstraction made of denormalized, statically defined tables Data duplicated over several tables©2012 DataStax 4
    • CQL3 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 Partition Clustering Key Key©2012 DataStax 5
    • CQL3 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 6
    • CQL3 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 treeTimeline Physical Layout [1735, author] [1735, body] [1742, author] [1742, body] gmason gwashington I chopped down the... phenry Give me liberty or give... [1767, author] [1767, body] [1794, author] [1794, body] ahamilton gwashington I chopped down the... jadams A government of laws...©2012 DataStax 7
    • Current Drivers Architecture CQL API Thrift API OO API DB API Thrift RPC Thrift RPC Client Library CQL Driver * This is a simplified view of drivers architecture. Details vary from one language to another.©2012 DataStax 8
    • New Drivers Architecture DB API CQL API OO API CQL Native Protocol Next Generation Driver * This is a simplified view of drivers architecture. Details vary from one language to another.©2012 DataStax 9
    • DataStax Java Driver • Reference Implementation • Asynchronous architecture based on Netty • Prepared Statements Support • Automatic Fail-over • Node Discovery • Cassandra Tracing Support • Tunable policies • LoadBalancingPolicy • ReconnectionPolicy •©2012 DataStax RetryPolicy 10
    • Request Pipelining Client Cassandra Without Request Pipelining With Client Cassandra Request Pipelining©2012 DataStax 11
    • Notifications Node Client Node Node Without Notifications With Notifications Node Client Node Node©2012 DataStax 12
    • Asynchronous Architecture Node Client Thread Node Client Driver Thread Node Client Thread Node©2012 DataStax 13
    • Asynchronous Architecture Node Client Thread 6 1 Node Client Driver 2 Thread 3 Node 5 4 Client Thread Node©2012 DataStax 14
    • LoadBalancingPolicy public interface LoadBalancingPolicy { HostDistance distance(Host host); Iterator<Host> newQueryPlan(Query query); [...] }©2012 DataStax 15
    • DCAwareRoundRobinPolicy Datacenter A Local nodes are queried first, if non Client Node are available, the request will be sent Client Node to a remote node. Node Client Client Node Client Node Node Client Datacenter B©2012 DataStax 16
    • TokenAwarePolicy Nodes that own a Replica of the data being read or written by the query will be contacted first. Replica Node Node Client Replica Node Node Replica Node©2012 DataStax 17
    • RetryPolicypublic interface RetryPolicy { RetryDecision onReadTimeout(Query query, ConsistencyLevel cl, [...] ); RetryDecision onWriteTimeout(Query query, ConsistencyLevel cl, [...] ); RetryDecision onUnavailable(Query query, ConsistencyLevel cl, [...] ); public static class RetryDecision { public static enum Type { RETRY, RETHROW, IGNORE }; private final Type type; private final ConsistencyLevel retryCL; [...] }}©2012 DataStax 18
    • Downgrading Consistency If the requested Consistency Level cannot be reached (QUORUM here), a second request with a lower CL is sent automatically. Node Replica Client Node Replica Node Replica©2012 DataStax 19
    • Connect and Write Cluster cluster = 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 20
    • 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 21
    • 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 22
    • Prepared Statements PreparedStatement ps = session.prepare("SELECT * FROM users WHERE id = ?"); BoundStatement bs = session.execute(ps.bind("123")).one().getInt("age"); bs.setString("k"); int age = session.execute(bs).one().getInt("age"); age = session.execute(ps.bind("123")).one().getInt("age");©2012 DataStax 23
    • Query Builder String query = "SELECT a,b,"C" FROM foo WHERE a IN (127.0.0.1,127.0.0.3) AND "C"=foo ORDER BY a ASC,b DESC LIMIT 42;"; Query select = select("a", "b", quote("C")).from("foo") .where(in("a", InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.3"))) .and(eq(quote("C"), "foo")) .orderBy(asc("a"), desc("b")) .limit(42);©2012 DataStax 24
    • Object Mapping @Table(name = "user") public class User { public enum Gender { @PartitionKey @EnumValue("m") @Column(name = "user_id") MALE, private String userId; @EnumValue("f") private String name; FEMALE; } private String email; private Gender gender; }©2012 DataStax 25
    • Inheritance@Table(name = "catalog")@Inheritance( @InheritanceValue("tv") subClasses = {Phone.class, TV.class}, public class TV column = "product_type" extends Product {)public abstract class Product { private float size; } @Column(name = "product_id") private String productId; private float price; private String vendor; private String model;}©2012 DataStax 26
    • Betas now available! https://github.com/datastax/
    • Stay Tuned! blog.datastax.com @mfiguiere