Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Astyanax - Cassandra Client

McManCSU
September 04, 2013

Astyanax - Cassandra Client

Quick overview of Netflix' Astyanax with usage examples, CQL and composite keys.

McManCSU

September 04, 2013
Tweet

More Decks by McManCSU

Other Decks in Technology

Transcript

  1. • Java Client • Wraps Cassandra’s Thrift interface • Project

    began as Hector refactor • Connection Pooling • Round Robin, Token Aware, Bag of Connections • Fault tolerance, retry policies • Simplified API - ‘fluent API’ • Granular queries • CQL(3) • Recipes and Utilities • Common Patterns, etc Astyanax, the son of Hector Wednesday, September 4, 13
  2. Connection Pool • Context based • Automatic failover • Host

    partitioning - token ranges • Pluggable components • Host selection (RR, Latency, etc.) • Retry strategies • Discovery strategies • Implementations: RR, Token Aware, Bag of Connections Wednesday, September 4, 13
  3. Latency Awareness • Connection pool can be latency aware •

    Not by default • Node starts compacting, different rack might be faster • Pluggable implementations: • SMA/EMA included (Simple Moving Average or Exponential Moving Average) • SMA works well enough Wednesday, September 4, 13
  4. Fluent API • Operations based on Keyspace • Serializers embedded

    • Specify: ColumnFamily, Row, Column • CQL & CQL3 support • Specify R/W consistency levels Wednesday, September 4, 13
  5. Contexts, Keyspaces & Column Families, Oh My! Context Keyspace Column

    Family Row Column Row Column Column Row Column Column ‣Discovery ‣ Connection Pool ‣Num Connections ‣Type ‣ R/W Consistency, ‣Fault Tolerance ‣Replication Factor ‣Replication Strategy ‣Serializers ‣Rows and Columns ‣Schemaless(ish) Data! Column Each Circle contains 1 or more sub-circle Wednesday, September 4, 13
  6. Column Family • static ColumnFamily • Create on KeySpace •

    Serializers (data type) Wednesday, September 4, 13
  7. Column Family • static ColumnFamily • Create on KeySpace •

    Serializers (data type) ValueSerializer KeySerializer Wednesday, September 4, 13
  8. Column Family • static ColumnFamily • Create on KeySpace •

    Serializers (data type) Defined once Wednesday, September 4, 13
  9. Reading and Writing • Singular Write • Implicit Serialization •

    Batch Writes • Multi-key • Multi-column Wednesday, September 4, 13
  10. CQL(3) • Use Cassandra as if it was SQL •

    CREATE TABLE xxx (yyy, zzz) • SELECT xxx FROM yyy WHERE aaa = ‘bbb’; • DELETE xxx FROM yyy; • INSERT INTO xxx (yyy) VALUES (zzz) • CQL3 allows composite, primary keys! Wednesday, September 4, 13
  11. CQL(3) Example Queries CREATE TABLE results (searched_value varchar, searched_type varchar,

    st_name varchar, version varchar, last_update timestamp, result varchar, rawData varchar, statusCode varchar, statusText varchar, uri varchar, PRIMARY KEY (searched_value, searched_type, st_name, version)); INSERT INTO results (searched_value, searched_type, st_name, version, last_update, result, rawData, statusCode, statusText, uri) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?); SELECT * FROM results WHERE searched_value=? AND searched_type=? AND st_name=? AND version=?; Wednesday, September 4, 13
  12. CQL(3) Example Queries CREATE TABLE results (searched_value varchar, searched_type varchar,

    st_name varchar, version varchar, last_update timestamp, result varchar, rawData varchar, statusCode varchar, statusText varchar, uri varchar, PRIMARY KEY (searched_value, searched_type, st_name, version)); INSERT INTO results (searched_value, searched_type, st_name, version, last_update, result, rawData, statusCode, statusText, uri) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?); SELECT * FROM results WHERE searched_value=? AND searched_type=? AND st_name=? AND version=?; Composite Key Wednesday, September 4, 13