Synchronization Part 2. REK s adaptation of Claypool s adaptation oftanenbaum s Distributed Systems Chapter 5 and Silberschatz Chapter 17

Similar documents
Synchronization. Chapter 5

Synchronization. Clock Synchronization

Synchronization Part II. CS403/534 Distributed Systems Erkay Savas Sabanci University

Synchronization (contd.)

PROCESS SYNCHRONIZATION

Database systems. Database: a collection of shared data objects (d1, d2, dn) that can be accessed by users

Distributed Synchronization. EECS 591 Farnam Jahanian University of Michigan

Part III Transactions

Transactions. A Banking Example

Mutual Exclusion. A Centralized Algorithm

Distributed Systems COMP 212. Revision 2 Othon Michail

Exam 2 Review. Fall 2011

Atomic Transac1ons. Atomic Transactions. Q1: What if network fails before deposit? Q2: What if sequence is interrupted by another sequence?

Distributed Systems Principles and Paradigms

DISTRIBUTED SYSTEMS [COMP9243] Lecture 5: Synchronisation and Coordination (Part 2) TRANSACTION EXAMPLES TRANSACTIONS.

DISTRIBUTED SYSTEMS [COMP9243] Lecture 5: Synchronisation and Coordination (Part 2) TRANSACTION EXAMPLES TRANSACTIONS.

Distributed Systems (ICE 601) Transactions & Concurrency Control - Part1

Chapter 16: Distributed Synchronization

Process Synchroniztion Mutual Exclusion & Election Algorithms

Chapter 18: Distributed

Clock Synchronization. Synchronization. Clock Synchronization Algorithms. Physical Clock Synchronization. Tanenbaum Chapter 6 plus additional papers

Last Class: Clock Synchronization. Today: More Canonical Problems

(Pessimistic) Timestamp Ordering. Rules for read and write Operations. Read Operations and Timestamps. Write Operations and Timestamps

CSE 5306 Distributed Systems. Synchronization

Chapter 6 Synchronization

Distributed Systems. coordination Johan Montelius ID2201. Distributed Systems ID2201

(Pessimistic) Timestamp Ordering

11/7/2018. Event Ordering. Module 18: Distributed Coordination. Distributed Mutual Exclusion (DME) Implementation of. DME: Centralized Approach

Control. CS432: Distributed Systems Spring 2017

Silberschatz and Galvin Chapter 18

Last Class: Clock Synchronization. Today: More Canonical Problems

Coordination 1. To do. Mutual exclusion Election algorithms Next time: Global state. q q q

Distributed Transaction Management

Problem: if one process cannot perform its operation, it cannot notify the. Thus in practise better schemes are needed.

Synchronisation and Coordination (Part 2)

XI. Transactions CS Computer App in Business: Databases. Lecture Topics

Distributed Transactions

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Intro to DB CHAPTER 15 TRANSACTION MNGMNT

Chapter 22. Transaction Management

Mobile and Heterogeneous databases Distributed Database System Transaction Management. A.R. Hurson Computer Science Missouri Science & Technology

Advanced Topics in Distributed Systems. Dr. Ayman A. Abdel-Hamid. Computer Science Department Virginia Tech

Database Tuning and Physical Design: Execution of Transactions

Distributed Operating Systems. Distributed Synchronization

Topics in Reliable Distributed Systems

Foundation of Database Transaction Processing. Copyright 2012 Pearson Education, Inc.

Transactions. Transactions. Distributed Software Systems. A client s banking transaction. Bank Operations. Operations in Coordinator interface

Distributed Transactions Brian Nielsen

Transaction Management. Pearson Education Limited 1995, 2005

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Distributed Systems Synchronization

CMPSCI 677 Operating Systems Spring Lecture 14: March 9

Transactions. Transaction. Execution of a user program in a DBMS.

CS /15/16. Paul Krzyzanowski 1. Question 1. Distributed Systems 2016 Exam 2 Review. Question 3. Question 2. Question 5.

Intro to Transactions

Topics. File Buffer Cache for Performance. What to Cache? COS 318: Operating Systems. File Performance and Reliability

Exam 2 Review. October 29, Paul Krzyzanowski 1

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

CS5412: TRANSACTIONS (I)


T ransaction Management 4/23/2018 1

Concurrency Control in Distributed Systems. ECE 677 University of Arizona

CHAPTER 3 RECOVERY & CONCURRENCY ADVANCED DATABASE SYSTEMS. Assist. Prof. Dr. Volkan TUNALI

CSE 486/586 Distributed Systems

Database System Concepts

TRANSACTION PROPERTIES

CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [DISTRIBUTED MUTUAL EXCLUSION] Frequently asked questions from the previous class survey

CS October 2017

Weak Levels of Consistency

Distributed Transaction Management 2003

CS455: Introduction to Distributed Systems [Spring 2018] Dept. Of Computer Science, Colorado State University

Transactions and Locking. Rose-Hulman Institute of Technology Curt Clifton

Chapter 25: Advanced Transaction Processing

殷亚凤. Synchronization. Distributed Systems [6]

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences. Dr. Anis Koubaa. Spring 2014

Chapter 6 Synchronization (2)

Last Time. 19: Distributed Coordination. Distributed Coordination. Recall. Event Ordering. Happens-before

Introduction to Data Management. Lecture #26 (Transactions, cont.)

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

Transactions. ACID Properties of Transactions. Atomicity - all or nothing property - Fully performed or not at all

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

OUTLINE. Introduction Clock synchronization Logical clocks Global state Mutual exclusion Election algorithms Deadlocks in distributed systems

Problems Caused by Failures

Introduction to Transaction Processing Concepts and Theory

Distributed Systems 8L for Part IB

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

CHAPTER 4: INTERPROCESS COMMUNICATION AND COORDINATION

Transaction Management & Concurrency Control. CS 377: Database Systems

CSE 486/586: Distributed Systems

Distributed Databases

Introduction to Data Management CSE 344

UNIT-I MODES OF COMMUNICATION

SYNCHRONIZATION. DISTRIBUTED SYSTEMS Principles and Paradigms. Second Edition. Chapter 6 ANDREW S. TANENBAUM MAARTEN VAN STEEN

Parallel and Distributed Systems. Programming Models. Why Parallel or Distributed Computing? What is a parallel computer?

Chapter 7 (Cont.) Transaction Management and Concurrency Control

Transactions. Chapter 15. New Chapter. CS 2550 / Spring 2006 Principles of Database Systems. Roadmap. Concept of Transaction.

Distributed Algorithmic

Several of these problems are motivated by trying to use solutiions used in `centralized computing to distributed computing

UNIT-IV TRANSACTION PROCESSING CONCEPTS

Transcription:

Synchronization Part 2 REK s adaptation of Claypool s adaptation oftanenbaum s Distributed Systems Chapter 5 and Silberschatz Chapter 17 1

Outline Part 2! Clock Synchronization! Clock Synchronization Algorithms! Logical Clocks! Election Algorithms! Mutual Exclusion! Distributed Transactions! Concurrency Control Distributed Computing Systems 2

Election Algorithms! Many distributed algorithms such as mutual exclusion and deadlock detection require a coordinator process.! When the coordinator process fails, the distributed group of processes must execute an election algorithm to determine a new coordinator process.! These algorithms will assume that each active process has a unique priority id. Distributed Computing Systems 3

The Bully Algorithm When any process, P, notices that the coordinator is no longer responding it initiates an election: 1. P sends an election message to all processes with higher id numbers. 2. If no one responds, P wins the election and becomes coordinator. 3. If a higher process responds, it takes over. Process P s job is done. Distributed Computing Systems 4

The Bully Algorithm! At any moment, a process can receive an election message from one of its lower-numbered colleagues.! The receiver sends an OK back to the sender and conducts its own election.! Eventually only the bully process remains. The bully announces victory to all processes in the distributed group. Distributed Computing Systems 5

Bully Algorithm Example! Process 4 notices 7 down.! Process 4 holds an election.! Process 5 and 6 respond, telling 4 to stop.! Now 5 and 6 each hold an election. Distributed Computing Systems 6

Bully Algorithm Example Process 6 tells process 5 to stop.! Process 6 (the bully) wins and tells everyone.! If processes 7 comes up, starts elections again. Distributed Computing Systems 7

A Ring Algorithm! Assume the processes are logically ordered in a ring {implies a successor pointer and an active process list} that is unidirectional. When any process, P, notices that the coordinator is no longer responding it initiates an election: 1. P sends message containing P s process id to the next available successor. Distributed Computing Systems 8

A Ring Algorithm 2. At each active process, the receiving process adds its process number to the list of processes in the message and forwards it to its successor. 3. Eventually, the message gets back to the sender. 4. The initial sender sends out a second message letting everyone know who the coordinator is {the process with the highest number} and indicating the current members of the active list of processes. Distributed Computing Systems 9

A Ring Algorithm Even if two ELECTIONS start at once, everyone will pick the same leader. Distributed Computing Systems 10

Outline Part 2! Clock Synchronization! Clock Synchronization Algorithms! Logical Clocks! Election Algorithms! Mutual Exclusion! Distributed Transactions! Concurrency Control Distributed Computing Systems 11

Mutual Exclusion! To guarantee consistency among distributed processes that are accessing shared memory, it is necessary to provide mutual exclusion when accessing a critical section.! Assume n processes. Distributed Computing Systems 12

A Centralized Algorithm for Mutual Exclusion Assume a coordinator has been elected. A process sends a message to the coordinator requesting permission to enter a critical section. If no other process is in the critical section, permission is granted. If another process then asks permission to enter the same critical region, the coordinator does not reply (Or, it sends permission denied ) and queues the request. When a process exits the critical section, it sends a message to the coordinator. The coordinator takes first entry off the queue and sends that process a message granting permission to enter the critical section. Distributed Computing Systems 13

A Centralized Algorithm for Mutual Exclusion Distributed Computing Systems 14

A Distributed Algorithm for Mutual Exclusion Ricart and Agrawala algorithm (1981) assumes there is a mechanism for totally ordering of all events in the system (e.g. Lamport s algorithm) and a reliable message system. 1. A process wanting to enter critical sections (cs) sends a message with (cs name, process id, current time) to all processes (including itself). 2. When a process receives a cs request from another process, it reacts based on its current state with respect to the cs requested. There are three possible cases: Distributed Computing Systems 15

A Distributed Algorithm for Mutual Exclusion (cont.) a) If the receiver is not in the cs and it does not want to enter the cs, it sends an OK message to the sender. b) If the receiver is in the cs, it does not reply and queues the request. c) If the receiver wants to enter the cs but has not yet, it compares the timestamp of the incoming message with the timestamp of its message sent to everyone. {The lowest timestamp wins.} If the incoming timestamp is lower, the receiver sends an OK message to the sender. If its own timestamp is lower, the receiver queues the request and sends nothing. Distributed Computing Systems 16

A Distributed Algorithm for Mutual Exclusion (cont.)! After a process sends out a request to enter a cs, it waits for an OK from all the other processes. When all are received, it enters the cs.! Upon exiting cs, it sends OK messages to all processes on its queue for that cs and deletes them from the queue. Distributed Computing Systems 17

A Distributed Algorithm for Mutual Exclusion Distributed Computing Systems 18

A Token Ring Algorithm a) An unordered group of processes on a network. b) A logical ring constructed in software. A process must have token to enter. Distributed Computing Systems 19

Mutual Exclusion Algorithm Comparison Algorithm Messages per entry/exit Delay before entry (in message times) Problems Centralized 3 2 Coordinator crash Distributed 2 ( n 1 ) 2 ( n 1 ) Process crash Token ring 1 to 0 to n 1 Lost token, process crash! Centralized is the most efficient.! Token ring efficient when many want to use critical region. Distributed Computing Systems 20

Outline Part 2! Clock Synchronization! Clock Synchronization Algorithms! Logical Clocks! Election Algorithms! Mutual Exclusion! Distributed Transactions! Concurrency Control Distributed Computing Systems 21

The Transaction Model! The transaction model ensures mutual exclusion and supports atomic operations.! Consider using PC to:! Withdraw $100 from account 1! Deposit $100 to account 2! Interruption of the transaction is the problem. In distributed systems, this happens when a connection is broken. Distributed Computing Systems 22

The Transaction Model! If a transaction involves multiple actions or operates on multiple resources in a sequence, the transaction by definition is a single, atomic action. Namely,! It all happens, or none of it happens.! If process backs out, the state of the resources is as if the transaction never started. {This may require a rollback mechanism.} Distributed Computing Systems 23

Transaction Primitives Primitive BEGIN_TRANSACTION END_TRANSACTION ABORT_TRANSACTION READ WRITE Description Make the start of a transaction Terminate the transaction and try to commit Kill the transaction and restore the old values Read data from a file, a table, or otherwise Write data to a file, a table, or otherwise The primitives may be system calls, libraries or statements in a language (Sequential Query Language or SQL). Distributed Computing Systems 24

Example: Reserving Flight from White Plains to Nairobi 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) a) Transaction to reserve three flights commits. b) Transaction aborts when third flight is unavailable. Distributed Computing Systems 25

Transaction Properties [ACID] 1) Atomic: transactions are indivisible to the outside world. 2) Consistent: system invariants are not violated. 3) Isolated: concurrent transactions do not interfere with each other. {serializable} 4) Durability: once a transaction commits, the changes are permanent. {requires a distributed commit mechanism} Distributed Computing Systems 26

Classification of Transactions! Flat Transactions {satisfy ACID properties}! Limited partial results cannot be committed.! Example: what if want to keep first part of flight reservation? If abort and then restart, those might be gone.! Example: what if want to move a Web page. All links pointing to it would need to be updated. Requiring a flat transaction could lock resources for a long time.! Also Distributed and Nested Transactions Distributed Computing Systems 27

Nested vs. Distributed Transactions! Nested transaction gives you a hierarchy! Commit mechanism is complicated with nesting.! Distributed transaction is flat but across distributed data (example: JFK and Nairobi dbase) Distributed Computing Systems 28

Private Workspace! File system with transaction across multiple files! Normally, updates seen + No way to undo.! Private Workspace " need to copy files.! Only update Public Workspace when done.! If abort transaction, remove private copy.! But copy can be expensive! Distributed Computing Systems 29

Private Workspace a) Original file index (descriptor) and disk blocks b) Copy descriptor only. Copy blocks only when written. Modified block 0 and appended block 3 {shadow blocks} c) Replace original file (new blocks plus descriptor) after commit. Distributed Computing Systems 30

Writeahead Log x = 0; Log Log Log y = 0; BEGIN_TRANSACTION; x = x + 1; [x = 0 / 1] [x = 0 / 1] [x = 0 / 1] y = y + 2 [y = 0/2] [y = 0/2] x = y * y; [x = 1/4] END_TRANSACTION; (a) (b) (c) (d) b) d) log records old and new values before each statement is executed.! If transaction commits, nothing to do.! If transaction is aborted, use log to rollback. Distributed Computing Systems 31

Outline Part 2! Clock Synchronization! Clock Synchronization Algorithms! Logical Clocks! Election Algorithms! Mutual Exclusion! Distributed Transactions! Concurrency Control Distributed Computing Systems 32

Concurrency Control Allow parallel execution (ensure atomic) (ensure serial) General organization of managers for handling transactions. Distributed Computing Systems 33

Concurrency Control! General organization of managers for handling distributed transactions. Distributed Computing Systems 34

Serializability Allow parallel execution, but end result as if serial BEGIN_TRANSACTION x = 0; x = x + 1; END_TRANSACTION (a) BEGIN_TRANSACTION x = 0; x = x + 2; END_TRANSACTION (b) BEGIN_TRANSACTION x = 0; x = x + 3; END_TRANSACTION (c) Schedule 1 Schedule 2 Schedule 3 x = 0; x = x + 1; x = 0; x = x + 2; x = 0; x = x + 3 x = 0; x = 0; x = x + 1; x = x + 2; x = 0; x = x + 3; x = 0; x = 0; x = x + 1; x = 0; x = x + 2; x = x + 3; Concurrency controller needs to manage Legal Legal Illegal Distributed Computing Systems 35

Silberschatz Slide Atomicity! Either all the operations associated with a program unit are executed to completion, or none are performed.! Ensuring atomicity in a distributed system requires a local transaction coordinator, which is responsible for the following: Distributed Computing Systems 36

Silberschatz Slide Atomicity! Starting the execution of the transaction.! Breaking the transaction into a number of subtransactions, and distribution these subtransactions to the appropriate sites for execution.! Coordinating the termination of the transaction, which may result in the transaction being committed at all sites or aborted at all sites.! Assume each local site maintains a log for recovery. Distributed Computing Systems 37

Silberschatz Slide Two-Phase Commit Protocol (2PC)! Assumes fail-stop model.! Execution of the protocol is initiated by the coordinator after the last step of the transaction has been reached.! When the protocol is initiated, the transaction may still be executing at some of the local sites.! The protocol involves all the local sites at which the transaction executed.! Example: Let T be a transaction initiated at site S i and let the transaction coordinator at S i be C i. Distributed Computing Systems 38

Silberschatz Slide Phase 1: Obtaining a Decision! C i adds <prepare T> record to the log.! C i sends <prepare T> message to all sites.! When a site receives a <prepare T> message, the transaction manager determines if it can commit the transaction.! If no: add <no T> record to the log and respond to C i with <abort T> message.! If yes:! add <ready T> record to the log.! force all log records for T onto stable storage.! transaction manager sends <ready T> message to C i. Distributed Computing Systems 39

Phase 1 (Cont.)! Coordinator collects responses! All respond ready, decision is commit.! At least one response is abort, decision is abort.! At least one participant fails to respond within time out period, decision is abort. Silberschatz Slide Distributed Computing Systems 40

Phase 2: Recording Decision in the Database Silberschatz Slide! Coordinator adds a decision record <abort T> or <commit T> to its log and forces record onto stable storage.! Once that record reaches stable storage it is irrevocable (even if failures occur).! Coordinator sends a message to each participant informing it of the decision (commit or abort message).! Participants take appropriate action locally. Distributed Computing Systems 41

Two-Phase Locking 1. When scheduler receives an operation oper(t,x) from the TM, it tests for operation conflict with any other operation for which it already granted a lock. If conflict, oper(t,x) is delayed. No conflict " lock for x is granted and oper(t,x) is passed to DM. Distributed Computing Systems 42

Two-Phase Locking 2. The scheduler will never release a lock for x until DM indicates it has performed the operation for which the lock was set. 3. Once the scheduler has released a lock on behalf of T, T will NOT be permitted to acquire another lock. Distributed Computing Systems 43

Two-Phase Locking Distributed Computing Systems 44

Strict Two-Phase Locking! Always reads value written by a committed transaction. " This policy eliminates cascading aborts.! Releasing locks at the end of the transaction means transaction is unaware of the release operation. Distributed Computing Systems 45