eec-681/781 distributed computing systems lecture 12 wenbing zhao [email protected] cleveland state...

28
EEC-681/781 EEC-681/781 Distributed Computing Distributed Computing Systems Systems Lecture 12 Lecture 12 Wenbing Zhao Wenbing Zhao [email protected] [email protected] Cleveland State University Cleveland State University

Post on 21-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

EEC-681/781EEC-681/781Distributed Computing Distributed Computing

SystemsSystems

Lecture 12Lecture 12

Wenbing ZhaoWenbing [email protected]@ieee.org

Cleveland State UniversityCleveland State University

Page 2: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

22

OutlineOutline

• Project report requirement

• Transaction processing concepts

• Distributed transaction and two phase commit

• Midterm #2– 12/6 Wednesday

Page 3: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

33

Project Report RequirementProject Report Requirement

• Theory track– Introduction: define the problem and provide

motivation why we need a solution– Background: so that readers can understand the

techniques used to solve the problem– Current state of the art: what are the fundamental

techniques used to solve the problem. Ideally, provide a taxonomy of the techniques

– Open issues and future research directions: what are the hard problems remaining to be solved?

Page 4: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

44

Project Report RequirementProject Report Requirement• Implementation track

– Introduction: define the problem domain and your implementation. Provide motivation on your system

– System model: assumption, restrictions, models– Design: component diagram, class diagram, pseudo

code, algorithms, header explanation– Implementation: what language, tools, libraries did you

use, a simple user guide on how to user your system– Performance and testing: throughput, latency, test

cases– Related work– Conclusion and future work

Page 5: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

55

Project RequirementProject Requirement

• What you should NOT do– Take an application from Internet or your friend => F grade– False claim of working prototype, fabricate performance data and

test cases => F grade– Use other’s slides for presentation

• What you should do– If used any open source code, acknowledge it in both your

source code and your report, and provide reference– Extensively comment your code– Follow good naming and coding conventions– Use a source version control system, such as cvs, svn– If your code does not work, acknowledge it in your report

Page 6: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

66

Project Report RequirementProject Report Requirement

• Report format: IEEE Transactions format. 4-10 pages– MS Word Template

• http://www.ieee.org/portal/cms_docs/pubs/transactions/TRANS-JOUR.DOC

– LaTex Template • http://www.ieee.org/portal/cms_docs/pubs/transactions/

IEEEtran.zip (main text)

• http://www.ieee.org/portal/cms_docs/pubs/transactions/IEEEtranBST.zip (bibliography)

• Report due: Dec 13 mid-night (electronic copy of the report & source code is required)

Page 7: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

77

Why Transaction Processing?Why Transaction Processing?

• To achieve a form of fault tolerance– If something bad happens in a middle of a set of

operations, we abort and rollback to the original state

Page 8: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

88

Transaction and ACID PropertiesTransaction and ACID Properties

• Atomicity: All operations either succeed, or all of them fail. When the transaction fails, the state of the object will remain unaffected by the transaction.

• Consistency: A transaction establishes a valid state transition. • Isolation: Concurrent transactions do not interfere with each other.

It appears to each transaction T that other transactions occur either before T, or after T, but never both.

• Durability: After the execution of a transaction, its effects are made permanent: changes to the state survive failures.

A transaction is a collection of operations on the state of an object (database, object composition, etc.) that satisfies the following properties:

Page 9: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

99

Primitives for TransactionsPrimitives for Transactions

Primitive Description

BEGIN_TRANSACTION Make the start of a transaction

END_TRANSACTION Terminate the transaction and try to commit

ABORT_TRANSACTION Kill the transaction and restore the old values

READ Read data from a file, a table, or otherwise

WRITE Write data to a file, a table, or otherwise

BEGIN_TRANSACTION reserve WP -> JFK; reserve JFK -> Nairobi; reserve Nairobi -> Malindi;END_TRANSACTION

(a)

BEGIN_TRANSACTION reserve WP -> JFK; reserve JFK -> Nairobi; reserve Nairobi -> Malindi full =>ABORT_TRANSACTION (b)

Example transactions

Page 10: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1010

Transaction ClassificationTransaction Classification

• Flat transactions: a sequence of operations that satisfies the ACID properties (the most common one)

• Nested transactions: A hierarchy of transactions that allows– Concurrent processing of subtransactions, and – Recovery per subtransaction

• Distributed transactions: A (flat) transaction that span multiple databases distributed across the network

Page 11: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1111

Implementation of TransactionsImplementation of Transactions

• Private workspace

• Writeahead log

Page 12: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1212

Private WorkspacePrivate Workspace

The file index and disk blocks for a three-block file

The situation after a transaction has modified

block 0 and appended block 3

After committing

A transaction gets its own copy of the (part of the) database. When things go wrong delete copy, otherwise commit the changes to the original

Page 13: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1313

Writeahead LogWriteahead Log

x = 0;

y = 0;

BEGIN_TRANSACTION;

x = x + 1;

y = y + 2

x = y * y;

END_TRANSACTION;

(a)

Log

[x = 0 / 1]

(b)

Log

[x = 0 / 1]

[y = 0 / 2]

(c)

Log

[x = 0 / 1]

[y = 0 / 2]

[x = 1 / 4]

(d)

A transaction The log before & after each statement is executed

Use a writeahead log in which changes are recorded allowing one to roll back when things go wrong

Page 14: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1414

Concurrency Control Concurrency Control

• Goal: Increase efficiency by allowing several transactions to execute at the same time

• Constraint: Effect should be the same as if the transactions were executed in some serial order

General organization of managers for handling

transactions

Page 15: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1515

Concurrency Control Concurrency Control

General organization of managers for handling distributed transactions

Page 16: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1616

SerializabilitySerializability

• Consider a collection E of transactions T1, … Tn• Goal is to conduct a serializable execution of E:

– Transactions in E are possibly concurrently executed according to some schedule S

– Schedule S is equivalent to some totally ordered execution of T1, … Tn

• Two operations Op(Ti, x) and Op(Tj, x) on the same data item x, and from a set of logs may conflict at a data manager:– read-write conflict (rw): One is a read operation while the other

is a write operation on x– write-write conflict (ww): Both are write operations on x

Page 17: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1717

Basic Scheduling TheoremBasic Scheduling Theorem

• Concurrency control - process conflicting reads and writes in certain relative orders

• Read-write and write-write conflicts can be synchronized independently, as long as we stick to a total ordering of transactions that is consistent with both types of conflicts

Page 18: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1818

Synchronization TechniquesSynchronization Techniques

• Two-phase locking: Before reading or writing a data item, a lock must be obtained. After a lock is released, the transaction is not allowed to acquire any more locks

• Timestamp ordering: Operations in a transaction are timestamped, and data managers are forced to handle operations in timestamp order

• Optimistic control: Don’t prevent things from going wrong, but correct the situation if conflicts actually did happen

Page 19: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

1919

Two-phase LockingTwo-phase Locking

• There are only READ and WRITE operations within transactions

• Locks are granted and released only by scheduler

• Locking policy is to avoid conflicts between operations

Page 20: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2020

Two-phase LockingTwo-phase Locking• Rule 1: When client submits Op(Ti,x), scheduler tests

whether it conflicts with an operation Op(Tj,x) from some other client. If no conflict then grant Op(Ti,x), otherwise delay execution of Op(Ti,x)– Conflicting operations are executed in the same order as that

locks are granted

• Rule 2: If Op(Ti,x) has been granted, do not release the lock until Op(Ti,x) has been executed by data manager– Guarantees LOCK => Op => RELEASE order

• Rule 3: If RELEASE(Ti,x) has taken place, no more locks for Ti may be granted– Combined with rule 1, guarantees that all pairs of conflicting

operations of two transactions are done in the same order

Page 21: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2121

Two-Phase LockingTwo-Phase Locking

• Centralized 2PL: A single site handles all locks• Primary 2PL: Each data item is assigned a primary site to handle its locks. Data

is not necessarily replicated• Distributed 2PL: Assumes data can be replicated. Each primary is responsible

for handling locks for its data, which may reside at remote data managers

Page 22: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2222

Two-phase Locking: ProblemsTwo-phase Locking: Problems• Problem 1: System can come into a deadlock. How?

– Practical solution: put a timeout on locks and abort transaction on expiration.

• Problem 2: When should the scheduler actually release a lock:– (1) when operation has been executed

– (2) when it knows that no more locks will be requested

• No good way of testing condition (2) unless transaction has been committed or aborted

• Moreover: Assume the following execution sequence takes place:RELEASE(Ti,x) => LOCK(Tj,x) => ABORT(Ti).

• Consequence: scheduler will have to abort Tj as well (cascaded aborts)

• Solution: Release all locks only at commit/abort time (strict two-phase locking)

Page 23: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2323

Strict Two-Phase Locking Strict Two-Phase Locking

Page 24: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2424

Two-Phase Commit – Achieving Atomicity Two-Phase Commit – Achieving Atomicity in Distributed Transactionsin Distributed Transactions

• Model: The client who initiated the computation acts as a coordinator; processes required to commit are the participants

• Phase 1a: Coordinator sends VOTE_REQUEST to participants (also called a pre-write)

• Phase 1b: When participant receives VOTE_REQUEST it returns either YES or NO to coordinator. If it sends NO, it aborts its local computation

• Phase 2a: Coordinator collects all votes; if all are YES, it sends COMMIT to all participants, otherwise it sends ABORT

• Phase 2b: Each participant waits for COMMIT or ABORT and handles accordingly

Page 25: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2525

Two-Phase Commit Two-Phase Commit

The finite state machine for the

coordinator in 2PC

The finite state machine for a

participant

Page 26: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2626

2PC – Failing Participant2PC – Failing Participant

• Initial state: No problem, as participant was unaware of the protocol

• Ready state: Participant is waiting to either commit or abort. After recovery, participant needs to know which state transition it should make => log the coordinator’s decision

• Abort state: Need to make entry into abort state idempotent

• Commit state: Also make entry into commit state idempotent

Consider participant crash in one of its states, and the subsequent recovery to that state:

Page 27: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2727

2PC – Failing Coordinator2PC – Failing Coordinator• If it fails, the final decision is not available until the

coordinator recovers• Alternative: Let a participant P in the ready state

timeout when it hasn’t received the coordinator’s decision– P tries to find out what other participants know

• Question: Can P not succeed in getting the required information?

Page 28: EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao wenbing@ieee.org Cleveland State University

Fall Semester 2006Fall Semester 2006 EEC-681: Distributed Computing SystemsEEC-681: Distributed Computing Systems Wenbing ZhaoWenbing Zhao

2828

2PC – Failing Coordinator2PC – Failing Coordinator• Question: Can P not succeed in getting the required

information? • Observation: Essence of the problem is that a

recovering participant cannot make a local decision: it is dependent on other (possibly failed) processes– There might exist one participant that has received a COMMIT

decision from the coordinator and subsequently failed (more or less concurrently failed with the coordinator)

– The rest of participants cannot unilaterally decide to abort the transaction