目录
正在加载目录…
正在阅读专栏 分布式共识系统专栏 第 49 篇 · 共 59 篇 · 83%

论文:Distributed Snapshots: Determining Global States of Distributed Systems

发布于 2026-09-21 10:09 · 最后编辑于 2026-09-21 18:15 · 版本 v2 · 字数 24,943 · 预计阅读 50 分钟 👁 21 次阅读

本篇整理 K. Mani Chandy 与 Leslie Lamport 的《Distributed Snapshots: Determining Global States of Distributed Systems》。每一页保留 Microsoft Research / ACM 官方 PDF 的原始页面图;页面图保留原文排版、Figure、state-transition diagram、公式、伪代码、脚注、版权声明和 References,下面严格按 PDF 页序给出中文译文。global state、channel state、marker、stable property、consistent cut、snapshot 等术语按语境保留 English 或中英并列。

论文:Distributed Snapshots: Determining Global States of Distributed Systems

相关文章:论文:Time, Clocks, and the Ordering of Events in a Distributed System · 6.5840:Lecture 04 Fault-Tolerant Agreement and Paxos · 6.5840:Lecture 06 RSM and Raft 1

TL;DR

  • 问题:在没有 shared clock、shared memory、也不暂停 underlying computation 的情况下,记录 distributed system 的一个有意义的 global state。
  • 模型:processes 通过可靠、FIFO、finite-delay 的 directed channels 通信;global state 由所有 process states 与 channel states 组成。
  • 核心算法:process 记录自己的 state,然后沿 outgoing channels 发送 marker;第一次收到 marker 的 process 记录自己的 state,并把该 channel 记录为空;已经记录 state 的 process 则把 marker 之前收到的 messages 记为 channel state。
  • 正确性:marker 诱导出的 recorded global state 不一定曾经作为实际瞬间出现,但它位于某个 computation 的可达状态序列中;因此可以用于检测 stable property。
  • 用途:termination detection、deadlock detection、token disappearance、checkpoint/restart,以及任何可以表达为 stable property 的全局判断。

名词解释

名词含义本文译法
global state所有 process states 与 channel states 的集合global state;全局状态
channel state已发送但尚未被接收的 messages sequencechannel state;通道状态
stable property一旦为 true,之后所有 reachable global states 中仍为 true 的 propertystable property;稳定性质
snapshot记录各 process 与各 channel 的 global statesnapshot;快照
marker不改变 underlying computation、用于划定 channel recording 边界的特殊 messagemarker;标记消息
consistent global state能够在某个合法 computation 中出现的 process/channel states 组合consistent global state;一致全局状态
prerecording eventprocess 记录自己 state 之后发生的 eventprerecording event
postrecording eventprocess 记录自己 state 之前发生的 eventpostrecording event
y(S)在 global state S 上计算 stable property 的 Boolean predicateproperty predicate

目录

章节内容
版本与来源论文出版信息、官方 PDF 与固定边界
原文页面与逐页翻译13 个 PDF 页面按原页保留并翻译
机制索引marker algorithm、consistent state 与 stable-property detection
本篇验收页数、图片、算法、定理与 References 覆盖范围

版本与来源

  • 论文标题:Distributed Snapshots: Determining Global States of Distributed Systems。
  • 作者与机构:K. Mani Chandy,University of Texas at Austin;Leslie Lamport,Stanford Research Institute。
  • 发表信息:ACM Transactions on Computer Systems,Vol. 3,No. 1,February 1985,pp. 63–75。
  • 官方来源:Microsoft Research publication page;Microsoft Research / ACM PDF。
  • 本地固定文件:source/distributed-snapshots.pdf。
  • PDF 固定信息:13 页;SHA-256:6d1a44f209fe073b34e7fc9c6d5a30871846bdc182e292184435224cf333bedf。
  • 附件处理:每页按原始 page rectangle 以 2× 渲染为 PNG,存放于 assets/48 Distributed Snapshots/,正文按原图比例嵌入。Figure 1–8、state-transition diagrams、global-state diagrams 和伪代码均由原始页面图保留。
  • 翻译边界:覆盖 Abstract、Introduction、stable property、system model、Examples 2.1/2.2、global-state-recording algorithm、termination、recorded global state properties、Theorem 1、proof、stability detection、Acknowledgments 和 11 条 References。

原文页面与逐页翻译

第 1 页:Abstract、Introduction 开始与系统问题

distributed snapshots p01

Distributed Snapshots: Determining Global States of Distributed Systems

作者:K. Mani Chandy,University of Texas at Austin;Leslie Lamport,Stanford Research Institute。

Abstract

本文给出一种 algorithm,使 distributed system 中的 process 能够在 computation 进行期间确定 system 的 global state。

distributed systems 中的许多问题都可以表述为 detecting global states 的问题。例如,global state detection algorithm 有助于解决一大类问题:stable property detection。stable property 是会持续存在的 property:一旦 stable property 变为 true,此后它就一直保持 true。stable property 的例子包括:“computation 已经终止”“system 处于 deadlock 中”以及“token ring 中所有 tokens 都消失了”。stable property detection problem,就是设计 algorithm 来检测给定的 stable property。

global state detection 也可以用于 checkpointing。

分类与主题词:C.2.4「Computer-Communication Networks:Distributed Systems——distributed applications、distributed databases、network operating systems」;D.4.1「Operating Systems:Process Management——concurrency、deadlocks、multiprocessing/multiprogramming、mutual exclusion、scheduling、synchronization」;D.4.5「Operating Systems:Reliability——backup procedures、checkpoint/restart、fault-tolerance、verification」。

General Terms:Algorithms。
Additional Key Words and Phrases:Global States、Distributed deadlock detection、distributed systems、message communication systems。

1. INTRODUCTION

本文给出一些 algorithms,使 distributed system 中的 process 能够在 computation 期间确定 system 的 global state。

distributed system 中的 processes 通过发送和接收 messages 进行通信。一个 process 可以记录自己的 state,以及它发送和接收的 messages;除此之外,它什么也记录不了。为了确定整个 system 的 state,process p 必须寻求其他 processes 的合作:其他 processes 记录自己的 local states,并把记录的 local states 发送给 p。

版权与使用声明(原文页内声明的译文):只要 copies 不用于 direct commercial advantage,并且 copies 上出现 ACM copyright notice、publication title 及其 date,同时注明 copying 是经 ACM 许可进行的,就允许免费复制本材料的全部或部分。其他复制方式或 republication,需要支付 fee 和/或取得 specific permission。

本研究部分得到 Air Force Office of Scientific Research Grant AFOSR 81-0205 以及 National Science Foundation Grant MCS 81-04459 支持。

作者地址:K. M. Chandy,Department of Computer Sciences,University of Texas at Austin,Austin, TX 78712;L. Lamport,Stanford Research Institute,Menlo Park, CA 94025。

第 2 页:Global-state detection、stable property 与 phase

distributed snapshots p02

除非拥有 shared clock,否则所有 processes 不可能在精确相同的 instant 记录 local states。我们的任务是设计 algorithms,使 processes 记录自己的 states 和 communication channels 的 states,并且记录下来的 process states 与 channel states 的集合构成一个 global system state。

global-state-detection algorithm 必须叠加在 underlying computation 之上:它必须与 underlying computation concurrent 地运行,但不能改变 underlying computation。

state-detection algorithm 扮演一组 photographers 的角色:他们观察一个 panoramic、dynamic scene,例如充满迁徙 birds 的 sky;这个 scene 太大,无法用一张照片捕获。photographers 必须拍摄多张 snapshots,再把它们拼成整体场景的图像。这些 snapshots 不能因为 synchronization problem 而在精确相同的 instant 拍摄。此外,photographers 不应打扰被拍摄的过程:例如,他们不能让天空中所有 birds 在拍照时保持 motionless。然而,拼出的 composite picture 必须是 meaningful 的。我们面对的问题,就是定义 “meaningful”,然后确定应当怎样拍照。

现在描述一类可以用 global-state-detection algorithm 解决的重要问题。令 y 是定义在 distributed system D 的 global states 上的 predicate function;也就是说,对于 global state S,y(S) 为 true 或 false。

如果对于从 D 的 global state S 可达的所有 global states S′,y(S) 都蕴含 y(S′),那么称 predicate y 是 D 的 stable property。换句话说,如果 y 是 stable property,并且在 D 的一次 computation 中某个 point 上 y 为 true,那么在该 computation 的所有后续 points 上 y 都为 true。

stable property 的例子是:“computation 已终止”“system deadlocked”“token ring 中所有 tokens 都消失”。

若干 distributed-system problems 都可以表述为一个 general problem:设计 algorithm,让 distributed system 中的 process 确定 system 的 stable property y 是否成立。deadlock detection 和 termination detection 都是 stable-property detection problem 的 special cases。后文会给出 algorithm 的细节;基本思路是先确定 system 的 global state S,再计算 y(S),判断 stable property 是否成立。

已经有一些通过确定 distributed system global states 来解决 deadlock 和 termination problems 的 algorithms。Gligor 和 Shattuck 指出,许多已发表的 algorithms 是 incorrect 或 impractical 的。其原因可能是:local process states、global system states 与 distributed computation 中 points 之间的关系没有被充分理解。本文的贡献之一,就是定义这些关系。

许多 distributed algorithms 被组织成一系列 phases。每个 phase 由一个 transient part 和一个 stable part 组成:transient part 中完成有用工作,stable part 中 system endlessly、uselessly 地循环。stable behavior 的出现表示 phase 已经结束。一个 phase 类似 sequential program 中的一系列 iterations:反复执行,直到连续两次 iterations 不再产生变化,也就是达到 stability。必须检测 stability,才能终止一个 phase 并启动下一个 phase。

第 3 页:System model 开始

distributed snapshots p03

computational phase 的 termination 不等同于 computation 的 termination。当 computation 终止时,所有 activities 都停止:不再发送 messages,process states 也不再变化。stable behavior 期间仍可能存在 activity,用来表明 computational phase 的结束:messages 可能被发送和接收,processes 可能改变 states,但这些 activity 除了 signal phase end 之外没有其他用途。

本文关注 stable system properties 的 detection;activity 的 cessation 只是 stable property 的一个例子。

严格说,“system deadlocked” 这样的 properties 并不一定 stable,因为 deadlock 可能被 “broken”,computation 可能重新启动。不过,为了让 exposition 简单,我们把整体问题划分为两个问题:

  1. 检测一个 phase 的 termination,并通知所有 processes 该 phase 已结束;
  2. 启动一个新的 phase。

下面这个 property 是 stable 的:“第 k 个 computational phase 已经终止”,其中 k = 1, 2, …。因此,本文方法可用于检测给定 k 的第 k 个 phase 的 termination。

本文只讨论 detecting stable properties。没有讨论启动下一个 computation phase,因为这个问题的 solution 会因 application 而显著不同:database deadlock detection 与 diffusing computation termination detection 的 solution 就不同。

我们必须依据某个 system model 来描述 algorithms。所选 model 本身并不重要;也可以使用其他 models 来组织讨论。下面只非正式地描述 model,并且只描述使 algorithms 清楚所需的细节。

2. MODEL OF A DISTRIBUTED SYSTEM

distributed system 由有限集合的 processes 和有限集合的 channels 组成。它用一个 labeled、directed graph 描述:vertices 表示 processes,edges 表示 channels。Figure 1 是一个例子。

channels 假设具有 infinite buffers、没有 errors,并按发送顺序 delivery messages。(作 infinite-buffer 假设只是为了便于 exposition;如果能够证明没有 process 会尝试把 message 加入 full buffer,那么也可以假设 bounded buffers。)message 在 channel 中经历的 delay 可以 arbitrary,但必须 finite。

沿 channel 接收的 messages sequence,是沿该 channel 发送的 messages sequence 的一个 initial subsequence。channel 的 state,就是沿 channel 已发送、但尚未沿该 channel 接收的 messages sequence。

一个 process 由一组 states、该集合中的一个 initial state,以及一组 events 定义。process p 中的 event e 是一个 atomic action,它可以改变 p 自身的 state,以及与 p incident 的至多一个 channel c 的 state:如果 c 从 p directed away,c 的 state 可以被沿 c 发送 message 改变;如果 c directed towards p,则可以被沿 c 接收 message 改变。

event e 用下面五元组定义:

  1. event 发生的 process p;
  2. event 发生前 process p 的 state s;
  3. event 发生后 process p 的 state s′;
  4. state 被改变的 channel c(如果有);
  5. 沿 c 发送或接收的 message M(如果有)。

如果 event 的发生没有改变任何 channel 的 state,那么 M 和 c 都使用特殊符号 null。

第 4 页:Global state、computation 与 Example 2.1 开始

distributed snapshots p04

distributed system 的 global state 是各 component process states 和 channel states 的集合。initial global state 中,每个 process 都处于自己的 initial state,每个 channel 都是 empty sequence。

event 的发生可能改变 global state。令 e = (p, s, s′, M, c)。当且仅当以下条件成立时,说 event e 可以在 global state S 中发生:

  1. global state S 中 process p 的 state 是 s;
  2. 如果 c 是 directed towards p 的 channel,那么 S 中 c 的 state 是一个以 M 为 head 的 messages sequence。

定义 function next:next(S, e) 是 event e 在 global state S 发生后紧接着的 global state。只有当 event e 能在 S 中发生时,next(S, e) 才有定义;此时 next(S, e) 与 S 相同,除了:

  1. next(S, e) 中 process p 的 state 是 s′;
  2. 如果 e 是 process p 从 directed-towards channel c 接收 message,那么 next(S, e) 中 c 的 state 是从 S 的 c state 的 head 删除 M 后的 sequence;
  3. 如果 c 是 directed-away channel,那么 next(S, e) 中 c 的 state 是在 S 的 c state tail 添加 M 后的 sequence。

令 seq = (eᵢ : 0 ≤ i ≤ n) 是 distributed system 的 component processes 中的一串 events。当且仅当对 0 ≤ i ≤ n,event eᵢ 能在 global state Sᵢ 中发生,且 S₀ 是 initial global state、Sᵢ₊₁ = next(Sᵢ, eᵢ) 时,称 seq 是 system 的一个 computation。

另有一种基于 Lamport [6] 的 model,把 computations 看作 events 的 partially ordered sets,见文献 [7]。

Example 2.1

为了说明 distributed system 的定义,考虑 Figure 2 所示的简单 system:它包含两个 processes p 和 q,以及两个 channels c 和 c′。

system 中有一个在两个 processes 之间传递的 token,因此称它为 single-token conservation system。每个 process 有两个 states:s₀ 和 s₁;s₀ 表示 process 不持有 token,s₁ 表示 process 持有 token。p 的 initial state 是 s₁,q 的 initial state 是 s₀。

每个 process 有两个 events:

  1. 从 s₁ 转换到 s₀,同时发送 token;
  2. 从 s₀ 转换到 s₁,同时接收 token。

Figure 3 给出了 process 的 state-transition diagram。Figure 4 给出了 global states 和 transitions。

system computation 对应于 Figure 4 global-state-transition diagram 中从 initial global state 出发的一条 path。

system computations 的例子包括:

  1. empty sequence;
  2. (p sends token, q receives token, q sends token)。

下面这串 sequence 不是 system computation:(p sends token, q sends token)。因为当 q 处于 s₀ 时,event “q sends token” 不能发生。

为简洁起见,按照 transition 顺序,将四个 global states 分别称为:(1) in-p、(2) in-c、(3) in-q 和 (4) in-c′,表示 token 所在的位置。后文会用这个 example 来推动 algorithm 的设计。

第 5 页:Example 2.1 的 diagrams 与 computation

distributed snapshots p05

Figure 2 是 Example 2.1 和 Example 2.2 中 simple distributed system 的图。图中标出了 channel 与 process。

Figure 3 是 Example 2.1 中 process 的 state-transition diagram:process 收到 token 后进入持有 token 的 state,发送 token 后进入 token 不在本地的 state。

Figure 4 是 single-token conservation system 的 global states 和 transitions。四个 global states 分别是 token 在 p 中、token 在 channel c 中、token 在 q 中,以及 token 在 channel c′ 中。

一个 system computation 就是 global-state-transition diagram 中从 initial global state 出发的一条 path。

“empty sequence” 是一个 computation;(p sends token, q receives token, q sends token) 也是一个 computation。相反,(p sends token, q sends token) 不是 computation,因为 q sends token 发生时,q 仍处于没有 token 的 s₀。

第 6 页:Example 2.2 与 nondeterministic computations

distributed snapshots p06

Example 2.2

这个 example 说明 nondeterministic computations。nondeterminism 在 snapshot algorithm 中扮演有趣的角色。

在 Example 2.1 中,每个 global state 恰好只有一个可能发生的 event。现在考虑 topology 与 Example 2.1 相同的 system(见 Figure 2),但两个 processes 的定义分别由 Figures 5 和 6 的 state-transition diagrams 给出。

Figure 7 展示了一次 computation。注意,一个 global state 可能允许多个 transitions。例如,在 initial global state 中,events “p sends M” 和 “q sends M′” 都可以发生;这两个 events 之后的 states 不同。

Figure 5 描述 process p 的 transitions:它从 initial state 出发,发送 M 后进入另一个 state,并在随后收到 M′ 时发生下一次转换。Figure 6 描述 process q 的相应 transitions。Figure 7 展示了一个可能的执行顺序:先由 p 发送 M,再由 q 发送 M′,然后 p 接收 M′。

Figure 5–7:Example 2.2 的 process state-transition diagrams 与一条 computation。原始 diagrams 保留在本页图片中。

3. THE ALGORITHM

3.1 Motivation for the Steps of the Algorithm

global-state recording algorithm 的工作方式如下:每个 process 记录自己的 state;对于每个 channel,由该 channel 两端的两个 processes 合作记录 channel state。

因为没有 global clock,无法保证所有 processes 和 channels 的 states 在同一个 instant 被记录。不过,我们要求被记录的 process states 和 channel states 构成一个 “meaningful” global system state。

global-state recording algorithm 必须叠加在 underlying computation 之上:它必须与 underlying computation concurrent 地运行,但不能改变 underlying computation。algorithm 可以发送 messages,也可以要求 processes 执行 computations;但是,record global state 所需的 messages 和 computations 不得 interfere with underlying computation。

下面用一个 example 推导 algorithm 的 steps。先假设 channel state 可以被 instantaneously record;channel state 应如何记录,会在后文讨论。

令 c 是从 p 指向 q 的 channel。这个 example 的目的是形成直觉:channel c 的 state 应在什么 instant 记录,以及这与 process p、q 的 states 被记录的 instants 有什么关系。

Example 3.1

考虑 single-token conservation system。假设 process p 的 state 在 global state in-p 被记录,于是记录的 p state 显示 token 在 p 中。现在假设 system 转换到 in-c(因为 p 发送 token)。再假设 channel c、channel c′ 和 process q 的 states 都在 global state in-c 被记录:记录的 channel c state 显示 token 在其中,而记录的 channel c′ 和 process q states 显示它们不持有 token。

用这种方式拼出的 composite global state 会显示 system 中有两个 tokens:一个在 p 中,一个在 c 中。但在 single-token conservation system 中,从 initial global state 出发,一次 computation 不可能到达含有两个 tokens 的 global state!

不一致产生的原因是:p 的 state 在 p 沿 c 发送 message 之前被记录,而 c 的 state 在该 message 发送之后被记录。令 n 为 p 的 state 被记录之前沿 c 发送的 messages 数量,令 n′ 为 c 的 state 被记录之前沿 c 发送的 messages 数量。这个 example 暗示:当 n < n′ 时,记录的 global state 可能 inconsistent。

再考虑另一种情况。假设 c 的 state 在 global state in-p 被记录,随后 system 转换到 in-c,然后在 in-c 记录 c′、p 和 q 的 states。记录出的 global state 显示 system 中没有 token。

这个 example 暗示:如果 channel c 的 state 在 p 沿 c 发送 message 之前被记录,而 p 的 state 在发送之后被记录,也就是 n > n′,那么 recorded global state 可能 inconsistent。

由这些 examples 可以得到:通常,一个 consistent global state 要求

n = n′。 (1)

第 7 页:Marker 的动机

distributed snapshots p07

global-state recording algorithm 先让每个 process 记录自己的 state,再由每条 channel 两端的 processes 合作记录 channel state。由于没有 global clock,无法保证所有 process states 和 channel states 在同一个 instant 被记录,但要求组合出的结果构成一个 “meaningful” global system state。

algorithm 必须叠加在 underlying computation 上,与它 concurrent 地运行,却不能改变它。algorithm 可以发送 messages,也可以要求 processes 执行 computations;但这些额外 messages 和 computations 不得 interfere with underlying computation。

令 c 是从 p 到 q 的 channel。先假设 channel state 可以 instantaneously record,后文再讨论如何真正记录 channel state。

Example 3.1

考虑 single-token conservation system。假设 process p 的 state 在 global state in-p 中被记录,所以记录的 p state 显示 token 在 p 中。然后 system 转换到 in-c(因为 p 发送 token)。如果 channel c、channel c′ 和 process q 的 states 都在 in-c 中被记录,那么记录的 c state 显示 token 在 c 中,而记录的 c′ 和 q states 显示它们不持有 token。

这样拼出的 composite global state 会显示 system 中有两个 tokens:一个在 p,另一个在 c。但这个 single-token conservation system 从 initial global state 出发不可能到达含有两个 tokens 的 global state。

不一致的原因是:p 的 state 在 p 沿 c 发送 message 之前被记录,而 c 的 state 在 message 发送之后被记录。令 n 为 p 的 state 被记录之前沿 c 发送的 messages 数量,令 n′ 为 c 的 state 被记录之前沿 c 发送的 messages 数量。这个 example 暗示,当 n < n′ 时,记录出的 global state 可能 inconsistent。

再考虑另一种情况:c 的 state 在 in-p 中被记录,system 随后转到 in-c,然后在 in-c 中记录 c′、p 和 q 的 states。记录出的 global state 显示 system 中没有 token。

这说明,当 channel c 的 state 在 p 沿 c 发送 message 之前被记录,而 p 的 state 在发送之后被记录,也就是 n > n′ 时,recorded global state 也可能 inconsistent。

因此,通常要得到 consistent global state,必须有:

n = n′。 (1)

第 8 页:Marker 与 Global-State-Detection Algorithm Outline

distributed snapshots p08

令 m 为在 q 的 state 被记录之前沿 c 接收的 messages 数量,令 m′ 为在 c 的 state 被记录之前沿 c 接收的 messages 数量。类似地,consistency 要求:

m = m′。 (2)

在任何 state 中,沿 channel 接收的 messages 数量不能超过沿该 channel 发送的 messages 数量,因此:

n′ ≥ m′。 (3)

结合前面的关系,还能得到:

n ≥ m。 (4)

记录的 channel c state 必须是:sender state 被记录之前沿 channel 发送的 messages sequence,减去 receiver state 被记录之前沿 channel 接收的 messages sequence。也就是说,如果 n′ = m′,记录的 c state 是 empty sequence;如果 n′ > m′,记录的 c state 是 p 沿 c 发送的第 m′ + 1 到第 n′ 个 messages。

因此,process p 可以在沿 c 发送第 n 个 message 之后、继续沿 c 发送其他 messages 之前,发送一个特殊 message,称为 marker。marker 不影响 underlying computation。

channel c 的 state,就是 q 记录自己的 state 之后、q 沿 c 收到 marker 之前收到的 messages sequence。为了保证 equation (4),q 必须在沿 c 收到 marker 之后、收到沿 c 的其他 messages 之前记录自己的 state(如果尚未记录)。

3.2 Global-State-Detection Algorithm Outline

Marker-Sending Rule for a Process p
对于每个与 p incident、且 directed away from p 的 channel c:p 在记录自己的 state 之后、沿 c 发送更多 messages 之前,沿 c 发送一个 marker。

Marker-Receiving Rule for a Process q
当沿 channel c 收到 marker 时:

  • 如果 q 还没有记录自己的 state:
    1. q 记录自己的 state;
    2. q 将 channel c 的 state 记录为空 sequence。
  • 否则,q 将 channel c 的 state 记录为:q 记录自己 state 之后、沿 c 收到 marker 之前收到的 messages sequence。

第 9 页:Termination 与 recorded global state 的例子

distributed snapshots p09

3.3 Termination of the Algorithm

marker receiving rule 和 marker sending rule 保证:如果每条 channel 都收到 marker,那么每个 process 都会记录自己的 state 以及所有 incoming channels 的 states。

为了保证 global-state recording algorithm 在 finite time 内终止,每个 process 必须保证:

  • L1:任何 marker 都不会永远停留在 incident input channel 中;
  • L2:从 algorithm initiation 开始,process 会在 finite time 内记录自己的 state。

algorithm 可以由一个或多个 processes 启动;每个启动它的 process 都会 spontaneously record 自己的 state,而不必等待从其他 processes 收到 markers。什么原因会让 process spontaneously record state,稍后再讨论。

如果 process p 记录自己的 state,并且存在从 p 到 process q 的 channel,那么 q 会在 finite time 内记录自己的 state:p 会沿该 channel 发送 marker,而 q 会在 finite time 内收到 marker(由 L1 保证)。

因此,如果 p 记录 state,且 system graph 中存在从 p 到 q 的 path,那么 q 也会在 finite time 内记录 state;证明方式是对 path 上的 processes 做 induction:path 上的每个 process 都会在 finite time 内记录 state。

若对于每个 process q,要么 q spontaneously record state,要么存在一条从 spontaneously record state 的 process p 到 q 的 path,则 algorithm 在 finite time 内终止。

特别地,如果 graph 是 strongly connected,且至少有一个 process spontaneously record 自己的 state,那么在保证 L1 的前提下,所有 processes 都会在 finite time 内记录各自的 states。

到这里,algorithm 允许每个 process 记录自己的 state 和 incoming channels 的 states。还必须把记录的 process states 与 channel states 收集、组装成 recorded global state。本文不描述收集这些 recorded information 的 algorithms,因为这类 algorithms 已在其他文献中给出。

在 topology strongly connected 的 system 中,一个简单的 information-collection algorithm 是:每个 process 将自己记录的信息沿所有 outgoing channels 发送;第一次收到某份 information 的 process 复制它,并沿自己的所有 outgoing channels 继续传播。这样,所有 recorded information 都会在 finite time 内到达所有 processes,所有 processes 都能确定 recorded global state。

4. PROPERTIES OF THE RECORDED GLOBAL STATE

为了直观理解 algorithm 记录出的 global state 的 properties,研究 Example 2.2。假设 process p 的 state 在 Figure 7 的 global state S₀ 中被记录,因此记录的 p state 是 A。记录 state 后,p 沿 channel c 发送 marker。

现在假设 system 依次进入 global states S₁、S₂、S₃,而 marker 仍在 transit;当 system 处于 global state S₃ 时,q 收到 marker。q 收到 marker 后记录自己的 state D,并把 c 的 state 记录为空 sequence。记录完自己的 state 后,q 沿 channel c′ 发送 marker。

p 收到这个 marker 后,将 c′ 的 state 记录为只包含一个 message M′ 的 sequence。algorithm 记录的 global state S* 如 Figure 8 所示。recording algorithm 在 global state S₀ 启动,并在 global state S₃ 终止。

注意,algorithm 记录的 global state S* 与 computation 中实际出现的 global states S₀、S₁、S₂、S₃ 都不相同。如果 recorded global state 从未出现过,这个 algorithm 有什么用?下一节回答这个问题。

第 10 页:Theorem 1 的目标与 recorded state

distributed snapshots p10

令 seq = (eᵢ, 0 ≤ i) 是一次 distributed computation;令 Sᵢ 是 seq 中 event eᵢ 之前 system 紧接着所处的 global state。

假设 algorithm 在 global state Sₗ 启动,并在 global state Sᵣ 终止,其中 0 ≤ l ≤ r。换句话说,如果 l > 0,algorithm 在 eₗ₋₁ 之后、eₗ 之前启动;如果 r > 0,algorithm 在 eᵣ₋₁ 之后、eᵣ 之前终止。

Example 2.2 已经说明,recorded global state S* 可能与实际出现的任意 global state Sₖ 都不同。接下来证明:

  1. S* 可以从 Sₗ reach;
  2. Sᵣ 可以从 S* reach。

具体地,要证明存在一次 computation seq′,满足:

  1. seq′ 是 seq 的一个 permutation,因此 Sₗ、S*、Sᵣ 都作为 global states 出现在 seq′ 中;
  2. Sₗ = S*,或 Sₗ 在 seq′ 中早于 S*;
  3. Sᵣ = S*,或 S* 在 seq′ 中早于 Sᵣ。

THEOREM 1. 存在一个 computation seq′ = (eᵢ′, 0 ≤ i),使得:

  1. 对于所有 i < l 或 i ≥ r,eᵢ′ = eᵢ;
  2. 子序列 (eᵢ′, l ≤ i < r) 是原子序列 (eᵢ, l ≤ i < r) 的一个 permutation;
  3. 对于所有 i ≤ l 或 i ≥ r,Sᵢ′ = Sᵢ;
  4. 存在某个 k,l ≤ k ≤ r,使得 S* = Sₖ′。

第 11 页:Theorem 1 proof 与 permutation

distributed snapshots p11

Proof. 在 seq 中,如果 event eᵢ 位于 process p,且 p 在 seq 中位于 eᵢ 之后记录自己的 state,那么称 eᵢ 是 prerecording event。如果 event eᵢ 位于 process p,且 p 在 seq 中位于 eᵢ 之前记录自己的 state,则称 eᵢ 是 postrecording event。

i < l 的所有 events 都是 prerecording events,i > r 的所有 events 都是 postrecording events。对于某个 l < j < r,可能出现一个 postrecording event eⱼ₋₁ 在一个 prerecording event eⱼ 之前;这只能发生在两个 events 位于不同 processes 的情况下。因为,如果 eⱼ₋₁ 和 eⱼ 位于同一个 process,且 eⱼ₋₁ 是 postrecording event,那么 eⱼ 也会是 postrecording event。

我们通过 permutation seq 构造 computation seq′,使所有 prerecording events 都出现在所有 postrecording events 之前。将证明:在 seq′ 中,所有 prerecording events 之后、所有 postrecording events 之前的 global state 就是 S*。

假设 seq 中有一个 postrecording event eⱼ₋₁ 紧接着位于一个 prerecording event eⱼ 之前。下面证明,交换 eⱼ₋₁ 和 eⱼ 后得到的 sequence 仍然是一次 computation。

这两个 events 位于不同 processes。令 p 为 eⱼ₋₁ 所在的 process,令 q 为 eⱼ 所在的 process。

eⱼ₋₁ 发生时不可能发送一条 message、而该 message 在 eⱼ 被接收。原因是:

  1. 如果 eⱼ₋₁ 沿 channel c 发送 message,那么因为 eⱼ₋₁ 是 postrecording event,marker 必须在 eⱼ₋₁ 之前已经沿 c 发送;
  2. 如果 eⱼ 沿 channel c 接收 message,那么由于 channels 是 FIFO,marker 必须在 eⱼ 之前已经沿 c 被接收;
  3. 根据 marker-receiving rule,在这种情况下 eⱼ 也会是 postrecording event,矛盾。

eⱼ₋₁ 发生不会改变 process q 的 state,因为 eⱼ₋₁ 位于不同的 process p。

如果 eⱼ 是 q 沿 channel c 接收 message M 的 event,那么在 eⱼ₋₁ 发生之前,M 必须已经位于 c 的 head:因为 eⱼ₋₁ 发送的 message 不可能恰好在 eⱼ 被接收。因此,event eⱼ 可以在 global state Sⱼ₋₁ 中发生。

eⱼ 的发生不会改变 process p 的 state,所以 eⱼ₋₁ 可以在 eⱼ 之后发生。因此,sequence

text
e₀, …, eⱼ₋₂, eⱼ, eⱼ₋₁

也是一次 computation。

令 seq* 为 seq 的 permutation,只把 eⱼ 与 eⱼ₋₁ 交换。于是 seq* 也是一次 computation。令 Sᵢ* 为 seq* 中第 i 个 event 之前的 global state。由上面的论证,对于除 i = j 外的所有 i,都有 Sᵢ* = Sᵢ。

反复交换那些紧跟在 prerecording events 后面的 postrecording events,就能得到 seq′ 的 permutation,使得:

  1. 所有 prerecording events 都先于所有 postrecording events;
  2. seq′ 是一次 computation;
  3. 对于 i < l 或 i ≥ r,eᵢ′ = eᵢ;
  4. 对于 i ≤ l 或 i ≥ r,Sᵢ′ = Sᵢ。

现在证明:在 seq′ 中,所有 prerecording events 之后、所有 postrecording events 之前的 global state 是 S*。

需要证明两点:

  1. S* 中每个 process 的 state,等于该 process 执行属于它的 prerecorded events sequence 后得到的 state;
  2. S* 中每个 channel c 的 state,等于“沿 c 的 prerecorded sends 对应的 messages sequence”减去“沿 c 的 prerecorded receives 对应的 messages sequence”。

第一点是 trivial 的。下面证明第二点。令 c 是从 process p 到 process q 的 channel。S* 中记录的 channel c state,是 q 记录自己的 state 之后、q 沿 c 收到 marker 之前收到的 messages sequence。p 沿 c 发送 marker 之前发送的 messages sequence,正是沿 c 的 prerecorded sends 对应的 sequence。因此第二点成立。

第 12 页:Example 4.1 与 Stability Detection

distributed snapshots p12

Example 4.1

这个 example 说明 computation seq′ 如何从 computation seq 得到。考虑 Example 2.2。Figure 7 中 computation 的 events sequence 是:

text
e₀: p sends M and changes state to B       (postrecording event)
e₁: q sends M′ and changes state to D      (prerecording event)
e₂: p receives M′ and changes state to A    (postrecording event)

因为 postrecording event e₀ 紧接着位于 prerecording event e₁ 之前,所以交换它们,得到 permutation seq′:

text
e₀′: q sends M′ and changes state to D     (prerecording event)
e₁′: p sends M and changes state to B      (postrecording event)
e₂′: p receives M′ and changes state to A   (postrecording event)

在 seq′ 中,所有 prerecording events 都先于所有 postrecording events。读者可以自行证明,e₀′ 之后的 global state 就是 recorded global state。

5. STABILITY DETECTION

现在解决 Section 1 描述的 stability-detection problem。研究它,是因为它代表许多 practical problems,例如 distributed deadlock detection。

stability-detection algorithm 定义如下:

Input:一个 stable property y。

Output:一个 Boolean value definite,满足:

y(Sₗ) ⇒ definite,并且 definite ⇒ y(Sᵣ),

其中 Sₗ 与 Sᵣ 分别是 algorithm 被启动和终止时 system 的 global states。

algorithm 的 input 是 function y 的定义。在 algorithm 执行期间,system 中的某个 process 可以把外部定义的 function y 应用于某个 global state S,从而得到 y(S)。

称 algorithm 的 output 是 Boolean value definite,是指:

  1. 某个 specially designated process(例如 p)进入一个 special state,并从此保持在该 state,以表示 output definite = true;
  2. p 进入另一个 special state,并从此保持在该 state,以表示 output definite = false。

definite = true 意味着:当 algorithm 终止时,stable property 已经成立。但 definite = false 意味着:当 algorithm 启动时,stable property 尚未成立。

要特别强调:definite = true 为我们提供的是 algorithm termination 时 system state 的信息;而 definite = false 提供的是 algorithm initiation 时 system state 的信息。特别地,不能从 algorithm 输出 definite = false 推断 stable property 在 algorithm termination 时仍不成立。

stability-detection problem 的 solution 是:

text
begin
    record a global state S*
    definite := y(S*)
end

第 13 页:Stability Detection 正确性、Acknowledgments 与 References

distributed snapshots p13

stability-detection algorithm 的 correctness 来自以下 facts:

  1. S* 可以从 Sₗ reach;
  2. Sᵣ 可以从 S* reach(Theorem 1);
  3. 根据 stable property 的 definition,对于所有从 S reachable 的 S′,都有 y(S) ⇒ y(S′)。

因此,如果 y(Sₗ) 为 true,那么 S* 中 y 为 true,algorithm 输出 definite = true;如果 algorithm 输出 definite = false,则 y(S*) 为 false,从而 y(Sₗ) 必为 false。这个 output 语义正好满足 stability-detection problem 的要求。

ACKNOWLEDGMENTS

感谢 J. Misra 在定义 global state detection problem 方面作出的 contributions。感谢 E. W. Dijkstra 和 C. S. Scholten 的 comments,尤其是他们对 Theorem 1 proof 的 comments。当前 proof version 的 outline 是他们提出的。Dijkstra 关于该主题的 note [3] 为 stability-detection problem 提供了富有启发性的 insight。

感谢 C. A. R. Hoare、F. Schneider 和 G. Andrews 对本文提供 detailed comments。感谢 Anita Jones 和 anonymous referees 提出的 suggestions。

REFERENCES

  1. Chandy, K. M., and Misra, J. “Distributed Computation on Graphs: Shortest Path Algorithms.” Communications of the ACM 25(11), Nov. 1982, 833–837。
  2. Chandy, K. M., Misra, J., and Haas, L. “Distributed Deadlock Detection.” ACM Transactions on Computer Systems 1(2), May 1983, 144–156。
  3. Dijkstra, E. W. “The Distributed Snapshot of K. M. Chandy and L. Lamport.” Technical Report EWD 864a, University of Texas, Austin, 1984。
  4. Dijkstra, E. W., and Scholten, C. S. “Termination Detection for Diffusing Computations.” Information Processing Letters 12(1), Aug. 1980, 1–4。
  5. Gligor, V. D., and Shattuck, S. H. “Deadlock Detection in Distributed Systems.” IEEE Transactions on Software Engineering SE-6(5), Sep. 1980, 435–440。
  6. Lamport, L. “Time, Clocks, and the Ordering of Events in a Distributed System.” Communications of the ACM 21(7), Jul. 1978, 558–565。
  7. Lamport, L., and Chandy, K. M. “On Partially-Ordered Event Models of Distributed Computations.” Submitted for publication。
  8. Mahoud, S. A., and Riordan, J. S. “Software Controlled Access to Distributed Databases.” INFOR 15(1), Feb. 1977, 22–36。
  9. Menasce, D., and Muntz, R. “Locking and Deadlock Detection in Distributed Data Bases.” IEEE Transactions on Software Engineering SE-5(3), May 1979, 195–202。
  10. Misra, J., and Chandy, K. M. “Termination Detection of Diffusing Computations in Communicating Sequential Processes.” ACM Transactions on Programming Languages and Systems 4(1), Jan. 1982, 37–43。
  11. Obermarck, R. “Distributed Deadlock Detection Algorithm.” ACM Transactions on Database Systems 7(2), Jun. 1982, 187–208。

Received January 1984; revised September 1984; accepted 7 December 1984。

机制索引

机制本文位置核心含义
Global stateModel所有 process states 与 channel states 的组合
Stable propertyIntroduction一旦为 true,之后 reachable states 中一直为 true
Channel stateModel / Example 3.1已发送但尚未接收的 messages sequence
MarkerSection 3划定 channel state recording 边界的特殊 message
Marker-sending ruleSection 3.2process 记录 state 后、继续发送 computation messages 前发送 marker
Marker-receiving ruleSection 3.2第一次 marker 触发 local state recording,后续 marker 结束该 channel recording
L1 / L2Section 3.3marker 最终到达;process 在 finite time 内记录 state
Theorem 1Section 4recorded state 等价于某个 permutation computation 中实际可达的 state
Stability detectionSection 5record S* 后计算 y(S*),得到有界语义的 Boolean output

与本专栏其他内容的关系

  • 与 Time and Clocks 的关系:Time/Clocks 用 logical ordering 描述 causality;Distributed Snapshots 则不依赖 shared clock,而用 marker 构造 meaningful global state。
  • 与 checkpoint/restart 的关系:snapshot 给出 process states 与 in-flight messages 的一致组合,可作为 checkpoint 的逻辑基础;实际 durable checkpoint 还需要 storage、failure recovery 与 versioning。
  • 与 deadlock / termination detection 的关系:这些问题可以先转化为 stable property y,再由 snapshot algorithm 记录 S* 并计算 y(S*)。
  • 与 Raft snapshot 的关系:Raft snapshot 是 replicated state machine 的日志压缩与持久化 checkpoint;本文 snapshot 是 asynchronous distributed computation 的 global-state recording,两者都叫 snapshot,但 state boundary、正确性目标和 failure model 不同。

本篇验收

  • [x] Microsoft Research / ACM 官方 PDF 已固定到 source/distributed-snapshots.pdf。
  • [x] 13 个 PDF 页面均已按原始 page rectangle 渲染为 PNG,并保存到 assets/48 Distributed Snapshots/。
  • [x] 13 个页面图片均在对应译文前按原页顺序嵌入,并保留原始 page image 的宽高比例。
  • [x] Abstract、Introduction、stable property、system model、Figure 1–8、Examples 2.1/2.2/3.1/4.1、marker rules、termination、Theorem 1、proof、stability detection、Acknowledgments 和 11 条 References 均已覆盖。
  • [x] global state、channel state、marker、stable property、consistent global state、prerecording/postrecording event 等术语按本系列约定保留 English 或中英并列。
  • [x] 本地源文件 SHA-256:6d1a44f209fe073b34e7fc9c6d5a30871846bdc182e292184435224cf333bedf。

参考资料

← 返回列表
← 上一篇 论文:Time, Clocks, and the Ordering of Events in a Distributed System 下一篇 → 论文:Impossibility of Distributed Consensus with One Faulty Process

评论 (0)

暂无评论,来留下第一条吧。
登录 或 注册 后才能发表评论