election algorithmscs-4513, d-term 20071 synchronization (continued) cs-4513 d-term 2007 (slides...

36
Election Algorith ms CS-4513, D-Term 2007 1 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th ed., by Silbershatz, Galvin, & Gagne, Modern Operating Systems, 2 nd ed., by Tanenbaum, and Distributed Systems: Principles & Paradigms, 2 nd ed. By Tanenbaum and Van Steen)

Upload: vivian-burns

Post on 28-Dec-2015

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 1

Synchronization (continued)

CS-4513D-Term 2007

(Slides include materials from Operating System Concepts, 7th ed., by Silbershatz, Galvin, & Gagne, Modern Operating Systems, 2nd ed., by Tanenbaum, and Distributed Systems: Principles & Paradigms, 2nd

ed. By Tanenbaum and Van Steen)

Page 2: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 2

Review

• Real time not very good tool for some kinds of synchronization is distributed systems

• Logical “clocks”• Always monotonic

• Moved forward whenever a “later” message appears

• Mutual exclusion• Centralized control

• Decentralized & Distributed control

• Token control

Page 3: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 3

NTP (Network Time Protocol)

• Question: what is = TB – TA?

• Assume transit time is approximately the same both ways

• Assume that B is the time server that A wants to synchronize to

A

B

T1

T2 T3

T4

Page 4: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 4

NTP (Network Time Protocol)

• A knows (T4 – T1) from its own clock

• B reports T3 and T2 in response to NTP request

• A computes total transit time of

A

B

T1

T2 T3

T4

2314 TTTT

Page 5: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 5

• One-way transit time is approximately ½ total, i.e.,

• B’s clock at T4 reads approximately

NTP (Network Time Protocol)

A

B

T1

T2 T3

T4

22

321423143

TTTTTTTTT

2

2314 TTTT

Page 6: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 6

NTP (Network Time Protocol)

• B’s clock at T4 reads approximately (from previous slide)

• Thus, difference between B and A clocks at T4 is

A

B

T1

T2 T3

T4

22

43124

3214 TTTTT

TTTT

2

3214 TTTT

Page 7: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 7

Questions?

Page 8: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 8

Election Algorithms

• If we are using one process as a coordinator for a shared resource …

• …how do we select that one process?

• Often, there is no owner or master that is automatically considered as coordinator

• E.g., Grapevine, there is no owner for a Registry• By contrast:–DNS has a master for every domain

Page 9: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 9

Solution – an Election

• All nodes currently involved get together to choose a coordinator

• If the coordinator crashes or becomes isolated, elect a new coordinator

• If a previously crashed or isolated node, comes on line, a new election may have to be held.

Page 10: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 10

Election Algorithms

• Wired systems• Bully algorithm

• Ring algorithm

• Wireless systems

• Very large-scale systems

Page 11: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 11

Bully Algorithm

• Assume • All processes know about each other

• Processes numbered uniquely

• Suppose P notices no coordinator• Sends election message to all higher numbered

processes

• If none response, P takes over as coordinator

• If any responds, P yields

• …

Page 12: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 12

Bully Algorithm (continued)

• …

• Suppose Q receives election message• Replies OK to sender, saying it will take over

• Sends a new election message to higher numbered processes

• Repeat until only one process left standing• Announces victory by sending message saying that

it is coordinator

Page 13: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 13

Bully Algorithm (continued)

Page 14: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 14

Bully Algorithm (continued)

• …

• Suppose R comes back on line• Sends a new election message to higher numbered

processes

• Repeat until only one process left standing• Announces victory by sending message saying that

it is coordinator (if not already coordinator)

• Existing (lower numbered) coordinator yields• Hence the term “bully”

Page 15: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 15

Alternative – Ring Algorithm

• All processed organized in ring• Independent of process number

• Suppose P notices no coordinator• Sends election message to successor with own

process number in body of message

• (If successor is down, skip to next process, etc.)

• Suppose Q receives an election message• Adds own process number to list in message body

• …

Page 16: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 16

Alternative – Ring Algorithm

• Suppose P receives an election message with its own process number in body

• Changes message to coordinator message, preserving body

• All processes recognize highest numbered process as new coordinator

• If multiple messages circulate …• …they will all contain same list of processes

(eventually)

• If process comes back on-line• Calls new election

Page 17: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 17

Ring Algorithm (continued)

Page 18: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 18

Wireless Networks

• Different assumptions• Message passing is less reliable

• Network topology constantly changing

• Expanding ring of broadcast• Election messages

• Decision rules for when to yield

• Not very well developed.• Topic of current research

Page 19: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 19

Very Large Scale Networks

• Sometimes more than one node should be selected

• Nodes organized as peers and super-peers• Elections held within each peer group

• Super-peers coordinate among themselves

Page 20: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 20

Questions?

Page 21: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 21

Digression

Domain Name Service

Page 22: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 22

DNS

• Maps names of the form

www.cs.wpi.edu

to IP addresses

• Maps aliases to names

• Maps mailbox requests to names

• Maps service requests to names

• Maps IP addresses to names• I.e., reverse mapping

Page 23: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 23

DNS Naming Hierarchy

Page 24: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 24

Iterative Resolution of Names

Page 25: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 25

Iterative Resolution of Names

Page 26: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 26

DNS Domain Registry Database

• Text file containing records• Each record is {Name, Type, value(s)}

Page 27: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 27

Example

Page 28: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 28

DNS Implementation

• One master copy per domain or subdomain• Edited manually by system administrator

• Multiple slave copies• Automatically copied / updated periodically from

master

• Stored in file on slave server, reloaded up restart

• Caching in DNS clients• Lots and lots of caching

• Entries include TTL (time-to-live) specification

Page 29: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 29

Implementation in Linux/Unix

• BIND — Berkeley Internet Name Domain• http://www.bind9.net/

• named — the Name Daemon– Implements local DNS service– Multiple databases

• Primary or secondary

• Secondary database points back to primary

– Pointer to “higher level” service• For resolving names not in own database

Page 30: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 30

Example

• Want to find www.cs.wpi.edu• My DNS contacts DNS server 68.87.71.226

• A Comcast server specified in my DHCP lease

• Comcast DNS service• Almost certainly has root (global) domain in cache

• Probably has many .edu entries in cache (very large)

• Possibly has .wpi.edu in cache (many local users)

• May have .cs.wpi.edu

• Consults cache or official server for IP address• nslookup

Page 31: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 31

Example (continued)

C:\>nslookup cs.wpi.eduServer: cns.chelmsfdrdc2.ma.boston.comcast.netAddress: 68.87.71.226

Non-authoritative answer:Name: cs.wpi.eduAddress: 130.215.28.181

Page 32: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 32

Some Special Cases

• Google

• Yahoo

• MSN• Need to distribute names geographically

• Need to distribute different addresses for same name

• Special handling of replicated databases

• More (perhaps) later in term

Page 33: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 33

Naming Privacy

• Problem:– corporations need to have own domains

• www.merl.com

• Some public hosts – mail server, web server, etc.

• Does not want to expose names of internal hosts to outside world

• E.g., proprietary stuff

• But wants to make them visible internally• hotspur.merl.com

Page 34: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 34

Solution

• Two name services for same domain name!• Internal

• External

• External — visible to Internet (DMZ)• Database contains only a few names

• Points to other internet DNS’s for resolution of internet names

• Internal — seen only by internal hosts• Database contains all internal names

• Points to external version for resolution of internet names

Page 35: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 35

Result

• Internal names can be resolved internally, not externally

• hotspur.merl.com

• Internal names and IP addresses are invisible on Internet

• All external names can be resolved internally

• Two levels of indirection

Page 36: Election AlgorithmsCS-4513, D-Term 20071 Synchronization (continued) CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th

Election AlgorithmsCS-4513, D-Term 2007 36

Questions?

Next Topic