Download presentation
Presentation is loading. Please wait.
1
Apache Cassandra for the SQLServer DBA
2
It’s all about me...
3
Case studies
4
History Originally developed at Facebook for its Inbox Search feature
Released to Google Code as open source in 2006 Became an Apache Incubator project in 2008 Top-level project in 2010 Named after a character from geek Greek mythology (something about a curse on an Oracle)
5
CAP theorem Cassandra is “AP” Not to say that C isn’t possible
Consistency is ‘tune-able’ Consistency Availability Partition tolerance 5
6
Peer-to-peer Cluster Nodes Token Ranges / vNodes 6
7
Token Assignment Token ranges
8
Availability / Tolerance
1 - 20 24 F 78 K 24 F RF = 3 78 K 24 F 78 K
9
Consistency Levels ALL – All replicas must respond
ANY – Closest available replica ONE – Closest available repl… wait….what ??!?? QUORUM – for RF3, 2 out of 3 LOCAL_QUORUM – for RF3, 2 out of…. wait… not again ??!!?? …plus some others that are less easy to describe…. ANY is for write consistency, ONE is for read.
10
Consistency ALL A ! A ! 32 = A ? A !
11
Consistency ONE A ! A ! 32 = A? A !
12
Consistency QUORUM B ! A ! 32=B ? B !
13
Write path Commit Log Data MemTable SSTable
14
Write path 1 A 2 B 4 c 1 A 2 B 3 A 4 c 1 A 2 B 3 A 5 F 4 c 5 F 5 F 4 c
15
Compaction Worth mentioning here, so I have
Quite complex to cover in less than an hour Optimises SStables based on Level, Size-tier (default), or Time- Window strategies Has a major impact on your storage requirements It happens…
16
Demo – Creating a keyspace
17
Design for speed Table per query Partition per query
18
CQL “SELECT * FROM ?? WHERE x = “ INSERT UPDATE DELETE
…it’s quite simple, really…
19
Simple datatypes 17 data types, 12 of which are most common CQL Type
Constants Description bigint integers 64-bit signed long counter Distributed counter value (64-bit long) float integers, floats 32-bit IEEE-754 floating point Java type int 32-bit signed integer text strings UTF-8 encoded string timestamp integers, strings Date plus time, encoded as 8 bytes since epoch (01/01/1970) timeuuid uuids Type 1 UUID only uuid A UUID in standard UUID format varchar list n/a A collection of one or more ordered elements map A JSON-style array of literals: { literal : literal, literal : literal ... } set A collection of one or more elements
20
Consider this table… CREATE TABLE pubs (id INT, title TEXT,
author TEXT, genre TEXT, published INT, PRIMARY KEY (id) );
21
Cassandra data layout Cells Key Value Partitions Partition Key
22
Primary Key determines partition key
PRIMARY KEY (id)
23
Composite Partition Keys
CREATE TABLE pubs_by_title_year (title TEXT, author TEXT, genre TEXT, published INT, PRIMARY KEY ((title, published)) ); Note double brackets on PRIMARY KEY – we’ll come on to that later. 25
24
Clustering columns CREATE TABLE pubs_by_year_title (published INT, title TEXT, author TEXT, genre TEXT, id INT, PRIMARY KEY ((published), title) ); Clustering columns need to be part of the Primary Key to be searchable, but not part of the Partition Key. They divide the rows between the partitions. 26
25
Effect on layout 2014 I did DBCC you coming : author
I did DBCC you coming : Genre O. DeeBeaSea Horror Slow train to SOS_Scheduler : author Slow train to SOS_Scheduler : Genre R.T. Fishall Humour 2015 Mamma Mia ! That index… !! : author Mamma Mia ! That index… !! : Genre Richard Munn Horror Plan the plan's planny plan : author Plan the plan's planny plan : Genre A. Noob Management
26
Demo – creating tables and adding data
27
Things to remember INSERT vs. UPDATE Tombstones
Garbage collection removes tombstoned records – default interval 10 days. Cleaned up on compaction Hinted hand-off Anti-entropy operations (read-repair)
28
Things you can’t do JOIN * Use Foreign Keys Implement 3rd Normal form
Actually, throw away any thought of normalisation Add additional indexes * Create Stored Procedures – use BATCH instead Maths (except min, max, avg, sum, and count) Use non-key columns as search predicates
29
Demo - Let’s do some shenanigans….
30
exit;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.