SlideShare uma empresa Scribd logo
1 de 24
Cassandra Java APIs
Old and New – A Comparison
Shahryar Sedghi
Toronto Cassandra User Group
Sep. 18, 2013
#TCUG 2
Who am I?
www.linkedin.com/pub/shahryar-sedghi/1/439/420
@ shahryar.sedghi@parseix.com
Founder at
www.parseix.com
• Did some work on IBM Hierarchical databases (IMS DB / DOS DL1) in late 70s early 80s
• Worked extensively on IBM’s first (World’s first) relational Database (SQL/DS) in early 80s
• Have worked with Oracle and DB2 for years (not as a DBA)
• Started working on Cassandra, late 2011 (1.0.5)
@parseix
#TCUG 3
Disclaimer
• Code samples used here except for Astyanax
(that was just taken from the website) have
worked once in a certain release of Cassandra.
Only JDBC (modified) and new Java Driver
have been tested with Cassandra 1.2
#TCUG 4
Agenda
• What a Java API for Cassandra needs?
• A basic introduction to Cassandra data model
• Thrift
• Thrift based APIs
• Binary Protocol
• DATASTAX new Java API
#TCUG 5
A Java Database API
• Typically used in Java Application Servers
– Thread Safe
– Connection Pooling
• When used with Cassandra
– Tolerates database Machine/Network failure
– Load balancing
– Reconnects to the failed machine when its back
• Together they should provide a highly
available environment for Web apps without
an expensive HA investment
#TCUG 6
Cassandra Data Model at a Glance
B
A
D
K
B1 Value11 B2 Value12 B3 Value13 B4 Value14
A1 Value21 A2 Value22 A3 Value23
D1 Value51 D2 Value52 D3 Value53 D4 Value54 D5 Value55
• Is a row key, by default (best practice) it is not sorted, it is sorted by hash of the Key
• All columns of one row reside in one node
• Is a column name, 2 billion distinct column names can be in one row
• Columns are sorted by column name (Ascending or Descending)
• Is a column value, it can be null or can be a different type for each column in each
row. E.G. A1 can be an Integer and D1 can be a String
• If all 1s and all 2s and all 3s, … (e.g., A1,B1, C1) column values carry the same
data type, it can be used like a relational DB with CQL 2, better scalability and less
functionality, but not the best use of Cassandra
C C1 Value61 C2 Value62
D51 Value551 D52 Value552 D53 Value553
Super Column (Deprecated)
#TCUG 7
Data Model -Composite Columns
122 11:firstName
• We would like to model the following data structure:
{deptartmentId Integer, employeeId Integer, firtName String, lastName String}
11:lastName 12:firstName 12:lastName 13:firstName 13:lastName
departmentId 122, employeeId 11, 12 and 13
225 17:firstName 17:lastName 19:firstName 19:lastName
departmentId 225, employeeId 17 and 19
• CQL3
create table department(
departmentid int,
employeeid int,
firstname text,
lastname text,
PRIMARY KEY (departmentid ,
employeeid)
);
• departmentId is called Partition key
• employeeId is called Clustering key
Logical Row
Physical Row
#TCUG 8
Thrift
• An Apache Project
• YaRPC (Remote Procedure Call)
• Has an IDL (Interface Definition Language) like other RPCs
• Language Neutral
• Easier than many others to use
• Good fit for early releases of Cassandra to support all sorts
of clients
– Apparently not every client works as well as Java and Python
• Is RPC a good fit for database interaction? Yes and no
• Cassandra thrift by default listens on 9160
#TCUG 9
Thrift Importance for Cassandra
• Any Clients, except new DATASTAX drivers for Java
and .NET are using Thrift underneath
– Including Hector, JDBC and Astyanax
• Supports
– Ring Discovery
– Native access to Cassandra
– CQL 2
– CQL 3
• JDBC and Astyanax may move to native driver in the
future
#TCUG 10
Thrift Example: Ring Discovery
Ttransport transport = new TFramedTransport(new
TSocket(“192.168.1.14", 9160));
TProtocol protocol = new TBinaryProtocol(transport);
client = new Cassandra.Client(protocol);
transport.open();
List<TokenRange> trList = client.describe_ring(“mydb");
TokenRange tr = trList.get(0);
for(String endpoint: tr.getEndpoints()){
System.out.println(endpoint);
}
#TCUG 11
Thrift Example: Get All Row Keys
ColumnParent columnParent = new ColumnParent(“xyz");
SlicePredicate predicate = new SlicePredicate();
predicate.setSlice_range(new SliceRange(ByteBuffer.wrap(new
byte[0]), ByteBuffer.wrap(new byte[0]), false, 1)); // Here you can
specify a slice
KeyRange keyRange = new KeyRange(); //Get all keys, or set a range
List<KeySlice> keySlices = client.get_range_slices(columnParent,
predicate, keyRange, ConsistencyLevel.ONE); // or null in this case
ArrayList<Integer> list = new ArrayList<Integer>();
for (KeySlice ks : keySlices) {
list.add(ByteBuffer.wrap(ks.getKey()).getInt());
System.out.println(ByteBuffer.wrap(ks.getKey()).getInt());
}
#TCUG 12
Hector
• Most Commonly used Java API for Cassandra
• Using Thrift underneath
• Among the other features:
– Connection Pooling
– Ring Discovery and automatic Failover
– automatic retry of downed hosts
– automatic discovery of additional hosts in the
cluster
– suspension of hosts for a short period of time
after several timeouts
#TCUG 13
Hector Example: Read All RowKeys
Cluster myCluster = HFactory.getOrCreateCluster(" MyCluster ", "127.0.0.1:9160");
ConfigurableConsistencyLevel ccl = new ConfigurableConsistencyLevel();
ccl.setDefaultReadConsistencyLevel(HConsistencyLevel.ONE);
Keyspace myKeyspace = HFactory.createKeyspace(("MYDB", , myCluster, ccl);
RangeSlicesQuery<Integer, Composite, String> rangeSlicesQuery =
HFactory.createRangeSlicesQuery(myKeyspace, IntegerSerializer.get(),
CompositeSerializer.get(), StringSerializer.get());
QueryResult<OrderedRows<Integer, Composite, String>> result =
rangeSlicesQuery.setColumnFamily(CF).setKeys(0, -1).setReturnKeysOnly().execute();
OrderedRows<Integer, Composite, String> orderedRows = result.get();
ArrayList<Integer> list = new ArrayList<Integer>();
for(Row<Integer, Composite, String> row: orderedRows){
list.add(row.getKey());
}
#TCUG 14
Astyanax
• Developed by Netflix
• Supports all Hector functions, much easier
• Much better connection pool and failover than Hector
• More than an API for Cassandra
– Provides some database functionality at the API level, called
Recipes
• Parallel all rows query
• Message Queue
• Chunked Object Store
• many more
• Utilities
– JSON Writer, CVS Importer
• Netflix expressed the plan to move to binary protocol at
Cassandra Summit 2013
#TCUG 15
Astyanax Example: Pagination
ColumnList<String> columns; int pageize = 10;
try {
RowQuery<String, String> query = keyspace
.prepareQuery(CF_STANDARD1) .getKey("A")
.setIsPaginating() .withColumnRange(new
RangeBuilder().setMaxSize(pageize).build());
while (!(columns = query.execute().getResult()).isEmpty()) {
for (Column<String> c : columns) {
// do something like c.getStringValue()
}
}
} catch (ConnectionException e) { }
#TCUG 16
JDBC(Java Database Connectivity)
• Standard Java Database API
• Only supports CQL to access Cassandra
• Current Cassandra JDBC driver is a shallow
implementation of JDBC on top of Thrift
• URL is like:
– jdbc:cassandra://192.168.1.5:9160?version=3.0.0
• All Java Application Servers support connection
pooling for JDBC
• No database failover and Cassandra Cluster support
• Helps to convert relational database apps to Cassandra
#TCUG 17
JDBC Example: Insert
• This code can run in a Servlet or an “EJB”!!! with some minor
modification
• Nothing in this code points to Cassandra or Thrift classes
• insertQuery for CQL is not always as simple as this
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
DataSource datasource = (DataSource) envCtx.lookup("jdbc/cassandra");
Connection cqlCon = datasource.getConnection();
String insertQuery = "INSERT INTO department(departmentid, employeeid, firstname,
lastname) VALUES ( ?, ?, ? )";
PreparedStatment statement = cqlCon.prepareStatement(insertQuery);
statement.setInt(1, 122);
statement.setInt(2, 11);
statement.setString(3, "John");
statement.setString(4, "Doe");
statement.close();
cqlCon.close();
#TCUG 18
Cassandra Binary Protocol
• Inherently asynchronous
– Can be used synchronously as well
• Frame and stream based
– Many Request with different Stream id can be sent asynchronously
– A set of frames belong to the same stream coming from the server
• Certain events are pushed from the server
– Topology change
– Status Change
– Schema change
• Because of the asynchronous nature, can easily be integrated
with new technologies like WebSockets and Servlet 3.0, 3.1
• Listens on port 9042
#TCUG 19
DATASTAX Java Driver
• Implements the Binary Protocol client side
• Similar to JDBC but easier in certain areas
– Specific to Cassandra, not portable
• Supports CQL and plan to support OO and DB APIs
• Supports
– Query Builder (who wants this?)
– Node Discovery
– Connection pooling
– Reconnection policies
– Load balancing policies
– Retry policies
• Cursor support announced during Cassandra Summit
2013
#TCUG 20
DATASTAX Java Driver : Cluster and Session
Cluster cluster = Cluster.builder().addContactPoint(
"192.168.1.14","192.168.1.15").
withRetryPolicy(DowngradingConsistencyRetryPolicy.
INSTANCE).
withReconnectionPolicy(new
ConstantReconnectionPolicy(1000L)).
withLoadBalancingPolicy(new
DCAwareRoundRobinPolicy("DC1")).
withCredentials("myuser", "mypassword“).build();
Session session = cluster.connect(("mykeyspace"));
#TCUG 21
DATASTAX Java Driver Example: Select
String selectQuery = "select * from department where departmentid = ? ";
PreparedStatment statement = session.prepare(selectQuery);
statement.setConsistencyLevel(ConsistencyLevel.ONE);
BoundStatement query = statement.bind(122);
ResultSet result = session.execute(query); // you can do async here and
// get a Future instead
for(Row row:result){
System.out.println(row.getInt("employeeid"));
System.out.println(row.getString(“firstname"));
System.out.println(row.getString(“lastname"));
}
#TCUG 22
References
• Thrift
http://wiki.apache.org/cassandra/ThriftExamples
• Hector
http://hector-client.github.io/hector/build/html/index.html
• Astyanax
https://github.com/Netflix/astyanax/wiki
• JDBC
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/
• DATASTAX Java Driver
http://www.datastax.com/documentation/developer/java-driver/1.0/webhelp/index.html
– YouTube Presentation, Cassandra Summit 2013
http://www.youtube.com/watch?v=fZfLQABJxuc
– Slideshare, Cassandra Summit 2013
http://www.slideshare.net/planetcassandra/cassandra-summit-data-stax-java-driver
– Mailing list
client-dev@cassandra.apache.org , enroll at http://cassandra.apache.org/
#TCUG 23
Thanks
And especially Victor Anjos
#TCUG 24

Mais conteúdo relacionado

Mais procurados

Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3Eric Evans
 
Cassandra Summit 2015: Intro to DSE Search
Cassandra Summit 2015: Intro to DSE SearchCassandra Summit 2015: Intro to DSE Search
Cassandra Summit 2015: Intro to DSE SearchCaleb Rackliffe
 
Cassandra Community Webinar: Apache Cassandra Internals
Cassandra Community Webinar: Apache Cassandra InternalsCassandra Community Webinar: Apache Cassandra Internals
Cassandra Community Webinar: Apache Cassandra InternalsDataStax
 
Cassandra and Spark
Cassandra and Spark Cassandra and Spark
Cassandra and Spark datastaxjp
 
Bay area Cassandra Meetup 2011
Bay area Cassandra Meetup 2011Bay area Cassandra Meetup 2011
Bay area Cassandra Meetup 2011mubarakss
 
Building Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::ClientBuilding Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::ClientMike Friedman
 
Introduction to .Net Driver
Introduction to .Net DriverIntroduction to .Net Driver
Introduction to .Net DriverDataStax Academy
 
How you can contribute to Apache Cassandra
How you can contribute to Apache CassandraHow you can contribute to Apache Cassandra
How you can contribute to Apache CassandraYuki Morishita
 
Building a High-Performance Distributed Task Queue on MongoDB
Building a High-Performance Distributed Task Queue on MongoDBBuilding a High-Performance Distributed Task Queue on MongoDB
Building a High-Performance Distributed Task Queue on MongoDBMongoDB
 
Apache Cassandra, part 3 – machinery, work with Cassandra
Apache Cassandra, part 3 – machinery, work with CassandraApache Cassandra, part 3 – machinery, work with Cassandra
Apache Cassandra, part 3 – machinery, work with CassandraAndrey Lomakin
 
Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Viet-Dung TRINH
 
Cassandra and Rails at LA NoSQL Meetup
Cassandra and Rails at LA NoSQL MeetupCassandra and Rails at LA NoSQL Meetup
Cassandra and Rails at LA NoSQL MeetupMichael Wynholds
 
C* Summit 2013: Cassandra at Instagram by Rick Branson
C* Summit 2013: Cassandra at Instagram by Rick BransonC* Summit 2013: Cassandra at Instagram by Rick Branson
C* Summit 2013: Cassandra at Instagram by Rick BransonDataStax Academy
 
Distributed Applications with Apache Zookeeper
Distributed Applications with Apache ZookeeperDistributed Applications with Apache Zookeeper
Distributed Applications with Apache ZookeeperAlex Ehrnschwender
 
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...ScyllaDB
 
Designing Scalable and Extendable Data Pipeline for Call Of Duty Games
Designing Scalable and Extendable Data Pipeline for Call Of Duty GamesDesigning Scalable and Extendable Data Pipeline for Call Of Duty Games
Designing Scalable and Extendable Data Pipeline for Call Of Duty GamesYaroslav Tkachenko
 
Background Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbitBackground Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbitRedis Labs
 
Percona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationPercona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationMydbops
 
Scaling Twitter with Cassandra
Scaling Twitter with CassandraScaling Twitter with Cassandra
Scaling Twitter with CassandraRyan King
 
Introduction to apache zoo keeper
Introduction to apache zoo keeper Introduction to apache zoo keeper
Introduction to apache zoo keeper Omid Vahdaty
 

Mais procurados (20)

Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3
 
Cassandra Summit 2015: Intro to DSE Search
Cassandra Summit 2015: Intro to DSE SearchCassandra Summit 2015: Intro to DSE Search
Cassandra Summit 2015: Intro to DSE Search
 
Cassandra Community Webinar: Apache Cassandra Internals
Cassandra Community Webinar: Apache Cassandra InternalsCassandra Community Webinar: Apache Cassandra Internals
Cassandra Community Webinar: Apache Cassandra Internals
 
Cassandra and Spark
Cassandra and Spark Cassandra and Spark
Cassandra and Spark
 
Bay area Cassandra Meetup 2011
Bay area Cassandra Meetup 2011Bay area Cassandra Meetup 2011
Bay area Cassandra Meetup 2011
 
Building Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::ClientBuilding Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::Client
 
Introduction to .Net Driver
Introduction to .Net DriverIntroduction to .Net Driver
Introduction to .Net Driver
 
How you can contribute to Apache Cassandra
How you can contribute to Apache CassandraHow you can contribute to Apache Cassandra
How you can contribute to Apache Cassandra
 
Building a High-Performance Distributed Task Queue on MongoDB
Building a High-Performance Distributed Task Queue on MongoDBBuilding a High-Performance Distributed Task Queue on MongoDB
Building a High-Performance Distributed Task Queue on MongoDB
 
Apache Cassandra, part 3 – machinery, work with Cassandra
Apache Cassandra, part 3 – machinery, work with CassandraApache Cassandra, part 3 – machinery, work with Cassandra
Apache Cassandra, part 3 – machinery, work with Cassandra
 
Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016
 
Cassandra and Rails at LA NoSQL Meetup
Cassandra and Rails at LA NoSQL MeetupCassandra and Rails at LA NoSQL Meetup
Cassandra and Rails at LA NoSQL Meetup
 
C* Summit 2013: Cassandra at Instagram by Rick Branson
C* Summit 2013: Cassandra at Instagram by Rick BransonC* Summit 2013: Cassandra at Instagram by Rick Branson
C* Summit 2013: Cassandra at Instagram by Rick Branson
 
Distributed Applications with Apache Zookeeper
Distributed Applications with Apache ZookeeperDistributed Applications with Apache Zookeeper
Distributed Applications with Apache Zookeeper
 
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
 
Designing Scalable and Extendable Data Pipeline for Call Of Duty Games
Designing Scalable and Extendable Data Pipeline for Call Of Duty GamesDesigning Scalable and Extendable Data Pipeline for Call Of Duty Games
Designing Scalable and Extendable Data Pipeline for Call Of Duty Games
 
Background Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbitBackground Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbit
 
Percona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationPercona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL Administration
 
Scaling Twitter with Cassandra
Scaling Twitter with CassandraScaling Twitter with Cassandra
Scaling Twitter with Cassandra
 
Introduction to apache zoo keeper
Introduction to apache zoo keeper Introduction to apache zoo keeper
Introduction to apache zoo keeper
 

Destaque

Cassandra DataTables Using RESTful API
Cassandra DataTables Using RESTful APICassandra DataTables Using RESTful API
Cassandra DataTables Using RESTful APISimran Kedia
 
Cassandra at NoSql Matters 2012
Cassandra at NoSql Matters 2012Cassandra at NoSql Matters 2012
Cassandra at NoSql Matters 2012jbellis
 
Cassandra NodeJS driver & NodeJS Paris
Cassandra NodeJS driver & NodeJS ParisCassandra NodeJS driver & NodeJS Paris
Cassandra NodeJS driver & NodeJS ParisDuyhai Doan
 
Using Cassandra with your Web Application
Using Cassandra with your Web ApplicationUsing Cassandra with your Web Application
Using Cassandra with your Web Applicationsupertom
 
Application Development with Apache Cassandra as a Service
Application Development with Apache Cassandra as a ServiceApplication Development with Apache Cassandra as a Service
Application Development with Apache Cassandra as a ServiceWSO2
 
NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayEdureka!
 
Developing with Cassandra
Developing with CassandraDeveloping with Cassandra
Developing with CassandraSperasoft
 

Destaque (7)

Cassandra DataTables Using RESTful API
Cassandra DataTables Using RESTful APICassandra DataTables Using RESTful API
Cassandra DataTables Using RESTful API
 
Cassandra at NoSql Matters 2012
Cassandra at NoSql Matters 2012Cassandra at NoSql Matters 2012
Cassandra at NoSql Matters 2012
 
Cassandra NodeJS driver & NodeJS Paris
Cassandra NodeJS driver & NodeJS ParisCassandra NodeJS driver & NodeJS Paris
Cassandra NodeJS driver & NodeJS Paris
 
Using Cassandra with your Web Application
Using Cassandra with your Web ApplicationUsing Cassandra with your Web Application
Using Cassandra with your Web Application
 
Application Development with Apache Cassandra as a Service
Application Development with Apache Cassandra as a ServiceApplication Development with Apache Cassandra as a Service
Application Development with Apache Cassandra as a Service
 
NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin Way
 
Developing with Cassandra
Developing with CassandraDeveloping with Cassandra
Developing with Cassandra
 

Semelhante a Cassandra Java APIs Old and New – A Comparison

Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by ScyllaScylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by ScyllaScyllaDB
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQLSatoshi Nagayasu
 
Trivadis TechEvent 2016 Big Data Cassandra, wieso brauche ich das? by Jan Ott
Trivadis TechEvent 2016 Big Data Cassandra, wieso brauche ich das? by Jan OttTrivadis TechEvent 2016 Big Data Cassandra, wieso brauche ich das? by Jan Ott
Trivadis TechEvent 2016 Big Data Cassandra, wieso brauche ich das? by Jan OttTrivadis
 
Big data analytics with Spark & Cassandra
Big data analytics with Spark & Cassandra Big data analytics with Spark & Cassandra
Big data analytics with Spark & Cassandra Matthias Niehoff
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentationMurat Çakal
 
SparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsSparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsDatabricks
 
Chicago Kafka Meetup
Chicago Kafka MeetupChicago Kafka Meetup
Chicago Kafka MeetupCliff Gilmore
 
How to use the new Domino Query Language
How to use the new Domino Query LanguageHow to use the new Domino Query Language
How to use the new Domino Query LanguageTim Davis
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Michael Renner
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentationMichael Keane
 
Writing Continuous Applications with Structured Streaming Python APIs in Apac...
Writing Continuous Applications with Structured Streaming Python APIs in Apac...Writing Continuous Applications with Structured Streaming Python APIs in Apac...
Writing Continuous Applications with Structured Streaming Python APIs in Apac...Databricks
 
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...DataStax
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersBen van Mol
 
Lambda at Weather Scale - Cassandra Summit 2015
Lambda at Weather Scale - Cassandra Summit 2015Lambda at Weather Scale - Cassandra Summit 2015
Lambda at Weather Scale - Cassandra Summit 2015Robbie Strickland
 
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016DataStax
 
Real-Time Spark: From Interactive Queries to Streaming
Real-Time Spark: From Interactive Queries to StreamingReal-Time Spark: From Interactive Queries to Streaming
Real-Time Spark: From Interactive Queries to StreamingDatabricks
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in CassandraJairam Chandar
 

Semelhante a Cassandra Java APIs Old and New – A Comparison (20)

Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by ScyllaScylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL
 
Trivadis TechEvent 2016 Big Data Cassandra, wieso brauche ich das? by Jan Ott
Trivadis TechEvent 2016 Big Data Cassandra, wieso brauche ich das? by Jan OttTrivadis TechEvent 2016 Big Data Cassandra, wieso brauche ich das? by Jan Ott
Trivadis TechEvent 2016 Big Data Cassandra, wieso brauche ich das? by Jan Ott
 
Big data analytics with Spark & Cassandra
Big data analytics with Spark & Cassandra Big data analytics with Spark & Cassandra
Big data analytics with Spark & Cassandra
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentation
 
SparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsSparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDs
 
Chicago Kafka Meetup
Chicago Kafka MeetupChicago Kafka Meetup
Chicago Kafka Meetup
 
How to use the new Domino Query Language
How to use the new Domino Query LanguageHow to use the new Domino Query Language
How to use the new Domino Query Language
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentation
 
Presentation
PresentationPresentation
Presentation
 
Cassandra Overview
Cassandra OverviewCassandra Overview
Cassandra Overview
 
Writing Continuous Applications with Structured Streaming Python APIs in Apac...
Writing Continuous Applications with Structured Streaming Python APIs in Apac...Writing Continuous Applications with Structured Streaming Python APIs in Apac...
Writing Continuous Applications with Structured Streaming Python APIs in Apac...
 
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET Developers
 
Lambda at Weather Scale - Cassandra Summit 2015
Lambda at Weather Scale - Cassandra Summit 2015Lambda at Weather Scale - Cassandra Summit 2015
Lambda at Weather Scale - Cassandra Summit 2015
 
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
 
Cassandra training
Cassandra trainingCassandra training
Cassandra training
 
Real-Time Spark: From Interactive Queries to Streaming
Real-Time Spark: From Interactive Queries to StreamingReal-Time Spark: From Interactive Queries to Streaming
Real-Time Spark: From Interactive Queries to Streaming
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in Cassandra
 

Último

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 

Último (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

Cassandra Java APIs Old and New – A Comparison

  • 1. Cassandra Java APIs Old and New – A Comparison Shahryar Sedghi Toronto Cassandra User Group Sep. 18, 2013
  • 2. #TCUG 2 Who am I? www.linkedin.com/pub/shahryar-sedghi/1/439/420 @ shahryar.sedghi@parseix.com Founder at www.parseix.com • Did some work on IBM Hierarchical databases (IMS DB / DOS DL1) in late 70s early 80s • Worked extensively on IBM’s first (World’s first) relational Database (SQL/DS) in early 80s • Have worked with Oracle and DB2 for years (not as a DBA) • Started working on Cassandra, late 2011 (1.0.5) @parseix
  • 3. #TCUG 3 Disclaimer • Code samples used here except for Astyanax (that was just taken from the website) have worked once in a certain release of Cassandra. Only JDBC (modified) and new Java Driver have been tested with Cassandra 1.2
  • 4. #TCUG 4 Agenda • What a Java API for Cassandra needs? • A basic introduction to Cassandra data model • Thrift • Thrift based APIs • Binary Protocol • DATASTAX new Java API
  • 5. #TCUG 5 A Java Database API • Typically used in Java Application Servers – Thread Safe – Connection Pooling • When used with Cassandra – Tolerates database Machine/Network failure – Load balancing – Reconnects to the failed machine when its back • Together they should provide a highly available environment for Web apps without an expensive HA investment
  • 6. #TCUG 6 Cassandra Data Model at a Glance B A D K B1 Value11 B2 Value12 B3 Value13 B4 Value14 A1 Value21 A2 Value22 A3 Value23 D1 Value51 D2 Value52 D3 Value53 D4 Value54 D5 Value55 • Is a row key, by default (best practice) it is not sorted, it is sorted by hash of the Key • All columns of one row reside in one node • Is a column name, 2 billion distinct column names can be in one row • Columns are sorted by column name (Ascending or Descending) • Is a column value, it can be null or can be a different type for each column in each row. E.G. A1 can be an Integer and D1 can be a String • If all 1s and all 2s and all 3s, … (e.g., A1,B1, C1) column values carry the same data type, it can be used like a relational DB with CQL 2, better scalability and less functionality, but not the best use of Cassandra C C1 Value61 C2 Value62 D51 Value551 D52 Value552 D53 Value553 Super Column (Deprecated)
  • 7. #TCUG 7 Data Model -Composite Columns 122 11:firstName • We would like to model the following data structure: {deptartmentId Integer, employeeId Integer, firtName String, lastName String} 11:lastName 12:firstName 12:lastName 13:firstName 13:lastName departmentId 122, employeeId 11, 12 and 13 225 17:firstName 17:lastName 19:firstName 19:lastName departmentId 225, employeeId 17 and 19 • CQL3 create table department( departmentid int, employeeid int, firstname text, lastname text, PRIMARY KEY (departmentid , employeeid) ); • departmentId is called Partition key • employeeId is called Clustering key Logical Row Physical Row
  • 8. #TCUG 8 Thrift • An Apache Project • YaRPC (Remote Procedure Call) • Has an IDL (Interface Definition Language) like other RPCs • Language Neutral • Easier than many others to use • Good fit for early releases of Cassandra to support all sorts of clients – Apparently not every client works as well as Java and Python • Is RPC a good fit for database interaction? Yes and no • Cassandra thrift by default listens on 9160
  • 9. #TCUG 9 Thrift Importance for Cassandra • Any Clients, except new DATASTAX drivers for Java and .NET are using Thrift underneath – Including Hector, JDBC and Astyanax • Supports – Ring Discovery – Native access to Cassandra – CQL 2 – CQL 3 • JDBC and Astyanax may move to native driver in the future
  • 10. #TCUG 10 Thrift Example: Ring Discovery Ttransport transport = new TFramedTransport(new TSocket(“192.168.1.14", 9160)); TProtocol protocol = new TBinaryProtocol(transport); client = new Cassandra.Client(protocol); transport.open(); List<TokenRange> trList = client.describe_ring(“mydb"); TokenRange tr = trList.get(0); for(String endpoint: tr.getEndpoints()){ System.out.println(endpoint); }
  • 11. #TCUG 11 Thrift Example: Get All Row Keys ColumnParent columnParent = new ColumnParent(“xyz"); SlicePredicate predicate = new SlicePredicate(); predicate.setSlice_range(new SliceRange(ByteBuffer.wrap(new byte[0]), ByteBuffer.wrap(new byte[0]), false, 1)); // Here you can specify a slice KeyRange keyRange = new KeyRange(); //Get all keys, or set a range List<KeySlice> keySlices = client.get_range_slices(columnParent, predicate, keyRange, ConsistencyLevel.ONE); // or null in this case ArrayList<Integer> list = new ArrayList<Integer>(); for (KeySlice ks : keySlices) { list.add(ByteBuffer.wrap(ks.getKey()).getInt()); System.out.println(ByteBuffer.wrap(ks.getKey()).getInt()); }
  • 12. #TCUG 12 Hector • Most Commonly used Java API for Cassandra • Using Thrift underneath • Among the other features: – Connection Pooling – Ring Discovery and automatic Failover – automatic retry of downed hosts – automatic discovery of additional hosts in the cluster – suspension of hosts for a short period of time after several timeouts
  • 13. #TCUG 13 Hector Example: Read All RowKeys Cluster myCluster = HFactory.getOrCreateCluster(" MyCluster ", "127.0.0.1:9160"); ConfigurableConsistencyLevel ccl = new ConfigurableConsistencyLevel(); ccl.setDefaultReadConsistencyLevel(HConsistencyLevel.ONE); Keyspace myKeyspace = HFactory.createKeyspace(("MYDB", , myCluster, ccl); RangeSlicesQuery<Integer, Composite, String> rangeSlicesQuery = HFactory.createRangeSlicesQuery(myKeyspace, IntegerSerializer.get(), CompositeSerializer.get(), StringSerializer.get()); QueryResult<OrderedRows<Integer, Composite, String>> result = rangeSlicesQuery.setColumnFamily(CF).setKeys(0, -1).setReturnKeysOnly().execute(); OrderedRows<Integer, Composite, String> orderedRows = result.get(); ArrayList<Integer> list = new ArrayList<Integer>(); for(Row<Integer, Composite, String> row: orderedRows){ list.add(row.getKey()); }
  • 14. #TCUG 14 Astyanax • Developed by Netflix • Supports all Hector functions, much easier • Much better connection pool and failover than Hector • More than an API for Cassandra – Provides some database functionality at the API level, called Recipes • Parallel all rows query • Message Queue • Chunked Object Store • many more • Utilities – JSON Writer, CVS Importer • Netflix expressed the plan to move to binary protocol at Cassandra Summit 2013
  • 15. #TCUG 15 Astyanax Example: Pagination ColumnList<String> columns; int pageize = 10; try { RowQuery<String, String> query = keyspace .prepareQuery(CF_STANDARD1) .getKey("A") .setIsPaginating() .withColumnRange(new RangeBuilder().setMaxSize(pageize).build()); while (!(columns = query.execute().getResult()).isEmpty()) { for (Column<String> c : columns) { // do something like c.getStringValue() } } } catch (ConnectionException e) { }
  • 16. #TCUG 16 JDBC(Java Database Connectivity) • Standard Java Database API • Only supports CQL to access Cassandra • Current Cassandra JDBC driver is a shallow implementation of JDBC on top of Thrift • URL is like: – jdbc:cassandra://192.168.1.5:9160?version=3.0.0 • All Java Application Servers support connection pooling for JDBC • No database failover and Cassandra Cluster support • Helps to convert relational database apps to Cassandra
  • 17. #TCUG 17 JDBC Example: Insert • This code can run in a Servlet or an “EJB”!!! with some minor modification • Nothing in this code points to Cassandra or Thrift classes • insertQuery for CQL is not always as simple as this Context envCtx = (Context) new InitialContext().lookup("java:comp/env"); DataSource datasource = (DataSource) envCtx.lookup("jdbc/cassandra"); Connection cqlCon = datasource.getConnection(); String insertQuery = "INSERT INTO department(departmentid, employeeid, firstname, lastname) VALUES ( ?, ?, ? )"; PreparedStatment statement = cqlCon.prepareStatement(insertQuery); statement.setInt(1, 122); statement.setInt(2, 11); statement.setString(3, "John"); statement.setString(4, "Doe"); statement.close(); cqlCon.close();
  • 18. #TCUG 18 Cassandra Binary Protocol • Inherently asynchronous – Can be used synchronously as well • Frame and stream based – Many Request with different Stream id can be sent asynchronously – A set of frames belong to the same stream coming from the server • Certain events are pushed from the server – Topology change – Status Change – Schema change • Because of the asynchronous nature, can easily be integrated with new technologies like WebSockets and Servlet 3.0, 3.1 • Listens on port 9042
  • 19. #TCUG 19 DATASTAX Java Driver • Implements the Binary Protocol client side • Similar to JDBC but easier in certain areas – Specific to Cassandra, not portable • Supports CQL and plan to support OO and DB APIs • Supports – Query Builder (who wants this?) – Node Discovery – Connection pooling – Reconnection policies – Load balancing policies – Retry policies • Cursor support announced during Cassandra Summit 2013
  • 20. #TCUG 20 DATASTAX Java Driver : Cluster and Session Cluster cluster = Cluster.builder().addContactPoint( "192.168.1.14","192.168.1.15"). withRetryPolicy(DowngradingConsistencyRetryPolicy. INSTANCE). withReconnectionPolicy(new ConstantReconnectionPolicy(1000L)). withLoadBalancingPolicy(new DCAwareRoundRobinPolicy("DC1")). withCredentials("myuser", "mypassword“).build(); Session session = cluster.connect(("mykeyspace"));
  • 21. #TCUG 21 DATASTAX Java Driver Example: Select String selectQuery = "select * from department where departmentid = ? "; PreparedStatment statement = session.prepare(selectQuery); statement.setConsistencyLevel(ConsistencyLevel.ONE); BoundStatement query = statement.bind(122); ResultSet result = session.execute(query); // you can do async here and // get a Future instead for(Row row:result){ System.out.println(row.getInt("employeeid")); System.out.println(row.getString(“firstname")); System.out.println(row.getString(“lastname")); }
  • 22. #TCUG 22 References • Thrift http://wiki.apache.org/cassandra/ThriftExamples • Hector http://hector-client.github.io/hector/build/html/index.html • Astyanax https://github.com/Netflix/astyanax/wiki • JDBC http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/ • DATASTAX Java Driver http://www.datastax.com/documentation/developer/java-driver/1.0/webhelp/index.html – YouTube Presentation, Cassandra Summit 2013 http://www.youtube.com/watch?v=fZfLQABJxuc – Slideshare, Cassandra Summit 2013 http://www.slideshare.net/planetcassandra/cassandra-summit-data-stax-java-driver – Mailing list client-dev@cassandra.apache.org , enroll at http://cassandra.apache.org/