Distributed Systems [Fall 2012]



Similar documents
Last Class: Semaphores

We mean.network File System

Lab 2 : Basic File Server. Introduction

Chapter 6, The Operating System Machine Level

Network File System (NFS)

Chapter 11 Distributed File Systems. Distributed File Systems

Client/Server and Distributed Computing

! Past few lectures: Ø Locks: provide mutual exclusion Ø Condition variables: provide conditional synchronization

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

Semaphores and Monitors: High-level Synchronization Constructs

1.4 SOFTWARE CONCEPTS

A Deduplication File System & Course Review

CS11 Java. Fall Lecture 7

Web DNS Peer-to-peer systems (file sharing, CDNs, cycle sharing)

CS3210: Crash consistency. Taesoo Kim

Amoeba Distributed Operating System

SYSTEM ecos Embedded Configurable Operating System

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

Network File System (NFS) Pradipta De

RAID Storage, Network File Systems, and DropBox

G Porcupine. Robert Grimm New York University

Principles and characteristics of distributed systems and environments

Parallel Programming

Distributed File Systems

Middleware Lou Somers

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Why Threads Are A Bad Idea (for most purposes)

Distributed File Systems. Chapter 10

Microkernels & Database OSs. Recovery Management in QuickSilver. DB folks: Stonebraker81. Very different philosophies

Lecture 6: Semaphores and Monitors

Monitors, Java, Threads and Processes

6.828 Operating System Engineering: Fall Quiz II Solutions THIS IS AN OPEN BOOK, OPEN NOTES QUIZ.

I/O. Input/Output. Types of devices. Interface. Computer hardware

Linux Driver Devices. Why, When, Which, How?

Agenda. Distributed System Structures. Why Distributed Systems? Motivation

Lecture 18: Reliable Storage

Distributed Data Management

Dr Markus Hagenbuchner CSCI319. Distributed Systems

Running a Workflow on a PowerCenter Grid

E) Modeling Insights: Patterns and Anti-patterns

Client/Server Computing Distributed Processing, Client/Server, and Clusters

Operating Systems 4 th Class

Processes and Non-Preemptive Scheduling. Otto J. Anshus

First-class User Level Threads

Middleware: Past and Present a Comparison

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)

ZooKeeper. Table of contents

Implementing the Hadoop Distributed File System Protocol on OneFS Jeff Hughes EMC Isilon

Big Data Storage Options for Hadoop Sam Fineberg, HP Storage

Linux Kernel Architecture

Real Time Programming: Concepts

CS161: Operating Systems

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

Network Attached Storage. Jinfeng Yang Oct/19/2015

COS 318: Operating Systems

COS 318: Operating Systems. Virtual Machine Monitors

Have both hardware and software. Want to hide the details from the programmer (user).

Chapter 18: Database System Architectures. Centralized Systems

Lecture 6: Introduction to Monitors and Semaphores

CSC 2405: Computer Systems II

10.2 THE CODA FILE SYSTEM

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

A distributed system is defined as

Introduction. What is an Operating System?

Operating Systems Principles

The ConTract Model. Helmut Wächter, Andreas Reuter. November 9, 1999

Database Replication with Oracle 11g and MS SQL Server 2008

Lecture 25 Symbian OS

CHAPTER 6: DISTRIBUTED FILE SYSTEMS

File Management. COMP3231 Operating Systems. Kevin Elphinstone. Tanenbaum, Chapter 4

Centralized Systems. A Centralized Computer System. Chapter 18: Database System Architectures

Distributed File Systems. NFS Architecture (1)

Topics in Computer System Performance and Reliability: Storage Systems!

Local Area Networks transmission system private speedy and secure kilometres shared transmission medium hardware & software

Distribution transparency. Degree of transparency. Openness of distributed systems

1 Organization of Operating Systems

Chapter 11 I/O Management and Disk Scheduling

Concurrent Programming

How To Understand The Concept Of A Distributed System

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

How To Make A Distributed System Transparent

Project Group High- performance Flexible File System

Introduction to Database Systems. Module 1, Lecture 1. Instructor: Raghu Ramakrishnan UW-Madison

CSE 120 Principles of Operating Systems

Last class: Distributed File Systems. Today: NFS, Coda

About the File Manager 2

It is the thinnest layer in the OSI model. At the time the model was formulated, it was not clear that a session layer was needed.

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Topics. Producing Production Quality Software. Concurrent Environments. Why Use Concurrency? Models of concurrency Concurrency in Java

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

The Microsoft Windows Hypervisor High Level Architecture

COMP5426 Parallel and Distributed Computing. Distributed Systems: Client/Server and Clusters

Chapter 13 File and Database Systems

Chapter 13 File and Database Systems

Transcription:

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, http://www.cs.cmu.edu/~dga/15-440/f12/lectures/05-concurrency.txt)

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 2

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 s Incrementally scalable Tolerates and recovers from node, network, disk failures 3

Design (Reminder) client workstations (applications) file system interface (creat,read,write,..) YFS YFS YFS file service put/get acquire, release extent extent extent lock lock extent service (data) lock service 4

Design (Reminder) file system interface (creat,read,write,..) YFS extent put/get extent YFS extent lock YFS acquire, release Extent Service: stores the data (dir and file contents) replicated for fault tolerance incrementally scalable with more s lock 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 s Lock Service: ensure consistent updates by multiple yfs s replicated for fault tolerance 5

YFS Server Implements FS Logic Application program: creat( /d1/f1, 0777) creat( /d1/f1 ) YFS YFS file system interface YFS put/get acquire, release YFS : extent extent extent lock lock 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

Concurrent Accesses Cause Inconsistency time App 1: creat( /d1/f1, 0777) Server S1: GET /d1 Find file f1 in /d1 If not exists PUT modified /d1 App 2: creat( /d1/f2, 0777) Server S2: GET /d1 Find file f2 in /d1 If not exists PUT modified /d1 What is the final result of /d1? What should it be? 7

Solution: Use a Lock Service to Synchronize Access time App 1: creat( /d1/f1, 0777) Server S1: LOCK( /d1 ) GET /d1 Find file f1 in /d1 If not exists PUT modified /d1 UNLOCK( /d1 ) App 2: creat( /d1/f2, 0777) Server S2: LOCK( /d1 ) GET /d1 8

Putting It Together creat( /d1/f1 ) YFS extent file system interface (creat,read,write,..) creat( /d1/f1 ) put/get YFS 2. get( /d1 ) 3. put( /d1 ) 4. release( /d1 ) extent extent 1. acquire( /d1 ) acquire, release lock lock YFS 9

Another Problem: Naming creat( /d1/f1 ) YFS extent file system interface (creat,read,write,..) creat( /d1/f1 ) 1. acquire( /d1 ) put/get extent YFS 2. get( /d1 ) 3. put( /d1 ) 4. release( /d1 ) extent acquire, release lock lock YFS Any issues with this version? 10

Another Problem: Naming time App 1: creat( /d0/d1/f1, 0777) Server S1: acquire( /d0/d1 ) GET /d1 Find file f1 in /d1 If not exists PUT modified /d1 release( /d0/d1 ) App 2: Server S2: rename( /d0, /d2 ) rename( /d3, /d0 ) Same problem occurs for reading/writing files, if we use their names when identifying them on the. 11

Solution: Using GUIDs time App 1: creat( /d0/d1/f1, 0777) Server S1: acquire(d1_id) d1 = GET d1_id Find file f1 in d1 If not exists PUT(d1_id, modified d1) release(d1_id) App 2: Server S2: rename( /d0, /d2 ) rename( /d3, /d0 ) GUIDs are globally-unique, location-independent names GUID principle is pervasive in FSes and DSes! Think of inode numbers 12

Labs 1-5: Build a Simplified YFS Version yfs yfs User-level kernel App FUSE syscall Single extent to store data Extent lock Communication using in-house RPC 13

Lab Schedule Lab 1: lock Programming with threads RPC semantics Lab 2: basic file Lab 3: sharing of files Lab 4: file locking Lab 5: caching locks 14

Lab 1: Lock Server Lock service consists of: Lock : grant a lock to clients, one at a time Lock client: talk to to acquire/release locks Correctness: At most one lock is granted to any client Additional requirement: acquire() at client does not return until lock is granted 15

Lab 1 Steps Step 1: Implement 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! Work in layers, submit imperfect but on time! 16

YFS s RPC library lock_client lock_ rpc call marshal args transmit RPC request receive marshal args rpc handler wait work rpc call return unmarshal args receive RPC response transmit unmarshal args rpc handler return rpcc rpcs cl->call(lock_protocol::acquire, x, ret).reg(lock_protocol::acquire, &ls, &lock_::acquire) 17

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 18

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 synchronization primitives that raise level of abstraction 19

Semaphores Integer variable x that allows interaction via 2 operations: x.p(): while (x == 0) wait; --x x.v(): ++x 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

Example: Thread-Safe FIFO Queue 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(): clear 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? 21

FIFO Queue with Mutexes q.initialize(): q.sq = NewSQueue() q.mutex = 1 q.insert(x): q.sq.insert(x) q.remove(): x = q.sq.remove() return x q.flush(): q.sq.flush() Are we done? 22

FIFO Queue with Mutexes q.initialize(): q.sq = NewSQueue() q.mutex = 1 q.insert(x): q.sq.insert(x) q.remove(): x = q.sq.remove() return x q.flush(): q.sq.flush() Are we done? Nope: Remove doesn t block when buffer s empty 23

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.sq.insert(x) q.items.v() q.remove(): q.items.p() x = q.sq.remove() return x q.flush(): q.sq.flush() q.items = 0 Are we done? 24

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.sq.insert(x) q.items.v() q.flush() q.remove(): q.items.p() x = q.sq.remove() return x q.flush(): q.sq.flush() q.items = 0 Are we done? Nope: Just Insert & Remove work fine, but Flush messes things up 25

Fixing Race with Mutex? q.initialize(): q.sq = NewSQueue() q.mutex = 1 q.items = 0 q.insert(x): q.sq.insert(x) q.items.v() q.remove(): q.items.p() x = q.sq.remove() return x q.flush(): q.sq.flush() q.items = 0 Are we done? Yes, from a correctness perspective Nope, from a liveness perspective -- deadlock 26

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 27

FIFO Queue with Condition Variable q.initialize(): q.sq = NewSQueue() q.mutex = 1 q.cvar = NewCond(q.mutex) q.insert(x): q.sq.insert(x) q.cvar.signal() q.remove(): if q.sq.isempty(): q.cvar.wait() x = q.sq.remove() return x q.flush(): q.sq.flush() Are we done? Still Nope: Wait() has 3 steps: - Unlock atomic - Wait for signal q.flush() - Lock 28

Thread-Safe FIFO Queue q.initialize(): q.sq = NewSQueue() q.mutex = 1 q.cvar = NewCond(q.mutex) q.insert(x): q.sq.insert(x) q.cvar.signal() q.remove(): while q.sq.isempty(): q.cvar.wait() x = q.sq.remove() return x q.flush(): q.sq.flush() 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 level of abstraction 29

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 30

Analogy: The Generals Dilemma e.g., carrier pigeon Let s attack together at 0500pm OK Hmm, should I attack? Did he get my OK? 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) 31

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 predefined 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 32

Next Time Clocks in distributed systems Clock synchronization problem Logical (protocol) clocks 33