Apache Cassandra and Drivers

download Apache Cassandra and Drivers

of 63

  • date post

    14-Apr-2017
  • Category

    Technology

  • view

    1.752
  • download

    0

Embed Size (px)

Transcript of Apache Cassandra and Drivers

  • Apache Cassandra and DriversOverview of Apache Cassandra and DataStax Drivers

    Bulat Shakirzyanov@avalanche123

    Sandeep Tamhankar@stamhankar999

    https://goo.gl/cBsRVv

  • IntroductionCassandra Overview

  • 2015 DataStax, All Rights Reserved.

    Datacenter Datacenter

    Cassandra Topology

    3

    Node

    NodeNode

    Node

    Client Client

    Node

    NodeNode

    Node

    Client Client

    Cluster

  • 2015 DataStax, All Rights Reserved.

    Datacenter Datacenter

    Request Coordinator

    4

    Node

    NodeNode

    Node

    Client Client

    Node

    NodeCoordinator

    Node

    Client Client

    Coordinator node:Forwards requeststo corresponding replicas

  • 2015 DataStax, All Rights Reserved.

    Datacenter

    Row Replica

    5

    Replica

    NodeNode

    Replica

    Client Client

    Datacenter

    Node

    Node

    Replica

    Client Client

    Coordinator

    Replica node:Stores a slice of total rows of each keyspace

  • 2015 DataStax, All Rights Reserved.

    Token Ring

    6

    121

    2

    3

    4567

    8

    9

    1011

  • 2015 DataStax, All Rights Reserved.

    Token Ring

    6

    -263 (+263 - 1)

    Murmur3 Partitioner

  • 2015 DataStax, All Rights Reserved.

    Token Ring

    6

    Node

    1112Node

    121

    Node

    12

    Node

    23

    Node

    34

    Node

    45

    Node

    56Node

    67

    Node

    78

    Node

    89

    Node

    910

    Node

    1011

    -263 (+263 - 1)

    Murmur3 Partitioner

  • 2015 DataStax, All Rights Reserved.

    Keyspaces

    7

    CREATE KEYSPACE default WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': 3 }

  • 2015 DataStax, All Rights Reserved.

    C*

    Data Partitioning

    8

    KeyspaceRow

    token(PK) = 1RF = 3

    Partitioner:Gets a token by hashing the primary key of a row

  • 2015 DataStax, All Rights Reserved.

    C*

    Replication Strategy

    9

    Keyspace 1

    Row

    RF = 3

    Replication strategy:Determines the first

    replica for the row

    token(PK) = 1

  • 2015 DataStax, All Rights Reserved.

    C*

    Replication Factor

    10

    KeyspaceRow

    RF = 3

    Replication factor:Specifies total number of replicas for each row

    token(PK) = 1

  • 2015 DataStax, All Rights Reserved.

    Coordinator

    Node Replica

    ReplicaNode

    11

    ReplicaApplication

    Consistency Level

    RF = 3, CL = Quorum

  • 2015 DataStax, All Rights Reserved.

    Coordinator

    Node Replica

    ReplicaNode

    11

    ReplicaApplication

    Consistency Level

    RF = 3, CL = Quorum

    INSERT

  • 2015 DataStax, All Rights Reserved.

    Coordinator

    Node Replica

    ReplicaNode

    11

    ReplicaApplication

    Consistency Level

    RF = 3, CL = Quorum

    INSERT

  • 2015 DataStax, All Rights Reserved.

    Coordinator

    Node Replica

    ReplicaNode

    11

    ReplicaApplication

    Consistency Level

    RF = 3, CL = Quorum

    INSERT

  • 2015 DataStax, All Rights Reserved.

    Coordinator

    Node Replica

    ReplicaNode

    11

    ReplicaApplication

    Consistency Level

    RF = 3, CL = Quorum

    INSERT

  • DataStax DriversSmart clients for Apache Cassandra

  • 2015 DataStax, All Rights Reserved.

    Goals of DataStax Drivers

    Consistent set of features across languages Asynchronous execution of requests Load balancing Fault tolerant Address Resolution (multi-region!) Automatic cluster discovery and reconnection

    Flexible to the core Consistent terminology Open source

    13

  • 2015 DataStax, All Rights Reserved. 14

  • Asynchronous ExecutionIO Reactor, Request Pipelining and Future Composition

  • 2015 DataStax, All Rights Reserved.

    Asynchronous Core

    16

    Application Thread

    Business Logic

    Driver

    Background Thread

    IO Reactor

  • 2015 DataStax, All Rights Reserved.

    Request Pipelining

    17

    Client

    WithoutRequest Pipelining

    Server

    Client Server WithRequest Pipelining1

    2

    2

    3

    1

    3

    1

    2

    3

    1

    2

    3

  • 2015 DataStax, All Rights Reserved.

    What is a Future?

    Represents the result of an asynchronous operation Returned by any *_async method in the Ruby driver

    execute_async prepare_async

    Will block if asked for the true result

    18

  • 2015 DataStax, All Rights Reserved.

    Future Composition

    19

    select_user = session.prepare('SELECT * FROM users WHERE id = ?') select_page = session.prepare('SELECT * FROM pages WHERE slug = ?') user_ids = [1, 2, 3, 4] futures = user_ids.map do |id| future = session.execute_async(select_user, arguments: [id])

    future.then do |users| user = users.first future = session.execute_async(select_page, arguments: [user['username']])

    future.then do |pages| page = pages.first

    User.new(user, Page.new(page)) end end end Cassandra::Future.all(futures).get

  • 2015 DataStax, All Rights Reserved.

    select_user = session.prepare('SELECT * FROM users WHERE id = ?') select_page = session.prepare('SELECT * FROM pages WHERE slug = ?') user_ids = [1, 2, 3, 4] futures = user_ids.map do |id| future = session.execute_async(select_user, arguments: [id])

    future.then do |users| user = users.first future = session.execute_async(select_page, arguments: [user['username']])

    future.then do |pages| page = pages.first

    User.new(user, Page.new(page)) end end end Cassandra::Future.all(futures).get

    Future Composition

    20

  • 2015 DataStax, All Rights Reserved.

    select_user = session.prepare('SELECT * FROM users WHERE id = ?') select_page = session.prepare('SELECT * FROM pages WHERE slug = ?') user_ids = [1, 2, 3, 4] futures = user_ids.map do |id| future = session.execute_async(select_user, arguments: [id])

    future.then do |users| user = users.first future = session.execute_async(select_page, arguments: [user['username']])

    future.then do |pages| page = pages.first

    User.new(user, Page.new(page)) end end end Cassandra::Future.all(futures).get

    Future Composition

    21

  • 2015 DataStax, All Rights Reserved.

    select_user = session.prepare('SELECT * FROM users WHERE id = ?') select_page = session.prepare('SELECT * FROM pages WHERE slug = ?') user_ids = [1, 2, 3, 4] futures = user_ids.map do |id| future = session.execute_async(select_user, arguments: [id])

    future.then do |users| user = users.first future = session.execute_async(select_page, arguments: [user['username']])

    future.then do |pages| page = pages.first

    User.new(user, Page.new(page)) end end end Cassandra::Future.all(futures).get

    Future Composition

    22

  • 2015 DataStax, All Rights Reserved.

    select_user = session.prepare('SELECT * FROM users WHERE id = ?') select_page = session.prepare('SELECT * FROM pages WHERE slug = ?') user_ids = [1, 2, 3, 4] futures = user_ids.map do |id| future = session.execute_async(select_user, arguments: [id])

    future.then do |users| user = users.first future = session.execute_async(select_page, arguments: [user['username']])

    future.then do |pages| page = pages.first

    User.new(user, Page.new(page)) end end end Cassandra::Future.all(futures).get

    Future Composition

    23

  • 2015 DataStax, All Rights Reserved.

    select_user = session.prepare('SELECT * FROM users WHERE id = ?') select_page = session.prepare('SELECT * FROM pages WHERE slug = ?') user_ids = [1, 2, 3, 4] futures = user_ids.map do |id| future = session.execute_async(select_user, arguments: [id])

    future.then do |users| user = users.first future = session.execute_async(select_page, arguments: [user['username']])

    future.then do |pages| page = pages.first

    User.new(user, Page.new(page)) end end end Cassandra::Future.all(futures).get

    Future Composition

    24

  • 2015 DataStax, All Rights Reserved.

    Future Composition

    25

    [#, ... ]

  • 2015 DataStax, All Rights Reserved.

    Pop Quiz: How to make this faster?

    26

    select_user = session.prepare('SELECT * FROM users WHERE id = ?') select_page = session.prepare('SELECT * FROM pages WHERE slug = ?') user_ids = [1, 2, 3, 4] futures = user_ids.map do |id| future = session.execute_async(select_user, arguments: [id])

    future.then do |users| user = users.first future = session.execute_async(select_page, arguments: [user['username']])

    future.then do |pages| page = pages.first

    User.new(user, Page.new(page)) end end end Cassandra::Future.all(futures).get

  • 2015 DataStax, All Rights Reserved.

    Pop Quiz: How to make this faster?

    27

    user_future = session.prepare_async(SELECT * FROM users WHERE id = ?') page_future = session.prepare_async(SELECT * FROM pages WHERE slug = ?) user_ids = [1, 2, 3, 4] futures = user_ids.map do |id| future = session.execute_async(user_future.get, arguments: [id])

    future.then do |users| user = users.first future = se