C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

27
Michaël Figuiere, Software Engineer, DataStax Alex Popescu, Sen.Product Manager, DataStax Cassandra made simple with CQL drivers and DevCenter #CASSANDRAEU

description

Speakers: Michaël Figuiere, Software Engineer at DataStax & Alex Popescu, Senior Product Manager at DataStax Video: http://www.youtube.com/watch?v=hK2dXLiYVMI&list=PLqcm6qE9lgKLoYaakl3YwIWP4hmGsHm5e&index=11 Is Cassandra too complex for newcomers? Besides the many improvements that have made their way into C* to dramatically simplify it and the finalized Cassandra Query Language, the SQL-like query language that should look familiar, new drivers have been created with a modern and efficient API. Last, but not least, DataStax is introducing *today* DevCenter 1.0, an IDE whose goal is to simplify developer's workflow even further and to improve their productivity. This presentation will show you how putting to work the new drivers and DevCenter can make your daily life with Cassandra nicer!

Transcript of C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Page 1: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Michaël Figuiere, Software Engineer, DataStax !

Alex Popescu, Sen.Product Manager, DataStax

Cassandra made simple with CQL drivers and DevCenter

#CASSANDRAEU

Page 2: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

#CASSANDRAEUAgenda

•Why building tools for Cassandra?

•DataStax Drivers •Core values

•Introducing DevCenter

Page 3: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

#CASSANDRAEUMotivation

«Use the right tool for the job»

... the best tools for the job

Page 4: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

#CASSANDRAEUWhy building tools for C*

•Too many choices

•Best practices

•distributed systems

•modern applications

•Friendly, Familiar, Integrated experience

Page 5: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

#CASSANDRAEUOne way or another

•Learn & experiment

•Implement

•Test

•Integrate

!

•Repeat

Page 6: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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

Page 7: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

* Reference Implementation

* Asynchronous architecture based on Netty

* Prepared Statements Support

* Automatic Fail-over

* Node Discovery

* Cassandra Tracing Support

* Tunable Policies

!

CQL Drivers Overview

Page 8: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Client

Without Request

Pipelining

With Request

Pipelining

Request PipeliningCassandra

Client Cassandra

Page 9: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Client

Without Notifications

With Notifications

NodeNode

Node

ClientNode

Node

Node

Notifications

Page 10: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Client Thread

Nod

Nod

Nod

Client Thread

Client Thread Nod

Driver

Asynchronous Architecture

Page 11: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

1

23

4

5

6Client Thread

Client Thread

Client Thread

Driver

Asynchronous Architecture

Nod

Nod

Nod

Nod

Page 12: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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', '[email protected]')");

Page 13: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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");}

Page 14: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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");}

Page 15: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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);

Page 16: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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

Page 17: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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

Page 18: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Load Balancing

Policy

Node

Node

Node

Load Balancing and Failover

Client

Retry Policy

Response

1 3

2

4

5

6

Health Monitor

Reconnection Notifications

Page 19: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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

Page 20: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

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.

Page 21: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

!!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

Page 22: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Client Page 1

+ Paging State 1

Nod

Nod Repli

Repli

Nod Repli

Automatic Paging

Query

Page 23: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Client

Page 2 + Paging State 2

Nod

Nod Repli

Repli

Nod Repli

Automatic Paging

Query + Paging State 1

Page 24: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

Introducing DevCenter 1.0

Page 25: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

#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

Page 26: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

#CASSANDRAEUDevCenter

Pull a Steve Jobs...

... brag about how brilliant DevCenter is

Page 27: C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter

#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