• No results found

Distributed Systems [Fall 2012]

N/A
N/A
Protected

Academic year: 2021

Share "Distributed Systems [Fall 2012]"

Copied!
33
0
0

Loading.... (view fulltext now)

Full text

(1)

Distributed Systems

[Fall 2012]

[W4995-2]

Lec 6: YFS Lab Introduction and

Local Synchronization Primitives

Slide acks: Jinyang Li, Dave Andersen, Randy Bryant

(http://www.news.cs.nyu.edu/~jinyang/fa10/notes/ds-lec2.ppt,

(2)

Outline

• Detailed YFS lab introduction

– Plus Lab 1 description

– From last lecture’s slides, which we didn’t cover

• Local synchronization primitives

– Semaphores

– Conditional variables

• Next time: distributed synchronization

(3)

YFS (Reminder)

• Instructional distributed file system developed by MIT

after a research distributed file system, called Frangipani

– Analogous to xv6 for OS courses

– When we discuss YFS, we really refer to Frangipani (or a simplified version thereof)

• YFS/Frangipani Goals:

– Aggregate many disks from many servers – Incrementally scalable

(4)

Design (Reminder)

client workstations (applications) lock service 4 file service

extent service (data)

file system interface (creat,read,write,..)

put/get acquire, release

YFS server YFS server YFS server lock server lock server extent server extent server extent server

(5)

Design (Reminder)

Extent Service:

• stores the data (dir and file contents) • replicated for fault tolerance

YFS Service:

• serves file system requests

• it’s stateless (i.e., doesn’t store data) • uses extent service to store data

• incrementally scalable with more servers

Lock Service:

• ensure consistent updates by multiple yfs servers

• replicated for fault tolerance

YFS server YFS server YFS server lock server lock server extent server extent server extent server

file system interface (creat,read,write,..)

(6)

YFS Server Implements FS Logic

• Application program:

creat(“/d1/f1”, 0777)

• YFS server:

1. GET root directory’s data from Extent Service

2. Find Extent Server address for dir “/d1” in root dir’s data 3. GET “/d1”s data from Extent Server

4. Find Extent Server address of “f1” in “/d1”’s data 5. If not exists

alloc a new data block for “f1” from Extent Service

add “f1” to “/d1”’s data, PUT modified “/d1” to Extent Serv. 6

YFS

server server YFS

YFS server lock server lock server extent server extent server extent server

file system interface

put/get acquire, release

(7)

Concurrent Accesses Cause

Inconsistency

App 1: creat(“/d1/f1”, 0777) Server S1: … GET “/d1” Find file “f1” in “/d1” If not exists … PUT modified “/d1” ti me App 2: creat(“/d1/f2”, 0777) Server S2: … GET “/d1” Find file “f2” in “/d1” If not exists … PUT modified “/d1”
(8)

Solution: Use a Lock Service to

Synchronize Access

App 1: creat(“/d1/f1”, 0777) Server S1: … GET “/d1” Find file “f1” in “/d1” If not exists … PUT modified “/d1” ti me App 2: creat(“/d1/f2”, 0777) Server S2: … GET “/d1” … LOCK(“/d1”) UNLOCK(“/d1”) LOCK(“/d1”) 8
(9)

Putting It Together

creat(“/d1/f1”)

file system interface (creat,read,write,..)

put/get acquire, release

YFS server YFS server YFS server lock server lock server extent server extent server extent server 4. release(“/d1”) 1. acquire(“/d1”) creat(“/d1/f1”) 2. get(“/d1”) 3. put(“/d1”)

(10)

Another Problem: Naming

file system interface (creat,read,write,..)

put/get acquire, release

YFS server YFS server YFS server lock server lock server extent server extent server extent server 4. release(“/d1”) 1. acquire(“/d1”) 2. get(“/d1”) 3. put(“/d1”)

Any issues with this version?

10

creat(“/d1/f1”)

(11)

Another Problem: Naming

App 1: creat(“/d0/d1/f1”, 0777) Server S1: … GET “/d1” Find file “f1” in “/d1” If not exists … PUT modified “/d1” ti me App 2: Server S2: … rename(“/d0”, “/d2”) rename(“/d3”, “/d0”) … acquire(“/d0/d1”) release(“/d0/d1”)

Same problem occurs for reading/writing files, if we use their names when identifying them on the server.

(12)

Solution: Using GUIDs

App 1: creat(“/d0/d1/f1”, 0777) Server S1: … d1 = GET d1_id Find file “f1” in d1 If not exists … PUT(d1_id, modified d1) ti me App 2: Server S2: … rename(“/d0”, “/d2”) rename(“/d3”, “/d0”) … acquire(d1_id) release(d1_id) 12 • GUIDs are globally-unique, location-independent names • GUID principle is pervasive in FSes and DSes!
(13)

User-level kernel App FUSE syscall

Labs 1-5:

Build a Simplified YFS Version

Extent server yfs server lock server yfs server Single extent server to store data

(14)

Lab Schedule

• Lab 1: lock server

– Programming with threads – RPC semantics

• Lab 2: basic file server

• Lab 3: sharing of files

• Lab 4: file locking

• Lab 5: caching locks

(15)

Lab 1: Lock Server

• Lock service consists of:

– Lock server: grant a lock to clients, one at a time – Lock client: talk to server to acquire/release locks

• Correctness:

– At most one lock is granted to any client

• Additional requirement:

(16)

Lab 1 Steps

• Step 1: Implement

server lock and client lock code

– Use in-house RPC mechanism:

• It’s a bit more primitive than Thrift and the like (see next slide)

• Step 2: Implement

at-most-once semantics

– How do we do that?

• Due next Friday, Sept 28 before midnight

– Absolutely no extensions!

– Lab is significantly more difficult than Lab 0, so start working on it NOW!

(17)

YFS’s RPC library

transmit wait receive marshal args unmarshal args lock_client rpcc rpc call rpc call return receive transmit marshal args unmarshal args lock_server rpc handler rpc handler return RPC request RPC response work rpcs cl->call(lock_protocol::acquire, x, ret)
(18)

Outline

• Detailed YFS lab introduction

– Plus Lab 1 description

– From last lecture’s slides, which we didn’t cover

• Local synchronization primitives

– Semaphores

– Conditional variables

• Next time: distributed synchronization

– Many of the primitives here distribute or build upon local primitives

(19)

Thread Synchronization (Reminder)

• What’s a thread?

• What’s a race condition?

• How do we avoid race conditions?

• Locks are very low level, and often times you need

more to accomplish a synchronization goal

– Hence, people have developed a variety of

(20)

Semaphores

• Integer variable x that allows interaction via 2 operations:

x.P():

x.V():

• Both operations are done

atomically

– All steps take place without any intervening operations

• Question: How do you implement a semaphore?

• When do we use semaphores?

20

while (x == 0) wait; --x

(21)

Example: Thread-Safe FIFO Queue

• Assume that we already have a sequential queue

implementation:

sq

– But sq is not thread-safe!

• So, how do we make

q

thread-safe?

q.Initialize():

initialize state

q.Insert(x):

add item into queue

q.Remove():

block until queue not empty;

return item at head of queue

q.Flush():

(22)

FIFO Queue with Mutexes

22 q.Initialize(): q.sq = NewSQueue() q.mutex = 1 q.Insert(x): q.mutex.lock() q.sq.Insert(x) q.mutex.unlock() q.Remove(): q.mutex.lock() x = q.sq.Remove() q.mutex.unlock() return x q.Flush(): q.mutex.lock() q.sq.Flush() q.mutex.unlock()

Are we done?

(23)

FIFO Queue with Mutexes

Are we done?

Nope: Remove doesn’t block when buffer’s empty

q.Initialize(): q.sq = NewSQueue() q.mutex = 1 q.Insert(x): q.mutex.lock() q.sq.Insert(x) q.mutex.unlock() q.Remove(): q.mutex.lock() x = q.sq.Remove() q.mutex.unlock() return x q.Flush(): q.mutex.lock() q.sq.Flush() q.mutex.unlock()

(24)

FIFO Queue with Semaphores

• Use semaphore to count number of elements in queue

24 q.Initialize(): q.sq = NewSQueue() q.mutex = 1 q.items = 0 q.Insert(x): q.mutex.lock() q.sq.Insert(x) q.mutex.unlock() q.items.V() q.Remove(): q.items.P() q.mutex.lock() x = q.sq.Remove() q.mutex.unlock() return x q.Flush(): q.mutex.lock() q.sq.Flush() q.items = 0 q.mutex.unlock()

Are we done?

(25)

FIFO Queue with Semaphores

• Use semaphore to count number of elements in queue

q.Initialize(): q.sq = NewSQueue() q.mutex = 1 q.items = 0 q.Insert(x): q.mutex.lock() q.sq.Insert(x) q.mutex.unlock() q.items.V() q.Remove(): q.items.P() q.mutex.lock() x = q.sq.Remove() q.mutex.unlock() return x q.Flush(): q.mutex.lock() q.sq.Flush() q.items = 0 q.mutex.unlock()

Are we done?

Nope: Just Insert & Remove work fine,

but Flush messes things up

(26)

Fixing Race with Mutex?

26 q.Initialize(): q.sq = NewSQueue() q.mutex = 1 q.items = 0 q.Insert(x): q.mutex.lock() q.sq.Insert(x) q.mutex.unlock() q.items.V() q.Remove(): q.mutex.lock() q.items.P() x = q.sq.Remove() q.mutex.unlock() return x q.Flush(): q.mutex.lock() q.sq.Flush() q.items = 0 q.mutex.unlock()

Are we done?

Yes, from a

correctness

perspective

(27)

Condition Variables

• Condition variables provide synchronization point,

where one thread suspends until activated by another

• Condition variable always associated with a mutex

• cvar.Wait()

:

– Must be called after locking mutex

– Atomically: { release mutex & suspend operation }

– When resume, lock the mutex (may have to wait for it)

• cvar.Signal()

:

– If no thread suspended, then no-op – Wake up one suspended thread

(28)

FIFO Queue with Condition Variable

28 q.Initialize(): q.sq = NewSQueue() q.mutex = 1 q.cvar = NewCond(q.mutex) q.Insert(x): q.mutex.lock() q.sq.Insert(x) q.cvar.Signal() q.mutex.unlock() q.Remove(): q.mutex.lock() if q.sq.IsEmpty(): q.cvar.Wait() x = q.sq.Remove() q.mutex.unlock() return x q.Flush(): q.mutex.lock() q.sq.Flush() q.mutex.unlock() Are we done?

Still Nope: Wait() has 3 steps:

- Unlock

- Wait for signal

- Lock

atomic

(29)

Thread-Safe FIFO Queue

• Actually, one could build this using mutexes

– Build semaphore using mutex

– Build cond variable using semaphore + mutex

– But, boy, it’s a mind-bender to do that – that’s why you want higher

q.Initialize(): q.sq = NewSQueue() q.mutex = 1 q.cvar = NewCond(q.mutex) q.Insert(x): q.mutex.lock() q.sq.Insert(x) q.cvar.Signal() q.mutex.unlock() q.Remove(): q.mutex.lock() while q.sq.IsEmpty(): q.cvar.Wait() x = q.sq.Remove() q.mutex.unlock() return x q.Flush(): q.mutex.lock() q.sq.Flush() q.mutex.unlock()

(30)

Synchronization in Distributed Systems

• As we’ve already seen in YFS Lab, distributed systems

have similar issues:

– Multiple processes on different machines share the same resource: the data (or a printer, or the user’s screen, …)

• Synchronization is even hairier in distributed systems,

as you have to worry about

failures

, not just

overlappings

– E.g.: when you get a lock, you may not even know you’ve gotten it 

(31)

Analogy: The Generals’ Dilemma

Let’s attack together at 0500pm

OK

Hmm, should I attack? Did he get my OK?

e.g., carrier pigeon

• Same with distributed systems: machines need to

agree on how to progress via an unreliable medium

• Things can get even messier if generals/machines can

also fail (or even worse, go rogue)…

(32)

Distributed Synchronization Mechanisms

• Logical clocks: clock synchronization is a real issue in distributed

systems, hence they often maintain logical clocks, which count operations on the shared resource

• Consensus: multiple machines reach majority agreement over the operations they should perform and their ordering

• Data consistency protocols: replicas evolve their states in pre-defined ways so as to reach a common state despite different views of the input

• Distributed locking services: machines grab locks from a

centralized, but still distributed, locking service, so as to coordinate their accesses to shared resources (e.g., files)

• Distributed transactions: an operation that involves multiple services either succeeds or fails at all of them

• We’re going to look at all of these in the following lectures

(33)

Next Time

• Clocks in distributed systems

– Clock synchronization problem – Logical (protocol) clocks

(http://www.news.cs.nyu.edu/~jinyang/fa10/notes/ds-lec2.ppt http://www.cs.cmu.edu/~dga/15-440/F12/lectures/05-concurrency.txt)

References

Related documents

• Obtain one IS lock at the table level granularity and multiple S locks at the page or tuple levels, or. • Obtain one S lock at the table

Using this tabular information, sensitivity (the percentage of recidivists who were judged to be at high risk), specificity (the percentage of non-recidivists who were

Dieude P, Guedj M, Wipff J, Ruiz B, Hachulla E, Diot E, Granel B, Sibilia J, Tiev K, Mouthon L, Cracowski JL, Carpentier PH, Amoura Z, Fajardy I, Avouac J, Meyer O, Kahan A, Boileau

- - Max Min Max Min d dt Position Sensor Permanent Magnet AC Motor Current Sensors Position Regulator Ele c tr onic Com m u ta tor Speed Regulator Speed Feedback Position

horse racing, horse racing system, horse betting, horse betting system, horse laying, horse laying system, horse racing software horse tips, sports betting, lay betting,

First evidence for a novel redox group located in the membrane arm of complex I has been obtained by means of combined UV/Vis, EPR, and FT-IR spectroscopy applied to complex I

• UConn 2000 Deferred Maintenance/Code/ADA Renovation Lump Sum Project List by Fiscal Year • Non-UConn 2000 Projects Approved by B&G.. Project

2.8 Cancellation/Termination: If the Contractor defaults in its agreement to provide personnel or equipment to the University's satisfaction, or in any other way fails to