数据库中数据存取、事务恢复处理、redo、undo和检查点

Data Access 数据存取

  • Physical blocks are those blocks residing on the disk
  • Buffer blocks are the blocks residing temporarily in main memory
  • Block movements between disk and main memory are initiated through the following two operations
  • input(A) transfers the physical block A to main memory
  • output(B) transfers the buffer block B to the disk

Transaction transfers data items between system buffer blocks and its private work-area using the following operations :

  • read(X) assigns the value of data item X to the local variable xi
  • write(X) assigns the value of local variable xi to data item X in the buffer block
  • both these commands may issue an input(BX) instruction before the assignment, if the block BX in which X resides is not in main memory

Log-Based Recovery

  • When transaction Ti starts, it registers itself by writing a log record
  • Before Ti executes write(X), a log record <Ti, X, V1, V2> is written, where V1 is the value of X before the write (the old value), and V2 is the value to be written to X (the new value)
  • When Ti finishes it last statement (partially committed state), the log record is written. Then the transaction enters the committed state

Concurrency Control and Recovery

Undo and Redo Operations

  • undo(Ti) – restores the value of all data items updated by Ti to their old values, going backwards from the last log record for Ti
    1. Each time a data item X is restored to its old value V a special log record <Ti , X, V> is written out
    2. When undo of a transaction is complete, a log record is written out
  • redo(Ti) – sets the value of all data items updated by Ti to the new values, going forward from the first log record for Ti
    1. No logging is done in this case

Recovering from Failure

When recovering after failure:

  • Transaction Ti needs to be undone if the log

    Contains the record ,
    But does not contain either the record or

  • Transaction Ti needs to be redone if the log

    Contains the records
    And contains the record or

Checkpoints

  • Streamline recovery procedure by periodically performing checkpointing

    1. Output all log records currently residing in main memory onto stable storage
    2. Output all modified buffer blocks to the disk
    3. Write a log record onto stable storage where L is a list of all transactions active at the time of checkpoint
    4. All updates are stopped while doing checkpointing
  • During recovery we need to consider only the most recent transaction Ti that started before the checkpoint, and transactions that started after Ti

    1. Scan backwards from end of log to find the most recent record
    2. Only transactions that are in L or started after the checkpoint need to be redone or undone
    3. Transactions that committed or aborted before the checkpoint already have all their updates output to stable storage

Redo phase:

  1. Find last record, and set undo-list to L
  2. Scan forward from above record
    1. Whenever a record <Ti, Xj, V1, V2> or <Ti, Xj, V2> is found, redo it by writing V2 to Xj
    2. Whenever a log record is found, add Ti to undo-list
    3. Whenever a log record or is found, remove Ti from undo-list

Undo phase:

  1. Scan log backwards from end
    1. Whenever a log record <Ti, Xj, V1, V2> is found where Ti is in undo-list perform same actions as for transaction rollback:
      • perform undo by writing V1 to Xj
      • write a log record <Ti , Xj, V1>
    2. Whenever a log record is found where Ti is in undo-list
      • Write a log record
      • Remove Ti from undo-list
    3. Stop when undo-list is empty, i.e., has been found for every transaction in undo-list
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值