第 3 章 分布式系统的同步

download 第 3 章  分布式系统的同步

If you can't read please download the document

description

第 3 章 分布式系统的同步. 中国科技大学软件学院 丁箐. 主要内容. 3.1 时钟同步 3.2 互斥 3.3 选举算法 3.4 原子性事务 3.5 分布式系统中的死锁. 主要内容. 3.1 时 钟 同步 3.2 互斥 3.3 选举算法 3.4 原子性事务 3.5 分布式系统中的死锁. 3.1 时钟同步. 分布式算法的特点 相关 信息散布 在多个场地上 每个进程只能基于 本地信息 做决定 应避免因 单点故障 造成整个系统的失败 不存在公共时钟或精确的 全局时间. 时钟同步问题. output.o : - PowerPoint PPT Presentation

Transcript of 第 3 章 分布式系统的同步

  • 3

  • 3.1 3.2 3.3 3.4 3.5

  • 3.1 3.2 3.3 3.4 3.5

  • 3.1

  • makefile

    output.o cc C output.c

    Connect

    Process

    2144

    2145

    2146

    2147

    2142

    2143

    2144

    2145

    output.o

    output.c

  • +clock skew: ababambmabab, bc,acconcurrent

  • LamportaC(a if ab;C(a)
  • Lamport

    Process

    60

    54

    48

    42

    36

    30

    24

    18

    12

    6

    0

    80

    72

    64

    56

    48

    40

    32

    24

    16

    8

    0

    100

    90

    80

    70

    60

    50

    40

    30

    20

    10

    0

    A

    B

    C

    D

    (a)

    76

    70

    48

    42

    36

    30

    24

    18

    12

    6

    0

    85

    77

    69

    61

    48

    40

    32

    24

    16

    8

    0

    100

    90

    80

    70

    60

    50

    40

    30

    20

    10

    0

    A

    B

    C

    D

    (b)

    0

    1

    2

    0

    1

    2

  • 12 solar-day/86400

  • 9192631770=1TAIUTCTAIWWVGEOS1020

  • Cp(t), t UTC dC/dt =1 dC/dt 1 dC/dt < 1

    Process

    ,C

    UTCt

    dC/dt1

  • Christians -- WWVUTC/2 ,10010

    911

  • Berkeley

    Process

    State

    3:00

    3:00

    3:00

    3:00

    3:25

    2:50

    3:00

    0

    -10

    +25

    3:25

    2:50

    3:05

    +5

    +15

    -20

    3:05

    3:05

    (a)

    (b)

    (c)

  • iT0+iR T0+(i+1)R S

  • OSF DCEUTC

  • IDtstimestampTCtmts(m)
  • lease

  • 3.1 3.2 3.3 3.4 3.5

  • 3.2 Critical Section

  • 3--

    CCC

  • Win Thread CreateMutex()WaitForSingleObject()ReleaseMutex()

    InitializeCriticalSection()EnterCriticalSection()LeaveCriticalSection()

  • Ricart-Agrawala1. PR 2. PPRRPOKPRPPRPPOK;P3. POKR4. PROK

  • 01202020022

  • nn2n-1)

  • 322n-12n-110n-1

  • 3.1 3.2 3.3 3.4 3.5

  • 3.3

  • Bully

    PEPQ,PQ456564656

  • PCEEPPC52

  • 3.1 3.2 3.3 3.4 3.5

  • 3.4 Atomic 1

    2

  • Stable Storage

  • 1BEGIN_TRA NSACTION2END_TRANSACTION3ABORT_TRANSACTION4READ5WRITE

  • BEGIN TRANSACTION reserve WPJFK reserve JFKNairobi reserve NairobiMalindi END TRANSACTION BEGIN TRANSACTION

    reserve WPJFK reserve JFKNairobi NairobiMalindi full

    ABORT TRASACTION JFKNairobi

  • AtomicConsistentIsolatedSerializable:Durable

  • Isolated

    Process

    BEGIN_TRANSACTIONx = 0; x = x+1;END_TRANSACTION

    BEGIN_TRANSACTIONx = 0; x = x+2;END_TRANSACTION

    BEGIN_TRANSACTIONx = 0; x = x+3;END_TRANSACTION

    (a)

    (b)

    (c)

    1

    2

    3

    x=0; x=x+1; x=0; x=x+2; x=0; x=x+3;

    x=0; x=0; x=x+1; x=x+2; x=0; x=x+3;

    x=0; x=0; x=x+1; x=0; x=x+2; x=x+3;

    (d)

  • TWTW03

  • WALin-place

  • Rollback:undo,

  • (a) (b)-(d)

    Process

    x=0;y=0;BEGIN_TRANSACTION x=x+1; y=y+2; x=y*y;END_TRANSACTION

    (a)

    x = 0/1

    x = 0/1

    y = 0/2

    x = 1/4

    x = 0/1

    y = 0/2

    (b)

    (c)

    (d)

  • two-phase commit protocol

  • (Concurrency Control)serializable(R)(W)

    RWRW

  • (2PL) 2PL2PCcascaded abort)WFG timeout)

  • (Optimistic)

  • (Timestamp)T T;

  • T()
  • 2PL

  • 3.1 3.2 3.3 3.4 3.5

  • 3.5 [Dijkstra,1965]P, free

  • -PR:(1)PR; (2) R P;/

  • BR,TT

    (a)0 (b)1(c)(d)

    Process

    Process name

    A

    S

    R

    B

    0

    (a)

    C

    T

    S

    1

    (b)

    C

    S

    A

    R

    (c)

    T

    B

    C

    S

    (d)

    T

    A

    R

    B

  • ChandyMisraHaasPidPid Pid e.g. 0,2,3,0,4,6,0,5,7 ,0,8,0

  • DWDL90%// p1; L(p1)p1 1) if ( waitQueue = p2->p1->p0 ) then if ( L(p1)p'1->p0 ) then if ( L(p1)
  • -(wait-die)0t0, 1t1t0
  • -wound-wait)0t0,1t1t0