20
CS162 Section Lecture 11

CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Embed Size (px)

Citation preview

Page 1: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

CS162 Section

Lecture 11

Page 2: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Project 4

• Implement a distributed key-value store that uses– Two-Phase Commit for atomic operations,– Replication for performance and fault-tolerance, – Encryption for security

Page 3: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Distributed Key-Value Store

0

216

247270

2111

Coordinator

Client 1

Client 2

Client 3

Client 4

Client 5

Page 4: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Consistent Hashing

• SlaveServer 128-bit ID using java.util.GUID– Slave count known in

advance– Nodes will come back if

fails (no permanent failure)

• Hash Keys to 128-bit numbers

0

216

247270

2111

27

2111 + 1

266

Page 5: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

KVClient (Library)

Client-side Program

KVClient (Library)

Client-side Program

KVClient (Library)

Client-side Program

Socket Server

KVClientHandler

KVMessage

Coordinator Server

GET PUT DEL

KVIn

terf

ace

KVCache(LRU Cache) Available

Threads

Job Queue

Thread Pool

Update

TPCMaster (Library)

KVM

essa

ge

Page 6: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

TPCMessage

Key-Value Server Key-Value Server Key-Value Server

KeyValue Server

Socket Server

TPCClientHandler

KVIn

terf

ace

KVCache(LRU

Cache)

KVIn

terf

ace

KVStoreAvailable Threads

Job Queue

Thread Pool

TPCLog

Page 7: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Key Server KVCache KVStore

1. Get WriteLock

1. Get WriteLock2. Update Value3. Get Exclusive Lock on AccessList4. Release WriteLock5. Update AccessList6. Release lock on AccessList

PUT (K,V)

2. Release WriteLock1. Got ReadLock

Update Value

GET (K)

1. Get ReadLock

Client 2Client 1

Success

1. Get ReadLock2. Get Value3. Get Exclusive Lock on AccessList4. Release ReadLock5. Update AccessList6. Release lock on AccessList

2. Release ReadLockK, V

Get ReadLockblocked

Page 8: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Coordinator KVCache

1. Get WriteLockPUT (K,V)

GET (K)

Client 2Client 1 SlaveServer 1 SlaveServer 2

PREPARE

RESPONSE (READY/ABORT)

DECISION (COMMIT/ABORT)

ACK

Phase 3Phase 3

2PCGet ReadLock

blocked

Page 9: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Coordinator KVCacheClient 2Client 1 SlaveServer 1 SlaveServer 2

1. Got WriteLock2. Update Value3. Get Exclusive Lock on AccessList4. Release WriteLock5. Update AccessList6. Release lock on AccessList

2. Release WriteLock1. Get ReadLock

Success

Get ReadLockblocked

1. Got ReadLock2. Get Value3. Get Exclusive Lock on AccessList4. Release ReadLock5. Update AccessList6. Release lock on AccessList

2. Release ReadLockK, V

Page 10: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Recovery from Site Log Entries

Ready

Commit

REDO

Abort

Ignore

Don’t Know

Consult Master

Page 11: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

What is MTBF?What is MTTR?

Page 12: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Fault Models

• Failures are independent*So, single fault tolerance is a big win

• Hardware fails fast (blue-screen, panic, …)• Software fails-fast (or stops responding/hangs)• Software often repaired by reboot:

– Heisenbugs – Works On Retry– (Bohrbugs – Faults Again On Retry)

• Operations tasks: major source of outage– Utility operations – UPS/generator maintenance– Software upgrades, configuration changes

Page 13: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Fault Tolerance Techniques

• Fail fast modules: work or stop

• Spare modules: yield instant repair time

• Process/Server pairs: Mask HW and SW faults

• Transactions: yields ACID semantics (simple fault model)

Page 14: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Fault-tolerance in MapReduce

• What if – A task crashes– A node crashes

• Worker node• Master node

– A task is going slow

Page 15: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Key Security Properties

• Authentication • Data integrity • Confidentiality • Non-repudiation

Page 16: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Lxvnkbgz Vhffngbvtmbhg pbma Vkrimhzktiar

• Vhffngbvtmbhg bg ikxlxgvx hy twoxkltkbxl• Maxkx bl t dxr, ihllxllbhg hy pabva teehpl

wxvhwbgz, unm pbmahnm pabva wxvhwbgz bl bgyxtlbuex– Manl, dxr fnlm ux dxim lxvkxm tgw ghm znxlltuex

Page 17: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Securing Communication with Cryptography

• Communication in presence of adversaries• There is a key, possession of which allows

decoding, but without which decoding is infeasible– Thus, key must be kept secret and not guessable

Page 18: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Using Symmetric Keys • Same key for encryption and decryption

InternetEncrypt withsecret key

Decrypt withsecret key

Plaintext (m) m

Ciphertext

• Transferring keys over the network is problematic

Page 19: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Public Key / Asymmetric Encryption

• Sender uses receiver’s public key– Advertised to everyone

• Receiver uses complementary private key– Must be kept secret

InternetEncrypt withpublic key

Decrypt withprivate key

Plaintext Plaintext

Ciphertext

Page 20: CS162 Section Lecture 11. Project 4 Implement a distributed key-value store that uses – Two-Phase Commit for atomic operations, – Replication for performance

Properties of RSA

• Requires generating large, random prime numbers– Algorithms exist for quickly finding these (probabilistic!)

• Requires exponentiation of very large numbers– Again, fairly fast algorithms exist

• Overall, much slower than symmetric key crypto– One general strategy: use public key crypto to exchange a (short) symmetric session key

• Use that key then with AES or such

• How difficult is recovering d, the private key? – Equivalent to finding prime factors of a large number

• Many have tried - believed to be very hard (= brute force only)• (Though quantum computers can do so in polynomial time!)