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

Automatic Failover in RethinkDB

Automatic Failover in RethinkDB

Jorge Silva

July 27, 2015
Tweet

More Decks by Jorge Silva

Other Decks in Programming

Transcript

  1. What is RethinkDB? • Open source database for building realtime

    web applications • NoSQL database that stores schemaless JSON documents • Distributed database that is easy to scale
  2. What makes it distributed? • Allows simple sharding and replication

    of tables • Allows you to easily connect nodes to a cluster using `--join`
  3. The problem • When one of your nodes goes down,

    you needed to manually decide what to do
  4. What's new in 2.1 • RethinkDB 2.1 introduces automatic failover

    • It uses Raft as the consensus algorithm
  5. Replicas • Primary replicas serve as the authoritative copy of

    the data • Secondary replicas serve as a mirror of the primary replica
  6. Automatic Failover • In RethinkDB, automatic failover takes care of

    promoting secondary replicas into primary replicas when a primary replica is unavailable • The cluster picks new primaries by voting. New server need a majority vote.
  7. Step #2: ssh into raspberry pis // Check devices in

    network $ nmap -sn *.*.*.0/24 // ssh into raspberry pis $ ssh pi@redisgeek $ ssh pi@pishark
  8. Step #3: Start RethinkDB // Start RethinkDB in both Raspberry

    Pis pi@mrpi1 ~ $ rethinkdb \ -n redisgeek \ -t pi -t redisgeek \ --bind all \ --join 104.236.171.225
  9. Step #5: Insert test data // Insert data into table

    r.table('data') .insert( // Insert data form Reddit r.http('reddit.com/r/rethinkdb.json') ('data')('children').map(r.row('data')) ) // Query data r.table('data')
  10. Step #1: Move data // Move all data to `redisgeek`

    r.table('data') .reconfigure({ shards: 1, replicas: { 'redisgeek': 1 }, primaryReplicaTag: 'redisgeek' })
  11. What happened? • We move all our data in 'redisgeek'

    • We disconnected 'redisgeek' from the network • Because we can't communicate with 'redisgeek' (primary replica), our data in inaccessible
  12. Step #1: Make main primary // Make `main` the primary

    replica r.table('data') .reconfigure({ shards: 1, replicas: { 'main': 1, 'redisgeek': 1, 'pishark': 1 }, primaryReplicaTag: 'main' })
  13. What happened? • Because the primary replica is connected data

    can be read • Because a majority of nodes are disconnected, data can't be written