The idea: cache on the client, but who tells it about changes?

A distributed file system lets many machines use files that live on one server, as if they were local. Going to the server for every read would be slow, so clients cache file data. The hard part is the other client: when B changes the file, how does A find out that its cached copy is old? NFS and AFS give opposite answers. In NFS the client asks the server now and then. In AFS the server promises to tell the client.

Left, NFS v3: a stateless server and a client that caches 4 KB blocks and the file's attributes; it sends GETATTR on every open and when the 3 to 60 second attribute timeout runs out, and READ per missing block. Right, AFS: a server with a callback table listing A and B; the client caches the whole file on its disk, fetches it with FetchData on open, sends it back with StoreData on close, and the server sends a CallBack break to the other holders.
NFS clients poll with GETATTR and cache blocks; AFS clients cache whole files and the server keeps a list of whom to warn.

On the canvas two clients, A and B, share /home/a/notes.txt. It is 8 KB, two blocks of 4 KB. Its content is shown as versions: at the start both blocks are v1, and a write always rewrites block 0, so one write makes the file v2 | v1. Time is a clock in whole seconds; it moves only when you wait. Every message is a box that flies between a client and the server, and the header counts the messages and the KB of file data they carried.

NFS v3: a stateless server and file handles

An NFS server keeps no state about its clients: no list of who opened what, no open-file table. Each request says everything the server needs. A file is named by a file handle, an opaque value the server hands out. Here it is fh 0x2A: inode 4711, generation 1, which stays valid across a reboot because both numbers are on disk. The client gets it with LOOKUP(dir fh, "notes.txt"); after that every call names the file by the handle: GETATTR(fh) for the attributes, READ(fh, offset, 4096), WRITE(fh, offset, 4096). There is no OPEN or CLOSE call in NFS v3: open and close happen only on the client.

Most of these calls are idempotent: "read 4096 bytes at offset 4096" can be sent twice with the same result. That is what lets a client simply resend a request when no reply comes. For the few calls that are not idempotent (REMOVE, RENAME, CREATE), servers keep a small duplicate request cache keyed by xid, as shown in RPC Failure Semantics.

The attribute cache and its timeout

The NFS client caches blocks in its page cache, and the file's attributes (size, modification time, change counter: here "version"). Cached blocks are used only while the cached attributes are trusted. How long is set by the mount options acregmin = 3 s and acregmax = 60 s. On Linux the timeout starts at 3 s. Each time a GETATTR finds the file unchanged it doubles, up to 60 s; when the file has changed it goes back to 3 s and the cached blocks are dropped. A file nobody writes is checked less and less often. In Demo 5 client A reads at t = 3, 9 and 21 and sends one GETATTR each time; the timeout grows 3 → 6 → 12 → 24 s, and a read at t = 22 sends nothing. Twelve messages in all, six of them for the first open (LOOKUP and two READs).

Close-to-open consistency and the stale read

NFS makes one promise, close-to-open consistency: when a client closes a file, its dirty blocks are written to the server (WRITE ... FILE_SYNC on the page), and when a client opens a file it sends GETATTR whatever the timeout says. So a client that opens the file after another client closed it sees the new data. In Demo 1 B writes at t = 6; A opens at t = 7, its GETATTR sees version 2, A drops its blocks, reads both again and gets v2 | v1. A sent 14 messages, B 4 (a LOOKUP and one WRITE): 18 messages and 20 KB of file data.

The promise says nothing about a client that keeps the file open. In Demo 3 A opens and reads at t = 0, B writes at t = 1, and A reads again at t = 2 without reopening. A's attributes are 2 s old, under the 3 s timeout, so A reads its page cache and sends nothing: stale data, v1 | v1, while the server has v2 | v1. At t = 4 the attributes have expired, GETATTR sees the change, and the next read is correct. Two writers inside one timeout window cannot see each other in time; applications that need that use file locks (NLM) or open with O_DIRECT, or mount with noac (no attribute cache, a GETATTR before every use).

Two time-down diagrams of the same steps. Left, NFS: A reads v1 at t = 0, B writes v2 at t = 1, A reads again at t = 2 from its cache: stale v1, because its attributes are trusted until t = 3; at t = 4 A sends GETATTR, sees version 2 and reads v2. Right, AFS: A fetches the whole file at t = 0, B stores v2 at t = 1 and the server sends A a callback break; A keeps reading its old copy at t = 2 and t = 4, and only its next open fetches v2.
Inside the 3 s window NFS serves stale blocks; AFS learns of the change at once but shows it only at the next open.

AFS: whole files and callbacks

The Andrew File System (CMU, 1980s) was built for thousands of clients per server, so it cuts the messages. On open the client's cache manager fetches the whole file (FetchData, 8 KB) to its local disk, and the server records a callback promise: "I will tell you if this file changes". While the promise holds, an open costs no message at all. Reads and writes go to the local copy. On close a changed file goes back whole (StoreData), and the server breaks the callback of every other client in its table (CallBack). Their copies stay on disk, but their next open fetches the file again.

Demo 2 runs the steps of Demo 1 under AFS: A's second open at t = 5 sends nothing, B's store at t = 6 breaks A's callback, A fetches again at t = 7. That is 10 messages instead of 18, but 32 KB of file data instead of 20: AFS moves whole files even when one block changed. Demo 4 runs the steps of Demo 3: A hears about the change at t = 1, yet its reads at t = 2 and t = 4 still return the old copy, because AFS shows changes at the next open, not in the middle of one (session semantics). Two stale reads, then the open at t = 4 fetches v2 | v1.

Server reboots

Statelessness pays off when the server crashes. In Demo 6 the NFS server reboots at t = 5 and is back at t = 7. A's GETATTR at t = 5 is lost; a hard-mounted client waits timeo (2 s on the page) and resends the same request. The server answers as if nothing happened, and handle 0x2A still works. 17 messages, one of them lost.

The AFS server's callback table is in memory, so a reboot loses it (Demo 7). At t = 5 A opens from its copy while the server is down: AFS clients keep working from cache. When the server is back each client's periodic probe notices the restart and marks its callbacks suspect. At t = 8 B opens and sends FetchStatus: the version is the same, so the copy is fine and the server records a new callback. No data moves; A stays suspect until it next opens.

Counting messages

the same stepsNFS v3AFS
Demos 1 and 2: open, reopen, B writes, reopen18 messages, 20 KB10 messages, 32 KB
Demos 3 and 4: B writes while A keeps the file open18 messages, 20 KB, 1 stale read10 messages, 32 KB, 2 stale reads
Demos 6 and 7: server reboot17 messages (1 lost), 16 KB10 messages, 16 KB

NFS spends small messages to keep the server simple and crash-proof. AFS spends server memory and whole-file transfers to make repeated opens free. NFS v4 moved toward AFS: it has OPEN and CLOSE, and delegations, which are callbacks under another name.

The same "how long may I trust my copy?" question shows up on the web as max-age, ETag and 304 Not Modified in HTTP Caching. A file system built for huge files read in streams, with no client cache at all, is HDFS / GFS. On one machine the kernel's block cache is the subject of The Page Cache: read() vs mmap(), and how a path becomes an inode is What open() Does: Linux VFS Path Lookup.

See also Network Storage: One Read over NFS, iSCSI and NVMe-oF for how a file-level read compares with block-level iSCSI and NVMe over Fabrics.

What the page leaves out

  • NFS v3 unstable writes and COMMIT, write-behind before close, the 1-second mtime granularity problem, and the directory attribute cache (acdirmin, acdirmax).
  • Real timeouts: Linux timeo is 60 s over TCP and 1.1 s doubling over UDP; the page uses a fixed 2 s.
  • NFS locking (NLM and the status monitor) and NFS v4 (OPEN, leases, delegations).
  • AFS directories (the client looks each one up and caches it too), volumes and the volume location server, chunked caching in AFS-3, Kerberos tokens, and callback expiry times.
  • Real AFS RPC names carry prefixes (RXAFS_FetchData, RXAFSCB_CallBack); the "probe" is a simplified stand-in for the cache manager's server checks.

On the mind map

Open the Distributed Systems mind mapDistributedSystemsReplication: copies of data · what reads seeReplicationPartitioning: split data over nodesPartitioningTime and membership: order events, know who is aliveTime and membershipConsensus: agree on one value or logConsensusTransactions: one change across many servicesTransactionsMessaging: send events between systemsMessagingKafka internals: a replicated append-only logKafka internalsRedis internals: one thread, data in memoryRedis internalsKubernetes: reconcile desired stateKubernetesResilience and speed: stay up and fast under loadResilience and speedPartitioning vs shardingPartitioning vs shardingone server vs many; shard key mattersConsistent hashingConsistent hashingring: adding a node moves few keysChord DHTChord DHTfingers halve the distance: O(log N) hopsBitTorrent and the DHTBitTorrent and the DHTEvery downloader also uploadsRange vs hash partitioningRange vs hash partitioningrange: fast scans; hash: no hot spotRebalancing partitionsRebalancing partitionsmod N vs fixed vs dynamic: keys movedRedis ClusterRedis Cluster16384 hash slots, MOVED and ASKMapReduceMapReducemap, shuffle by key, reducePregel superstepsPregel superstepscompute, message, barrier, vote to haltSpark RDD lineageSpark RDD lineageLazy recipe; shuffle cuts stagesMapReduce joinsMapReduce joinssort-merge, skew, broadcast and merge joinsS3 object storageS3 object storagedata plus parity shards rebuild a fileRendezvous hashingRendezvous hashinghighest hash score of key+node winsHDFS / GFS file layoutHDFS / GFS file layoutNamenode maps blocks; datanodes pipelineNFS vs AFS cachingNFS polls GETATTR; AFS gets callbacksNFS vs iSCSI vs NVMe-oFNFS vs iSCSI vs NVMe-oFFile level: server runs the filesystemOpen the Distributed Systems mind mapDistributed Systemssplit data over nodesPartitioningPartitioning vs shardingPartitioning vs shardingone server vs many; shard key mattersConsistent hashingConsistent hashingring: adding a node moves few keysChord DHTChord DHTfingers halve the distance: O(log N) hopsBitTorrent and the DHTBitTorrent and the DHTEvery downloader also uploadsRange vs hash partitioningRange vs hash partitioningrange: fast scans; hash: no hot spotRebalancing partitionsRebalancing partitionsmod N vs fixed vs dynamic: keys movedRedis ClusterRedis Cluster16384 hash slots, MOVED and ASKMapReduceMapReducemap, shuffle by key, reducePregel superstepsPregel superstepscompute, message, barrier, vote to haltSpark RDD lineageSpark RDD lineageLazy recipe; shuffle cuts stagesMapReduce joinsMapReduce joinssort-merge, skew, broadcast and merge joinsS3 object storageS3 object storagedata plus parity shards rebuild a fileRendezvous hashingRendezvous hashinghighest hash score of key+node winsHDFS / GFS file layoutHDFS / GFS file layoutNamenode maps blocks; datanodes pipelineNFS vs AFS cachingNFS polls GETATTR; AFS gets callbacksNFS vs iSCSI vs NVMe-oFNFS vs iSCSI vs NVMe-oFFile level: server runs the filesystem
This page on the Distributed Systems mind map · 104 pages in 10 branches · open it to see the whole map and test yourself in recall mode.