acid and modularity in the cloud

63
ACID and Modularity in the ACID and Modularity in the Cloud Cloud Liuba Shrira Brandeis University

Upload: haven

Post on 23-Jan-2016

25 views

Category:

Documents


0 download

DESCRIPTION

ACID and Modularity in the Cloud. Liuba Shrira Brandeis University. Trends. Applications are moving to the Cloud - new (FB, Zymba…) and established (MSFT Office..) Users want applications to run everywhere - MacBook, iPhone, iPad. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: ACID and Modularity in the Cloud

ACID and Modularity in the CloudACID and Modularity in the Cloud

Liuba Shrira

Brandeis University

Page 2: ACID and Modularity in the Cloud

Trends Trends

Applications are moving to the Cloud

- new (FB, Zymba…) and established (MSFT Office..)

Users want applications to run everywhere

- MacBook, iPhone, iPad

Page 3: ACID and Modularity in the Cloud

Cloud: Democracy for DevelopersCloud: Democracy for Developers

Resources: Amazon, Google, Microsoft… (IaS)

Platforms: Android, App Store (PaS)

Page 4: ACID and Modularity in the Cloud

Challenges RemainChallenges Remain

- Consistency in the presence of failures

- Predictable performance in the presence of varying load

Developers want to use tried and true tools

- how to adapt?

Developers need new tools

- how to build?

Page 5: ACID and Modularity in the Cloud

Transactions: true and tried toolTransactions: true and tried tool

Invented by Gray, Lomet

make developers life easier..

The proverbial transaction :

Begin

Transfer money from account x to y

Commit (or Abort)

Page 6: ACID and Modularity in the Cloud

Transactions: ACID PropertiesTransactions: ACID Properties

Transactions provide four intertwined properties:• Atomicity. Transactions can never “partly commit”; their updates are

applied “all or nothing”.

The system guarantees this using recovery, concurrency control

• Consistency. Each transaction T transitions the dataset from one semantically consistent state to another.

The developer guarantees this by correctly marking transaction boundaries.

• Isolation. All updates by T1 are either entirely visible to T2, or are not visible at all.

System guaranteed through concurrency control.

• Durability. Updates made by T are “never” lost once T commits.

The system guarantees this by writing updates to stable storage, + recovery.

Page 7: ACID and Modularity in the Cloud

Type-Specific SerializabilityType-Specific Serializability

In some cases, application logic can tolerate apparent conflicts

• E.g. when all writes commuteE.g. increment/decrement (a.k.a. “escrow transactions”)

Note: doesn’t work in some cases for (American) bank accounts

Account cannot go below $0.00!!

This kind of app logic is not known to DB

• Only sees R/W requests

T1: x=R(B), W(B=x-1), z=R(A), W(A=z+1)T2: y=R(A), W(A=y-1) u=R(B), W (B=u+1)

Page 8: ACID and Modularity in the Cloud

Transactional Concurrency ControlTransactional Concurrency Control

Three ways to ensure a serial-equivalent order on conflicts:

• Option 1: execute transactions serially.

slow

• Option 2: pessimistic concurrency control: block T until transactions with conflicting operations are done.

use locks for mutual exclusion

two-phase locking (2PL)

• Option 3: optimistic concurrency control: proceed as if no conflicts will occur, and recover if constraints are violated.

Repair the damage by rolling back (aborting) one of the conflicting transactions.

• Other options: hybrid, type-specific

Page 9: ACID and Modularity in the Cloud

Recovery ProtocolRecovery Protocol

Model:

Persistent data lives on disk or flash

Transactions compute in memory (volatile)

ACID - need way to ensure A & D in the presence of crashes, aborts

Approach: recovery protocol

Page 10: ACID and Modularity in the Cloud

Idea:Write-Ahead Logging (WAL)Idea:Write-Ahead Logging (WAL)

The Write-Ahead Logging Protocol: Must write the log record for an update before the corresponding

data gets to disk. Must force all log records for a Xact before commit. (so transaction

is not committed until all of its log records including its “commit” record are on the stable log.)

#1 helps guarantee Atomicity.

#2 helps guarantee Durability.

# ( 1+2) + lazy disk update helps guarantee good Performance.

Page 11: ACID and Modularity in the Cloud

Got ACID!Got ACID!

Page 12: ACID and Modularity in the Cloud

Distributed SystemDistributed System

Servers hosted in a datacenterhold data

Clients

Page 13: ACID and Modularity in the Cloud

Disadvantages of LockingDisadvantages of LockingPessimistic concurrency control has a number of key

disadvantages in distributed systems:

• Overhead. Locks cost to acquire, pay even if no conflict occurs.

• Low concurrency.

If locks are too coarse, they reduce concurrency unnecessarily.

Need for strict 2PL makes it even worse.

• Low availability.

A client cannot make progress if the server or lock holder is temporarily unreachable.

Page 14: ACID and Modularity in the Cloud

Optimistic Concurrency ControlOptimistic Concurrency Control

OCC skips the locking and takes action only when a conflict actually occurs.

“ better to apologize than ask for permission”

Page 15: ACID and Modularity in the Cloud

Simple Validation for OCCSimple Validation for OCCOCC validation is simple with a few assumptions:

• Transactions update a private “tentative” copy of data.

Updates from T are not visible to S until T validates/commits.

• Transactions validate and commit serially at a central point.

Transaction manager keeps track for each transaction T:Maintain a read set R(T) and a write set W(T) of

items/objects read and written by T.

T cannot affect S if S commits before T, so we only need to worry about whether or not T observed writes by S.

Page 16: ACID and Modularity in the Cloud

System with caching System with caching

Clients run transactions access objects fetched from server, compute, update, and put back

Servers in a datacenterhold master copies

ClientsHold cached copies

Page 17: ACID and Modularity in the Cloud

Caching SystemCaching System

Problem 1 (client/server): If the client caches data and updates locally, the cache must be consistent at start of each transaction.

Otherwise, there is no guarantee that T observes writes by an S that committed before T started.

Validation queue may grow without bound.

Problem 2 (multiple servers): validation/commit is no longer serial.

Page 18: ACID and Modularity in the Cloud

Client/Server OCC with cachingClient/Server OCC with caching

Key idea: use cache invalidations) to simplify validation checks, allowing clients to cache objects across transactions.• Each server keeps a conservative cached set of objects cached

by each client C.

• If a validated S has modified an object x in C’s cached set:1. Callback client to invalidate its cached copy of x.

2. Client aborts/restarts any local action T with x in R(T).

3. x is in C’s invalid set until C acks the invalidate.

• A transaction T from client C fails validation if there is any object x in R(T) that is also in C’s invalid set.

.

Page 19: ACID and Modularity in the Cloud

Disconnected Transaction SystemDisconnected Transaction System

Scenario:

Mobile clients run transactions : access objects fetched from server, compute, update, and put back

Servers in a datacenterhold master copies

Mobile clientsHold cached copies

Page 20: ACID and Modularity in the Cloud

Disconnected Client/Server Disconnected Client/Server

Key idea: disconnected client runs tentative transactions,

a tentative commit of T adds a record R(T), W(T) to a tentative transaction log.• Server accumulates invalid set for each client C

• A client reconnects and validates log using invalid set. 1. Client aborts any tentative transaction T with x in R(T) and

either x in invalid set or x in W(D), where D is a tentative

transaction that already aborted.

2. Client commits at the server remaining tentative transactions

• Client obtains new values from the server and retries or “reconciles” aborted transactions.

.

Page 21: ACID and Modularity in the Cloud

A Problem with Optimistic ConcurrencyA Problem with Optimistic Concurrency

• Validate read/write conflicts at reconnection (easy)

• If no conflicts, can commitEffects become permanent

• If conflicts, transactions abortRoll effects back (hate it…)

• or reconcileAsk client for help (complex..)

Page 22: ACID and Modularity in the Cloud

Problems with Pessimistic and OptimisticProblems with Pessimistic and Optimistic

Pessimistic - slow and no good for disconnection

Optimistic – complex to reconcile, clients hate rollback

Page 23: ACID and Modularity in the Cloud

A “hybrid” approach: ReservationsA “hybrid” approach: Reservations

• Optimistic for private data

• Avoid conflicts using reservations for shared data Special locks with timeouts

• Exploit object type to gain concurrencye.g. commutative updates

Page 24: ACID and Modularity in the Cloud

Type-specific synchronization example: Type-specific synchronization example: inventory control with inventory control with escrowescrow reservations reservations

Joe

Mary

Server

in-stock

Page 25: ACID and Modularity in the Cloud

Type-specific synchronization:Type-specific synchronization:inventory control with escrow reservations inventory control with escrow reservations

Joe

Mary

Server

in-stock

Page 26: ACID and Modularity in the Cloud

Type-specific synchronization: Type-specific synchronization: inventory control with escrow reservations inventory control with escrow reservations

Joe

Mary

Server

in-stock

Page 27: ACID and Modularity in the Cloud

Type-specific synchronization: Type-specific synchronization: inventory control with escrow reservations inventory control with escrow reservations

Joe

Mary

Server

$$

in-stock

Page 28: ACID and Modularity in the Cloud

Type-specific synchronization: Type-specific synchronization: inventory control with escrow reservations inventory control with escrow reservations

$$

Joe

Mary

Server

in-stock

Page 29: ACID and Modularity in the Cloud

Type-specific synchronization: Type-specific synchronization: inventory control with escrow reservations inventory control with escrow reservations

$$

Joe

Mary

Server$$$

in-stock

Page 30: ACID and Modularity in the Cloud

Type-specific synchronization: Type-specific synchronization: inventory control with escrow reservations inventory control with escrow reservations

$$$$$

Joe

Mary

Server

in-stock

Page 31: ACID and Modularity in the Cloud

Type-specific synchronization: Type-specific synchronization: inventory control with escrow reservations inventory control with escrow reservations

$$$$$

Joe

Mary

Server

- Joe can commit updates to in-stock escrow object yet in-stock master copy has changed since Joe fetched it- Not possible with conventional read/write conflict validation- Relies on type-specific “escrow” synchronization

in-stock

Page 32: ACID and Modularity in the Cloud

In the 80’s and 90’s ... In the 80’s and 90’s ...

Many clever type-specific CC protocols

Page 33: ACID and Modularity in the Cloud

Deal-BreakerDeal-Breaker

Where does type-specific code live?

• Server’s concurrency & recovery engine

IT manager says - “you want what?”

• Install customized (unstable, buggy?) code in my high-performance enterprise-critical box engine?

Page 34: ACID and Modularity in the Cloud

Upshot:Upshot:

IT managers want commodity servers!

• Reliability

• Performance

• Stability

Page 35: ACID and Modularity in the Cloud

New modular approach: Exo-leasing New modular approach: Exo-leasing

Can get the benefits of type-specific synchronization without modifying the servers

Can run on top of commodity servers• attractive for cloud systems

Plus extra benefits ...

Page 36: ACID and Modularity in the Cloud

We wantWe want

Mobile Inventory Example:• Ability to acquire sales reservations so disconnected

transactions can commit without conflicts

• Proper outcome in the absence of failures: only finalized sales commit - abort recovery

• Proper outcome in the case of failures: if sale not finalized, reservation is released - crash recovery

without

modification to server concurrency and recovery code

Page 37: ACID and Modularity in the Cloud

Generic commodity servers

Top-level tnx

Reservations

Object cache

Exo system architecture

- Clients run top-level transactions and reservation transactions

- Servers process all transactions identically, using generic r/w optimistic concurrency control

- Invalid set tracks stale copies

Client

Page 38: ACID and Modularity in the Cloud

Mobile Client Steps

Begin top-level transactionObtain reservations

Loop {Refresh/load objects into local cacheDisconnect from serverLoop{ Perform local tentative transactions Locally validate tentative transactions against reservationsConnect to the server Renew or obtain new reservations if necessary

} Commit top-level transaction i.e. atomically validate/abort local transactions and

finalize used reservations and release unused reservations.

Page 39: ACID and Modularity in the Cloud

Inside reservation: Escrow objects Inside reservation: Escrow objects

Object o of escrow type

split (delta)

merge (delta)

balance

Split and merge ops commute when balance is positive

(Escrow is a Fragmentable object type)

Page 40: ACID and Modularity in the Cloud

Client-side reservations Client-side reservations

Acquire escrow reservation method• Executed as a transaction

• Split op decreases in-stock value, if balance allows and stores an inverse (merge op) in a local log with a lease (expiration time)

• the log lives inside the escrow object

• the log is written to the server when the reservation method commits

• other clients that reconnect and fetch the escrow object observe these changes

Release escrow reservation method• Similar..

Page 41: ACID and Modularity in the Cloud

Client reconnects to serverClient reconnects to serverto commit to commit top-level transactiontop-level transaction

Client invokes

object-specific commit confirmation actions to make changes covered by leases permanent

When top-level transaction commits

confirmation actions take effect

Page 42: ACID and Modularity in the Cloud

Synchronization conflictsSynchronization conflicts

What if Mary committed a reservation on the same object?

My stale object copy detected

My client applies inverse, re-fetches a fresh copy and retries

Page 43: ACID and Modularity in the Cloud

FailuresFailures

What if my client crashes, or fails to reconnect in time?

Reservation lease expires

Other client notices an expired lease, cleans up (applies inverse) . That is lazy recovery

Page 44: ACID and Modularity in the Cloud

So: client reconnects to serverSo: client reconnects to serverto commit top-level transactionto commit top-level transaction

Client invokes object-specific commit confirmation actions to make changes covered by leases permanent

Client also invokes object-specific confirmation actions to clean-up changes covered by observed expired leases

When top-level transaction commits confirmation actions take effect

Page 45: ACID and Modularity in the Cloud

Example: exo-leasingExample: exo-leasing

Page 46: ACID and Modularity in the Cloud

ConsiderationsConsiderations

No one notices expiration • not needed?

Many notice• First cleanup makes other copies stale

Performance• Retry OK for moderate contention

Clock skew • Use server clock

Security• OK in appliance (plus recent security techniques)

Page 47: ACID and Modularity in the Cloud

Exo-leasing : 2-level transaction systemExo-leasing : 2-level transaction systemLow-level:

generic server

runs base transactions r/w OCC

High-level:

application transactions run on clients

synchronize using escrow objects

Page 48: ACID and Modularity in the Cloud

Durability - from base transactions

I&C - semantic

Atomicity -

reservations like locks,

but unlike locks

must release reservations at commit

can be lazy on aborts

ACID for high-level transactions

Page 49: ACID and Modularity in the Cloud

Server-side 80-90’s protocolServer-side 80-90’s protocol implementationsimplementations

Typically look like a monitor• Monitor procedures manage reservations

• A mutex protects the shared state

Advantage of exo approach• Can convert server-side to client-side

• Can exploit existing clever 80-90’s algorithms on commodity servers

Page 50: ACID and Modularity in the Cloud

Transformation: Transformation: Server-side Escrow Server-side Escrow to Client-sideto Client-side

Service object exports a collection of methods

(acquire, release, expire)

Object implementation consists of

procedures implementing the methods (split and merge)

plus shared state they are manipulating:

- log of outstanding reservations with leases and inverses

- internal state ( in-stock balance object)

Code resembles a monitor:

a type specific lock manager and

a mutex protecting shared state

Exo Transformation:

Client caches the escrow object,

runs methods on cached copy, updates server copy at commit.

Cache coherence protocol (invalid sets) replaces mutex

Plus two-level transaction system Application level transactions are ACID with semantic I

Reservations (semantic locks + timeouts) run as regular ACID

Page 51: ACID and Modularity in the Cloud

Promised extra benefitPromised extra benefit

“I have extra, want my reservation? “

In today transaction systems must reconnect

Exo-leasing enables

transfer without reconnecting

Page 52: ACID and Modularity in the Cloud

Reservation TransferReservation Transfer

Insight:

• The client side in exo-leasing carries the complete type-specific synchronization logic

• A helper client can “give-up” some of his reservations and transfer it to a requester client, to allow requester to avoid conflicts

Page 53: ACID and Modularity in the Cloud

Internet Datacenter

Application

Escrow objects

Cache

Application

Escrow objects

Cache

Somewhere in the Kerala ...

Commodity servers

Page 54: ACID and Modularity in the Cloud

Begin top-level transactionObtain reservations Loop {

Refresh/load objects into local cacheDisconnect from serverLoop{ Perform local tentative transactions Validate tentative transactions against reservations Record transaction results Connect to collaborator // Start reservation split and transfer Refresh/load objects if desired Provide some reservations if desired Obtain new reservations if desired } // End reservation split and transferConnect to the server Release some reservations if desiredRenew or obtain new reservations if necessary

} Commit top-level transaction i.e. atomically validate/abort local transactions and

release unused reservations.

Page 55: ACID and Modularity in the Cloud

Transfer Correctness Transfer Correctness

An execution with a transfer must be equivalent to one without transfer, where reservations are acquired by interacting with the servers

Helper and requester can crash, or reconnect in any order

A transfer protocol ( transfer is logged both in helper and requester, ..) recovers in all cases

Page 56: ACID and Modularity in the Cloud

Example: split and transferExample: split and transfer

Page 57: ACID and Modularity in the Cloud

Summary: Summary: classic transactionsclassic transactions

ACID Transactions: a basic abstraction simplifies how programmers deal with concurrency and failures

CC: locking

Recovery

In distributed systems

optimistic CC works better,

but need conflict reconciliation

Type-specific CC: can avoid conflicts

but prior approaches face a barrier

Page 58: ACID and Modularity in the Cloud

Summary: Summary: exo-leasingexo-leasing

Makes it possible to run type-specific synchronization on generic commodity servers (good for cloud..)

Enables a new features: reservation transfer between mobile clients

We examined escrow, but approach is general – can recycle clever schemes from 80’s and 90’s

Page 59: ACID and Modularity in the Cloud

Any Questions?Any Questions?

Builds on:

Thor system (SIGMOD 95, MIT project)

MX system (ECOOP 06, Brandeis project)

Exo-leasing system (Middleware 08, Brandeis + Doug Terry)

Future work:

client side merge for CRDT

server side PSI (builds on snapshot system called Retro)

Page 60: ACID and Modularity in the Cloud

Glossing over: Glossing over: Experimental evaluation

• Prior studies show performance benefit oftype-specific reservations (Prequica, 80’s-90’s)

mobile C2C transfer (Tian, Flynn, Issarny...)

• Do not repeat, focus on the cost of doing business with exo-leasing

the overhead of disconnected validation

• The upshot: cost is moderate

Page 61: ACID and Modularity in the Cloud

Skipping: Skipping:

System design and implementation details for client side

• 2-level transaction system + open nested transactions for reservations (server side: Lomet/Weikum )

• mobile cooperative caching system (Tian 06, Blue 07)

Page 62: ACID and Modularity in the Cloud

Extension 1: long running transactionsExtension 1: long running transactions

Exo-leasing • Helps long-running update transactions

Snapshot Isolation • Help long-running queries (read-only transactions)

How about both ?

See our ExoSnap paper proposal.

Page 63: ACID and Modularity in the Cloud

Extension 2: Extension 2:

Exo-leasing • Helps fragmentable types

CRDTS• Help commutative types

How about both?

in progress.. client side