distributed systems
play

Distributed Systems CS425/ECE428 05/01/2020 Todays agenda - PowerPoint PPT Presentation

Distributed Systems CS425/ECE428 05/01/2020 Todays agenda Distributed key-value stores Intro to key-value stores Design requirements and CAP Theorem Case study: Cassandra Acknowledgements: Prof. Indy Gupta Recap Cloud


  1. Distributed Systems CS425/ECE428 05/01/2020

  2. Today’s agenda • Distributed key-value stores • Intro to key-value stores • Design requirements and CAP Theorem • Case study: Cassandra • Acknowledgements: Prof. Indy Gupta

  3. Recap • Cloud provides distributed computing and storage infrastructure as a service. • Running a distributed job on the cloud cluster can be very complex: • Must deal with parallelization, scheduling, fault-tolerance, etc. • MapReduce is a powerful abstraction to hide this complexity. • User programming via easy-to-use API. • Distributed computing complexity handled by underlying frameworks and resource managers.

  4. Distributed datastores • Distributed datastores • Service for managing distributed storage. • Distributed NoSQL key-value stores • BigTable by Google • HBase open-sourced by Yahoo and used by Hadoop. • DynamoDB by Amazon • Cassandra by Facebook • Voldemort by LinkedIn • MongoDB, • … • Spanner is not a NoSQL datastore. It’s more like a distributed relational database.

  5. The Key-value Abstraction • (Business) Key à Value • (twitter.com) tweet id à information about tweet • (amazon.com) item number à information about it • (kayak.com) Flight number à information about flight, e.g., availability • (yourbank.com) Account number à information about it

  6. The Key-value Abstraction (2) • It’s a dictionary data-structure. • Insert, lookup, and delete by key • E.g., hash table, binary tree • But distributed . • Sound familiar? • Remember Distributed Hash tables (DHT) in P2P systems (e.g. Chord)? • Key-value stores reuse many techniques from DHTs.

  7. Isn’t that just a database? • Yes, sort of. • Relational Database Management Systems (RDBMSs) have been around for ages • e.g. MySQL is the most popular among them • Data stored in structured tables based on a Schema • Each row (data item) in a table has a primary key that is unique within that table. • Queried using SQL (Structured Query Language). • Supports joins.

  8. Relational Database Example users table user_id name zipcode blog_url blog_id 101 Alice 12345 alice.net 1 Example SQL queries 1. SELECT zipcode 422 Charlie 45783 charlie.com 3 FROM users WHERE name = “ Bob ” 555 Bob 99910 bob.blogspot.com 2 2. SELECT url Foreign keys Primary keys FROM blog WHERE id = 3 blog table 3. SELECT users.zipcode, id url last_updated num_posts blog.num_posts FROM users JOIN blog 1 alice.net 5/2/14 332 ON users.blog_url = blog.url 2 bob.blogspot.com 4/2/13 10003 3 charlie.com 6/15/14 7

  9. Mismatch with today’s workloads • Data: Large and unstructured • Lots of random reads and writes • Sometimes write-heavy • Foreign keys rarely needed • Joins infrequent

  10. Key-value/NoSQL Data Model • NoSQL = “Not Only SQL” • Necessary API operations: get(key) and put(key, value) • And some extended operations, e.g., “CQL” in Cassandra key- value store • Tables • Like RDBMS tables, but … • May be unstructured: May not have schemas • Some columns may be missing from some rows • Don’t always support joins or have foreign keys 1 0 • Can have index tables, just like RDBMSs

  11. Key-value/NoSQL Data Model Value Key users table user_id name zipcode blog_url • Unstructured 101 Alice 12345 alice.net • No schema imposed 422 Charlie charlie.com 555 99910 bob.blogspot.com • Columns Missing from some Rows Value • No foreign keys, Key joins may not be blog table supported id url last_updated num_posts 1 alice.net 5/2/14 332 2 bob.blogspot.com 10003 3 charlie.com 6/15/14

  12. How to design a distributed key-value datastore?

  13. Design Requirements • High performance, low cost, and scalability. • Speed (high throughput and low latency for read/write) • Low TCO (total cost of operation) • Fewer system administrators • Incremental scalability • Scale out: add more machines. • Scale up: upgrade to powerful machines. • Cheaper to scale out than to scale up.

  14. Design Requirements • High performance, low cost, and scalability. • Avoid single-point of failure • Replication across multiple nodes. • Consistency: reads return latest written value by any client (all nodes see same data at any time). • Different from the C of ACID properties for transaction semantics! • Availability: every request received by a non-failing node in the system must result in a response (quickly). • Follows from requirement for high performance. • Partition-tolerance: the system continues to work in spite of network partitions.

  15. CAP Theorem • C onsistency : reads return latest written value by any client (all nodes see same data at any time). • A vailability : every request received by a non-failing node in the system must result in a response (quickly). • P artition-tolerance : the system continues to work in spite of network partitions. • In a distributed system you can only guarantee at most 2 out of the above 3 properties. • Proposed by Eric Brewer (UC Berkeley) • Subsequently proved by Gilbert and Lynch (NUS and MIT)

  16. CAP Theorem N1 N2 • Data replicated across both N1 and N2. • If network is partitioned, N1 can no longer talk to N2. • Consistency + availability require N1 and N2 must talk. • no partition-tolerance. • Partition-tolerance + consistency: • only respond to requests received at N1 (no availability). • Partition-tolerance + availability: • write at N1 will not be captured by a read at N2 (no consistency).

  17. CAP Tradeoff • Starting point for NoSQL Revolution Consistency • A distributed storage system can achieve at HBase, HyperTable, Conventional most two of C, A, and P . BigTable, Spanner RDBMSs (non-replicated) • When partition-tolerance is important, you have to choose between Partition-tolerance Availability consistency and availability Cassandra, RIAK, Dynamo, Voldemort

  18. Case Study: Cassandra

  19. Cassandra • A distributed key-value store. • Intended to run in a datacenter (and also across DCs). • Originally designed at Facebook. • Open-sourced later, today an Apache project. • Some of the companies that use Cassandra in their production clusters. • IBM, Adobe, HP , eBay, Ericsson, Symantec • Twitter, Spotify • PBS Kids • Netflix: uses Cassandra to keep track of your current position in the video you’re watching

  20. Data Partitioning: Key to Server Mapping • How do you decide which server(s) a key-value resides on? Cassandra uses a ring-based DHT but without finger or routing tables. One ring per DC 0 Say m=7 N16 N112 Primary replica for key K13 N96 N32 Read/write K13 N45 N80 Client Backup replicas for Coordinator key K13

  21. Partitioner • Component responsible for key to server mapping (hash function). • Two types: • Chord-like hash partitioning • Murmer3Partitioner (default): uses murmer3 hash function. • RandomPartitioner : uses MD5 hash function. • ByteOrderedPartitioner : Assigns ranges of keys to servers. • Easier for range queries (e.g., get me all twitter users starting with [a-b]) • Determines the primary replica for a key.

  22. Replication Policies Two options for replication strategy: 1.SimpleStrategy: • First replica placed based on the partitioner. • Remaining replicas clockwise in relation to the primary replica. 2.NetworkTopologyStrategy: for multi-DC deployments • Two or three replicas per DC. • Per DC • First replica placed according to Partitioner. • Then go clockwise around ring until you hit a different rack.

  23. Writes • Need to be lock-free and fast (no reads or disk seeks). • Client sends write to one coordinator node in Cassandra cluster. • Coordinator may be per-key, or per-client, or per-query. • Coordinator uses Partitioner to send query to all replica nodes responsible for key. • When X replicas respond, coordinator returns an acknowledgement to the client • X = any one, majority, all….(consistency spectrum) • More details later!

  24. Writes: Hinted Handoff • Always writable: Hinted Handoff mechanism • If any replica is down, the coordinator writes to all other replicas, and keeps the write locally until down replica comes back up. • When all replicas are down, the Coordinator (front end) buffers writes (for up to a few hours).

  25. Writes at a replica node On receiving a write 1. Log it in disk commit log (for failure recovery) 2. Make changes to appropriate memtables • Memtable = In-memory representation of multiple key-value pairs • Cache that can be searched by key • Write-back cache as opposed to write-through 3. Later, when memtable is full or old, flush to disk • Data File: An SSTable (Sorted String Table) – list of key-value pairs, sorted by key • Index file: An SSTable of (key, position in data sstable) pairs • And a Bloom filter (for efficient search) – next slide.

  26. Bloom Filter • Compact way of representing a set of items. • Checking for existence in set is cheap. • Some probability of false positives: an item not in set may check true as being in set. • Never false negatives. On insert, set all hashed bits. Large Bit Map 0 1 On check-if-present, 2 return true if all hashed bits set. 3 Hash1 • False positives Key-K Hash2 6 . False positive rate low 9 . • m=4 hash functions Hashm 111 • 100 items • 3200 bits 127 • FP rate = 0.02%

Recommend


More recommend