LECTURE 03 · 2026-02-10 · 基础

Google 文件系统(GFS)

Google File System

GFS 把常见故障、超大文件和批处理访问当作前提,用大 chunk、复制和单一 master 构造高吞吐文件系统。

156 MIN基础03 SOURCESFULL ARCHIVE

这讲要解决什么

开始前先确认
  • 能区分网络延迟、节点崩溃与部分失败
  • 会用状态机和不变量描述协议
  1. 解释架构与元数据的核心问题
  2. 按协议顺序推演租约与写入顺序
  3. 评估工程取舍:集中元数据简化全局管理,但必须用缓存、粗粒度 chunk 和短临界路径避免 master 成为瓶颈。

先接受 GFS 的工作负载,才能理解它为什么故意不像 POSIX

GFS 面对的是 Google 早期的大规模批处理:数百 MB 到数 GB 的文件、顺序读、大块追加、上千台廉价机器,以及机器和磁盘故障的常态。若用“小文件、低延迟随机写、严格 POSIX 覆盖语义”评价它,会把所有设计都看成缺陷;正确方法是先写出负载,再判断每个取舍是否匹配。

单 master 看似违反扩展直觉,却让命名、chunk 映射、租约和副本管理拥有一个简单的全局决策点。它之所以没有立即成为数据吞吐瓶颈,是因为客户端只向 master 询问元数据,真正字节直接在客户端和 chunkserver 之间流动。64 MB 大 chunk 又降低了元数据条目和查询频率。

代价同样明确:master 内存限制文件和 chunk 数;故障切换在原论文中不够自动;小文件和热点 chunk 表现差;一致性契约比普通文件系统弱。论文不是宣称这些问题不存在,而是展示在目标工作负载下如何用较弱、较专门的接口换取规模与恢复能力。

本讲按一次读、一次写、一次故障恢复来学习。每一步都区分三类状态:master 的命名/租约元数据、chunkserver 的数据副本、client 缓存的位置。只要这三层不混在一起,GFS 的控制流就会非常清楚。

架构与元数据

GFS 把文件切成固定大小 chunk,每个 chunk 由 64 位 handle 标识并复制到多个 chunkserver。master 保存命名空间、文件到 chunk 的映射以及副本位置;客户端先向 master 查询元数据,再直接与 chunkserver 传输数据,因此大流量不经过 master。master 的集中视图简化了副本放置、垃圾回收和负载均衡。

租约与写入顺序

写入时 master 为一个副本授予 lease,使其成为 primary。客户端把数据流水式推送到所有副本,primary 决定 mutation 的全局顺序并通知 secondary 按同一顺序执行。数据流和控制流分离:数据沿网络拓扑传输,控制消息负责确定一致顺序。lease 过期让 master 能在 primary 失联后安全改选。

一致性模型

GFS 不承诺传统 POSIX 的任意覆盖写语义。成功的串行写通常得到 defined 区域;并发写可能一致但 undefined。record append 允许系统选择偏移并至少追加一次,失败重试可能留下 padding 或重复记录,应用必须能识别和过滤。较弱语义与工作负载相匹配:追加式批处理比随机小写更常见。

恢复与运维

chunkserver 通过 checksum 检测静默损坏;master 根据心跳发现失联并补足副本。master 日志持久化关键元数据,checkpoint 缩短恢复时间。删除先改名为隐藏文件,延迟回收可减少误删代价。系统依赖持续的后台修复,而不是假设硬件可靠。

把命名控制面与块数据面分开

GFS master 维护文件名到 chunk handle 序列、chunk 版本、租约和副本位置等元数据;chunkserver 才保存实际数据。客户端先向 master 查询“某文件第 i 个 chunk 的 handle 与副本列表”,随后直接与选定 chunkserver 传输数据。master 不在每个字节的读写路径上,单点控制因而不会立刻成为大文件吞吐瓶颈。

64 MB chunk 是元数据和分片单位,不是最小 I/O。客户端仍可读写几 KB。大 chunk 减少 master 中的条目数、降低查找频率,并让长顺序传输摊薄连接开销;但小文件可能只落在一个 chunk 上,无法获得多磁盘并行,海量小文件还会把 master 的 RAM 与扫描 CPU 耗尽。

客户端缓存的是 handle 与位置,而不是永久真相。读时可以向任一合适副本请求;写时必须找到当前 primary。副本位置不必持久写入 master 日志,master 重启可询问所有 chunkserver 重新构建;文件命名映射与版本号则必须可靠保存,因为丢失后无法仅从散落的数据块确定原本文件结构和哪个副本最新。

这种分离是一种负载形状匹配:少量、较小的元数据请求集中到 master,大量、较长的数据流分散到 chunkserver。它不是“单 master 永远可扩展”的证明;随着文件数和客户端数增长,元数据本身也会成为主工作负载,后来 Colossus 必须分片控制面。

亲手走一遍 130 MB 偏移处的读取

假设 chunk 大小 64 MB,客户端读取 /logs/2026 的 offset 130 MB、长度 1 MB。客户端计算逻辑 chunk index=floor(130/64)=2,chunk 内 offset=2 MB。它向 master 发送文件名和 index 2,而不是把整个读请求交给 master。master 返回不可变 chunk handle、当前副本位置以及必要版本信息。

客户端从网络位置和负载中选择一个副本,直接发送 (handle, 2MB, 1MB)。chunkserver 从本地文件读取并校验 checksum 后返回。后续相邻读取可以复用缓存的 handle/位置;若选定副本不可达,客户端换另一个,并在必要时重新询问 master。

这个过程解释了 master 上的负载单位:它按“客户端第一次触及某个 chunk”处理元数据,而不是按每个数据包。也解释了副本位置为何可以由 chunkserver 重启后重新报告:数据在哪些机器上是可重建事实;文件名到哪些 handle 的顺序却不能从散落文件可靠推回,必须写入操作日志并 checkpoint。

再看缓存陈旧。客户端缓存的位置可能包含已下线或 stale 副本,因此失败后要刷新;handle 本身在创建后不会重新用于另一个 chunk,避免旧缓存误指向新数据。读路径不需要 primary,因为读取不改变副本顺序;写路径才需要租约 primary。

数据流与控制流为何走不同顺序

写入开始前,客户端从 master 获得某 chunk 的 primary 与 secondaries。客户端先把数据流水线推送到所有副本;这一步只把字节放入内存缓冲,并没有决定它在 chunk 中的逻辑顺序。所有副本收到数据后,客户端向 primary 发送写请求,primary 为并发写分配序号,并按该顺序本地应用,再把带序号的命令转给 secondaries。

把数据流与控制流分开是为了网络效率。客户端按照拓扑选择一条副本链传送大块数据,每台收到后立即转发,链路可流水并行;小控制消息由 primary 发给所有 secondary,确保各副本使用同一操作顺序。primary 决定的是 mutation order,不是充当所有数据字节的中转站。

普通 write 指定 offset;并发重叠写可能让某区域在所有成功副本上保持 defined,却不保证对应任一完整客户端写。record append 则让 primary 选择 offset,把一条记录作为单位追加;若剩余 chunk 空间不足,primary 填充到 chunk 末尾并让客户端在下一 chunk 重试。

GFS 的成功标准允许一些副本更新失败后返回错误,客户端重试会在已成功副本上再次追加,产生重复记录。应用要用 record ID 去重、magic number/checksum 跳过 padding 或损坏区域。性能与简单性的一部分成本因此从文件系统转移给知道这种语义的应用。

DIAGRAM IN CONTEXT

把上面的机制落到消息、状态与失败路径中。

GFS 写入:数据流与控制流分离客户端先流水推送字节,再由 primary 给 mutation 排序。
Clientpush dataS1 → S2 → S3
Clientwrite requestPrimary S1
S1ordered mutationS2 / S3
S2 / S3ackS1 → Client

为什么“先传数据、后排顺序”仍能让副本一致

一次 mutation 有两个阶段。大数据先沿 client→S1→S2→S3 的流水线传播,每个节点收到一段就转发;此时副本只缓存字节,不修改文件。随后客户端把写请求发给持有租约的 primary,primary 分配全局 mutation 序号、本地应用,再命令 secondaries 按同一序号应用。数据到达顺序与操作顺序被有意分离。

安全关键在于所有副本执行同一个由 primary 决定的序列。C1 的数据可能比 C2 先到 S2,但如果 primary 把 C2 编为 7、C1 编为 8,S2 必须按 7→8 执行。大字节不绕 primary,避免它成为网络瓶颈;小控制消息携带顺序,维护副本一致。

若某个 secondary 写失败,primary 返回错误,客户端可能重试。普通覆盖写的重复区域可能成为 inconsistent;record append 则由 primary 选择 offset,保证一条记录原子追加至少一次,但可能重复。应用用记录 ID 去重,用 checksum 和 padding 规则跳过无效区域。GFS 的契约必须和应用恢复方式一起阅读。

租约解决另一个维度:谁有资格分配序号。master 与旧 primary 失联后不能立即授权新 primary,必须等旧租约确定过期,否则两个节点可能各排一个序列。版本号再把没有参与新租约世代的副本标成 stale,防止它重新上线后污染读写。

租约如何阻止旧 primary 与新 primary 并存

master 无法区分 primary 进程崩溃和 master 到 primary 的网络断开。如果一失联就指定新 primary,旧 primary 可能仍服务客户端,形成 split brain。GFS 为每个活跃写 chunk 发放约 60 秒租约:master 承诺到期前不另选 primary,primary 承诺到期前停止作为 primary,除非成功续租。

失联时 master 必须等旧租约确定过期,才能给新副本租约。这牺牲了故障切换速度来换安全;租约依赖双方对时间上界的可靠实现。master 重启后也要等待一个租约周期,避免遗忘重启前仍有效的租约。仅有“心跳超时”不足以证明旧主不再行动。

每次指定新 primary 时,master 提升 chunk 版本号,并通知可用副本。没有参与升级的副本成为 stale;它即使重新上线,也不能被当成当前副本。chunkserver 报告本地 handle 与版本,master 用持久化的当前版本过滤过时数据,并在后台垃圾回收。

chunkserver 失败后的再复制存在时机取舍:立刻复制可能浪费带宽,因为机器或磁盘很快恢复;等待太久又增加剩余副本同时损坏、永久丢数据的风险。系统会按剩余副本数、活跃度等优先级恢复。三副本不是魔法数字,而是故障概率、修复时间、存储成本和数据价值之间的工程点。

用 defined、consistent 与成功返回读懂 GFS

GFS 论文把文件区域区分为 consistent 与 defined。consistent 表示所有客户端无论读哪个副本都会看到相同数据;defined 还要求该数据来自某次完整 mutation。成功的串行 write 通常让区域 defined;并发重叠 write 可能 consistent 但 undefined,因为一致字节不一定对应任一调用的完整内容;失败写入可能留下 inconsistent 区域。

record append 在成功返回时保证记录至少一次原子出现于所有副本,但前后可能有 padding,失败重试可能产生重复。这个契约适合批处理生成的日志、索引输入等顺序扫描工作负载:应用可以用校验和识别有效记录、用唯一 ID 去重。它不适合银行余额等必须线性一致、恰好一次更新的数据。

弱语义并非“系统不讲正确性”,而是把正确性定义缩窄到目标应用能承受的范围,从而减少全副本预提交、故障恢复同步和请求去重等成本。要实现更强语义,primary 在暴露写入前需确认所有副本能提交,新 primary 上任前需修齐日志,还要阻止客户端从 stale 副本成功读取。

复盘 GFS 时必须同时评价历史负载与长期演化:单 master、超大 chunk、宽松追加语义在早期 MapReduce 大文件场景中有效;后来文件数与客户端数增长暴露 RAM、CPU 和人工 failover 问题。一个设计在原始工作负载下成功,不等于它的限制会随规模线性延伸。

从论文的一致性表走向可测试的恢复判断

读论文 §4 时,把每个格子翻译成客户端能观察的实验。串行成功 write 后,所有副本同一区域相同且对应那次写,是 defined;并发重叠成功 write 后,各副本顺序一致但字节可能混合,不一定对应某个完整调用,是 consistent but undefined;失败 mutation 可能使副本不同,是 inconsistent。

这套词汇的价值在于避免模糊说“最终会一致”。你应能给每次 API 返回写一个后置条件,并说明客户端怎样检测或容忍未定义区域。record append 的后置条件是记录至少一次原子出现,周围可有 padding,失败重试可重复;这适合日志型批处理,却不适合余额扣减。

论文的 master snapshot、operation log、chunk version、stale replica 检测和 re-replication 共同构成恢复闭环。只复制数据文件不够,因为还要恢复哪个副本属于当前世代;只恢复 master 元数据也不够,因为副本数可能不足。控制面恢复与数据面修复是两条配合的循环。

把它连接到后续实验:Raft 会用复制日志替代单 master 的持久决策,用任期和日志匹配更严格地阻止旧主;但代价是每次提交需要多数派通信。GFS 在目标批处理工作负载中选择了更弱语义和集中控制,这正是课程要训练的设计判断。

教案覆盖地图

100%教师材料入库
12中文教学单元
01机制 / 板书图
03一手资料

覆盖口径:教师 notes/讲义原文逐行完整保留;中文教学单元覆盖课堂机制、失败路径与工程取舍;1/1 个显式板书占位已重绘;论文另设“问题—机制—证据—边界”阅读导航。覆盖不是用摘要替代原文,任何细节都可在页面末尾回查。

教师教案notes/l-gfs.txt

351 行 · 2,266 词 · 完整可搜索文本

论文 / FAQpapers/gfs.pdf

1,854 行 · 15,472 词 · 完整可搜索文本

论文 / FAQpapers/gfs-faq.txt

214 行 · 1,833 词 · 完整可搜索文本

展开中文教学单元映射(12 项)
  1. 01先接受 GFS 的工作负载,才能理解它为什么故意不像 POSIX
  2. 02架构与元数据
  3. 03租约与写入顺序
  4. 04一致性模型
  5. 05恢复与运维
  6. 06把命名控制面与块数据面分开
  7. 07亲手走一遍 130 MB 偏移处的读取
  8. 08数据流与控制流为何走不同顺序
  9. 09为什么“先传数据、后排顺序”仍能让副本一致
  10. 10租约如何阻止旧 primary 与新 primary 并存
  11. 11用 defined、consistent 与成功返回读懂 GFS
  12. 12从论文的一致性表走向可测试的恢复判断

论文要读到哪里

READING TARGETpapers/gfs.pdf
核心问题

怎样用单一控制面管理大量数据,同时让数据流不经过 master?

机制主线

master 管命名、chunk、租约和版本;客户端直接访问 chunkserver,primary 排序 mutation,secondaries 按相同次序执行。

必读证据

重点读 §2 设计假设、§3 架构、§4 一致性与恢复、§6 测量;对照 defined/consistent 表格理解契约。

适用边界

GFS 针对大文件和追加型批处理优化;小文件、强事务语义、快速 master failover 都不是原设计强项。

把直觉校准成不变量

误区

单一 master 会承载全部文件数据流。

客户端只向 master 查询元数据,真实数据直接在客户端和 chunkserver 之间传输。

误区

只记住正常路径就足以实现协议。

分布式协议的正确性主要由超时、重试、重排、崩溃恢复和旧消息路径决定。

知识检查

GFS primary 在一次 mutation 中主要决定什么?

下列哪项最准确概括本讲的主要工程取舍?

为什么“单一 master 会承载全部文件数据流。”是错误的?

离开本讲前,你应能复述

  • GFS 把文件切成固定大小 chunk,每个 chunk 由 64 位 handle 标识并复制到多个 chunkserver。
  • 集中元数据简化全局管理,但必须用缓存、粗粒度 chunk 和短临界路径避免 master 成为瓶颈。
  • 客户端只向 master 查询元数据,真实数据直接在客户端和 chunkserver 之间传输。

完整官方资料附录

以下是本讲对应官方材料的可搜索离线文本。中文精读负责解释;资料附录保留原始细节、例子、问答与代码,不以摘要替代原文。

课堂讲义notes/l-gfs.txt351 行 · 2,266 词 · 完整收录
6.5840 2026 Lecture 3: GFS

The Google File System
Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung
SOSP 2003

Why are we reading this paper?
  GFS paper touches on many themes of 6.5840
    parallel performance, fault tolerance, replication, consistency
  good systems paper -- details from apps all the way to network
  successful real-world design

Important distributed system ideas
  Build fault-tolerant applications using fault-tolerant storage
  Sharding
  Primary-backup replication protocol
  Leases to ensure 1 primary
  Checksums for detecting faulty hardware/software
  Sacrifice consistency for performance/simplicity

GFS context
  Many Google services needed a big fast unified storage system
    Mapreduce, crawler, indexer, log storage/analysis
  Shared among multiple applications e.g. crawl, index, analyze
  Huge capacity
  Huge performance
  Fault tolerant
  But:
    just for internal Google use
    aimed at batch big-data performance, not interactive

GFS overview
  100s/1000s of clients (e.g. MapReduce worker machines)
  100s of chunkservers, each with its own disk
  one coordinator

Capacity story?
  big files split into 64 MB chunks
  each file's chunks striped/sharded over chunkservers
    so a file can be much larger than any one disk
  each chunk in a Linux file

Throughput story?
  clients talk directly to chunkservers to read/write data
  if lots of clients access different chunks, huge parallel throughput
  read or write

Fault tolerance story?
  each 64 MB chunk stored (replicated) on three chunkservers
  client writes are sent to all of a chunk's copies
  a read just needs to consult one copy

What are the steps when client C wants to read a file?
  1. C sends filename and offset to coordinator (CO) (if not cached)
     CO has a filename -> array-of-chunkhandle table
     and a chunkhandle -> list-of-chunkservers table
  2. CO finds chunk handle for that offset
  3. CO replies with chunkhandle + list of chunkservers
  4. C caches handle + chunkserver list
  5. C sends request to nearest chunkserver
     chunk handle, offset
  6. chunk server reads from chunk file on disk, returns to client

Clients only ask coordinator where to find a file's chunks
  clients cache name -> chunkhandle info
  coordinator does not handle data, so (hopefully) not heavily loaded

What about writes?
  Client knows which chunkservers hold replicas that must be updated.
  How should we manage updating of replicas of a chunk?

A bad replication scheme
  (This is *not* what GFS does)
  [diagram: C, S1, S2, S3]
  Client sends update to each replica chunkserver
  Each chunkserver applies the update to its copy

What can go wrong?
  *Two* clients write the same data at the same time
    i.e. "concurrent writes"
    Chunkservers may see the updates in different orders!
    Again, the risk is that, later, two clients may read different content

Idea: primary/secondary replication
  (or primary/backup)
  For each chunk, designate one server as "primary".
  Clients send write requests just to the primary.
    The primary alone manages interactions with secondary servers.
    (Some designs send reads just to primary, some also to secondaries)
  The primary chooses the order for all client writes.
    Tells the secondaries -- with sequence numbers -- so all replicas
    apply writes in the same order, even for concurrent client writes.
  There are still many details to fill in, and we'll
    see a number of variants in upcoming papers.

What are the steps when C wants to write a file at some offset?
  paper's Figure 2
  1. C asks CO about file's chunk @ offset
  2. CO tells C the primary and secondaries
  3. C sends data to all (just temporary...), waits for all replies (?)
  4. C asks P to write
  5. P checks that lease hasn't expired
  6. P writes its own chunk file (a Linux file)
  7. P tells each secondary to write (copy temporary into chunk file)
  8. P waits for all secondaries to reply, or timeout
     secondary can reply "error" e.g. out of disk space
  9. P tells C "ok" or "error"
  10. C retries from start if error

What data may a client read after a failed write?
  Replicas may return different data
  Primary P updated its own state.
  But secondary S1 did not update (failed? slow? network problem?).
  Client C1 reads from P; Client C2 reads from S1.
    they will see different results!
  Such a departure from ideal behavior is an "anomaly".
    in non-replicated systems, this couldn't happen!
    data can be *inconsistent*
  Note: a successful writes doesn't lead to inconsistency

What is the result of concurrent writes?
  Clients break writes spanning chunks into two writes
  C1 writes chunks x and y at offset 0 and 1, respectively
  C2 writes chunks a b at offset 0 and 1
  A possible state of the replicas (without errors): [a y]
    x was overwritten by a
    b was overwritten with y
    x and b are lost!

GFS solution: atomic append of records
  Primary picks the offset and pads if record spans chunks
  Result for the above case: some interleaving of [a, b, x, and y]
  No data lost, but "empty" areas due to padding
  Note: client doesn't determine where the data is in the file
    primary picks the offset
    append returns offset where client's record is written
  Note: requires changing applications to use append instead of write

What data may a client read after a failed append?
  Read from a backup that has the record
  Read from a backup that didn't apply the append: a hole
  Read from a backup that recorded the initial and retried append
    duplicate records

Consistency: guarantees offered by a storage system to applications
  GFS consistency is complex! (Table 1)
  if primary tells client that a write succeeded,
    and no other client is writing the same part of the file,
    all readers will see the write.
    "defined"
  if successful concurrent writes to the same part of a file,
    and they all succeed,
    all readers will see the same content,
    but maybe it will be a mix of the writes.
    "consistent"
    E.g. C1 writes "ab", C2 writes "xy", everyone might see "xb".
  if primary doesn't tell the client that the write succeeded,
    different readers may see different content, or none.
    "inconsistent"

Why are these anomalies OK?
  They only intended to support a certain subset of their own applications.
    Written with knowledge of GFS's behavior.
  Probably mostly single-writer and Record Append.
  Writers could include checksums and record IDs.
    Readers could use them to filter out junk and duplicates.
  Later commentary by Google engineers suggests that it
  might have been better to make GFS more consistent.
  http://queue.acm.org/detail.cfm?id=1594206

What might better consistency look like?
  There are many possible answers.
  Trade-off between easy-to-use for client application programmers,
    and easy-to-implement for storage system designers.
  Maybe try to mimic local disk file behavior.
  Perhaps:
    * atomic writes: either all replicas are updated, or none,
      even if failures.
    * read sees latest write.
    * all readers see the same content (assuming no writes).
  We'll see more precision later.

Let's think about how GFS handles crashes of various entities.

A client crashes while writing?
  Either it got as far as asking primary to write, or not.

A secondary crashes just as the primary asks it to write?
  1. Primary may retry a few times, if secondary revives quickly
     with disk intact, it may execute the primary's request
     and all is well.
  2. Primary gives up, and returns an error to the client.
     Client can retry -- but why would the write work the second time around?
  3. Coordinator notices that a chunkserver is down.
     Periodically pings all chunk servers.
     Removes the failed chunkserver from all chunkhandle lists.
     Perhaps re-replicates, to maintain 3 replicas.
     Tells primary the new secondary list.

Re-replication after a chunkserver failure may take a Long Time.
  Since a chunkserver failure requires re-replication of all its chunks.
  80 GB disk, 10 MB/s network -> an hour or two for full copy.
  So the primary probably re-tries for a while,
    and the coordinator lets the system operate with a missing
    chunk replica,
    before declaring the chunkserver permanently dead.
  How long to wait before re-replicating?
    Too short: wasted copying work if chunkserver comes back to life.
    Too long: more failures might destroy all copies of data.

What if a primary crashes?
  Remove that chunkserver from all chunkhandle lists.
  For each chunk for which it was primary,
    wait for lease to expire,
    grant lease to another chunkserver holding that chunk.

What is a lease?
  Permission to act as primary for a given time (60 seconds).
  Primary promises to stop acting as primary before lease expires.
  Coordinator promises not to change primaries until after expiration.
  Separate lease per actively written chunk.

Why are leases helpful?
  The coordinator must be able to designate a new primary if the present
    primary fails.
  But the coordinator cannot distinguish "primary has failed" from
    "primary is still alive but the network has a problem."
  What if the coordinator designates a new primary while old one is active?
    two active primaries!
    C1 writes to P1, C2 reads from P2, doesn't seen C1's write!
    called "split brain" -- a disaster
  Leases help prevent split brain:
    Coordinator won't designate new primary until the current one is
    guaranteed to have stopped acting as primary.

What if the coordinator crashes?
  Two strategies.
  1. Coordinator writes critical state to its disk.
     If it crashes and reboots with disk intact,
     re-reads state, resumes operations.
  2. Coordinator sends each state update to a "backup coordinator",
     which also records it to disk; backup coordinator can take
     over if main coordinator cannot be restarted.

What information must the coordinator save to disk to recover from crashes?
  Table mapping file name -> array of chunk handles.
  Table mapping chunk handle -> current version #.
  What about the list of chunkservers for each chunk?
    A rebooted coordinator asks all the chunkservers what they store.
  A rebooted coordinator must also wait one lease time before
    designating any new primaries.

* Who/what decides the coordinator is dead, and chooses a replacement?
  Paper does not say.
  Could the coordinator replicas ping the coordinator,
    and automatically take over if no response?

* Suppose the coordinator reboots, and polls chunkservers.
  What if a chunkserver has a chunk, but it wasn't a secondary?
    I.e. the current primary wasn't keeping it up to date?
  Coordinator remembers version number per chunk, on disk.
    Increments each time it designates a new primary for the chunk.
  Chunkserver also remembers its version number per chunk.
  When chunkserver reports to coordinator, coordinator compares
    version number, only accepts if current version.

* What if a client has cached a stale (wrong) primary for a chunk?

* What if the reading client has cached a stale server list for a chunk?

* What if the primary crashes before sending append to all secondaries?
  Could a secondary that *didn't* see the append be chosen as the new primary?
  Is it a problem that the other secondary *did* see the append?

What would it take to have no anomalies -- strict consistency?
  I.e. all clients see the same file content.
  Too hard to give a real answer, but here are some issues.
  * All replicas should complete each write, or none -- "atomic write".
    Perhaps tentative writes until all promise to complete it?
    Don't expose writes until all have agreed to perform them!
  * Primary should detect duplicate client write requests.
  * If primary crashes, some replicas may be missing the last few ops.
    They must sync up.
  * Clients must be prevented from reading from stale ex-secondaries.
  You'll see solutions in Labs 2, 3, and 4!

* Are there circumstances in which GFS will break its guarantees?
  e.g. write succeeds, but subsequent readers don't see the data.
  All coordinator replicas permanently lose state (permanent disk failure).
    Read will fail.
  All chunkservers holding the chunk permanently lose disk content.
    Read will fail.
  CPU, RAM, network, or disk yields an incorrect value.
    checksum catches some cases, but not all
    Read may say "success" but yield the wrong data!
    Above errors were "fail-stop", but this is a "byzantine" failure.
  Time is not properly synchronized, so leases don't work out.
    So multiple primaries, maybe write goes to one, read to the other.
    Again, read may yield "success" but wrong data -- byzantine failure.

Performance (Figure 3)
  large aggregate throughput for read
    94 MB/sec total for 16 clients + 16 chunkservers
      or 6 MB/second per client
      is that good?
      one disk sequential throughput was about 30 MB/s
      one NIC was about 10 MB/s
    Close to saturating inter-switch link's 125 MB/sec (1 Gbit/sec)
    So: multi-client scalability is good
    Table 3 reports 500 MB/sec for cluster A, which was a lot
  writes to different files lower than possible maximum
    authors blame their network stack (but no detail)
  concurrent appends to single file
    limited by the server that stores last chunk
  hard to interpret after 15 years, e.g. how fast were the disks?

Retrospective interview with GFS engineer:
  http://queue.acm.org/detail.cfm?id=1594206
  file count was the biggest problem
    eventual numbers grew to 1000x those in Table 2 !
    hard to fit in coordinator RAM
    coordinator scanning of all files/chunks for GC is slow
  1000s of clients -> too much CPU load on coordinator
  coordinator fail-over initially manual, 10s of minutes, too long.
  applications had to be designed to cope with GFS semantics
    and limitations.
    more painful than expected.
  BigTable is one answer to many-small-files problem
  and Colossus apparently shards coordinator data over many coordinators

Summary
  case study of performance, fault-tolerance, consistency
    specialized for MapReduce applications
  good ideas:
    global cluster file system as universal infrastructure
    separation of naming (coordinator) from storage (chunkserver)
    sharding for parallel throughput
    huge files/chunks to reduce overheads
    primary to choose order for concurrent writes
    leases to prevent split-brain
  not so great:
    single coordinator performance
      ran out of RAM and CPU
    chunkservers not very efficient for small files
    lack of automatic fail-over to coordinator replica
    maybe consistency was too relaxed

---

http://queue.acm.org/detail.cfm?id=1594206
https://cloud.google.com/blog/products/storage-data-transfer/a-peek-behind-colossus-googles-file-system
PDF 文本转录papers/gfs.pdf1,854 行 · 15,472 词 · 完整收录
The Google File System
Sanjay Ghemawat, Howard Gobioff, and Shun-T ak Leung
Google∗
ABSTRACT
We have designed and implemented the Go ogle File Sys-
tem, a scalable distributed file system for large distributed
data-intensive applications. It provides fault tolerance while
running on inexpensive commodity hardware, and it delivers
high aggregate performance to a large number of clients.
While sharing many of the same goals as previous dis-
tributed file systems, our design has been driven by obser-
vations of our application workloads and technological envi-
ronment, both current and anticipated, that reflect a marked
departure from some earlier file system assumptions. This
has led us to reexamine traditional choices and explore rad-
ically different design points.
The file system has successfully met our storage needs.
It is widely deployed within Google as the storage platform
for the generation and processing of data used by our ser-
vice as well as research and development efforts that require
large data sets. The largest cluster to date provides hun-
dreds of terabytes of storage across thousands of disks on
over a thousand machines, and it is concurrently accessed
by hundreds of clients.
In this paper, we present file system interface extensions
designed to support distributed applications, discuss many
aspects of our design, and report measurements from both
micro-benchmarks and real world use.
Categories and Subject Descriptors
D[ 4]: 3— Distributed file systems
General Terms
Design, reliability, performance, measurement
Keywords
Fault tolerance, scalability, data storage, clustered storage
∗ The authors can be reached at the following addresses:
{sanjay,hgobioff,shuntak}@google.com.
Permission to make digital or hard copies of all or part of this work for
personal or classroom use is granted without fee provided that copies are
not made or distributed for profit or commercial advantage and that copies
bear this notice and the full citation on the first page. To copy otherwise, to
republish, to post on servers or to redistribute to lists, requires prior specific
permission and/or a fee.
SOSP’03, October 19–22, 2003, Bolton Landing, New York, USA.
Copyright 2003 ACM 1-58113-757-5/03/0010 ...$5.00.
1. INTRODUCTION
We have designed and implemented the Go ogle File Sys-
tem (GFS) to meet the rapidly growing demands of Google’s
data processing needs. GFS shares many of the same goals
as previous distributed file systems such as performance,
scalability, reliability, and availability. However, its design
has been driven by key observations of our application work-
loads and technological environment, both current and an-
ticipated, that reflect a marked departure from some earlier
file system design assumptions. We have reexamined tradi-
tional choices and explored radically different points in the
design space.
First, component failures are the norm rather than the
exception. The file system consists of hundreds or even
thousands of storage machines built from inexpensive com-
modity parts and is accessed by a comparable number of
client machines. The quantity and quality of the compo-
nents virtually guarantee that some are not functional at
any given time and some will not recover from their cur-
rent failures. We have seen problems caused by application
bugs, operating system bugs, human errors, and the failures
of disks, memory, connectors, networking, and power sup-
plies. Therefore, constant monitoring, error detection, fault
tolerance, and automatic recovery must be integral to the
system.
Second, files are huge by traditional standards. Multi-GB
files are common. Each file typically contains many applica-
tion objects such as web documents. When we are regularly
working with fast growing data sets of many TBs comprising
billions of objects, it is unwieldy to manage billions of ap-
proximately KB-sized files even when the file system could
support it. As a result, design assumptions and parameters
such as I/O operation and block sizes have to be revisited.
Third, most files are mutated by appending new data
rather than overwriting existing data. Random writes within
afi l ea r ep r a c t i c a l l yn o n - e x i s t e n t . O n c ew r i t t e n ,t h efi l e s
are only read, and often only sequentially. A variety of
data share these characteristics. Some may constitute large
repositories that data analysis programs scan through. Some
may be data streams continuously generated by running ap-
plications. Some may be archival data. Some may be in-
termediate results produced on one machine and processed
on another, whether simultaneously or later in time. Given
this access pattern on huge files, appending becomes the fo-
cus of performance optimization and atomicity guarantees,
while caching data blocks in the client loses its appeal.
Fourth, co-designing the applications and the file system
API benefits the overall system by increasing our flexibility.

For example, we have relaxed GFS’s consistency mo del to
vastly simplify the file system without imposing an onerous
burden on the applications. We have also introduced an
atomic append operation so that multiple clients can append
concurrently to a file without extra synchronization between
them. These will be discussed in more details later in the
paper.
Multiple GFS clusters are currently deployed for different
purposes. The largest ones have over 1000 storage nodes,
over 300 TB of disk storage, and are heavily accessed by
hundreds of clients on distinct machines on a continuous
basis.
2. DESIGN OVERVIEW
2.1 Assumptions
In designing a file system for our needs, we have been
guided by assumptions that offer both challenges and op-
portunities. W e alluded to some key observations earlier
and now lay out our assumptions in more details.
• The system is built from many inexpensive commodity
components that often fail. It must constantly monitor
itself and detect, tolerate, and recover promptly from
component failures on a routine basis.
• The system stores a modest number of large files. We
expect a few million files, each typically 100 MB or
larger in size. Multi-GB files are the common case
and should be managed efficiently. Small files must be
supported, but we need not optimize for them.
• The workloads primarily consist of two kinds of reads:
large streaming reads and small random reads. In
large streaming reads, individual operations typically
read hundreds of KBs, more commonly 1 MB or more.
Successive operations from the same client often read
through a contiguous region of a file. A small ran-
dom read typically reads a few KBs at some arbitrary
offset. Performance-conscious applications often batch
and sort their small reads to advance steadily through
the file rather than go back and forth.
• The workloads also have many large, sequential writes
that append data to files. Typical operation sizes are
similar to those for reads. Once written, files are sel-
dom modified again. Small writes at arbitrary posi-
tions in a file are supported but do not have to be
efficient.
• The system must efficiently implement well-defined se-
mantics for multiple clients that concurrently append
to the same file. Our files are often used as producer-
consumer queues or for many-way merging. Hundreds
of producers, running one per machine, will concur-
rently append to a file. Atomicity with minimal syn-
chronization overhead is essential. The file may be
read later, or a consumer may be reading through the
file simultaneously.
• High sustained bandwidth is more important than low
latency. Most of our target applications place a pre-
mium on processing data in bulk at a high rate, while
few have stringent response time requirements for an
individual read or write.
2.2 Interface
GFS provides a familiar file system interface, though it
does not implement a standard API such as POSIX. Files are
organized hierarchically in directories and identified by path-
names. We support the usual operations to create, delete,
open, close, read,a n d write files.
Moreover, GFS has snapshot and record append opera-
tions. Snapshot creates a copy of a file or a directory tree
at low cost. Record append allows multiple clients to ap-
pend data to the same file concurrently while guaranteeing
the atomicity of each individual client’s append. It is use-
ful for implementing multi-way merge results and producer-
consumer queues that many clients can simultaneously ap-
pend to without additional locking. W e have found these
types of files to be invaluable in building large distributed
applications. Snapshot and record append are discussed fur-
ther in Sections 3.4 and 3.3 respectively.
2.3 Architecture
AG F Sc l u s t e rc o n s i s t so fas i n g l emaster and multiple
chunkservers and is accessed by multiple clients,a ss h o w n
in Figure 1. Each of these is typically a commodity Linux
machine running a user-level server process. It is easy to run
both a chunkserver and a client on the same machine, as long
as machine resources permit and the lower reliability caused
by running possibly flaky application code is acceptable.
Files are divided into fixed-size chunks.E a c h c h u n k i s
identified by an immutable and globally unique 64 bit chunk
handle assigned by the master at the time of chunk creation.
Chunkservers store chunks on local disks as Linux files and
read or write chunk data specified by a chunk handle and
byte range. For reliability, each chunk is replicated on multi-
ple chunkservers. By default, we store three replicas, though
users can designate different replication levels for different
regions of the file namespace.
The master maintains all file system metadata. This in-
cludes the namespace, access control information, the map-
ping from files to chunks, and the current locations of chunks.
It also controls system-wide activities such as chunk lease
management, garbage collection of orphaned chunks, and
chunk migration between chunkservers. The master peri-
odically communicates with each chunkserver in HeartBeat
messages to give it instructions and collect its state.
GFS client code linked into each application implements
the file system API and communicates with the master and
chunkservers to read or write data on behalf of the applica-
tion. Clients interact with the master for metadata opera-
tions, but all data-bearing communication goes directly to
the chunkservers. We do not provide the POSIX API and
therefore need not hook into the Linux vnode layer.
Neither the client nor the chunkserver caches file data.
Client caches offer little benefit because most applications
stream through huge files or have working sets too large
to be cached. Not having them simplifies the client and
the overall system by eliminating cache coherence issues.
(Clients do cache metadata, however.) Chunkservers need
not cache file data because chunks are stored as local files
and so Linux’s buffer cache already keeps frequently accessed
data in memory.
2.4 Single Master
Having a single master vastly simplifies our design and
enables the master to make sophisticated chunk placement

Legend:
Data messages
Control messages
Application (file name, chunk index)
(chunk handle,
chunk locations)
GFS master
File namespace
/foo/bar
Instructions to chunkserver
Chunkserver state
GFS chunkserverGFS chunkserver
(chunk handle, byte range)
chunk data
chunk 2ef0
Linux file system Linux file system
GFS client
Figure 1: GFS Architecture
and replication decisions using global knowledge. However,
we must minimize its involvement in reads and writes so
that it does not become a bottleneck. Clients never read
and write file data through the master. Instead, a client asks
the master which chunkservers it should contact. It caches
this information for a limited time and interacts with the
chunkservers directly for many subsequent operations.
Let us explain the interactions for a simple read with refer-
ence to Figure 1. First, using the fixed chunk size, the client
translates the file name and byte offset specified by the ap-
plication into a chunk index within the file. Then, it sends
the master a request containing the file name and chunk
index. The master replies with the corresponding chunk
handle and locations of the replicas. The client caches this
information using the file name and chunk index as the key.
The client then sends a request to one of the replicas,
most likely the closest one. The request specifies the chunk
handle and a byte range within that chunk. Further reads
of the same chunk require no more client-master interaction
until the cached information expires or the file is reopened.
In fact, the client typically asks for multiple chunks in the
same request and the master can also include the informa-
tion for chunks immediately following those requested. This
extra information sidesteps several future client-master in-
teractions at practically no extra cost.
2.5 Chunk Size
Chunk size is one of the key design parameters. We have
chosen 64 MB, which is much larger than typical file sys-
tem block sizes. Each chunk replica is stored as a plain
Linux file on a chunkserver and is extended only as needed.
Lazy space allocation avoids wasting space due to internal
fragmentation, perhaps the greatest objection against such
al a r g ec h u n ks i z e .
Al a r g ec h u n ks i z eo ff e r ss e v e r a li m p o r t a n ta d v a n t a g e s .
First, it reduces clients’ need to interact with the master
because reads and writes on the same chunk require only
one initial request to the master for chunk location informa-
tion. The reduction is especially significant for our work-
loads because applications mostly read and write large files
sequentially. Even for small random reads, the client can
comfortably cache all the chunk location information for a
multi-TB working set. Second, since on a large chunk, a
client is more likely to perform many operations on a given
chunk, it can reduce network overhead by keeping a persis-
tent TCP connection to the chunkserver over an extended
period of time. Third, it reduces the size of the metadata
stored on the master. This allows us to keep the metadata
in memory, which in turn brings other advantages that we
will discuss in Section 2.6.1.
On the other hand, a large chunk size, even with lazy space
allocation, has its disadvantages. A small file consists of a
small number of chunks, perhaps just one. The chunkservers
storing those chunks may become hot spots if many clients
are accessing the same file. In practice, hot spots have not
been a major issue because our applications mostly read
large multi-chunk files sequentially.
However, hot spots did develop when GFS was first used
by a batch-queue system: an executable was written to GFS
as a single-chunk file and then started on hundreds of ma-
chines at the same time. The few chunkservers storing this
executable were overloaded by hundreds of simultaneous re-
quests. We fixed this problem by storing such executables
with a higher replication factor and by making the batch-
queue system stagger application start times. A potential
long-term solution is to allow clients to read data from other
clients in such situations.
2.6 Metadata
The master stores three major types of metadata: the file
and chunk namespaces, the mapping from files to chunks,
and the locations of each chunk’s replicas. All metadata is
kept in the master’s memory. The first two types (names-
paces and file-to-chunk mapping) are also kept persistent by
logging mutations to an operation log stored on the mas-
ter’s local disk and replicated on remote machines. Using
al o ga l l o w su st ou p d a t et h em a s t e rs t a t es i m p l y ,r e l i a b l y ,
and without risking inconsistencies in the event of a master
crash. The master does not store chunk location informa-
tion persistently. Instead, it asks each chunkserver about its
chunks at master startup and whenever a chunkserver joins
the cluster.
2.6.1 In-Memory Data Structures
Since metadata is stored in memory, master operations are
fast. Furthermore, it is easy and efficient for the master to
periodically scan through its entire state in the background.
This periodic scanning is used to implement chunk garbage
collection, re-replication in the presence of chunkserver fail-
ures, and chunk migration to balance load and disk space

usage across chunkservers. Sections 4.3 and 4.4 will discuss
these activities further.
One potential concern for this memory-only approach is
that the number of chunks and hence the capacity of the
whole system is limited by how much memory the master
has. This is not a serious limitation in practice. The mas-
ter maintains less than 64 bytes of metadata for each 64 MB
chunk. Most chunks are full because most files contain many
chunks, only the last of which may be partially filled. Sim-
ilarly, the file namespace data typically requires less then
64 bytes per file because it stores file names compactly us-
ing prefix compression.
If necessary to support even larger file systems, the cost
of adding extra memory to the master is a small price to pay
for the simplicity, reliability, performance, and flexibility we
gain by storing the metadata in memory.
2.6.2 Chunk Locations
The master does not keep a persistent record of which
chunkservers have a replica of a given chunk. It simply polls
chunkservers for that information at startup. The master
can keep itself up-to-date thereafter because it controls all
chunk placement and monitors chunkserver status with reg-
ular HeartBeat messages.
We initially attempted to keep chunk lo cation information
persistently at the master, but we decided that it was much
simpler to request the data from chunkservers at startup,
and periodically thereafter. This eliminated the problem of
keeping the master and chunkservers in sync as chunkservers
join and leave the cluster, change names, fail, restart, and
so on. In a cluster with hundreds of servers, these events
happen all too often.
Another way to understand this design decision is to real-
ize that a chunkserver has the final word over what chunks
it does or does not have on its own disks. There is no point
in trying to maintain a consistent view of this information
on the master because errors on a chunkserver may cause
chunks to vanish spontaneously (e.g., a disk may go bad
and be disabled) or an operator may rename a chunkserver.
2.6.3 Operation Log
The operation log contains a historical record of critical
metadata changes. It is central to GFS. Not only is it the
only persistent record of metadata, but it also serves as a
logical time line that defines the order of concurrent op-
erations. Files and chunks, as well as their versions (see
Section 4.5), are all uniquely and eternally identified by the
logical times at which they were created.
Since the operation log is critical, we must store it reli-
ably and not make changes visible to clients until metadata
changes are made persistent. Otherwise, we effectively lose
the whole file system or recent client operations even if the
chunks themselves survive. Therefore, we replicate it on
multiple remote machines and respond to a client opera-
tion only after flushing the corresponding log record to disk
both locally and remotely . The master batches several log
records together before flushing thereby reducing the impact
of flushing and replication on overall system throughput.
The master recovers its file system state by replaying the
operation log. To minimize startup time, we must keep the
log small. The master checkpoints its state whenever the log
grows beyond a certain size so that it can recover by loading
the latest checkpoint from local disk and replaying only the
Wr i te
 Record Append
Serial
 defined
 defined
success
 interspersed with
Concurrent
 consistent
 inconsistent
successes
 but undefined
Fai l ur e
 inconsistent
Table 1: File Region State After Mutation
limited number of log records after that. The checkpoint is
in a compact B-tree like form that can be directly mapped
into memory and used for namespace lookup without ex-
tra parsing. This further speeds up recovery and improves
availability.
Because building a checkpoint can take a while, the mas-
ter’s internal state is structured in such a way that a new
checkpoint can be created without delaying incoming muta-
tions. The master switches to a new log file and creates the
new checkpoint in a separate thread. The new checkpoint
includes all mutations before the switch. It can be created
in a minute or so for a cluster with a few million files. When
completed, it is written to disk both locally and remotely.
Recovery needs only the latest complete checkpoint and
subsequent log files. Older checkpoints and log files can
be freely deleted, though we keep a few around to guard
against catastrophes. A failure during checkpointing does
not affect correctness because the recovery code detects and
skips incomplete checkpoints.
2.7 Consistency Model
GFS has a relaxed consistency model that supports our
highly distributed applications well but remains relatively
simple and efficient to implement. We now discuss GFS’s
guarantees and what they mean to applications. We also
highlight how GFS maintains these guarantees but leave the
details to other parts of the paper.
2.7.1 Guarantees by GFS
File namespace mutations (e.g., file creation) are atomic.
They are handled exclusively by the master: namespace
locking guarantees atomicity and correctness (Section 4.1);
the master’s operation log defines a global total order of
these operations (Section 2.6.3).
The state of a file region after a data mutation depends
on the type of mutation, whether it succeeds or fails, and
whether there are concurrent mutations. Table 1 summa-
rizes the result. A file region is consistent if all clients will
always see the same data, regardless of which replicas they
read from. A region is defined after a file data mutation if it
is consistent and clients will see what the mutation writes in
its entirety. When a mutation succeeds without interference
from concurrent writers, the affected region is defined (and
by implication consistent): all clients will always see what
the mutation has written. Concurrent successful mutations
leave the region undefined but consistent: all clients see the
same data, but it may not reflect what any one mutation
has written. Typically, it consists of mingled fragments from
multiple mutations. A failed mutation makes the region in-
consistent (hence also undefined): different clients may see
different data at different times. We describe below how our
applications can distinguish defined regions from undefined

regions. The applications do not need to further distinguish
between different kinds of undefined regions.
Data mutations may be writes or record appends.A w r i t e
causes data to be written at an application-specified file
offset. A record append causes data (the “record”) to be
appended atomically at least once even in the presence of
concurrent mutations, but at an offset of GFS’s choosing
(Section 3.3). (In contrast, a “regular” append is merely a
write at an offset that the client believes to be the current
end of file.) The offset is returned to the client and marks
the beginning of a defined region that contains the record.
In addition, GFS may insert padding or record duplicates in
between. They occupy regions considered to be inconsistent
and are typically dwarfed by the amount of user data.
After a sequence of successful mutations, the mutated file
region is guaranteed to be defined and contain the data writ-
ten by the last mutation. GFS achieves this by (a) applying
mutations to a chunk in the same order on all its replicas
(Section 3.1), and (b) using chunk version numbers to detect
any replica that has become stale because it has missed mu-
tations while its chunkserver was down (Section 4.5). Stale
replicas will never be involved in a mutation or given to
clients asking the master for chunk locations. They are
garbage collected at the earliest opportunity.
Since clients cache chunk locations, they may read from a
stale replica before that information is refreshed. This win-
dow is limited by the cache entry’s timeout and the next
open of the file, which purges from the cache all chunk in-
formation for that file. Moreover, as most of our files are
append-only, a stale replica usually returns a premature
end of chunk rather than outdated data. When a reader
retries and contacts the master, it will immediately get cur-
rent chunk locations.
Long after a successful mutation, component failures can
of course still corrupt or destroy data. GFS identifies failed
chunkservers by regular handshakes between master and all
chunkservers and detects data corruption by checksumming
(Section 5.2). Once a problem surfaces, the data is restored
from valid replicas as soon as possible (Section 4.3). A chunk
is lost irreversibly only if all its replicas are lost before GFS
can react, typically within minutes. Even in this case, it be-
comes unavailable, not corrupted: applications receive clear
errors rather than corrupt data.
2.7.2 Implications for Applications
GFS applications can accommodate the relaxed consis-
tency model with a few simple techniques already needed for
other purposes: relying on appends rather than overwrites,
checkpointing, and writing self-validating, self-identifying
records.
Practically all our applications mutate files by appending
rather than overwriting. In one typical use, a writer gener-
ates a file from beginning to end. It atomically renames the
file to a permanent name after writing all the data, or pe-
riodically checkpoints how much has been successfully writ-
ten. Checkpoints may also include application-level check-
sums. Readers verify and process only the file region up
to the last checkpoint, which is known to be in the defined
state. Regardless of consistency and concurrency issues, this
approach has served us well. Appending is far more effi-
cient and more resilient to application failures than random
writes. Checkpointing allows writers to restart incremen-
tally and keeps readers from processing successfully written
file data that is still incomplete from the application’s per-
spective.
In the other typical use, many writers concurrently ap-
pend to a file for merged results or as a producer-consumer
queue. Record append’s append-at-least-once semantics pre-
serves each writer’s output. Readers deal with the occa-
sional padding and duplicates as follows. Each record pre-
pared by the writer contains extra information like check-
sums so that its validity can be verified. A reader can
identify and discard extra padding and record fragments
using the checksums. If it cannot tolerate the occasional
duplicates (e.g., if they would trigger non-idempotent op-
erations), it can filter them out using unique identifiers in
the records, which are often needed anyway to name corre-
sponding application entities such as web documents. These
functionalities for record I/O (except duplicate removal) are
in library code shared by our applications and applicable to
other file interface implementations at Google. With that,
the same sequence of records, plus rare duplicates, is always
delivered to the record reader.
3. SYSTEM INTERACTIONS
We designed the system to minimize the master’s involve-
ment in all operations. With that background, we now de-
scribe how the client, master, and chunkservers interact to
implement data mutations, atomic record append, and snap-
shot.
3.1 Leases and Mutation Order
Am u t a t i o ni sa no p e r a t i o nt h a tc h a n g e st h ec o n t e n t so r
metadata of a chunk such as a write or an append opera-
tion. Each mutation is performed at all the chunk’s replicas.
We use leases to maintain a consistent mutation order across
replicas. The master grants a chunk lease to one of the repli-
cas, which we call the primary.T h e p r i m a r y p i c k s a s e r i a l
order for all mutations to the chunk. All replicas follow this
order when applying mutations. Thus, the global mutation
order is defined first by the lease grant order chosen by the
master, and within a lease by the serial numbers assigned
by the primary.
The lease mechanism is designed to minimize manage-
ment overhead at the master. A lease has an initial timeout
of 60 seconds. However, as long as the chunk is being mu-
tated, the primary can request and typically receive exten-
sions from the master indefinitely. These extension requests
and grants are piggybacked on the HeartBeat messages reg-
ularly exchanged between the master and all chunkservers.
The master may sometimes try to revoke a lease before it
expires (e.g., when the master wants to disable mutations
on a file that is being renamed). Even if the master loses
communication with a primary, it can safely grant a new
lease to another replica after the old lease expires.
In Figure 2, we illustrate this process by following the
control flow of a write through these numbered steps.
1. The client asks the master which chunkserver holds
the current lease for the chunk and the locations of
the other replicas. If no one has a lease, the master
grants one to a replica it chooses (not shown).
2. The master replies with the identity of the primary and
the locations of the other ( secondary)r e p l i c a s . T h e
client caches this data for future mutations. It needs
to contact the master again only when the primary

Primary
Replica
Secondary
Replica B
Secondary
Replica A
Master
Legend:
Control
Data
3
Client
2
step 14
5
6
6
7
Figure 2: W rite Control and Data Flow
becomes unreachable or replies that it no longer holds
al e a s e .
3. The client pushes the data to all the replicas. A client
can do so in any order. Each chunkserver will store
the data in an internal LRU buffer cache until the
data is used or aged out. By decoupling the data flow
from the control flow, we can improve performance by
scheduling the expensive data flow based on the net-
work topology regardless of which chunkserver is the
primary. Section 3.2 discusses this further.
4. Once all the replicas have acknowledged receiving the
data, the client sends a write request to the primary.
The request identifies the data pushed earlier to all of
the replicas. The primary assigns consecutive serial
numbers to all the mutations it receives, possibly from
multiple clients, which provides the necessary serial-
ization. It applies the mutation to its own local state
in serial number order.
5. The primary forwards the write request to all sec-
ondary replicas. Each secondary replica applies mu-
tations in the same serial number order assigned by
the primary.
6. The secondaries all reply to the primary indicating
that they have completed the operation.
7. The primary replies to the client. Any errors encoun-
tered at any of the replicas are reported to the client.
In case of errors, the write may have succeeded at the
primary and an arbitrary subset of the secondary repli-
cas. (If it had failed at the primary, it would not
have been assigned a serial number and forwarded.)
The client request is considered to have failed, and the
modified region is left in an inconsistent state. Our
client code handles such errors by retrying the failed
mutation. It will make a few attempts at steps (3)
through (7) before falling back to a retry from the be-
ginning of the write.
If a write by the application is large or straddles a chunk
boundary , GFS client code breaks it down into multiple
write operations. They all follow the control flow described
above but may be interleaved with and overwritten by con-
current operations from other clients. Therefore, the shared
file region may end up containing fragments from different
clients, although the replicas will be identical because the in-
dividual operations are completed successfully in the same
order on all replicas. This leaves the file region in consistent
but undefined state as noted in Section 2.7.
3.2 Data Flow
We decouple the flow of data from the flow of control to
use the network efficiently. While control flows from the
client to the primary and then to all secondaries, data is
pushed linearly along a carefully picked chain of chunkservers
in a pipelined fashion. Our goals are to fully utilize each
machine’s network bandwidth, avoid network bottlenecks
and high-latency links, and minimize the latency to push
through all the data.
To fully utilize each machine’s network bandwidth, the
data is pushed linearly along a chain of chunkservers rather
than distributed in some other topology (e.g., tree). Thus,
each machine’s full outbound bandwidth is used to trans-
fer the data as fast as possible rather than divided among
multiple recipients.
To avoid network b ottlenecks and high-latency links (e.g.,
inter-switch links are often both) as much as possible, each
machine forwards the data to the “closest” machine in the
network topology that has not received it. Suppose the
client is pushing data to chunkservers S1 through S4. It
sends the data to the closest chunkserver, say S1. S1 for-
wards it to the closest chunkserver S2 through S4 closest to
S1, say S2. Similarly, S2 forwards it to S3 or S4, whichever
is closer to S2, and so on. Our network topology is simple
enough that “distances” can be accurately estimated from
IP addresses.
Finally, we minimize latency by pipelining the data trans-
fer over TCP connections. Once a chunkserver receives some
data, it starts forwarding immediately. Pipelining is espe-
cially helpful to us because we use a switched network with
full-duplex links. Sending the data immediately does not
reduce the receive rate. Without network congestion, the
ideal elapsed time for transferring B bytes to R replicas is
B/T + RL where T is the network throughput and L is la-
tency to transfer bytes between two machines. Our network
links are typically 100 Mbps ( T ), and L is far below 1 ms.
Therefore, 1 MB can ideally be distributed in about 80 ms.
3.3 Atomic Record Appends
GFS provides an atomic append operation called record
append.I n a t r a d i t i o n a l w r i t e , t h e c l i e n t s p e c i fi e s t h e o ff -
set at which data is to be written. Concurrent writes to
the same region are not serializable: the region may end up
containing data fragments from multiple clients. In a record
append, however, the client specifies only the data. GFS
appends it to the file at least once atomically (i.e., as one
continuous sequence of bytes) at an offset of GFS’s choosing
and returns that offset to the client. This is similar to writ-
ing to a file opened in O
 APPEND mode in Unix without the
race conditions when multiple writers do so concurrently.
Record append is heavily used by our distributed applica-
tions in which many clients on different machines append
to the same file concurrently. Clients would need addi-
tional complicated and expensive synchronization, for ex-
ample through a distributed lock manager, if they do so
with traditional writes. In our workloads, such files often

serve as multiple-producer/single-consumer queues or con-
tain merged results from many different clients.
Record append is a kind of mutation and follows the con-
trol flow in Section 3.1 with only a little extra logic at the
primary. The client pushes the data to all replicas of the
last chunk of the file Then, it sends its request to the pri-
mary. The primary checks to see if appending the record
to the current chunk would cause the chunk to exceed the
maximum size (64 MB). If so, it pads the chunk to the max-
imum size, tells secondaries to do the same, and replies to
the client indicating that the operation should be retried
on the next chunk. (Record append is restricted to be at
most one-fourth of the maximum chunk size to keep worst-
case fragmentation at an acceptable level.) If the record
fits within the maximum size, which is the common case,
the primary appends the data to its replica, tells the secon-
daries to write the data at the exact offset where it has, and
finally replies success to the client.
If a record append fails at any replica, the client retries the
operation. As a result, replicas of the same chunk may con-
tain different data possibly including duplicates of the same
record in whole or in part. GFS does not guarantee that all
replicas are bytewise identical. It only guarantees that the
data is written at least once as an atomic unit. This prop-
erty follows readily from the simple observation that for the
operation to report success, the data must have been written
at the same offset on all replicas of some chunk. Further-
more, after this, all replicas are at least as long as the end
of record and therefore any future record will be assigned a
higher offset or a different chunk even if a different replica
later becomes the primary. In terms of our consistency guar-
antees, the regions in which successful record append opera-
tions have written their data are defined (hence consistent),
whereas intervening regions are inconsistent (hence unde-
fined). Our applications can deal with inconsistent regions
as we discussed in Section 2.7.2.
3.4 Snapshot
The snapshot operation makes a copy of a file or a direc-
tory tree (the “source”) almost instantaneously, while min-
imizing any interruptions of ongoing mutations. Our users
use it to quickly create branch copies of huge data sets (and
often copies of those copies, recursively), or to checkpoint
the current state before experimenting with changes that
can later be committed or rolled back easily.
Like AFS [5], we use standard copy-on-write techniques to
implement snapshots. When the master receives a snapshot
request, it first revokes any outstanding leases on the chunks
in the files it is about to snapshot. This ensures that any
subsequent writes to these chunks will require an interaction
with the master to find the lease holder. This will give the
master an opportunity to create a new copy of the chunk
first.
After the leases have been revoked or have expired, the
master logs the operation to disk. It then applies this log
record to its in-memory state by duplicating the metadata
for the source file or directory tree. The newly created snap-
shot files point to the same chunks as the source files.
The first time a client wants to write to a chunk C after
the snapshot operation, it sends a request to the master to
find the current lease holder. The master notices that the
reference count for chunk C is greater than one. It defers
replying to the client request and instead picks a new chunk
handle C’. It then asks each chunkserver that has a current
replica of C to create a new chunk called C’. By creating
the new chunk on the same chunkservers as the original, we
ensure that the data can be copied locally, not over the net-
work (our disks are about three times as fast as our 100 Mb
Ethernet links). From this point, request handling is no dif-
ferent from that for any chunk: the master grants one of the
replicas a lease on the new chunk C’ and replies to the client,
which can write the chunk normally, not knowing that it has
just been created from an existing chunk.
4. MASTER OPERATION
The master executes all namespace operations. In addi-
tion, it manages chunk replicas throughout the system: it
makes placement decisions, creates new chunks and hence
replicas, and coordinates various system-wide activities to
keep chunks fully replicated, to balance load across all the
chunkservers, and to reclaim unused storage. We now dis-
cuss each of these topics.
4.1 Namespace Management and Locking
Many master operations can take a long time: for exam-
ple, a snapshot operation has to revoke chunkserver leases on
all chunks covered by the snapshot. We do not want to delay
other master operations while they are running. Therefore,
we allow multiple operations to be active and use locks over
regions of the namespace to ensure proper serialization.
Unlike many traditional file systems, GFS does not have
ap e r - d i r e c t o r yd a t as t r u c t u r et h a tl i s t sa l lt h efi l e si nt h a t
directory. Nor does it support aliases for the same file or
directory (i.e, hard or symbolic links in Unix terms). GFS
logically represents its namespace as a lookup table mapping
full pathnames to metadata. With prefix compression, this
table can be efficiently represented in memory. Each node
in the namespace tree (either an absolute file name or an
absolute directory name) has an associated read-write lock.
Each master operation acquires a set of locks before it
runs. Typically, if it involves /d1/d2/.../dn/leaf,i tw i l l
acquire read-locks on the directory names /d1, /d1/d2,. . . ,
/d1/d2/.../dn,a n de i t h e rar e a dl o c ko raw r i t el o c ko nt h e
full pathname /d1/d2/.../dn/leaf.N o t e t h a tleaf may be
afi l eo rd i r e c t o r yd e p e n d i n go nt h eo p e r a t i o n .
We now illustrate how this lo cking mechanism can prevent
afi l e /home/user/foo from being created while /home/user
is being snapshotted to /save/user.T h e s n a p s h o t o p e r -
ation acquires read locks on /home and /save,a n dw r i t e
locks on /home/user and /save/user.T h e fi l e c r e a t i o n a c -
quires read locks on /home and /home/user,a n daw r i t e
lock on /home/user/foo.T h e t w o o p e r a t i o n s w i l l b e s e r i -
alized properly because they try to obtain conflicting locks
on /home/user.F i l e c r e a t i o n d o e s n o t r e q u i r e a w r i t e l o c k
on the parent directory because there is no “directory”, or
inode-like, data structure to be protected from modification.
The read lock on the name is sufficient to protect the parent
directory from deletion.
One nice property of this locking scheme is that it allows
concurrent mutations in the same directory. For example,
multiple file creations can be executed concurrently in the
same directory: each acquires a read lock on the directory
name and a write lock on the file name. The read lock on
the directory name suffices to prevent the directory from
being deleted, renamed, or snapshotted. The write locks on

file names serialize attempts to create a file with the same
name twice.
Since the namespace can have many nodes, read-write lock
objects are allocated lazily and deleted once they are not in
use. Also, locks are acquired in a consistent total order
to prevent deadlock: they are first ordered by level in the
namespace tree and lexicographically within the same level.
4.2 Replica Placement
AG F Sc l u s t e ri sh i g h l yd i s t r i b u t e da tm o r el e v e l st h a n
one. It typically has hundreds of chunkservers spread across
many machine racks. These chunkservers in turn may be
accessed from hundreds of clients from the same or different
racks. Communication between two machines on different
racks may cross one or more network switches. Addition-
ally, bandwidth into or out of a rack may be less than the
aggregate bandwidth of all the machines within the rack.
Multi-level distribution presents a unique challenge to dis-
tribute data for scalability, reliability, and availability.
The chunk replica placement policy serves two purposes:
maximize data reliability and availability, and maximize net-
work bandwidth utilization. For both, it is not enough to
spread replicas across machines, which only guards against
disk or machine failures and fully utilizes each machine’s net-
work bandwidth. We must also spread chunk replicas across
racks. This ensures that some replicas of a chunk will sur-
vive and remain available even if an entire rack is damaged
or offline (for example, due to failure of a shared resource
like a network switch or power circuit). It also means that
traffic, especially reads, for a chunk can exploit the aggre-
gate bandwidth of multiple racks. On the other hand, write
traffic has to flow through multiple racks, a tradeoff we make
willingly.
4.3 Creation, Re-replication, Rebalancing
Chunk replicas are created for three reasons: chunk cre-
ation, re-replication, and rebalancing.
When the master creates ac h u n k ,i tc h o o s e sw h e r et o
place the initially empty replicas. It considers several fac-
tors. (1) We want to place new replicas on chunkservers with
below-average disk space utilization. Over time this will
equalize disk utilization across chunkservers. (2) We want to
limit the number of “recent” creations on each chunkserver.
Although creation itself is cheap, it reliably predicts immi-
nent heavy write traffic because chunks are created when de-
manded by writes, and in our append-once-read-many work-
load they typically become practically read-only once they
have been completely written. (3) As discussed above, we
want to spread replicas of a chunk across racks.
The master re-replicates ac h u n ka ss o o na st h en u m b e r
of available replicas falls below a user-specified goal. This
could happen for various reasons: a chunkserver becomes
unavailable, it reports that its replica may be corrupted, one
of its disks is disabled because of errors, or the replication
goal is increased. Each chunk that needs to be re-replicated
is prioritized based on several factors. One is how far it is
from its replication goal. For example, we give higher prior-
ity to a chunk that has lost two replicas than to a chunk that
has lost only one. In addition, we prefer to first re-replicate
chunks for live files as opposed to chunks that belong to re-
cently deleted files (see Section 4.4). Finally, to minimize
the impact of failures on running applications, we boost the
priority of any chunk that is blocking client progress.
The master picks the highest priority chunk and “clones”
it by instructing some chunkserver to copy the chunk data
directly from an existing valid replica. The new replica is
placed with goals similar to those for creation: equalizing
disk space utilization, limiting active clone operations on
any single chunkserver, and spreading replicas across racks.
To keep cloning traffic from overwhelming client traffic, the
master limits the numbers of active clone operations both
for the cluster and for each chunkserver. Additionally, each
chunkserver limits the amount of bandwidth it spends on
each clone operation by throttling its read requests to the
source chunkserver.
Finally, the master rebalances replicas periodically: it ex-
amines the current replica distribution and moves replicas
for better disk space and load balancing. Also through this
process, the master gradually fills up a new chunkserver
rather than instantly swamps it with new chunks and the
heavy write traffic that comes with them. The placement
criteria for the new replica are similar to those discussed
above. In addition, the master must also choose which ex-
isting replica to remove. In general, it prefers to remove
those on chunkservers with below-average free space so as
to equalize disk space usage.
4.4 Garbage Collection
After a file is deleted, GFS does not immediately reclaim
the available physical storage. It does so only lazily during
regular garbage collection at both the file and chunk levels.
We find that this approach makes the system much simpler
and more reliable.
4.4.1 Mechanism
When a file is deleted by the application, the master logs
the deletion immediately just like other changes. However
instead of reclaiming resources immediately, the file is just
renamed to a hidden name that includes the deletion times-
tamp. During the master’s regular scan of the file system
namespace, it removes any such hidden files if they have ex-
isted for more than three days (the interval is configurable).
Until then, the file can still be read under the new, special
name and can be undeleted by renaming it back to normal.
When the hidden file is removed from the namespace, its in-
memory metadata is erased. This effectively severs its links
to all its chunks.
In a similar regular scan of the chunk namespace, the
master identifies orphaned chunks (i.e., those not reachable
from any file) and erases the metadata for those chunks. In
a HeartBeat message regularly exchanged with the master,
each chunkserver reports a subset of the chunks it has, and
the master replies with the identity of all chunks that are no
longer present in the master’s metadata. The chunkserver
is free to delete its replicas of such chunks.
4.4.2 Discussion
Although distributed garbage collection is a hard problem
that demands complicated solutions in the context of pro-
gramming languages, it is quite simple in our case. We can
easily identify all references to chunks: they are in the file-
to-chunk mappings maintained exclusively by the master.
We can also easily identify all the chunk replicas: they are
Linux files under designated directories on each chunkserver.
Any such replica not known to the master is “garbage.”

The garbage collection approach to storage reclamation
offers several advantages over eager deletion. First, it is
simple and reliable in a large-scale distributed system where
component failures are common. Chunk creation may suc-
ceed on some chunkservers but not others, leaving replicas
that the master does not know exist. Replica deletion mes-
sages may be lost, and the master has to remember to resend
them across failures, both its own and the chunkserver’s.
Garbage collection provides a uniform and dependable way
to clean up any replicas not known to be useful. Second,
it merges storage reclamation into the regular background
activities of the master, such as the regular scans of names-
paces and handshakes with chunkservers. Thus, it is done
in batches and the cost is amortized. Moreover, it is done
only when the master is relatively free. The master can re-
spond more promptly to client requests that demand timely
attention. Third, the delay in reclaiming storage provides a
safety net against accidental, irreversible deletion.
In our experience, the main disadvantage is that the delay
sometimes hinders user effort to fine tune usage when stor-
age is tight. Applications that repeatedly create and delete
temporary files may not be able to reuse the storage right
away. We address these issues by expediting storage recla-
mation if a deleted file is explicitly deleted again. We also
allow users to apply different replication and reclamation
policies to different parts of the namespace. F or example,
users can specify that all the chunks in the files within some
directory tree are to be stored without replication, and any
deleted files are immediately and irrevocably removed from
the file system state.
4.5 Stale Replica Detection
Chunk replicas may become stale if a chunkserver fails
and misses mutations to the chunk while it is down. For
each chunk, the master maintains a chunk version number
to distinguish between up-to-date and stale replicas.
Whenever the master grants a new lease on a chunk, it
increases the chunk version number and informs the up-to-
date replicas. The master and these replicas all record the
new version number in their persistent state. This occurs
before any client is notified and therefore before it can start
writing to the chunk. If another replica is currently unavail-
able, its chunk version number will not be advanced. The
master will detect that this chunkserver has a stale replica
when the chunkserver restarts and reports its set of chunks
and their associated version numbers. If the master sees a
version number greater than the one in its records, the mas-
ter assumes that it failed when granting the lease and so
takes the higher version to be up-to-date.
The master removes stale replicas in its regular garbage
collection. Before that, it effectively considers a stale replica
not to exist at all when it replies to client requests for chunk
information. As another safeguard, the master includes
the chunk version number when it informs clients which
chunkserver holds a lease on a chunk or when it instructs
ac h u n k s e r v e rt or e a dt h ec h u n kf r o ma n o t h e rc h u n k s e r v e r
in a cloning operation. The client or the chunkserver verifies
the version number when it performs the operation so that
it is always accessing up-to-date data.
5. FAULT TOLERANCE AND DIAGNOSIS
One of our greatest challenges in designing the system is
dealing with frequent component failures. The quality and
quantity of components together make these problems more
the norm than the exception: we cannot completely trust
the machines, nor can we completely trust the disks. Com-
ponent failures can result in an unavailable system or, worse,
corrupted data. We discuss how we meet these challenges
and the tools we have built into the system to diagnose prob-
lems when they inevitably occur.
5.1 High Availability
Among hundreds of servers in a GFS cluster, some are
bound to be unavailable at any given time. W e keep the
overall system highly available with two simple yet effective
strategies: fast recovery and replication.
5.1.1 Fast Recovery
Both the master and the chunkserver are designed to re-
store their state and start in seconds no matter how they
terminated. In fact, we do not distinguish between normal
and abnormal termination; servers are routinely shut down
just by killing the process. Clients and other servers experi-
ence a minor hiccup as they time out on their outstanding
requests, reconnect to the restarted server, and retry. Sec-
tion 6.2.2 reports observed startup times.
5.1.2 Chunk Replication
As discussed earlier, each chunk is replicated on multiple
chunkservers on different racks. Users can specify different
replication levels for different parts of the file namespace.
The default is three. The master clones existing replicas as
needed to keep each chunk fully replicated as chunkservers
go offline or detect corrupted replicas through checksum ver-
ification (see Section 5.2). Although replication has served
us well, we are exploring other forms of cross-server redun-
dancy such as parity or erasure codes for our increasing read-
only storage requirements. We expect that it is challenging
but manageable to implement these more complicated re-
dundancy schemes in our very loosely coupled system be-
cause our traffic is dominated by appends and reads rather
than small random writes.
5.1.3 Master Replication
The master state is replicated for reliability. Its operation
log and checkpoints are replicated on multiple machines. A
mutation to the state is considered committed only after
its log record has been flushed to disk locally and on all
master replicas. For simplicity, one master process remains
in charge of all mutations as well as background activities
such as garbage collection that change the system internally.
When it fails, it can restart almost instantly. If its machine
or disk fails, monitoring infrastructure outside GFS starts a
new master process elsewhere with the replicated operation
log. Clients use only the canonical name of the master (e.g.
gfs-test), which is a DNS alias that can be changed if the
master is relocated to another machine.
Moreover, “shadow” masters provide read-only access to
the file system even when the primary master is down. They
are shadows, not mirrors, in that they may lag the primary
slightly, typically fractions of a second. They enhance read
availability for files that are not being actively mutated or
applications that do not mind getting slightly stale results.
In fact, since file content is read from chunkservers, appli-
cations do not observe stale file content. What could be

stale within short windows is file metadata, like directory
contents or access control information.
To keep itself informed, a shadow master reads a replica of
the growing operation log and applies the same sequence of
changes to its data structures exactly as the primary does.
Like the primary, it polls chunkservers at startup (and infre-
quently thereafter) to locate chunk replicas and exchanges
frequent handshake messages with them to monitor their
status. It depends on the primary master only for replica
location updates resulting from the primary’s decisions to
create and delete replicas.
5.2 Data Integrity
Each chunkserver uses checksumming to detect corruption
of stored data. Given that a GFS cluster often has thousands
of disks on hundreds of machines, it regularly experiences
disk failures that cause data corruption or loss on both the
read and write paths. (See Section 7 for one cause.) We
can recover from corruption using other chunk replicas, but
it would be impractical to detect corruption by comparing
replicas across chunkservers. Moreover, divergent replicas
may be legal: the semantics of GFS mutations, in particular
atomic record append as discussed earlier, does not guar-
antee identical replicas. Therefore, each chunkserver must
independently verify the integrity of its own copy by main-
taining checksums.
Ac h u n ki sb r o k e nu pi n t o6 4K Bb l o c k s . E a c hh a sac o r r e -
sponding 32 bit checksum. Like other metadata, checksums
are kept in memory and stored persistently with logging,
separate from user data.
For reads, the chunkserver verifies the checksum of data
blocks that overlap the read range before returning any data
to the requester, whether a client or another chunkserver.
Therefore chunkservers will not propagate corruptions to
other machines. If a block does not match the recorded
checksum, the chunkserver returns an error to the requestor
and reports the mismatch to the master. In response, the
requestor will read from other replicas, while the master
will clone the chunk from another replica. After a valid new
replica is in place, the master instructs the chunkserver that
reported the mismatch to delete its replica.
Checksumming has little effect on read performance for
several reasons. Since most of our reads span at least a
few blocks, we need to read and checksum only a relatively
small amount of extra data for verification. GFS client code
further reduces this overhead by trying to align reads at
checksum block boundaries. Moreover, checksum lookups
and comparison on the chunkserver are done without any
I/O, and checksum calculation can often be overlapped with
I/Os.
Checksum computation is heavily optimized for writes
that append to the end of a chunk (as opposed to writes
that overwrite existing data) because they are dominant in
our workloads. We just incrementally update the check-
sum for the last partial checksum block, and compute new
checksums for any brand new checksum blocks filled by the
append. Even if the last partial checksum block is already
corrupted and we fail to detect it now, the new checksum
value will not match the stored data, and the corruption will
be detected as usual when the block is next read.
In contrast, if a write overwrites an existing range of the
chunk, we must read and verify the first and last blocks of
the range being overwritten, then perform the write, and
finally compute and record the new checksums. If we do
not verify the first and last blocks before overwriting them
partially, the new checksums may hide corruption that exists
in the regions not being overwritten.
During idle periods, chunkservers can scan and verify the
contents of inactive chunks. This allows us to detect corrup-
tion in chunks that are rarely read. Once the corruption is
detected, the master can create a new uncorrupted replica
and delete the corrupted replica. This prevents an inactive
but corrupted chunk replica from fooling the master into
thinking that it has enough valid replicas of a chunk.
5.3 Diagnostic Tools
Extensive and detailed diagnostic logging has helped im-
measurably in problem isolation, debugging, and perfor-
mance analysis, while incurring only a minimal cost. With-
out logs, it is hard to understand transient, non-repeatable
interactions between machines. GFS servers generate di-
agnostic logs that record many significant events (such as
chunkservers going up and down) and all RPC requests and
replies. These diagnostic logs can be freely deleted without
affecting the correctness of the system. However, we try to
keep these logs around as far as space permits.
The RPC logs include the exact requests and responses
sent on the wire, except for the file data being read or writ-
ten. By matching requests with replies and collating RPC
records on different machines, we can reconstruct the en-
tire interaction history to diagnose a problem. The logs also
serve as traces for load testing and performance analysis.
The performance impact of logging is minimal (and far
outweighed by the benefits) because these logs are written
sequentially and asynchronously. The most recent events
are also kept in memory and available for continuous online
monitoring.
6. MEASUREMENTS
In this section we present a few micro-benchmarks to illus-
trate the bottlenecks inherent in the GFS architecture and
implementation, and also some numbers from real clusters
in use at Google.
6.1 Micro-benchmarks
We measured p erformance on a GFS cluster consisting
of one master, two master replicas, 16 chunkservers, and
16 clients. Note that this configuration was set up for ease
of testing. Typical clusters have hundreds of chunkservers
and hundreds of clients.
All the machines are configured with dual 1.4 GHz PIII
processors, 2 GB of memory, two 80 GB 5400 rpm disks, and
a1 0 0M b p sf u l l - d u p l e xE t h e r n e tc o n n e c t i o nt oa nH P2 5 2 4
switch. All 19 GFS server machines are connected to one
switch, and all 16 client machines to the other. The two
switches are connected with a 1 Gbps link.
6.1.1 Reads
N clients read simultaneously from the file system. Each
client reads a randomly selected 4 MB region from a 320 GB
file set. This is repeated 256 times so that each client ends
up reading 1 GB of data. The chunkservers taken together
have only 32 GB of memory, so we expect at most a 10% hit
rate in the Linux buffer cache. Our results should be close
to cold cache results.

Figure 3(a) shows the aggregate read rate for N clients
and its theoretical limit. The limit peaks at an aggregate of
125 MB/s when the 1 Gbps link between the two switches
is saturated, or 12.5 MB/s per client when its 100 Mbps
network interface gets saturated, whichever applies. The
observed read rate is 10 MB/s, or 80% of the per-client
limit, when just one client is reading. The aggregate read
rate reaches 94 MB/s, about 75% of the 125 MB/s link limit,
for 16 readers, or 6 MB/s per client. The efficiency drops
from 80% to 75% because as the number of readers increases,
so does the probability that multiple readers simultaneously
read from the same chunkserver.
6.1.2 Writes
N clients write simultaneously to N distinct files. Each
client writes 1 GB of data to a new file in a series of 1 MB
writes. The aggregate write rate and its theoretical limit are
shown in Figure 3(b). The limit plateaus at 67 MB/s be-
cause we need to write each byte to 3 of the 16 chunkservers,
each with a 12.5 MB/s input connection.
The write rate for one client is 6.3 MB/s, about half of the
limit. The main culprit for this is our network stack. It does
not interact very well with the pipelining scheme we use for
pushing data to chunk replicas. Delays in propagating data
from one replica to another reduce the overall write rate.
Aggregate write rate reaches 35 MB/s for 16 clients (or
2.2 MB/s per client), about half the theoretical limit. As in
the case of reads, it becomes more likely that multiple clients
write concurrently to the same chunkserver as the number
of clients increases. Moreover, collision is more likely for 16
writers than for 16 readers because each write involves three
different replicas.
Writes are slower than we would like. In practice this has
not been a major problem because even though it increases
the latencies as seen by individual clients, it does not sig-
nificantly affect the aggregate write bandwidth delivered by
the system to a large number of clients.
6.1.3 Record Appends
Figure 3(c) shows record append performance. N clients
append simultaneously to a single file. Performance is lim-
ited by the network bandwidth of the chunkservers that
store the last chunk of the file, independent of the num-
ber of clients. It starts at 6.0 MB/s for one client and drops
to 4.8 MB/s for 16 clients, mostly due to congestion and
variances in network transfer rates seen by different clients.
Our applications tend to produce multiple such files con-
currently. In other words, N clients append to M shared
files simultaneously where both N and M are in the dozens
or hundreds. Therefore, the chunkserver network congestion
in our experiment is not a significant issue in practice be-
cause a client can make progress on writing one file while
the chunkservers for another file are busy.
6.2 Real World Clusters
We now examine two clusters in use within Go ogle that
are representative of several others like them. Cluster A is
used regularly for research and development by over a hun-
dred engineers. A typical task is initiated by a human user
and runs up to several hours. It reads through a few MBs
to a few TBs of data, transforms or analyzes the data, and
writes the results back to the cluster. Cluster B is primarily
used for production data processing. The tasks last much
Cluster
 A
 B
Chunkservers
 342
 227
Available disk space
 72 TB
 180 TB
Used disk space
 55 TB
 155 TB
Number of Files
 735 k
 737 k
Number of Dead files
 22 k
 232 k
Number of Chunks
 992 k
 1550 k
Metadata at chunkservers
 13 GB
 21 GB
Metadata at master
 48 MB
 60 MB
Table 2: Characteristics of two GFS clusters
longer and continuously generate and process multi-TB data
sets with only occasional human intervention. In both cases,
as i n g l e“ t a s k ”c o n s i s t so fm a n yp r o c e s s e so nm a n ym a c h i n e s
reading and writing many files simultaneously.
6.2.1 Storage
As shown by the first five entries in the table, both clusters
have hundreds of chunkservers, support many TBs of disk
space, and are fairly but not completely full. “Used space”
includes all chunk replicas. Virtually all files are replicated
three times. Therefore, the clusters store 18 TB and 52 TB
of file data respectively.
The two clusters have similar numbers of files, though B
has a larger proportion of dead files, namely files which were
deleted or replaced by a new version but whose storage have
not yet been reclaimed. It also has more chunks because its
files tend to be larger.
6.2.2 Metadata
The chunkservers in aggregate store tens of GBs of meta-
data, mostly the checksums for 64 KB blocks of user data.
The only other metadata kept at the chunkservers is the
chunk version number discussed in Section 4.5.
The metadata kept at the master is much smaller, only
tens of MBs, or about 100 bytes per file on average. This
agrees with our assumption that the size of the master’s
memory does not limit the system’s capacity in practice.
Most of the per-file metadata is the file names stored in a
prefix-compressed form. Other metadata includes file own-
ership and permissions, mapping from files to chunks, and
each chunk’s current version. In addition, for each chunk we
store the current replica locations and a reference count for
implementing copy-on-write.
Each individual server, both chunkservers and the master,
has only 50 to 100 MB of metadata. Therefore recovery is
fast: it takes only a few seconds to read this metadata from
disk before the server is able to answer queries. However, the
master is somewhat hobbled for a period – typically 30 to
60 seconds – until it has fetched chunk location information
from all chunkservers.
6.2.3 Read and Write Rates
Table 3 shows read and write rates for various time p e-
riods. Both clusters had been up for about one week when
these measurements were taken. (The clusters had been
restarted recently to upgrade to a new version of GFS.)
The average write rate was less than 30 MB/s since the
restart. When we took these measurements, B was in the
middle of a burst of write activity generating about 100 MB/s
of data, which produced a 300 MB/s network load because
writes are propagated to three replicas.

0 5 10 15
Number of clients N
0
50
100Read rate (MB/s)
Network limit
Aggregate read rate
(a) Reads
0 5 10 15
Number of clients N
0
20
40
60Write rate (MB/s)
Network limit
Aggregate write rate
(b) Writes
0 5 10 15
Number of clients N
0
5
10Append rate (MB/s)
Network limit
Aggregate append rate
(c) Record appends
Figure 3: Aggregate Throughputs. Top curves show theoretical limits imp osed by our network top ology. Bottom curves
show measured throughputs. They have error bars that show 95% confidence intervals, which are illegible in some cases
because of low variance in measurements.
Cluster
 A
 B
Read rate (last minute)
 583 MB/s
 380 MB/s
Read rate (last hour)
 562 MB/s
 384 MB/s
Read rate (since restart)
 589 MB/s
 49 MB/s
Wr i te r ate (l as t m i nute)
 1M B / s
 101 MB/s
Wr i te r ate (l as t hour )
 2M B / s
 117 MB/s
Wr i te r ate (s i nce r es tar t)
 25 MB/s
 13 MB/s
Master ops (last minute)
 325 Ops/s
 533 Ops/s
Master ops (last hour)
 381 Ops/s
 518 Ops/s
Master ops (since restart)
 202 Ops/s
 347 Ops/s
Table 3: Performance Metrics for Two GFS Clusters
The read rates were much higher than the write rates.
The total workload consists of more reads than writes as we
have assumed. Both clusters were in the middle of heavy
read activity. In particular, A had been sustaining a read
rate of 580 MB/s for the preceding week. Its network con-
figuration can support 750 MB/s, so it was using its re-
sources efficiently. Cluster B can support peak read rates of
1300 MB/s, but its applications were using just 380 MB/s.
6.2.4 Master Load
Table 3 also shows that the rate of op erations sent to the
master was around 200 to 500 operations per second. The
master can easily keep up with this rate, and therefore is
not a bottleneck for these workloads.
In an earlier version of GFS, the master was occasionally
ab o t t l e n e c kf o rs o m ew o r k l o a d s . I ts p e n tm o s to fi t st i m e
sequentially scanning through large directories (which con-
tained hundreds of thousands of files) looking for particular
files. We have since changed the master data structures to
allow efficient binary searches through the namespace. It
can now easily support many thousands of file accesses per
second. If necessary, we could speed it up further by placing
name lookup caches in front of the namespace data struc-
tures.
6.2.5 Recovery Time
After a chunkserver fails, some chunks will become under-
replicated and must be cloned to restore their replication
levels. The time it takes to restore all such chunks depends
on the amount of resources. In one experiment, we killed a
single chunkserver in cluster B. The chunkserver had about
15,000 chunks containing 600 GB of data. To limit the im-
pact on running applications and provide leeway for schedul-
ing decisions, our default parameters limit this cluster to
91 concurrent clonings (40% of the number of chunkservers)
where each clone operation is allowed to consume at most
6.25 MB/s (50 Mbps). All chunks were restored in 23.2 min-
utes, at an effective replication rate of 440 MB/s.
In another experiment, we killed two chunkservers each
with roughly 16,000 chunks and 660 GB of data. This double
failure reduced 266 chunks to having a single replica. These
266 chunks were cloned at a higher priority, and were all
restored to at least 2x replication within 2 minutes, thus
putting the cluster in a state where it could tolerate another
chunkserver failure without data loss.
6.3 Workload Breakdown
In this section, we present a detailed breakdown of the
workloads on two GFS clusters comparable but not identi-
cal to those in Section 6.2. Cluster X is for research and
development while cluster Y is for production data process-
ing.
6.3.1 Methodology and Caveats
These results include only client originated requests so
that they reflect the workload generated by our applications
for the file system as a whole. They do not include inter-
server requests to carry out client requests or internal back-
ground activities, such as forwarded writes or rebalancing.
Statistics on I/O operations are based on information
heuristically reconstructed from actual RPC requests logged
by GFS servers. For example, GFS client code may break a
read into multiple RPCs to increase parallelism, from which
we infer the original read. Since our access patterns are
highly stylized, we expect any error to be in the noise. Ex-
plicit logging by applications might have provided slightly
more accurate data, but it is logistically impossible to re-
compile and restart thousands of running clients to do so
and cumbersome to collect the results from as many ma-
chines.
One should be careful not to overly generalize from our
workload. Since Google completely controls both GFS and
its applications, the applications tend to be tuned for GFS,
and conversely GFS is designed for these applications. Such
mutual influence may also exist between general applications

Operation
 Read
 Wr i te
 Record Append
Cluster
 XY
 XY
 XY
0K
 0.4 2.6
 00
 00
1B..1K
 0.1 4.1
 6.6 4.9
 0.2 9.2
1K..8K
 65.2 38.5
 0.4 1.0
 18.9 15.2
8K..64K
 29.9 45.1
 17.8 43.0
 78.0 2.8
64K..128K
 0.1 0.7
 2.3 1.9
 < .1 4.3
128K..256K
 0.2 0.3
 31.6 0.4
 < .1 10.6
256K..512K
 0.1 0.1
 4.2 7.7
 < .1 31.2
512K..1M
 3.9 6.9
 35.5 28.7
 2.2 25.5
1M..inf
 0.1 1.8
 1.5 12.3
 0.7 2.2
Table 4: Op erations Breakdown by Size (%). For
reads, the size is the amount of data actually read and trans-
ferred, rather than the amount requested.
and file systems, but the effect is likely more pronounced in
our case.
6.3.2 Chunkserver Workload
Table 4 shows the distribution of op erations by size. Read
sizes exhibit a bimodal distribution. The small reads (un-
der 64 KB) come from seek-intensive clients that look up
small pieces of data within huge files. The large reads (over
512 KB) come from long sequential reads through entire
files.
As i g n i fi c a n tn u m b e ro fr e a d sr e t u r nn od a t aa ta l li nc l u s -
ter Y. Our applications, especially those in the production
systems, often use files as producer-consumer queues. Pro-
ducers append concurrently to a file while a consumer reads
the end of file. Occasionally, no data is returned when the
consumer outpaces the producers. Cluster X shows this less
often because it is usually used for short-lived data analysis
tasks rather than long-lived distributed applications.
Write sizes also exhibit a bimo dal distribution. The large
writes (over 256 KB) typically result from significant buffer-
ing within the writers. Writers that buffer less data, check-
point or synchronize more often, or simply generate less data
account for the smaller writes (under 64 KB).
As for record appends, cluster Y sees a much higher per-
centage of large record appends than cluster X does because
our production systems, which use cluster Y, are more ag-
gressively tuned for GFS.
Table 5 shows the total amount of data transferred in op-
erations of various sizes. For all kinds of operations, the
larger operations (over 256 KB) generally account for most
of the bytes transferred. Small reads (under 64 KB) do
transfer a small but significant portion of the read data be-
cause of the random seek workload.
6.3.3 Appends versus Writes
Record appends are heavily used especially in our pro-
duction systems. For cluster X, the ratio of writes to record
appends is 108:1 by bytes transferred and 8:1 by operation
counts. For cluster Y, used by the production systems, the
ratios are 3.7:1 and 2.5:1 respectively. Moreover, these ra-
tios suggest that for both clusters record appends tend to
be larger than writes. F or cluster X, however, the overall
usage of record append during the measured period is fairly
low and so the results are likely skewed by one or two appli-
cations with particular buffer size choices.
As expected, our data mutation workload is dominated
by appending rather than overwriting. We measured the
amount of data overwritten on primary replicas. This ap-
Operation
 Read
 Wr i te
 Record Append
Cluster
 XY
 XY
 XY
1B..1K
 < .1 < .1
 < .1 < .1
 < .1 < .1
1K..8K
 13.8 3.9
 < .1 < .1
 < .1 0.1
8K..64K
 11.4 9.3
 2.4 5.9
 2.3 0.3
64K..128K
 0.3 0.7
 0.3 0.3
 22.7 1.2
128K..256K
 0.8 0.6
 16.5 0.2
 < .1 5.8
256K..512K
 1.4 0.3
 3.4 7.7
 < .1 38.4
512K..1M
 65.9 55.1
 74.1 58.0
 .1 46.8
1M..inf
 6.4 30.1
 3.3 28.0
 53.9 7.4
Table 5: Bytes Transferred Breakdown by Op era-
tion Size (%). For reads, the size is the amount of data
actually read and transferred, rather than the amount re-
quested. The two may differ if the read attempts to read
beyond end of file, which by design is not uncommon in our
workloads.
Cluster
 XY
Open
 26.1 16.3
Delete
 0.7 1.5
FindLocation
 64.3 65.8
FindLeaseHolder
 7.8 13.4
FindMatchingFiles
 0.6 2.2
All other combined
 0.5 0.8
Table 6: Master Requests Breakdown by Typ e (%)
proximates the case where a client deliberately overwrites
previous written data rather than appends new data. For
cluster X, overwriting accounts for under 0.0001% of bytes
mutated and under 0.0003% of mutation operations. For
cluster Y, the ratios are both 0.05%. Although this is minute,
it is still higher than we expected. It turns out that most
of these overwrites came from client retries due to errors or
timeouts. They are not part of the workload per se but a
consequence of the retry mechanism.
6.3.4 Master Workload
Table 6 shows the breakdown by typ e of requests to the
master. Most requests ask for chunk locations ( FindLo-
cation)f o rr e a d sa n dl e a s eh o l d e ri n f o r m a t i o n(FindLease-
Locker)f o rd a t am u t a t i o n s .
Clusters X and Y see significantly different numbers of
Delete requests because cluster Y stores production data
sets that are regularly regenerated and replaced with newer
versions. Some of this difference is further hidden in the
difference in Open requests because an old version of a file
may be implicitly deleted by being opened for write from
scratch (mode “w” in Unix open terminology).
FindMatchingFiles is a pattern matching request that sup-
ports “ls” and similar file system operations. Unlike other
requests for the master, it may process a large part of the
namespace and so may be expensive. Cluster Y sees it much
more often because automated data processing tasks tend to
examine parts of the file system to understand global appli-
cation state. In contrast, cluster X’s applications are under
more explicit user control and usually know the names of all
needed files in advance.
7. EXPERIENCES
In the process of building and deploying GFS, we have
experienced a variety of issues, some operational and some
technical.

Initially, GFS was conceived as the backend file system
for our production systems. Over time, the usage evolved
to include research and development tasks. It started with
little support for things like permissions and quotas but now
includes rudimentary forms of these. While production sys-
tems are well disciplined and controlled, users sometimes
are not. More infrastructure is required to keep users from
interfering with one another.
Some of our biggest problems were disk and Linux related.
Many of our disks claimed to the Linux driver that they
supported a range of IDE protocol versions but in fact re-
sponded reliably only to the more recent ones. Since the pro-
tocol versions are very similar, these drives mostly worked,
but occasionally the mismatches would cause the drive and
the kernel to disagree about the drive’s state. This would
corrupt data silently due to problems in the kernel. This
problem motivated our use of checksums to detect data cor-
ruption, while concurrently we modified the kernel to handle
these protocol mismatches.
Earlier we had some problems with Linux 2.2 kernels due
to the cost of fsync().I t s c o s t i s p r o p o r t i o n a l t o t h e s i z e
of the file rather than the size of the modified portion. This
was a problem for our large operation logs especially before
we implemented checkpointing. We worked around this for
at i m eb yu s i n gs y n c h r o n o u sw r i t e sa n de v e n t u a l l ym i g r a t e d
to Linux 2.4.
Another Linux problem was a single reader-writer lock
which any thread in an address space must hold when it
pages in from disk (reader lock) or modifies the address
space in an mmap() call (writer lock). We saw transient
timeouts in our system under light load and looked hard for
resource bottlenecks or sporadic hardware failures. Even-
tually, we found that this single lock blocked the primary
network thread from mapping new data into memory while
the disk threads were paging in previously mapped data.
Since we are mainly limited by the network interface rather
than by memory copy bandwidth, we worked around this by
replacing mmap() with pread() at the cost of an extra copy.
Despite occasional problems, the availability of Linux code
has helped us time and again to explore and understand
system behavior. When appropriate, we improve the kernel
and share the changes with the open source community.
8. RELATED WORK
Like other large distributed file systems such as AFS [5],
GFS provides a location independent namespace which en-
ables data to be moved transparently for load balance or
fault tolerance. Unlike AFS, GFS spreads a file’s data across
storage servers in a way more akin to xFS [1] and Swift [3] in
order to deliver aggregate performance and increased fault
tolerance.
As disks are relatively cheap and replication is simpler
than more sophisticated RAID [9] approaches, GFS cur-
rently uses only replication for redundancy and so consumes
more raw storage than xFS or Swift.
In contrast to systems like AFS, xFS, Frangipani [12], and
Intermezzo [6], GFS does not provide any caching below the
file system interface. Our target workloads have little reuse
within a single application run because they either stream
through a large data set or randomly seek within it and read
small amounts of data each time.
Some distributed file systems like Frangipani, xFS, Min-
nesota’s GFS[11] and GPFS [10] remove the centralized server
and rely on distributed algorithms for consistency and man-
agement. We opt for the centralized approach in order to
simplify the design, increase its reliability, and gain flexibil-
ity. In particular, a centralized master makes it much easier
to implement sophisticated chunk placement and replication
policies since the master already has most of the relevant
information and controls how it changes. We address fault
tolerance by keeping the master state small and fully repli-
cated on other machines. Scalability and high availability
(for reads) are currently provided by our shadow master
mechanism. Updates to the master state are made persis-
tent by appending to a write-ahead log. Therefore we could
adapt a primary-copy scheme like the one in Harp [7] to pro-
vide high availability with stronger consistency guarantees
than our current scheme.
We are addressing a problem similar to Lustre [8] in terms
of delivering aggregate performance to a large number of
clients. However, we have simplified the problem signifi-
cantly by focusing on the needs of our applications rather
than building a POSIX-compliant file system. Additionally,
GFS assumes large number of unreliable components and so
fault tolerance is central to our design.
GFS most closely resembles the NASD architecture [4].
While the NASD architecture is based on network-attached
disk drives, GFS uses commodity machines as chunkservers,
as done in the NASD prototype. Unlike the NASD work,
our chunkservers use lazily allocated fixed-size chunks rather
than variable-length objects. Additionally, GFS implements
features such as rebalancing, replication, and recovery that
are required in a production environment.
Unlike Minnesota’s GFS and NASD, we do not seek to
alter the model of the storage device. We focus on ad-
dressing day-to-day data processing needs for complicated
distributed systems with existing commodity components.
The producer-consumer queues enabled by atomic record
appends address a similar problem as the distributed queues
in River [2]. While River uses memory-based queues dis-
tributed across machines and careful data flow control, GFS
uses a persistent file that can be appended to concurrently
by many producers. The River model supports m-to-n dis-
tributed queues but lacks the fault tolerance that comes with
persistent storage, while GFS only supports m-to-1 queues
efficiently. Multiple consumers can read the same file, but
they must coordinate to partition the incoming load.
9. CONCLUSIONS
The Google File System demonstrates the qualities es-
sential for supporting large-scale data processing workloads
on commodity hardware. While some design decisions are
specific to our unique setting, many may apply to data pro-
cessing tasks of a similar magnitude and cost consciousness.
We started by reexamining traditional file system assump-
tions in light of our current and anticipated application
workloads and technological environment. Our observations
have led to radically different points in the design space.
We treat comp onent failures as the norm rather than the
exception, optimize for huge files that are mostly appended
to (perhaps concurrently) and then read (usually sequen-
tially), and both extend and relax the standard file system
interface to improve the overall system.
Our system provides fault tolerance by constant moni-
toring, replicating crucial data, and fast and automatic re-
covery. Chunk replication allows us to tolerate chunkserver

failures. The frequency of these failures motivated a novel
online repair mechanism that regularly and transparently re-
pairs the damage and compensates for lost replicas as soon
as possible. Additionally, we use checksumming to detect
data corruption at the disk or IDE subsystem level, which
becomes all too common given the number of disks in the
system.
Our design delivers high aggregate throughput to many
concurrent readers and writers performing a variety of tasks.
We achieve this by separating file system control, which
passes through the master, from data transfer, which passes
directly between chunkservers and clients. Master involve-
ment in common operations is minimized by a large chunk
size and by chunk leases, which delegates authority to pri-
mary replicas in data mutations. This makes possible a sim-
ple, centralized master that does not become a bottleneck.
We b elieve that improvements in our networking stack will
lift the current limitation on the write throughput seen by
an individual client.
GFS has successfully met our storage needs and is widely
used within Google as the storage platform for research and
development as well as production data processing. It is an
important tool that enables us to continue to innovate and
attack problems on the scale of the entire web.
ACKNOWLEDGMENTS
We wish to thank the following p eople for their contributions
to the system or the paper. Brain Bershad (our shepherd)
and the anonymous reviewers gave us valuable comments
and suggestions. Anurag Acharya, Jeff Dean, and David des-
Jardins contributed to the early design. Fay Chang worked
on comparison of replicas across chunkservers. Guy Ed-
jlali worked on storage quota. Markus Gutschke worked
on a testing framework and security enhancements. David
Kramer worked on performance enhancements. Fay Chang,
Urs Hoelzle, Max Ibel, Sharon Perl, Rob Pike, and Debby
Wallach commented on earlier drafts of the pap er. Many of
our colleagues at Google bravely trusted their data to a new
file system and gave us useful feedback. Yoshka helped with
early testing.
REFERENCES
[1] Thomas Anderson, Michael Dahlin, Jeanna Neefe,
David Patterson, Drew Roselli, and Randolph Wang.
Serverless network file systems. In Proceedings of the
15th ACM Symposium on Operating System
Principles,p a g e s1 0 9 – 1 2 6 ,C o p p e rM o u n t a i nR e s o r t ,
Colorado, December 1995.
[2] Remzi H. Arpaci-Dusseau, Eric Anderson, Noah
Treuhaft, David E. Culler, Joseph M. Hellerstein,
David Patterson, and Kathy Yelick. Cluster I/O with
River: Making the fast case common. In Proceedings
of the Sixth Workshop on Input/Output in Parallel
and Distributed Systems (IOPADS ’99) ,p a g e s1 0 – 2 2 ,
Atlanta, Georgia, May 1999.
[3] Luis-Felipe Cabrera and Darrell D. E. Long. Swift:
Using distributed disk striping to provide high I/O
data rates. Computer Systems ,4 ( 4 ) : 4 0 5 – 4 3 6 ,1 9 9 1 .
[4] Garth A. Gibson, David F. Nagle, Khalil Amiri, Jeff
Butler, Fay W. Chang, Howard Gobioff, Charles
Hardin, Erik Riedel, David Rochberg, and Jim
Zelenka. A cost-effective, high-bandwidth storage
architecture. In Proceedings of the 8th Architectural
Support for Programming Languages and Operating
Systems,p a g e s9 2 – 1 0 3 ,S a nJ o s e ,C a l i f o r n i a ,O c t o b e r
1998.
[5] John Howard, Michael Kazar, Sherri Menees, David
Nichols, Mahadev Satyanarayanan, Robert
Sidebotham, and Michael West. Scale and
performance in a distributed file system. ACM
Transactions on Computer Systems ,6 ( 1 ) : 5 1 – 8 1 ,
February 1988.
[6] InterMezzo. http://www.inter-mezzo.org, 2003.
[7] Barbara Liskov, Sanjay Ghemawat, Robert Gruber,
Paul Johnson, Liuba Shrira, and Michael Williams.
Replication in the Harp file system. In 13th
Symposium on Operating System Principles ,p a g e s
226–238, Pacific Grove, CA, October 1991.
[8] Lustre. http://www.lustreorg, 2003.
[9] David A. Patterson, Garth A. Gibson, and Randy H.
Katz. A case for redundant arrays of inexpensive disks
(RAID). In Proceedings of the 1988 ACM SIGMOD
International Conference on Management of Data ,
pages 109–116, Chicago, Illinois, September 1988.
[10] Frank Schmuck and Roger Haskin. GPFS: A
shared-disk file system for large computing clusters. In
Proceedings of the First USENIX Conference on File
and Storage Technologies,p a g e s2 3 1 – 2 4 4 ,M o n t e r e y ,
California, January 2002.
[11] Steven R. Soltis, Thomas M. Ruwart, and Matthew T.
O’Keefe. The Gobal File System. In Proceedings of the
Fifth NASA Goddard Space Flight Center Conference
on Mass Storage Systems and Technologies ,C o l l e g e
Park, Maryland, September 1996.
[12] Chandramohan A. Thekkath, Timothy Mann, and
Edward K. Lee. Frangipani: A scalable distributed file
system. In Proceedings of the 16th ACM Symposium
on Operating System Principles ,p a g e s2 2 4 – 2 3 7 ,
Saint-Malo, France, October 1997.
论文 FAQpapers/gfs-faq.txt214 行 · 1,833 词 · 完整收录
GFS FAQ

Q: Did having a single master turn out to be a good idea?

A: That idea simplified initial deployment but was not so great in the
long run. This article (GFS: Evolution on Fast Forward,
https://queue.acm.org/detail.cfm?id=1594206) says that as the years
went by and GFS use grew, a few things went wrong. The number of files
grew enough that it wasn't reasonable to store all files' metadata in
the RAM of a single master. The number of clients grew enough that a
single master didn't have enough CPU power to serve them. The fact
that switching from a failed master to one of its secondaries required
human intervention made recovery slow. Apparently Google's replacement
for GFS, Colossus, splits the master over multiple servers, and has
more automated master failure recovery.

Q: Why is atomic record append at-least-once, rather than exactly
once?

Section 3.1, Step 7, says that if a write fails at one of the
secondaries, the client re-tries the write. That will cause the data
to be appended more than once at the non-failed replicas. A different
design could detect duplicate client requests despite arbitrary
failures (e.g. a primary failure between the original request and the
client's retry). You'll implement such a design in the labs, at
considerable expense in complexity and performance.

Q: How does an application know what sections of a chunk consist of
padding and duplicate records?

A: To detect padding, applications can put a predictable magic number
at the start of a valid record, or include a checksum that will likely
only be valid if the record is valid. The application can detect
duplicates by including unique IDs in records. Then, if it reads a
record that has the same ID as an earlier record, it knows that they
are duplicates of each other. GFS provides a library for applications
that handles these cases. This aspect of the GFS design effectively
moves complexity from GFS to applications, which is perhaps not ideal.

Q: How can clients find their data given that atomic record append
writes it at an unpredictable offset in the file?

A: Append (and GFS in general) is mostly intended for applications
that sequentially read entire files. Such applications will scan the
file looking for valid records (see the previous question), so they
don't need to know the record locations in advance. For example, the
file might contain URLs encountered by a set of concurrent web
crawlers. The file offset of any given URL doesn't matter much;
readers just want to be able to read the entire set of URLs.

Q: What's a checksum?

A: A checksum algorithm takes a sequence of bytes as input and returns
a single number that's a function of that sequence. For example, a
simple checksum might be the sum of all the bytes in the input. GFS
stores the checksum of each 64 kilobyte "block" in each chunk. When a
chunkserver writes a block of data to its disk, it first computes the
checksum of the block, and saves the checksum on disk. When a
chunkserver reads a block from its disk, it also reads the relevant
previously-saved checksum, re-computes a checksum from the data read
from disk, and checks that the two checksums match. If the data was
corrupted by the disk, the checksums won't match, and the chunkserver
will know to return an error. Separately, some GFS applications store
their own checksums, over application-defined records, inside GFS
files, to distinguish between correct records and padding. CRC32 is an
example of a checksum algorithm.

Q: The paper mentions reference counts -- what are they?

A: They are part of the implementation of copy-on-write for snapshots.
When GFS creates a snapshot, it doesn't copy the chunks, but instead
increases the reference counter of each chunk. This makes creating a
snapshot inexpensive. If a client writes a chunk and the master
notices the reference count is greater than one, the master first
makes a copy so that the client can update the copy (instead of the
chunk that is part of the snapshot). You can view this as delaying the
copy until it is absolutely necessary. The hope is that not all chunks
will be modified and one can avoid making some copies.

Q: If an application uses the standard POSIX file APIs, would it need
to be modified in order to use GFS?

A: Yes, but GFS isn't intended for existing applications. It is
designed for newly-written applications, such as MapReduce programs.

Q: How does GFS determine the location of the nearest replica?

A: The paper hints that GFS does this based on the IP addresses of the
servers storing the available replicas. In 2003, Google must have
assigned IP addresses in such a way that if two IP addresses are close
to each other in IP address space, then they are also close to each
other in machine-room network topology (perhaps plugged into the same
Ethernet switch, or into Ethernet switches that are themselves
directly connected).

Q: What's a lease?

A: For GFS, a lease is a period of time for which the master grants a
chunkserver the ability to act as the primary for a particular chunk.
The master guarantees not to assign a different primary for the
duration of the lease, and the primary agrees to stop acting as
primary before the lease expires (unless the primary first asks the
master to extend the lease). Leases are a way to avoid having the
primary have to repeatedly ask the master if it is still primary -- it
knows it can act as primary for the next minute (or whatever the lease
interval is) without talking to the master again.

Q: Suppose S1 is the primary for a chunk, and the network between the
master and S1 fails. The master will notice and designate some other
server as primary, say S2. Since S1 didn't actually fail, are there
now two primaries for the same chunk?

A: That would be a disaster, since both primaries might apply
different updates to the same chunk. Luckily GFS's lease mechanism
prevents this scenario. The master granted S1 a 60-second lease to be
primary. S1 knows to stop being primary before its lease expires. The
master won't grant a lease to S2 until after the lease to S1 expires.
So S2 won't start acting as primary until after S1 stops.

Q: 64 megabytes sounds awkwardly large for the chunk size!

A: The 64 MB chunk size is the unit of book-keeping in the master, and
the granularity at which files are sharded over chunkservers. Clients
can issue smaller reads and writes -- they are not forced to deal
in whole 64 MB chunks. The point of using such a big chunk size is to
reduce the size of the meta-data tables in the master, and to avoid
limiting clients that want to do huge transfers to reduce overhead. On
the other hand, files less than 64 MB in size do not get much
parallelism.

Q: Does Google still use GFS?

A: GFS has been replaced by something called
Colossus, with the same overall goals, but improvements in master
performance and fault-tolerance. In addition, many applications within
Google have switched to more database-like storage systems such as
BigTable and Spanner. However, much of the GFS design lives on in
HDFS, the storage system for the Hadoop open-source MapReduce.

https://cloud.google.com/blog/products/storage-data-transfer/a-peek-behind-colossus-googles-file-system

Q: How acceptable is it that GFS trades correctness for performance
and simplicity?

A: This a recurring theme in distributed systems. Strong consistency
usually requires protocols that are complex and require communication
and waiting for replies (as we will see in the next few lectures). By
exploiting ways that specific application classes can tolerate relaxed
consistency, one can design systems that have good performance and
sufficient consistency. For example, GFS optimizes for MapReduce
applications, which need high read performance for large files and are
OK with having holes in files, records showing up several times, and
inconsistent reads. On the other hand, GFS would not be good for
storing account balances at a bank.

Q: What if the master fails?

A: There are replica masters with a full copy of the master state; the
paper's design requires some outside entity (a human?) to decide to
switch to one of the replicas after a master failure (Section 5.1.3).
We will see later how to build replicated services that automatically
switch to a backup server if the main server fails, and you'll build
such a thing in Lab 2.

Q: Why 3 replicas?

A: Perhaps this was the line of reasoning: two replicas are not enough
because, after one fails, there may not be enough time to re-replicate
before the remaining replica fails; three makes that scenario much
less likely. With 1000s of disks, low-probabilty events like multiple
replicas failing in short order occur uncomfortably often. Here is a
study of disk reliability from that era:
https://research.google.com/archive/disk_failures.pdf. You need to
factor in the time it takes to make new copies of all the chunks that
were stored on a failed disk; and perhaps also the frequency of power,
server, network, and software failures. The cost of disks (and
associated power, air conditioning, and rent), and the value of the
data being protected, are also relevant.

Q: What is internal fragmentation? Why does lazy allocation help?

A: Internal fragmentation is the space wasted when a system uses an
allocation unit larger than needed for the requested allocation. If
GFS allocated disk space in 64MB units, then a one-byte file would
waste almost 64MB of disk. GFS avoids this problem by allocating disk
space lazily. Every chunk is a Linux file, and Linux file systems use
block sizes of a few tens of kilobytes; so when an application creates
a one-byte GFS file, the file's chunk consumes only one Linux disk
block, not 64 MB.

Q: What benefit does GFS obtain from the weakness of its consistency?

A: It's easier to think about the additional work GFS would have to do
to achieve stronger consistency.

The primary should not let secondaries apply a write unless all the
secondaries will be able to do it. This likely requires two rounds of
communication -- one to ask all secondaries if they are alive and are
able to promise to do the write if asked, and (if all answer yes) a
second round to tell the secondaries to commit the write.

If the primary dies, some secondaries may have missed the last few
update messages the primary sent. This will cause the remaining secondaries
to have slightly differing copies of the data. Before resuming
operation, a new primary should ensure that all the secondaries have
identical copies.

Since clients re-send requests if they suspect something has gone
wrong, primaries would need to filter out operations that have already
been executed.

Clients cache chunk locations, and may send reads to a chunkserver
that holds a stale version of a chunk. GFS would need a way to
guarantee that this cannot succeed.