Synchronization. Clock Synchronization

Similar documents
Synchronization. Chapter 5

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

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

Chapter 6 Synchronization

Distributed Synchronization. EECS 591 Farnam Jahanian University of Michigan

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

CSE 5306 Distributed Systems. Synchronization

Synchronization (contd.)

CSE 5306 Distributed Systems

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

Distributed Systems Principles and Paradigms

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

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

殷亚凤. Synchronization. Distributed Systems [6]

Synchronization Part 1. REK s adaptation of Claypool s adaptation of Tanenbaum s Distributed Systems Chapter 5

Last Class: Naming. Today: Classical Problems in Distributed Systems. Naming. Time ordering and clock synchronization (today)

Distributed Systems Synchronization

Verteilte Systeme (Distributed Systems)

Part III Transactions

Distributed Systems COMP 212. Revision 2 Othon Michail

Clock and Time. THOAI NAM Faculty of Information Technology HCMC University of Technology

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

Distributed Coordination 1/39

Synchronization. Distributed Systems IT332

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

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

Distributed Operating Systems. Distributed Synchronization

(Pessimistic) Timestamp Ordering

Transactions. A Banking Example

Exam 2 Review. Fall 2011

PROCESS SYNCHRONIZATION

Synchronisation in. Distributed Systems. Co-operation and Co-ordination in. Distributed Systems. Kinds of Synchronisation. Clock Synchronization

Mutual Exclusion. A Centralized Algorithm

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

Clock-Synchronisation

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

Last Class: Clock Synchronization. Today: More Canonical Problems

Time Synchronization and Logical Clocks

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

Distributed Systems COMP 212. Lecture 17 Othon Michail

CMPSCI 677 Operating Systems Spring Lecture 14: March 9

DB2 Lecture 10 Concurrency Control

Multi-threaded programming in Java

ICT 6544 Distributed Systems Lecture 7

Control. CS432: Distributed Systems Spring 2017

UNIT-I MODES OF COMMUNICATION

CS 347 Parallel and Distributed Data Processing

Time in Distributed Systems

Synchronisation and Coordination (Part 2)


CS 347 Parallel and Distributed Data Processing

Frequently asked questions from the previous class survey

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

Failure Tolerance. Distributed Systems Santa Clara University

Causal Consistency and Two-Phase Commit

Distributed Systems Exam 1 Review. Paul Krzyzanowski. Rutgers University. Fall 2016

0: BEGIN TRANSACTION 1: W = 1 2: X = W + 1 3: Y = X * 2 4: COMMIT TRANSACTION

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

DATABASE DESIGN I - 1DL300

TIME ATTRIBUTION 11/4/2018. George Porter Nov 6 and 8, 2018

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

Silberschatz and Galvin Chapter 18

Distributed Transactions

DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK. UNIT I PART A (2 marks)

Distributed Systems. 12. Concurrency Control. Paul Krzyzanowski. Rutgers University. Fall 2017

Last Class: Naming. DNS Implementation

Chapter 16: Distributed Synchronization

Concurrency Control. Transaction Management. Lost Update Problem. Need for Concurrency Control. Concurrency control

Homework #2 Nathan Balon CIS 578 October 31, 2004

Distributed systems. Lecture 6: distributed transactions, elections, consensus and replication. Malte Schwarzkopf

Chapter 18: Distributed

Process Synchroniztion Mutual Exclusion & Election Algorithms

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

Exam 2 Review. October 29, Paul Krzyzanowski 1

PRIMARY-BACKUP REPLICATION

Distributed Systems. coordination Johan Montelius ID2201. Distributed Systems ID2201

Chapter 22. Transaction Management

Transaction Management. Pearson Education Limited 1995, 2005

TRANSACTION PROPERTIES

Fault Tolerance. Goals: transparent: mask (i.e., completely recover from) all failures, or predictable: exhibit a well defined failure behavior

Lecture 6: Logical Time

2. Time and Global States Page 1. University of Freiburg, Germany Department of Computer Science. Distributed Systems

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

Lecture 10: Clocks and Time

Concurrency Control in Distributed Systems. ECE 677 University of Arizona

DISTRIBUTED MUTEX. EE324 Lecture 11

Consistency in Distributed Systems

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

EE324 INTRO. TO DISTRIBUTED SYSTEMS LECTURE 13 TRANSACTIONS

wait with priority An enhanced version of the wait operation accepts an optional priority argument:

Topics in Reliable Distributed Systems

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

CprE Fault Tolerance. Dr. Yong Guan. Department of Electrical and Computer Engineering & Information Assurance Center Iowa State University

CS October 2017

CS 425 / ECE 428 Distributed Systems Fall 2017

Time. COS 418: Distributed Systems Lecture 3. Wyatt Lloyd

Concurrent & Distributed Systems Supervision Exercises

Concurrency control CS 417. Distributed Systems CS 417

Transcription:

Synchronization Clock Synchronization Logical clocks Global state Election algorithms Mutual exclusion Distributed transactions 1 Clock Synchronization Time is counted based on tick Time judged by query to counter Also: Time synchronized from external source Fine for centralized system, but: Distributed system? 2

Example: distributed make When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time. 3 Solar time Physical clocks 1 second = average time per day / 86400 Problem: days are getting longer Astronomical time Greenwich mean time Atomic time 1 second = 9,192,631,770 transition of Cesium 133 atom TAI: international atomic time 4

Universal Coordinated Time UTC: TAI seconds are of constant length, unlike solar seconds. Leap seconds are introduced when necessary to keep in phase with the sun. UTC is broadcast via Shortwave radio Satellite 5 Clock Synchronization Algorithms The relation between clock time and UTC when clocks tick at different rates. 6

Clock Synchronization Principles Drift rate: To assure no more than δ difference synchronize at least every: δ / (2ρ) seconds. 7 Cristian's Algorithm Needs to be adjusted UTC response Request + response time Interrupt handling time Only forward adjustments Getting the current time from a time server 8

The Berkeley Algorithm a) The time daemon asks all the other machines for their clock values b) The machines answer c) The time daemon tells everyone how to adjust their clock 9 Logical Clock Ordering more important than actual time happened-before relation: If a and b are two events in the same process, and a comes before b, then a b If a is the sending of a message, and b is the receipt of that message, then a b If a b and b c, then a c 10

Logical Clock timestamp C(e) for each event e If a and b are two events in the same process, and a b, then we demand that C(a) < C(b) If a corresponds to sending a message m, and b to the receipt of that message, then also C(a) < C(b) 11 Lamport Algorithm Each process P i maintains a local counter C i and adjusts this counter according to the following rules: 1. For any two successive events that take place within P i, C i is incremented by 1. 2. Each time a message m is sent by process P i, the message receives a timestamp T m = C i. 3. Whenever a message m is received by a process P j, P j adjusts its local counter C j : Cj = max{c j + 1, T m +1} 12

Lamport Timestamps Three processes, each with its own clock The clocks run at different rates Lamport's algorithm corrects the clocks 13 Example: Totally-Ordered Multicasting Updating a replicated database and leaving it in an inconsistent state 14

Global State Consists of local state for each process, plus all messages in transit Cut: distributed snapshot of the global state 15 Global State Cut examples consistent cut inconsistent cut 16

Global State determination 1/2 Organization of a process and channels for a distributed snapshot 17 Global State determination 2/2 b) Process Q receives a marker for the first time and records its local state c) Q records all incoming message d) Q receives a marker for its incoming channel and finishes recording the state of the incoming channel 18

Election algorithms Need to select process Act as coordinator Act as initiator Special purpose Selection from equals Assumption: process has unique number 19 Bully Election Algorithm 1/2 a. Process 4 holds an election b. Process 5 and 6 respond, telling 4 to stop c. Now 5 and 6 each hold an election 20

Bully Election Algorithm 2/2 d) Process 6 tells 5 to stop e) Process 6 wins and tells everyone 21 A Ring Election Algorithm 22

Mutual Exclusion Gain safe access to shared resource in a distributed system solutions: Via a centralized server Completely distributed with no topology imposed Completely distributed, making use of a (logical) ring 23 Mutual Exclusion: A Centralized Algorithm a) Process 1 asks the coordinator for permission to enter a critical region. Permission is granted b) Process 2 then asks permission to enter the same critical region. The coordinator does not reply c) When process 1 exits the critical region, it tells the coordinator, when then replies to 2 24

A Distributed Algorithm a) Two processes want to enter the same critical region at the same moment b) Process 0 has the lowest timestamp, so it wins c) When process 0 is done, it sends an OK also, so 2 can now enter the critical region 25 A Token Ring Algorithm a) An unordered group of processes on a network. b) A logical ring constructed in software. c) A token is passed around the ring to signify access right 26

Mutual Exclusion Algorithms 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 ) Crash of any process Token ring 1 to 0 to n 1 Lost token, process crash 27 Distributed Transactions Transaction model Transaction classifications Implementations Concurrency control 28

The Transaction Model (1) Updating a master tape is fault tolerant 29 The Transaction Model (2) 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 Examples of primitives for transactions 30

The Transaction Model (3) 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 31 Transaction properties Atomic To the outside world, the transaction happens indivisibly Consistent The transaction does not violate system invariants Isolated Concurrent transactions do not interfere with each other Durable Once a transaction commits, the changes are permanent 32

Distributed Transactions 33 Implementations Use a private workspace Each client gets its own copy of the (part of the) database When things go wrong delete copy, otherwise commit the changes to the original Example: File system Write-ahead log 34

Private Workspace a) The file index and disk blocks for a three-block file b) The situation after a transaction has modified block 0 and appended block 3 c) After committing 35 Write-ahead 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) A transaction b) d) The log before each statement is executed 36

Concurrency control Problem: 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 37 Concurrency Control Management 1/2 38

Concurrency Control Management 2/2 General organization of managers for handling distributed transactions. 39 Serializability BEGIN_TRANSACTION x = 0; x = x + 1; END_TRANSACTION BEGIN_TRANSACTION x = 0; x = x + 2; END_TRANSACTION BEGIN_TRANSACTION x = 0; x = x + 3; END_TRANSACTION Potential values for x: 1, 2, 3 Schedules 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; Legal Legal Illegal 40

Concurrency control implementation Transactions are a sequence of read and write operations Goal: properly schedule conflicting operations Read-write conflict Write-write conflict Multiple read operations to not conflict 2 approaches Pessimistic vs. optimistic 41 Two-Phase Locking 42

Distributed Two-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. 43 Two-Phase Locking Problem 1: System can come into a deadlock Practical solution: put a timeout on locks and abort transaction on expiration Problem 2: When should the scheduler actually release a lock: 1. when it knows that no more locks will be requested 2. when all operations have been executed Strict two-phase locking 44

Strict Two-Phase Locking 45 Timestamp ordering Transaction manager assigns a unique timestamp to each transaction Every data item is time-stamped with the timestamp of the transaction that read and wrote it If 2 operations conflict then the data manager processes the one with the lowest timestamp first 46

Timestamp Ordering Concurrency control using timestamps 47