Storage Systems

  • Goal: understand how to manage big data in a systematic way

  • Motivation: how to provide real-time read/write random-access to big data?

    • Data is organized in terms of many “records” and it us unlikely to fit on single machine (distributed)
    • MapReduce is designed for batch processing rather than real-time access
    • Database-like systems are needed to access data efficiently
  • Commercial Relational Database Management Systems (RDBMS)

    • We don’t use the traditional relational-based databases because
      • the scale is too large for most RDBMS
      • the cost could be very high
  • Distributed RDBMS

    • Two-phase commit (2PC) (transactions on multiple machines)
    • The client who initiated the computation acts as coordinator; processes required to commit are the participants

      • Phase 1a: Coordinator sends VOTE-REQUEST to participants
      • Phase 1b: When a participant receives VOTE-REQUEST, it returns either VOTE-COMMIT or VOTE-ABORT to coordinator. If it sends VOTE-ABORT, it aborts its local computation
      • Phase 2a: Coordinator collects all votes; if all are VOTE-COMMIT, it sends GLOBAL-COMMIT to all participants, otherwise it sends GLOBAL-ABORT
      • Phase 2b: Each participant waits for GLOBAL-COMMIT or GLOBAL- ABORT and handles accordingly

    • Assumptions and Limitations

      1. Persistent storage and write-ahead log at every node because we may need to roll back to the previous states
      2. The coordinator is the bottleneck (what if the coordinator dies?)
      3. 2PC is very slow

Key-Value Stores

  • Data model

    • Stores associations between keys and values
    • Keys are usually primitives (ints, strings, raw bytes, etc.)
    • Values can be primitive or complex (JSON, HTML fragments, etc.)
  • Operations

    1. Get: fetch value associated with key
    2. Put: set value associated with key
    • Optional: Multi-get, Multi-put, Range queries

BigTable

A distributed storage system for managing structured data
Designed to scale to a very large size (petabytes of data across thousands of servers)
Flexible and high-performance (for all of Google’s products)

  • Motivation: Lots of (semi-)structured data (e.g., url, user data, Geographic locations) and its scale is large

  • Objective:

    1. Want access to most current data at any time
    2. Very high read/write rates
    3. Efficient scans over all
    4. Efficient joins of large one-to-one and one-to-many datasets
    5. Examine data changes over time
  • Data model
    Map indexed by a row key, column key, and a timestamp

    • Example
      • Row key: reverse URL (reverse: can easily group the webpages in the same domain)
      • Column keys: attributes of web page (Contents, and anchors that reference the page)
      • Values: contents of web pages, and other information
  • Rows

    • Each read or write of data under a single row key is atomic
    • Maintained in sorted lexicographic order (for efficient row scans)
    • Row ranges dynamically partitioned into tablets
  • Columns

    • Grouped into column families
    • Column key = family:qualifier
    • Column families provide locality hints (E.g., anchor is a column family)
    • Few column families, but unbounded number of columns
  • Timestamp

    • 64-bit integers (real time in microseconds)

Organization

  1. Google File System: The raw storage for storing logs and data files
  2. Chubby: A distributed lock manager to keep replicas consists in presence of failures
  3. SSTable: A file format for storing BigTable data
  • SSTable

    • Persistent, ordered (the keys and values within the SSTable are stored) immutable (unmodifiable, cannot change the content in the table) map from keys to values, the index traced the key range
    • Sequence of blocks on disk plus an index for block lookup (for chasing design: sorted + range traced which can easily be chased efficiently BFI search)
  • Tablet

    • Multiple SSTables group together and build a Tablet
    • Dynamically partitioned range of rows
  • Table

    • Multiple tablets make up the table, SSTables can be shared (see fig.)

Architecture

Single-master, distributed storage architecture

  • BigTable master

    • Assigns tablets to tablet servers
    • Detects addition and expiration of tablet servers
    • Balances tablet server load
    • Handles garbage collection
    • Handles schema changes
  • Tablet servers

    • Each tablet server manages a set of tablets
      • Typically between ten to a thousand tablets (each 100-200 MB by default)
    • Handles read and write requests to the tablets
    • Splits tablets that have grown too large
  • Tablet Location

    • Given a key, search the location of tablet that stored the key-value pair
    • Implementation: B+ Tree:

      1. 1st level: root tablet contains location of all tablets
      2. 2nd level: metadata tablet contains locations of user tablets
      3. 3rd level: user tablets
      • Example:
        Given $1\text{KB}$ ($1024 \text{bytes}$) key and $128\text{MB}$ ($128 \times 2^{20} \text{bytes}$) tablet size.
        Qs: how much data it can index at the 1st level: $2^{27} / 2^{10} = 2^{17}$ keys to meta-data tablets
        Qs: how many user tablet that can be represented at the 2nd level: $2^{17} \times 2^{17} = 2^{34}$ keys to user tablets
        Qs: # key-value pair that can be represented: $2^{34} \times 2^{27} = 2^{61} \text{bytes}$ data (2048 petabytes)

  • Tablet Serving

    1. Write

      1. Updates committed to a commit log
      2. Recently committed updates are stored in memtable (The data will first store in the memtable until it’s full)
      3. Older updates are stored in a sequence of SSTables (It would be pushed into the SSTable Files with sorting process)
    2. Read

      1. form a merged view of SSTables and memtable
      2. read <key-value> pair
  • Compaction (Update)

    • Minor compaction
      • Converts the memtable into an SSTable
      • Reduces memory usage and log traffic on restart
    • Merging compaction
      • Reads the contents of a few SSTables and the memtable, and writes out a new SSTable
      • Reduces number of SSTables
    • Major compaction
      • Merging compaction that results in only one SSTable
      • No deletion records, only live data

HBase

  • Open-source clone of BigTable

  • Design
    HFile: Everything is managed in HFile, the actual storage file stored in HDFS, created to store HBase’s data fast and efficiently

    Key value pair in low level byte array

  • Data Model

    • HBase stores data in tables
      • Rows and columns
      • Row keys are identifiers, in the form of byte arrays
      • Row columns are grouped in column families
      • Tables are partitioned in regions
    • HBase uses Zookeeper for locking
  • Implementation: All similar to the BigTable

    • HBase master, multiple regionserver slaves (tablet server)
    • Operations
      • -ROOT- table holds the list of .META. table regions
      • .META. table holds list of user-space regions
    • Writes are appended to a commit log and then cached in memstore
    • Reads consult memstore first
  • Operation Modes

    1. Standalone Mode

      • Default mode
      • Does not use HDFS, but uses local filesystem instead
    2. Distributed Mode

      • Use HDFS for storage (pseudo-distributed and fully distributed)

Oriented

  • HBase is distributed and column-oriented (data is stored by columns)
  • RDBMS is fixed-schema and row-oriented (data is stored by rows)


Consider a query that processes only column 2, Row-oriented needs 4 reads (each for one row), while column-oriented only needs Needs 2 reads (each for one row split), which is frequently used in data analystic

  • Row-oriented

    • Easy to read a particular row of records (but may read unnecessary columns)
  • Column-oriented

    • Good if reads only involve a few columns
    • Efficient compression
    • Efficient sorting and indexing on compressed data

CAP Theorem

Any networked system providing shared data can provide only two of the three properties:

  1. C: consistency a shared and replicated data item appears as a single, up-to-date copy
    e.g., 3 raplicas in Google File System and want to ensure that they all have the same values

  2. A: availability the updates will always be eventually executed (have no idea when would the files be updated)

  3. P: partition tolerance partitioning of nodes can be tolerated

  • C & P: Distributed database systems

    1. Consistency: when a user writes data, the same piece of data is written to all storage servers
    2. Partition tolerance: all storage nodes are guaranteed to have the same piece of data (even tgough part of the system is disconnected)
    3. Availability CANNOT HOLD: If partition tolerance is provided, but when partition happens, it cannot update all the replicas
  • A & P: DNS System

    1. Availability: every node in system will always be available, no matter the <IP-name> pairs is valid or not
    2. Partition tolerance: every user (or machine) has its own DNS server on its own network, so network partitioning is not a problem
    3. Consistency CANNOT HOLD: For a updated IP address, it would be propagate to all DNS servers, which would take some time to do it. Before all servers recieve the update, some servers may still hold the wrong mapping, which is not consistency
  • C & A: Single-node database

    1. Consistency: one copy, which is consistent
    2. Availability: only update one single copy, which is available
    3. Partition tolerance CANNOT HOLD: when partition occurs, cannot access the copy
  • CAP in Reality

    • Partitions are rare; no need to forfeit Consistency or Availability, shouldn’t just give up either C or A for partition tolerance

Amazon Dynamo

  • Dynamo is designed as a highly available, key-value storage system

    • Failure is the normal case but many services on Amazon’s platform only need primary-key (item → content) access that RDBMS is unnecessary
  • Assumptions and Requirements

    • Simple read/write operations, uniquely identified by keys (objects tend to be small)
    • Notice: ACID (Atomicity, Consistency, Isolation, Durability), which ensure the correctness of all the replicas, gives poor availability
    • User can choose weaker consistency (C) for higher availability
    • No security issues
    • Dynamo aims to be always writable
  • Design Principles

    • Incremental scalability
      • System should be able to grow by adding a storage host (node) at a time
    • Symmetry (mainly different from BigTable)
      • Every node has the same set of responsibilities
    • Decentralization
      • Favor decentralized techniques over central coordinators
    • Heterogeneity
      • Workload partitioning should be proportional to capabilities of servers
  • Comparison with BigTable:

    • BigTable has more complicated key-value store, which applied column-store (column families and columns within them)
    • Bigtable: distrbute DB built on GFS, Dynamo: distributed hash table
    • Dynamo would not reject the updates but BigTable would reject the updates due to ensure consistency if the replicas are difference

Consistency and Availability

Strong consistency and high availability cannot be achieved simultaneously with high performance

  • Replication of objects is good as high availability and high read performance, but need to update all of them to maintain consistency

  • Eventual Consistency

    • Propagate updates to all replicas “eventually” (but it may take a long time)
    • Trade weak consistency for availability and performance

    • Reads may return old data that is yet updated
      Let the data store or the application to decide which one be picked

      • Data store can choose the “last write”
      • Application can do application-aware conflict resolution as app can aware of the meaning of the data (timestamp), or even fall back on “last write wins”

Storage

  • Key space of nodes = $\{ 0, 1, \dots, n-1 \}$
  • Set of objects $\{ o_1, o_2, \dots, o_k \}$
  • Distributed hash table: create a hash function h(x) that maps an element in $\{ o_1, o_2, \dots, o_k \}$ to number $i$, and the object $x$ would be stored in inode $i$
  • Notice: h(x) should be Deterministic, Efficient, Evenly distributed among all nodes
  • Example: h(x) = MD5(x) mod n, MD5 can create a 128-bit identifier
  • Limitation: Scalability If a node is add into the system, it should modify the hash function from n to n+1 nodes, which means it needs to re-organize all the objects to the new nodes.

  • Consistent Hashing

    First map the nodes to a hash ring (starting from 0 to a maximize value in the clockwise direction and each node is located in one position in the hash ring), then map the object to the location of the hash ring to determine which node would store that object.

    • The advantage is when a new server is added, only the data of the successor node is affected

    • For example:
      Node 26 is added, data from node 26 is migrated to node 26 and update the routing tables

  • Replication
    Stores an object to N storage servers:

    1. 1st server is the one that is closest to h(x) in the clockwise direction, i.e., successor(h(x))
    2. N-1 more servers, who are the clockwise successors of successor(h(x)), will store a redundant copy of object x

      e.g., h(x) = 15 and N = 3, 1st copy will stored in node 20, the former copies will be stored in node 30 and 40
  • Consistency

    • Challenge:

      • To decide which storage server(s) to store a particular object, without choosing all servers.
      • Choosing all servers implies strict consistency!
    • Strict consistency:

      • Any read on a data item x returns a value corresponding to the result of the most recent write on x
  • Client-Side Consistency

    1. Strong consistency (~Strict consistency)

      • After the update reports a finished update, all subsequent access returns the updated value
    2. Eventual consistency

      • After the update reports a finished update, the system may report the old value
      • Nevertheless, the system will eventually report the updated value
  • Configurable parameters

    1. N = the number of nodes that store replicas of the data
    2. W [1, N] = the number of replicas that need to acknowledge the receipt of update
    3. R [1, N] (read) = the number of replicas that are contacted when a data object is accessed, because there are a chance that some replicas may not been updated (choose the latest version)
    • If W + R > N, then it is strong consistency

      • e.g., If N = 3, W = 2, and R = 2, what may happen?
      • If N = 3, W = 2, R = 2, at least 2 out of 3 replicas are acknowledged during writing. Regardless which 2 replicas be read, have at least 1 server that overlaps with write that have received the acknowledgement. So it can ensure that user must read the latest replica (ensure at least one of the reading server have received the acknowledgement).
    • If W + R <= N, then it is eventual consistency

      • e.g., If N = 3, W = 2, and R = 1
    • Dynamo’s Setting: Common (N,R,W) in Dynamo: (3,2,2)

  • Partitions Handling
    • Sloppy quorum
      All reads/writes are performed on the first N healthy nodes from the preference list, which may not always be the first N nodes in the consistent hashing ring e.g., if node A is down, a replica is sent to node A’
    • Hinted handoff
      • Node A’ receives a hint that the update is temporary
      • A’ sends back the replica to A if A is recovered, and removes its replica