SlideShare a Scribd company logo
@AYeschenko
Aleksey Yeschenko
Apache Cassandra Committer, Engineer @DataStax
What’s New in Cassandra 2.0
What’s new in Cassandra 2.0
• Lightweight transactions (CAS)
• Eager retries
• Native protocol V2
• Notable Internal improvements
• New CQL3 features
• Triggers (prototype!)
CAS
CAS: When
SELECT * FROM users
WHERE username = ’jbellis’
[empty resultset]
INSERT INTO users (...)
VALUES (’jbellis’, ...)
Session 1
SELECT * FROM users
WHERE username = ’jbellis’
[empty resultset]
INSERT INTO users (...)
VALUES (’jbellis’, ...)
Session 2
When you absolutely require linearizable consistency
(think - safely creating a user with a unique username)
CAS: How
• Based on the Paxos consensus protocol
• Paxos state is durable
• All operations are quorum-based
• Immediate consistency with no leader election or failover
• Relatively expensive - requires 4 round trips vs. 1 for regular
updates. Use only in the parts of your application where it’s really
needed
• ConsistencyLevel.SERIAL
CAS: CQL3
// Insert a user with a unique username
INSERT INTO USERS (username, email, name)
VALUES ('jbellis', 'jbellis@datastax.com', 'Jonathan Ellis')
IF NOT EXISTS
// Reset user’s password transactionally
UPDATE users
SET reset_token = null AND password = ‘newpassword’
IF reset_token = ‘some-generated-reset-token’
CAS: Further Reading
• http://www.datastax.com/dev/blog/lightweight-transactions-in-
cassandra-2-0
• Paxos Made Simple: http://www.cs.utexas.edu/users/lorenzo/
corsi/cs380d/past/03F/notes/paxos-simple.pdf
• http://the-paper-trail.org/blog/consensus-protocols-paxos/
Eager Retries
Eager Retries
• New per-table setting: speculative_retry (NONE|Xpercentile|Xms|
ALWAYS)
• Will issue extra read commands to other replicas behind the scenes
if the current one(s) isn’t (aren’t) responding within the configured
milliseconds/percentile
• Minimizes read latencies, reduces the occurrence of read timeouts
if one or several of the replicas crash or become overloaded
• https://issues.apache.org/jira/browse/CASSANDRA-4705
Native Proto V2
Native Proto V2
• Paging (cursors)
• Batching prepared statements
• Parametrized statements without the explicit prepare phase
Native Proto V2: Paging
Statement stmt = new SimpleStatement("SELECT * FROM images");
stmt.setFetchSize(100);
ResultSet result = session.execute(stmt);
// Iterate over the ResultSet here (will transparently fetch new pages)
for (Row row : result) {
handleRow(row);
}
Native Proto V2: Paging
Native Proto V2: Paging
• Paging state = last seen partition key + last seen cell name +
remaining, opaque
• https://issues.apache.org/jira/browse/CASSANDRA-4415
Native Proto V2: Batching Prepared
PreparedStatement ps = session.prepare("INSERT INTO messages (user_id, msg_id,
title, body) VALUES (?, ?, ?, ?)");
BatchStatement batch = new BatchStatement();
batch.add(ps.bind(uid, mid1, title1, body1));
batch.add(ps.bind(uid, mid2, title2, body2));
batch.add(ps.bind(uid, mid3, title3, body3));
session.execute(batch);
Native Proto V2: Batching Prepared
• Variable statements count
• Can mix prepared and non-prepared statements in a single batch
• Fast
• https://issues.apache.org/jira/browse/CASSANDRA-4693
Native Proto V2: Parametrized Queries
// execute(String query, Object... values)
// executeAsync(String query, Object... values)
session.execute(
"INSERT INTO images (image_id, title, bytes) VALUES (?, ?, ?)",
imageId, imageTitle, imageBytes
);
Native Proto V2: Parametrized Queries
• One-off prepare+execute w/out the explicit prepare phase
• No need to escape the values
• No need to serialize non-string data as strings
• Esp. handy for blobs
• https://issues.apache.org/jira/browse/CASSANDRA-5349
(Some) Notable Internal Improvements
• Rewritten Streaming (CASSANDRA-5286)
• Tracking max/min values on clustering columns for optimized
reads (CASSANDRA-5514)
• Single pass compaction roughly doubling compaction speed for
large partitions (CASSANDRA-4180)
• Size-tiered compaction for LCS L0 when it gets behind
(CASSANDRA-5371)
• Default LCS sstable size increased to 160MB (from 5MB)
(CASSANDRA-5727)
• http://www.datastax.com/dev/blog/whats-under-the-hood-in-
cassandra-2-0
New CQL3 Features
New CQL3 Features
• ALTER TABLE DROP
• 2i on PRIMARY KEY columns
• Preparing TIMESTAMP, TTL and LIMIT
• Listing partition keys
CQL3: ALTER TABLE DROP
ALTER TABLE <table> DROP <column>;
// Immediately removes the column from table’s metadata
// Lazily gets rid of the data during compaction
CQL3: 2i on PRIMARY KEY columns
CREATE TABLE timeline (
event_id uuid,
week_in_year int,
created_at timeuuid,
content blob,
PRIMARY KEY ((event_id, week_in_year), created_at)
);
-- Invalid in C* 1.2, valid now in C* 2.0:
CREATE INDEX ON demo (event_id);
CREATE INDEX ON demo (week_in_year);
CREATE INDEX ON demo (created_at);
CQL3: Preparing Query Options
// Preparing LIMIT
session.prepare("SELECT * FROM foo LIMIT ?");
// Preparing TIMESTAMP and TTL
session.prepare("UPDATE foo USING TIMESTAMP ? AND TTL ? SET bar = ? WHERE baz = ?");
CQL3: Listing Partition Keys
SELECT event_id, week_in_year FROM timeline;
event_id | week_in_year
--------------------------------------+--------------
b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 1
b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 1
eb58d408-b264-41b9-928e-dd6c0e52888e | 1
eb58d408-b264-41b9-928e-dd6c0e52888e | 1
b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 2
b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 2
SELECT DISTINCT event_id, week_in_year FROM timeline;
event_id | week_in_year
--------------------------------------+--------------
b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 1
eb58d408-b264-41b9-928e-dd6c0e52888e | 1
b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 2
Triggers (Prototype!)
Triggers Interface
public interface ITrigger
{
/**
* Called exactly once per CF update, returned mutations are atomically
updated.
*
* @param key - Row Key for the update.
* @param update - Update received for the CF
* @return modifications to be applied, null if no action to be performed.
*/
public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update);
}
Triggers DML
CREATE TRIGGER <name> ON <table> USING <classname>;
DROP TRIGGER <name> ON <table>;
Triggers Summary
• Prototype
• Relies on logged batches
• Exposes internal classes - RowMutation, ColumnFamily
• Expect changes in 2.1
• http://www.datastax.com/dev/blog/whats-new-in-
cassandra-2-0-prototype-triggers-support
Questions?

More Related Content

PDF
Cassandra 3.0 Awesomeness
PPTX
Cassandra 2.2 & 3.0
DOCX
Custom faultpolicies
PDF
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
PDF
Pycon 2012 Apache Cassandra
PDF
Investigation of Transactions in Cassandra
PDF
Sessionization with Spark streaming
PPTX
Investigation of Transactions in Cassandra
Cassandra 3.0 Awesomeness
Cassandra 2.2 & 3.0
Custom faultpolicies
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Pycon 2012 Apache Cassandra
Investigation of Transactions in Cassandra
Sessionization with Spark streaming
Investigation of Transactions in Cassandra

What's hot (18)

DOCX
Casestudy
PDF
React, Redux and es6/7
PDF
PGConf.ASIA 2017 Logical Replication Internals (English)
PDF
知っておきたいSpring Batch Tips
DOC
Flashback (Practical Test)
PPTX
Apache Spark Structured Streaming + Apache Kafka = ♡
PDF
Cassandra Data Modeling
PDF
Data Processing Inside PostgreSQL
 
PDF
MySQL Audit using Percona audit plugin and ELK
PDF
Zookeeper
PDF
Using Apache Spark to Solve Sessionization Problem in Batch and Streaming
PDF
MySQL 5.5 Guide to InnoDB Status
PDF
Cassandra summit 2013 - DataStax Java Driver Unleashed!
PPTX
Introduction to apache zoo keeper
PDF
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
PDF
Python and cassandra
PDF
An Introduction To PostgreSQL Triggers
PDF
Administering and Monitoring SolrCloud Clusters
Casestudy
React, Redux and es6/7
PGConf.ASIA 2017 Logical Replication Internals (English)
知っておきたいSpring Batch Tips
Flashback (Practical Test)
Apache Spark Structured Streaming + Apache Kafka = ♡
Cassandra Data Modeling
Data Processing Inside PostgreSQL
 
MySQL Audit using Percona audit plugin and ELK
Zookeeper
Using Apache Spark to Solve Sessionization Problem in Batch and Streaming
MySQL 5.5 Guide to InnoDB Status
Cassandra summit 2013 - DataStax Java Driver Unleashed!
Introduction to apache zoo keeper
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
Python and cassandra
An Introduction To PostgreSQL Triggers
Administering and Monitoring SolrCloud Clusters
Ad

Viewers also liked (17)

PDF
Isabelle: Not Only a Proof Assistant
PDF
A Framework for Secure Service Composition
PDF
Integrating Application Security into a Software Development Process
PDF
On the Static Analysis of Hybrid Mobile Apps: A Report on the State of Apache...
PPTX
Thermal power plant1
PDF
r3-4-2009f_xts5000_new
PPTX
Effluent treatment plants
PDF
Agile Secure Software Development in a Large Software Development Organisatio...
PPTX
Springs-mechanical engineering
PDF
Security Testing: Myths, Challenges, and Opportunities - Experiences in Integ...
PPTX
Self compacting concrete
PPTX
Sugar mill
PPTX
civil engineering-Contracts
PPTX
Sistem Persamaan Linear dua variable
PPTX
Dimensi Tiga
PPTX
Daur hidup virus
PPTX
Tugas presentasi system teknik informatika kelompok iii
Isabelle: Not Only a Proof Assistant
A Framework for Secure Service Composition
Integrating Application Security into a Software Development Process
On the Static Analysis of Hybrid Mobile Apps: A Report on the State of Apache...
Thermal power plant1
r3-4-2009f_xts5000_new
Effluent treatment plants
Agile Secure Software Development in a Large Software Development Organisatio...
Springs-mechanical engineering
Security Testing: Myths, Challenges, and Opportunities - Experiences in Integ...
Self compacting concrete
Sugar mill
civil engineering-Contracts
Sistem Persamaan Linear dua variable
Dimensi Tiga
Daur hidup virus
Tugas presentasi system teknik informatika kelompok iii
Ad

Similar to What's new in Cassandra 2.0 (20)

PPTX
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
PPTX
PDF
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
PPT
11thingsabout11g 12659705398222 Phpapp01
PPT
11 Things About11g
PDF
Stream Processing made simple with Kafka
PPTX
Oracle database 12.2 new features
PDF
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
DOCX
Custom faultpolicies
DOCX
Custom faultpolicies
PDF
ETL With Cassandra Streaming Bulk Loading
PDF
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
PPTX
NET Systems Programming Learned the Hard Way.pptx
PPTX
DBA Commands and Concepts That Every Developer Should Know - Part 2
PPTX
DBA Commands and Concepts That Every Developer Should Know - Part 2
PDF
PgQ Generic high-performance queue for PostgreSQL
PDF
Windowing in Kafka Streams and Flink SQL
PDF
Introduction to Kafka Streams
PDF
10 Reasons to Start Your Analytics Project with PostgreSQL
PDF
Introduction to-mongo db-execution-plan-optimizer-final
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
11thingsabout11g 12659705398222 Phpapp01
11 Things About11g
Stream Processing made simple with Kafka
Oracle database 12.2 new features
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
Custom faultpolicies
Custom faultpolicies
ETL With Cassandra Streaming Bulk Loading
Die Neuheiten in MariaDB 10.2 und MaxScale 2.1
NET Systems Programming Learned the Hard Way.pptx
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2
PgQ Generic high-performance queue for PostgreSQL
Windowing in Kafka Streams and Flink SQL
Introduction to Kafka Streams
10 Reasons to Start Your Analytics Project with PostgreSQL
Introduction to-mongo db-execution-plan-optimizer-final

Recently uploaded (20)

PPTX
Chapter 5: Probability Theory and Statistics
PDF
August Patch Tuesday
PPTX
1. Introduction to Computer Programming.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Mushroom cultivation and it's methods.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Hybrid model detection and classification of lung cancer
PDF
Encapsulation theory and applications.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Web App vs Mobile App What Should You Build First.pdf
Chapter 5: Probability Theory and Statistics
August Patch Tuesday
1. Introduction to Computer Programming.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
A Presentation on Artificial Intelligence
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
OMC Textile Division Presentation 2021.pptx
Mushroom cultivation and it's methods.pdf
cloud_computing_Infrastucture_as_cloud_p
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Programs and apps: productivity, graphics, security and other tools
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Hybrid model detection and classification of lung cancer
Encapsulation theory and applications.pdf
A novel scalable deep ensemble learning framework for big data classification...
Hindi spoken digit analysis for native and non-native speakers
Web App vs Mobile App What Should You Build First.pdf

What's new in Cassandra 2.0

  • 1. @AYeschenko Aleksey Yeschenko Apache Cassandra Committer, Engineer @DataStax What’s New in Cassandra 2.0
  • 2. What’s new in Cassandra 2.0 • Lightweight transactions (CAS) • Eager retries • Native protocol V2 • Notable Internal improvements • New CQL3 features • Triggers (prototype!)
  • 3. CAS
  • 4. CAS: When SELECT * FROM users WHERE username = ’jbellis’ [empty resultset] INSERT INTO users (...) VALUES (’jbellis’, ...) Session 1 SELECT * FROM users WHERE username = ’jbellis’ [empty resultset] INSERT INTO users (...) VALUES (’jbellis’, ...) Session 2 When you absolutely require linearizable consistency (think - safely creating a user with a unique username)
  • 5. CAS: How • Based on the Paxos consensus protocol • Paxos state is durable • All operations are quorum-based • Immediate consistency with no leader election or failover • Relatively expensive - requires 4 round trips vs. 1 for regular updates. Use only in the parts of your application where it’s really needed • ConsistencyLevel.SERIAL
  • 6. CAS: CQL3 // Insert a user with a unique username INSERT INTO USERS (username, email, name) VALUES ('jbellis', 'jbellis@datastax.com', 'Jonathan Ellis') IF NOT EXISTS // Reset user’s password transactionally UPDATE users SET reset_token = null AND password = ‘newpassword’ IF reset_token = ‘some-generated-reset-token’
  • 7. CAS: Further Reading • http://www.datastax.com/dev/blog/lightweight-transactions-in- cassandra-2-0 • Paxos Made Simple: http://www.cs.utexas.edu/users/lorenzo/ corsi/cs380d/past/03F/notes/paxos-simple.pdf • http://the-paper-trail.org/blog/consensus-protocols-paxos/
  • 9. Eager Retries • New per-table setting: speculative_retry (NONE|Xpercentile|Xms| ALWAYS) • Will issue extra read commands to other replicas behind the scenes if the current one(s) isn’t (aren’t) responding within the configured milliseconds/percentile • Minimizes read latencies, reduces the occurrence of read timeouts if one or several of the replicas crash or become overloaded • https://issues.apache.org/jira/browse/CASSANDRA-4705
  • 11. Native Proto V2 • Paging (cursors) • Batching prepared statements • Parametrized statements without the explicit prepare phase
  • 12. Native Proto V2: Paging Statement stmt = new SimpleStatement("SELECT * FROM images"); stmt.setFetchSize(100); ResultSet result = session.execute(stmt); // Iterate over the ResultSet here (will transparently fetch new pages) for (Row row : result) { handleRow(row); }
  • 14. Native Proto V2: Paging • Paging state = last seen partition key + last seen cell name + remaining, opaque • https://issues.apache.org/jira/browse/CASSANDRA-4415
  • 15. Native Proto V2: Batching Prepared PreparedStatement ps = session.prepare("INSERT INTO messages (user_id, msg_id, title, body) VALUES (?, ?, ?, ?)"); BatchStatement batch = new BatchStatement(); batch.add(ps.bind(uid, mid1, title1, body1)); batch.add(ps.bind(uid, mid2, title2, body2)); batch.add(ps.bind(uid, mid3, title3, body3)); session.execute(batch);
  • 16. Native Proto V2: Batching Prepared • Variable statements count • Can mix prepared and non-prepared statements in a single batch • Fast • https://issues.apache.org/jira/browse/CASSANDRA-4693
  • 17. Native Proto V2: Parametrized Queries // execute(String query, Object... values) // executeAsync(String query, Object... values) session.execute( "INSERT INTO images (image_id, title, bytes) VALUES (?, ?, ?)", imageId, imageTitle, imageBytes );
  • 18. Native Proto V2: Parametrized Queries • One-off prepare+execute w/out the explicit prepare phase • No need to escape the values • No need to serialize non-string data as strings • Esp. handy for blobs • https://issues.apache.org/jira/browse/CASSANDRA-5349
  • 19. (Some) Notable Internal Improvements • Rewritten Streaming (CASSANDRA-5286) • Tracking max/min values on clustering columns for optimized reads (CASSANDRA-5514) • Single pass compaction roughly doubling compaction speed for large partitions (CASSANDRA-4180) • Size-tiered compaction for LCS L0 when it gets behind (CASSANDRA-5371) • Default LCS sstable size increased to 160MB (from 5MB) (CASSANDRA-5727) • http://www.datastax.com/dev/blog/whats-under-the-hood-in- cassandra-2-0
  • 21. New CQL3 Features • ALTER TABLE DROP • 2i on PRIMARY KEY columns • Preparing TIMESTAMP, TTL and LIMIT • Listing partition keys
  • 22. CQL3: ALTER TABLE DROP ALTER TABLE <table> DROP <column>; // Immediately removes the column from table’s metadata // Lazily gets rid of the data during compaction
  • 23. CQL3: 2i on PRIMARY KEY columns CREATE TABLE timeline ( event_id uuid, week_in_year int, created_at timeuuid, content blob, PRIMARY KEY ((event_id, week_in_year), created_at) ); -- Invalid in C* 1.2, valid now in C* 2.0: CREATE INDEX ON demo (event_id); CREATE INDEX ON demo (week_in_year); CREATE INDEX ON demo (created_at);
  • 24. CQL3: Preparing Query Options // Preparing LIMIT session.prepare("SELECT * FROM foo LIMIT ?"); // Preparing TIMESTAMP and TTL session.prepare("UPDATE foo USING TIMESTAMP ? AND TTL ? SET bar = ? WHERE baz = ?");
  • 25. CQL3: Listing Partition Keys SELECT event_id, week_in_year FROM timeline; event_id | week_in_year --------------------------------------+-------------- b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 1 b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 1 eb58d408-b264-41b9-928e-dd6c0e52888e | 1 eb58d408-b264-41b9-928e-dd6c0e52888e | 1 b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 2 b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 2 SELECT DISTINCT event_id, week_in_year FROM timeline; event_id | week_in_year --------------------------------------+-------------- b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 1 eb58d408-b264-41b9-928e-dd6c0e52888e | 1 b27288fa-a4cd-4c1d-b0eb-55a8fe0f9ec0 | 2
  • 27. Triggers Interface public interface ITrigger { /** * Called exactly once per CF update, returned mutations are atomically updated. * * @param key - Row Key for the update. * @param update - Update received for the CF * @return modifications to be applied, null if no action to be performed. */ public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update); }
  • 28. Triggers DML CREATE TRIGGER <name> ON <table> USING <classname>; DROP TRIGGER <name> ON <table>;
  • 29. Triggers Summary • Prototype • Relies on logged batches • Exposes internal classes - RowMutation, ColumnFamily • Expect changes in 2.1 • http://www.datastax.com/dev/blog/whats-new-in- cassandra-2-0-prototype-triggers-support