数据库系统英文课件:ch17 Recovery System_第1页
数据库系统英文课件:ch17 Recovery System_第2页
数据库系统英文课件:ch17 Recovery System_第3页
数据库系统英文课件:ch17 Recovery System_第4页
数据库系统英文课件:ch17 Recovery System_第5页
已阅读5页,还剩39页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Chapter 17: Recovery SystemChapter 17: Recovery SystemFailure ClassificationStorage StructureRecovery and AtomicityLog-Based RecoveryShadow PagingRecovery With Concurrent TransactionsBuffer ManagementFailure with Loss of Nonvolatile StorageAdvanced Recovery TechniquesARIES Recovery AlgorithmRemote B

2、ackup SystemsFailure Classification 故障分类Transaction failure :Logical errors: transaction cannot complete due to some internal error conditionSystem errors: the database system must terminate an active transaction due to an error condition (e.g., deadlock)System crash: a power failure or other hardwa

3、re or software failure causes the system to crash.Fail-stop assumption: non-volatile 非易失性 storage contents are assumed to not be corrupted by system crashDatabase systems have numerous integrity checks to prevent corruption of disk data Disk failure: a head crash or similar disk failure destroys all

4、 or part of disk storageDestruction is assumed to be detectable: disk drives use checksums to detect failuresRecovery AlgorithmsRecovery algorithms are techniques to ensure database consistency and transaction atomicity and durability despite failuresFocus of this chapterRecovery algorithms have two

5、 partsActions taken during normal transaction processing to ensure enough information exists to recover from failuresActions taken after a failure to recover the database contents to a state that ensures atomicity, consistency and durabilityStorage Structure Volatile storage:does not survive system

6、crashesexamples: main memory, cache memoryNonvolatile storage:survives system crashesexamples: disk, tape, flash memory, non-volatile (battery backed up) RAM Stable storage: 稳定存储器a mythical form of storage that survives all failuresapproximated by maintaining multiple copies on distinct nonvolatile

7、mediaStable-Storage ImplementationMaintain multiple copies of each block on separate diskscopies can be at remote sites to protect against disasters such as fire or flooding.Failure during data transfer can still result in inconsistent copies: Block transfer can result inSuccessful completionPartial

8、 failure: destination block has incorrect informationTotal failure: destination block was never updatedProtecting storage media from failure during data transfer (one solution):Execute output operation as follows (assuming two copies of each block):Write the information onto the first physical block

9、.When the first write successfully completes, write the same information onto the second physical block.The output is completed only after the second write successfully completes.Stable-Storage Implementation (Cont.)Protecting storage media from failure during data transfer (cont.):Copies of a block

10、 may differ due to failure during output operation. To recover from failure:First find inconsistent blocks:Expensive solution: Compare the two copies of every disk block.Better solution: Record in-progress disk writes on non-volatile storage (Non-volatile RAM or special area of disk). Use this infor

11、mation during recovery to find blocks that may be inconsistent, and only compare copies of these. Used in hardware RAID systems冗余磁盘阵列If either copy of an inconsistent block is detected to have an error (bad checksum), overwrite it by the other copy. If both have no error, but are different, overwrit

12、e the second block by the first block. Data AccessPhysical 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(B) transfers the physical bl

13、ock B to main memory.output(B) transfers the buffer block B to the disk, and replaces the appropriate physical block there.Each transaction Ti has its private work-area in which local copies of all data items accessed and updated by it are kept. Tis local copy of a data item X is called xi.We assume

14、, for simplicity, that each data item fits in, and is stored inside, a single block.Data Access (Cont.)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) as

15、signs the value of local variable xi to data item X in the buffer block.both these commands may necessitate the issue of an input(BX) instruction before the assignment, if the block BX in which X resides is not already in memory.Transactions Perform read(X) while accessing X for the first time; All

16、subsequent accesses are to the local copy. After last access, transaction executes write(X).output(BX) need not immediately follow write(X). System can perform the output operation when it deems fit.Example of Data AccessxYABx1y1 bufferBuffer Block A Buffer Block Binput(A)output(B) read(X)write(Y)di

17、skwork areaof T1work areaof T2 memoryx2Recovery and AtomicityModifying the database without ensuring that the transaction will commit may leave the database in an inconsistent state.Consider transaction Ti that transfers $50 from account A to account B; goal is either to perform all database modific

18、ations made by Ti or none at all. Several output operations may be required for Ti (to output A and B). A failure may occur after one of these modifications have been made but before all of them are made.Recovery and Atomicity (Cont.)To ensure atomicity despite failures, we first output information

19、describing the modifications to stable storage without modifying the database itself.We study two approaches:log-based recovery, andshadow-pagingWe assume (initially) that transactions run serially, that is, one after the other.Log-Based RecoveryA log is kept on stable storage. The log is a sequence

20、 of log records, and maintains a record of update activities on the database.When transaction Ti starts, it registers itself by writing a log recordBefore Ti executes write(X), a log record is written, where V1 is the value of X before the write, and V2 is the value to be written to X.When Ti finish

21、es it last statement, the log record is written. We assume for now that log records are written directly to stable storage (that is, they are not buffered)Two approaches using logsDeferred database modificationImmediate database modification方法1: Deferred Database ModificationThe deferred database mo

22、dification scheme records all modifications to the log, but defers all the writes to after partial commit.Assume that transactions execute serially 故障出现前的做法:Transaction starts by writing record to log. A write(X) operation results in a log record being written, where V is the new value for XNote: ol

23、d value is not needed for this schemeThe write is not performed on X at this time, but is deferred.When Ti partially commits 即事务执行完所有的语句, is written to the log Finally, the log records are read and used to actually execute the previously deferred writes.Deferred Database Modification (Cont.)故障出现后的做法

24、:a transaction needs to be redone if and only if both and are there in the log. Crashes can occur while the transaction is executing the original updates, or while recovery action is being takenexample transactions T0 and T1 (T0 executes before T1):T0: read (A)T1 : read (C)A: - A - 50 C:-C- 100Write

25、 (A) write (C)read (B)B:- B + 50write (B)Deferred Database Modification (Cont.)Below we show the log as it appears at three instances of time.If log on stable storage at time of crash is as in case:(a) No redo actions need to be taken(b) redo(T0) must be performed since is present (c) redo(T0) must

26、be performed followed by redo(T1) since and are present方法2: Immediate Database ModificationThe immediate database modification scheme allows database updates of an uncommitted transaction to be made as the writes are issued.故障发生前的做法:Update log record must be written before database item is written u

27、pdate logs must have both old value and new value We assume that the log record is output directly to stable storageCan be extended to postpone log record output, so long as prior to execution of an output(B) operation for a data block B, all log records corresponding to items B must be flushed to s

28、table storageOutput of updated blocks can take place at any time before or after transaction commitOrder in which blocks are output can be different from the order in which they are written.Immediate Database Modification ExampleLog Write OutputTo, B, 2000, 2050 A = 950 B = 2050 C = 600 BB, BC BANot

29、e: BX denotes block containing X.x1Immediate Database Modification (Cont.)Recovery procedure has two operations instead of one: undo(Ti) restores the value of all data items updated by Ti to their old values, going backwards from the last log record for Tiredo(Ti) sets the value of all data items up

30、dated by Ti to the new values, going forward from the first log record for TiBoth operations must be idempotent 幂等的. That is, even if the operation is executed multiple times the effect is the same as if it is executed once故障发生后:When recovering after failure:Transaction Ti needs to be undone if the

31、log contains the record , but does not contain the record .Transaction Ti needs to be redone if the log contains both the record and the record .Undo operations are performed first, then redo operations.Immediate DB Modification Recovery Example Below we show the log as it appears at three instances

32、 of time.Recovery actions in each case above are:(a) undo (T0): B is restored to 2000 and A to 1000.(b) undo (T1) and redo (T0): C is restored to 700, and then A and B are set to 950 and 2050 respectively.(c) redo (T0) and redo (T1): A and B are set to 950 and 2050 respectively. Then C is set to 600

33、Checkpoints 检查点目标: 减少故障恢复时的开销Problems in recovery procedure as discussed earlier :searching the entire log is time-consumingwe might unnecessarily redo transactions which have already output their updates to the database.出现故障前的做法:Streamline recovery procedure by periodically performing checkpointing

34、 Output all log records currently residing in main memory onto stable storage.Output all modified buffer blocks to the disk.Write a log record onto stable storage.Checkpoints (Cont.)During recovery we need to consider only the most recent transaction Ti that started before the checkpoint, and transa

35、ctions that started after Ti. 出现故障时的做法:Scan backwards from end of log to find the most recent record Continue scanning backwards till a record is found. Need only consider the part of log following above start record. Earlier part of log can be ignored during recovery, and can be erased whenever des

36、ired.For all transactions (starting from Ti or later) with no , execute undo(Ti). (Done only in case of immediate modification.)Scanning forward in the log, for all transactions starting from Ti or later with a , execute redo(Ti).Example of CheckpointsT1 can be ignored (updates already output to dis

37、k due to checkpoint)T2 and T3 redone.T4 undoneTcTfT1T2T3T4checkpointsystem failureRecovery With Concurrent Transactions大致了解We modify the log-based recovery schemes to allow multiple transactions to execute concurrently.All transactions share a single disk buffer and a single logA buffer block can ha

38、ve data items updated by one or more transactionsWe assume concurrency control using strict two-phase locking;i.e. the updates of uncommitted transactions should not be visible to other transactionsOtherwise how to perform undo if T1 updates A, then T2 updates A and commits, and finally T1 has to ab

39、ort?Logging is done as described earlier. Log records of different transactions may be interspersed in the log.The checkpointing technique and actions taken on recovery have to be changedsince several transactions may be active when a checkpoint is performed.Recovery With Concurrent Transactions (Co

40、nt.)Checkpoints are performed as before, except that the checkpoint log record is now of the form where L is the list of transactions active at the time of the checkpointWe assume no updates are in progress while the checkpoint is carried out (will relax this later)When the system recovers from a cr

41、ash, it first does the following:Initialize undo-list and redo-list to emptyScan the log backwards from the end, stopping when the first record is found. For each record found during the backward scan:if the record is , add Ti to redo-listif the record is , then if Ti is not in redo-list, add Ti to

42、undo-listFor every Ti in L, if Ti is not in redo-list, add Ti to undo-listRecovery With Concurrent Transactions (Cont.)At this point undo-list consists of incomplete transactions which must be undone, and redo-list consists of finished transactions that must be redone.Recovery now continues as follo

43、ws:Scan log backwards from most recent record, stopping when records have been encountered for every Ti in undo-list.During the scan, perform undo for each log record that belongs to a transaction in undo-list.Locate the most recent record.Scan log forwards from the record till the end of the log.Du

44、ring the scan, perform redo for each log record that belongs to a transaction on redo-listExample of RecoveryGo over the steps of the recovery algorithm on the following log: /* Scan in Step 4 stops here */Log Record BufferingLog record buffering: log records are buffered in main memory, instead of

45、of being output directly to stable storage. 减少外设IO次数Log records are output to stable storage when a block of log records in the buffer is full, or a log force日志强制 operation is executed.Log force is performed to commit a transaction by forcing all its log records (including the commit record) to stab

46、le storage.Several log records can thus be output using a single output operation, reducing the I/O cost.Log Record Buffering (Cont.)The rules below must be followed if log records are buffered:Log records are output to stable storage in the order in which they are created. Transaction Ti enters the

47、 commit state only when the log record has been output to stable storage.Before a block of data in main memory is output to the database, all log records pertaining to data in that block must have been output to stable storage. This rule is called the write-ahead logging 先写日志or WAL ruleStrictly spea

48、king WAL only requires undo information to be outputDatabase BufferingDatabase maintains an in-memory buffer of data blocksWhen a new block is needed, if buffer is full an existing block needs to be removed from bufferIf the block chosen for removal has been updated, it must be output to diskAs a re

49、sult of the write-ahead logging rule, if a block with uncommitted updates is output to disk, log records with undo information for the updates are output to the log on stable storage first.No updates should be in progress on a block when it is output to disk. Can be ensured as follows.Before writing

50、 a data item, transaction acquires exclusive lock on block containing the data itemLock can be released once the write is completed. Such locks held for short duration are called latches.Before a block is output to disk, the system acquires an exclusive latch on the blockEnsures no update can be in

51、progress on the blockBuffer Management (Cont.)Database buffer can be implemented eitherin an area of real main-memory reserved for the database, orin virtual memoryImplementing buffer in reserved main-memory has drawbacks:Memory is partitioned before-hand between database buffer and applications, li

52、miting flexibility. Needs may change, and although operating system knows best how memory should be divided up at any time, it cannot change the partitioning of memory.Buffer Management (Cont.)Database buffers are generally implemented in virtual memory in spite of some drawbacks: 容易导致额外的磁盘IOWhen op

53、erating system needs to evict 移出a page that has been modified, to make space for another page, the page is written to swap space on disk.When database decides to write buffer page to disk, buffer page may be in swap space, and may have to be read from swap space on disk and output to the database on

54、 disk, resulting in extra I/O! Known as dual paging problem.Ideally when swapping out a database buffer page, operating system should pass control to database, which in turn outputs page to database instead of to swap space (making sure to output log records first)Dual paging can thus be avoided, bu

55、t common operating systems do not support such functionality.Failure with Loss of Nonvolatile StorageSo far we assumed no loss of non-volatile storageTechnique similar to checkpointing used to deal with loss of non-volatile storagePeriodically dump转贮 the entire content of the database to stable stor

56、ageNo transaction may be active during the dump procedure; a procedure similar to checkpointing must take placeOutput all log records currently residing in main memory onto stable storage.Output all buffer blocks onto the disk.Copy the contents of the database to stable storage.Output a record to lo

57、g on stable storage.To recover from disk failurerestore database from most recent dump. Consult the log and redo all transactions that committed after the dumpCan be extended to allow transactions to be active during dump; known as fuzzy dump or online dumpWill study fuzzy checkpointing laterRemote

58、Backup SystemsRemote Backup SystemsRemote backup systems provide high availability by allowing transaction processing to continue even if the primary site is destroyed.Remote Backup Systems (Cont.)Detection of failure: Backup site 备份站点 must detect when primary site has failed to distinguish primary

59、site failure from link failure maintain several communication links between the primary and the remote backup.Transfer of control: To take over control , backup site first perform recovery using its copy of the database and all the long records it has received from the primary. Thus, completed transactions are redone and incomplet

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论