Distributed computingβs first great use was the distributed file system distributed file system A file system in which client machines access files and directories stored on a server (or a few servers) over a network, rather than on their own local disks. The arrangement enables data sharing across clients (the same view of the files from any machine), centralized administration and backup, and better security. Ideally it offers transparent access β behaving just like a local file system. defined in ch. 49 β open in glossary : many client machines, one server (or a few) that holds the disks, and files accessed over a network.
Why centralize like this instead of using local disks? Chiefly sharing β you get the same view of your files from any client β plus centralized administration/backup and security (lock the servers in a room). The catch is a new challenge that runs through the whole chapter: failure.
The Crux: How To Build A Distributed File System
How do you build one? What are the key aspects to think about, whatβs easy to get wrong, and what can we learn from existing systems?49.1 A Basic Distributed File System
A DFS has two software halves. The client-side
file system client-side file system The client half of a distributed file system. It receives the application's file-system system calls, holds what little client state exists (the mapping from an integer file descriptor to a server file handle, and the current file offset), and translates each call into the appropriate protocol messages sent to the server.
defined in ch. 49 β open in glossary
fields the applicationβs ordinary syscalls (open, read,
write, close, mkdir, β¦) and turns them into protocol messages; the
file server file server The server half of a distributed file system: it stores the data on its disks and responds to protocol messages from clients. In a stateless design each message it receives is self-contained, carrying all the information needed to complete the request, so the server need remember nothing between requests.
defined in ch. 49 β open in glossary
stores the data and answers those
messages (reading from its disk or in-memory cache). Together they define the
systemβs behavior:
A crucial goal is transparent access transparent access The goal that a distributed file system look and feel just like a local one: the client application uses the same standard API (open, read, write, close, mkdir, β¦) and gets the same view of files, differing only β perhaps β in performance. No one would want a file system that required a different, painful set of APIs. defined in ch. 49 β open in glossary : the DFS presents the same POSIX API as a local file system, so to applications it looks no different (except, perhaps, in performance). A cached re-read might even generate no network traffic at all.
49.2 On to NFS
Sunβs Network File System network file system NFS β Sun Microsystems' early and hugely successful distributed file system. Rather than a proprietary product, Sun defined it as an open protocol (publishing the exact client/server message formats), so many vendors could build interoperable NFS servers. The classic version studied is NFSv2, whose overriding goal is simple and fast server crash recovery. defined in ch. 49 β open in glossary (NFS) was one of the earliest and most successful. Sunβs clever move: instead of a proprietary product, they defined an open protocol β just the exact message formats clients and servers exchange. Anyone could build an NFS server, so a competitive market grew (Oracle/Sun, NetApp, EMC, IBM, β¦), and interoperability held. We study the classic NFSv2.
49.3 Focus: Simple and Fast Server Crash Recovery
NFSv2βs overriding design goal is simple, fast server crash recovery. In a many-client, single-server world, every minute the server is down idles every client β βas the server goes, so goes the entire system.β So recovery had to be trivial.
Aside: Why Servers Crash
Plenty of reasons: a power outage; a bug in the millions of lines of server code (even good code has a few bugs per thousand lines); a memory leak that slowly exhausts RAM. And in a distributed system the network itself can partition β a perfectly healthy server can look crashed simply because itβs unreachable.49.4 Key to Fast Crash Recovery: Statelessness
NFSv2βs answer is a stateless protocol stateless protocol A protocol in which the server keeps no state about individual clients β it does not track which files a client has open, current file offsets, or which blocks a client caches. Every request carries all the information needed to complete it. This is NFSv2's central design choice: it makes crash recovery trivial, because after a crash the server simply restarts and clients, at worst, retry their requests. defined in ch. 49 β open in glossary : the server tracks nothing about clients β not which files are open, not file offsets, not which blocks a client caches. Every request carries all the information needed to complete it.
Contrast a stateful protocol stateful protocol A protocol in which the server maintains state about each client β for example, an open file descriptor mapping to a particular file. Such shared state complicates crash recovery: a server crash loses the state (so outstanding operations can no longer be completed), and a client crash leaks server-side resources (like the open file) that the server must somehow detect and reclaim.
defined in ch. 49 β open in glossary
. Consider
ordinary open(), which returns a file descriptor used by later reads:
char buffer[MAX];
int fd = open("foo", O_RDONLY); // get descriptor "fd"
read(fd, buffer, MAX); // read MAX from foo via "fd"
read(fd, buffer, MAX); // read MAX again
...
close(fd); // close file
If the server tracked that fd, it would be
distributed state distributed state Ousterhout's term for state that is shared between a client and a server β such as the meaning of an open file descriptor that the server tracks on the client's behalf. Distributed state is exactly what a stateless protocol avoids, precisely because keeping it consistent across crashes of either side is hard.
defined in ch. 49 β open in glossary
(Ousterhoutβs term) β shared
between client and server β and that is exactly what makes recovery hard:
1Normal: the server tracks the open file
A stateful open() returns fd = 3; the server records "fd 3 β foo" in its open-file table. Subsequent read(fd) requests rely on the server remembering that mapping.
Itβs worse still with client crashes: a client that open()s a file and then
dies never sends close(), so the serverβs open descriptor leaks until it somehow
notices. For all these reasons NFS went stateless β each request self-contained,
no recovery protocol, the server just restarts and clients (at worst) retry.
Check yourself: a stateless distributed file system
1.Why route file access through a central server instead of letting each client use its local disk?
2.What does 'transparent access' mean for a distributed file system?
3.What are the two software pieces of a client/server distributed file system?
4.NFSv2's overriding design goal is simple, fast server crash recovery. What protocol property achieves it?
5.Why does a stateful design β where open() makes the server track a file descriptor β complicate crash recovery?