Consistency in distributed systems Distributed systems Transactions Overview

Consistency in distributed systems Distributed systems Transactions

Overview § Transactions § ACID § Concurrency § Locking § Timestamping § Optimistic concurrency control

transactions § Distributed systems is essentially about understanding when to use and when not to use transactions § Examples of transaction-based systems § Banking systems § Airline Ticketing systems § Email system? § Web cache coherence?

ACID transactions § Problem § Update state on several distributed hosts § Conditions § § Atomic Consistent Isolation Durable

In simple words § Either do all x steps or don’t do anything § A transaction must not be affected by other ongoing transactions § Before and after the transaction everyone should be consistent § Your changes must remain consistent once you are done

Subtle issues § Transactions implicitly give you an “undo” button § Recoverable from failures § Transactions serialize operations, without compromising concurrency § As much as a function of transactional model as good software engineering

A Simple transaction § mybank. Account. withdraw(1000) if (mybank. Account. balance > 5000) mybank. Account. withdraw (3000) else my. Wifebank. Account. transfer(mybank. Ac count, (5000))

Distributed transaction Open Transaction Source Server A Server B Server C

Distributed transaction Withdraw Money Deposit Money Source Server A Server B Server C

Distributed transaction Close Transaction Source Server A Server B Server C

Under the hood § Requests are serialized § Changes saved in durable storage § Multiple transactions can run concurrently

Commit protocol § Voting phase § Preparation of commitment § Everyone answers yes § Then commit § Two Phase Commit

2 Phase Commit Can commit? Client yes Do Committed Server

Failure model? § Any NACK, Time-out, causes Abort § Server Crash? § Client Crash? § Coordinator based model? § Coordinator crash?

Concurrency in transactions § Nested transactions § Child transactions run in tandem § Parallel (different hosts) § Concurrent (different data) § Parent can commit even if a child aborts § However § If the parent aborts, should a child abort?

Nested Transactions

Deep nesting § Provisional commit § Level 3 “can” commit § Level 2 can only provisionally commit § Can end up with orphan transactions

Two Phase Commit § Blocking § How?

Three-phase Commit

concurrency § Lamport timestamps § Typically NTP time § Nest lecture § Optimistic concurrency control
- Slides: 20