C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
Post on 27-Jan-2015
108 Views
Preview:
DESCRIPTION
Transcript
Michaël Figuiere, Software Engineer, DataStax !
Alex Popescu, Sen.Product Manager, DataStax
Cassandra made simple with CQL drivers and DevCenter
#CASSANDRAEU
#CASSANDRAEUAgenda
•Why building tools for Cassandra?
•DataStax Drivers •Core values
•Introducing DevCenter
#CASSANDRAEUMotivation
«Use the right tool for the job»
... the best tools for the job
#CASSANDRAEUWhy building tools for C*
•Too many choices
•Best practices
•distributed systems
•modern applications
•Friendly, Familiar, Integrated experience
#CASSANDRAEUOne way or another
•Learn & experiment
•Implement
•Test
•Integrate
!
•Repeat
CQL The new face of Cassandra* CQL
* Simpler Data Model using Denormalized Tables * SQL-like Query Language * Schema Definition
* CQL Native Protocol * Introduced in Cassandra 1.2 * Designed for CQL * Thrift will keep being supported by Cassandra
* Reference Implementation
* Asynchronous architecture based on Netty
* Prepared Statements Support
* Automatic Fail-over
* Node Discovery
* Cassandra Tracing Support
* Tunable Policies
!
CQL Drivers Overview
Client
Without Request
Pipelining
With Request
Pipelining
Request PipeliningCassandra
Client Cassandra
Client
Without Notifications
With Notifications
NodeNode
Node
ClientNode
Node
Node
Notifications
Client Thread
Nod
Nod
Nod
Client Thread
Client Thread Nod
Driver
Asynchronous Architecture
1
23
4
5
6Client Thread
Client Thread
Client Thread
Driver
Asynchronous Architecture
Nod
Nod
Nod
Nod
Connect and Write
Cluster cluster = new 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')");
Read from a table
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");}
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");}
Read with Callbacksfinal ResultSetFuture future = session.executeAsync("SELECT * FROM test");!future.addListener(new Runnable() { public run() { for (Row row : future.get()) {! String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email"); } }}, executor);
public void setUserByPreparedStatement(User user) {!! BoundStatement bs = setUser.bind();!! bs.setString("username", user.getUsername());! bs.setString("firstname", user.getFirstname());! bs.setString("lastname", user.getLastname());! bs.setString("email", user.getEmail());! bs.setDate("created_date", user.getCreated_date());!! ! ! session.execute(bs); !}
Using Prepared Statements
Query query = select().all().from("videodb", "videos")! .where(eq("videoId", videoId)).limit(10);!! query.setConsistencyLevel(ConsistencyLevel.ONE);!! ResultSet rs = session.execute(query);!
Using the Query Builder
Load Balancing
Policy
Node
Node
Node
Load Balancing and Failover
Client
Retry Policy
Response
1 3
2
4
5
6
Health Monitor
Reconnection Notifications
Node
Node
NodeClient
Datacenter B
Client
Client
Datacenter A Local nodes are queried first, if non are available, the request will be sent to a remote node.
Multi Datacenter Load Balancing
Node
Node
NodeClient
Client
Client
Token Aware Load Balancing
Node
Node
Replica Node
Client
Node
NodeReplica
Replica
Nodes that own a Replica of the data being read or written by the query will be contacted first.
!!cluster = Cluster.builder()! .addContactPoints("10.0.0.1", "10.0.0.2") .withLoadBalancingPolicy(Policies.defaultLoadBalancingPolicy())! .build();!!session = cluster.connect(keyspace);!
Create your own policy!
Add a Load Balancing Policy
Client Page 1
+ Paging State 1
Nod
Nod Repli
Repli
Nod Repli
Automatic Paging
Query
Client
Page 2 + Paging State 2
Nod
Nod Repli
Repli
Nod Repli
Automatic Paging
Query + Paging State 1
Introducing DevCenter 1.0
#CASSANDRAEUDevCenter•DevCenter is a free visual query tool that can be used by both developers and admins for creating and running CQL queries and commands against Apache Cassandra and DataStax Enterprise
•DevCenter is the smarter and friendlier brother of cqlsh
#CASSANDRAEUDevCenter
Pull a Steve Jobs...
... brag about how brilliant DevCenter is
#CASSANDRAEU
*DataStax drivers:
http://github.com/datastax
*DevCenter:
http://www.datastax.com/dev/blog/datastax-devcenter-1-0-is-here
http://www.datastax.com/download/clientdrivers
!
Quick links
top related