5. Cursors
Before - manual paging
• Have to keep track of position
• Complex for compound
primary keys
CREATE TABLE timeline (
...
PRIMARY KEY (uid, event_id)
);
SELECT * FROM timeline
WHERE (uid = :last_key
AND event_id > :last_event)
OR token(uid) >
token(:last_key)
LIMIT 100;
6. Cursors
Now
Statement s = new SimpleStatement(‚SELECT * FROM timeline‛);
s.setFetchSize(100);
// transparently fetches next pages
ResultSet result = session.execute(s);
for (Row row : result) {
dooStuff(row);
}
7. Cursors
Now
Statement s = new SimpleStatement(‚SELECT * FROM timeline‛);
s.setFetchSize(100);
// transparently fetches next pages
ResultSet result = session.execute(s);
for (Row row : result) {
dooStuff(row);
// x2
}
13. CQL3
• SELECT DISTINCT partition_key;
• CREATE TABLE IF NOT EXISTS tbl_name;
• Aliases
SELECT event_id, dateOf(created_at) AS creation_date;
14. CQL3
• SELECT DISTINCT partition_key;
• CREATE TABLE IF NOT EXISTS tbl_name;
• Aliases
SELECT event_id, dateOf(created_at) AS creation_date
• ALTER TABLE tbl DROP column_name;
15. Lightweight Transactions
SESSION 1
SESSION 2
SELECT * FROM users
WHERE USERNAME = ‘lyuben’;
SELECT * FROM users
WHERE USERNAME = ‘lyuben’;
[empty resultset]
[empty resultset]
INSERT INTO users (...)
VALUES (‘lyubent’, ...)
INSERT INTO users (...)
VALUES (‘lyubent’, ...)
Last write wins.
User
exists?
If not,
create
user
20. Paxos
A family of protocols for solving consensus
in a network of unreliable processors.
Wikipedia
21. Paxos
• Immediate Consistency
• QUARUM based operations
• Unfinished operations’ states sent to leader
during prepare phase
• Paxos state is durable
22. LWT – Use when Appropriate
• Expensive – x4 round trips
• Eventual consistency is your friend
23. Lightweight Transactions – CQL
INSERT INTO USERS (username, email ...)
VALUES (‘lyuben’, ‘ltodorov@datastax.com’, ... )
IF NOT EXISTS;
26. Tracing
• Detailed view of what’s going on
• Great for debugging queries
cqlsh:test> TRACING ON;
Now tracing requests.
27. Tracing insert
cqlsh:test> INSERT INTO example (i, j) VALUES ('key', 7);
Tracing session: 69fc9cb0-4fb3-11e3-84ae-612d9c5d36d9
activity
| timestamp
| source
| source_elapsed
------------------------------------+--------------+-----------+---------------Determining replicas for mutation | 18:09:34,722 | 127.0.0.1 |
3507
Sending message to /127.0.0.2 | 18:09:34,724 | 127.0.0.1 |
5720
Acquiring switchLock read lock | 18:09:34,732 | 127.0.0.2 |
6043
Appending to commitlog | 18:09:34,732 | 127.0.0.2 |
6305
Adding to example memtable | 18:09:34,732 | 127.0.0.2 |
6373
Enqueuing response to /127.0.0.1 | 18:09:34,733 | 127.0.0.2 |
6978
Message received from /127.0.0.2 | 18:09:34,737 | 127.0.0.1 |
19055
Processing response from /127.0.0.2 | 18:09:34,738 | 127.0.0.1 |
19993
Request complete | 18:09:34,739 | 127.0.0.1 |
20322
28. Tracing tombstone
cqlsh:test> SELECT * FROM example;
Tracing session: 79d55380-4fb7-11e3-9ac8-612d9c5d36d9
activity
| timestamp
| source
| source_elapsed
-----------------------------------------+--------------+-----------+--------------...
Sending message to /127.0.0.2 | 18:38:39,291 | 127.0.0.1 |
601
Read 10 live and 100000 tombstoned cells | 18:38:39,291 | 127.0.0.2 |
31655
Scanned 1 rows and matched 1 | 18:38:39,292 | 127.0.0.2 |
31693
Message received from /127.0.0.2 | 18:38:39,292 | 127.0.0.1 |
33150
Enqueuing response to /127.0.0.1 | 18:38:39,292 | 127.0.0.2 |
33724
Processing response from /127.0.0.2 | 18:38:39,292 | 127.0.0.1 |
34704
Sending message to /127.0.0.1 | 18:38:39,292 | 127.0.0.2 |
35220
...
29. Row Marker
CREATE TABLE tbl (
key int,
a text,
b text,
PRIMARY KEY (key)
);
UPDATE tbl SET a=null, b=null WHERE key=1;
DELETE FROM tbl where key=2;
33. Rapid Read Protection
Configuring rapid read protection
# retry if request takes longer than 10ms
ALTER TABLE example WITH speculative_retry = '10ms';
# retry if request takes longer then 99% of requests
ALTER TABLE example WITH speculative_retry = '99percentile';
36. Going Off Heap
• Bloom Filters
1 - 2GB per billion entries
• Compression Offsets
1 - 3GB per TB of compressed data
37. Going Off Heap
• Bloom Filters
1 - 2GB per billion entries
• Compression Offsets
1 - 3GB per TB of compressed data
• Partition Summary
Depends on # of rows per partition