山大數(shù)據(jù)庫系統(tǒng)英語課件16恢復(fù)系統(tǒng)_第1頁
山大數(shù)據(jù)庫系統(tǒng)英語課件16恢復(fù)系統(tǒng)_第2頁
山大數(shù)據(jù)庫系統(tǒng)英語課件16恢復(fù)系統(tǒng)_第3頁
山大數(shù)據(jù)庫系統(tǒng)英語課件16恢復(fù)系統(tǒng)_第4頁
山大數(shù)據(jù)庫系統(tǒng)英語課件16恢復(fù)系統(tǒng)_第5頁
已閱讀5頁,還剩90頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Chapter 16: Recovery SystemChapter 16: Recovery SystemFailure ClassificationStorage StructureRecovery and AtomicityLog-Based RecoveryRemote Backup SystemsFailure ClassificationTransaction failure :Logical errors: transaction cannot complete due to some internal error conditionSystem errors: the data

2、base system must terminate an active transaction due to an error condition (e.g., deadlock)System crash: a power failure or other hardware or software failure causes the system to crash.Fail-stop assumption: non-volatile storage contents are assumed to not be corrupted by system crashDatabase system

3、s have numerous integrity checks to prevent corruption of disk data Disk failure: a head crash or similar disk failure destroys all or part of disk storageDestruction is assumed to be detectable: disk drives use checksums to detect failuresRecovery AlgorithmsConsider transaction Ti that transfers $5

4、0 from account A to account BTwo updates: subtract 50 from A and add 50 to B Transaction Ti requires updates to A and B to be output to the database. A failure may occur after one of these modifications have been made but before both of them are made. Modifying the database without ensuring that the

5、 transaction will commit may leave the database in an inconsistent stateNot modifying the database may result in lost updates if failure occurs just after transaction commitsRecovery algorithms have two partsActions taken during normal transaction processing to ensure enough information exists to re

6、cover from failuresActions taken after a failure to recover the database contents to a state that ensures atomicity, consistency and durabilityStorage StructureVolatile storage:does not survive system crashesexamples: main memory, cache memoryNonvolatile storage:survives system crashesexamples: disk

7、, tape, flash memory, non-volatile (battery backed up) RAM but may still fail, losing dataStable storage:a mythical form of storage that survives all failuresapproximated by maintaining multiple copies on distinct nonvolatile mediaSee book for more details on how to implement stable storageStable-St

8、orage 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 failure: dest

9、ination 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.When the firs

10、t 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 may differ du

11、e 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 information during

12、recovery to find blocks that may be inconsistent, and only compare copies of these. Used in hardware RAID systemsIf 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, overwrite the second block b

13、y 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 block B to main memory

14、.output(B) transfers the buffer block B to the disk, and replaces the appropriate physical block there.We assume, for simplicity, that each data item fits in, and is stored inside, a single block.Example of Data AccessX Y ABx1y1 bufferBuffer Block A Buffer Block Binput(A)output(B) read(X)write(Y)dis

15、kwork areaof T1work areaof T2 memoryx2Data Access (Cont.)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.Transferring data items between system buffer blocks and its private work-a

16、rea done by: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.Note: output(BX) need not immediately follow write(X). System can perform the output operation when it deems fit.Transactions Must perform

17、read(X) before accessing X for the first time (subsequent reads can be from local copy) write(X) can be executed at any time before the transaction commitsRecovery and AtomicityTo ensure atomicity despite failures, we first output information describing the modifications to stable storage without mo

18、difying the database itself.We study log-based recovery mechanisms in detailWe first present key conceptsAnd then present the actual recovery algorithmLess used alternative: shadow-paging (brief details in book)Log-Based RecoveryA log is kept on stable storage. The log is a sequence of log records,

19、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 (the old value), and V2 is the value to be written to X (the new value)

20、. When Ti finishes it last statement, the log record is written. Two approaches using logsDeferred database modificationImmediate database modificationImmediate Database ModificationThe immediate-modification scheme allows updates of an uncommitted transaction to be made to the buffer, or the disk i

21、tself, before the transaction commitsUpdate log record must be written before database item is writtenWe assume that the log record is output directly to stable storage(Will see later that how to postpone log record output to some extent)Output of updated blocks to stable storage can take place at a

22、ny time before or after transaction commitOrder in which blocks are output can be different from the order in which they are written.The deferred-modification scheme performs updates to buffer/disk only at the time of transaction commitSimplifies some aspects of recoveryBut has overhead of storing l

23、ocal copyTransaction CommitA transaction is said to have committed when its commit log record is output to stable storage all previous log records of the transaction must have been output already Writes performed by a transaction may still be in the buffer when the transaction commits, and may be ou

24、tput laterImmediate Database Modification ExampleLog Write OutputTo, B, 2000, 2050 A = 950 B = 2050 C = 600 BB , BC BANote: BX denotes block containing X.BC output before T1 commitsBA output after T0 commitsConcurrency Control and RecoveryWith concurrent transactions, all transactions share a single

25、 disk buffer and a single logA buffer block can have data items updated by one or more transactionsWe assume that if a transaction Ti has modified an item, no other transaction can modify the same item until Ti has committed or abortedi.e. the updates of uncommitted transactions should not be visibl

26、e to other transactionsOtherwise how to perform undo if T1 updates A, then T2 updates A and commits, and finally T1 has to abort?Can be ensured by obtaining exclusive locks on updated items and holding the locks till end of transaction (strict two-phase locking)Log records of different transactions

27、may be interspersed in the log.Undo and Redo OperationsUndo of a log record writes the old value V1 to XRedo of a log record writes the new value V2 to XUndo and Redo of Transactionsundo(Ti) restores the value of all data items updated by Ti to their old values, going backwards from the last log rec

28、ord for Tieach time a data item X is restored to its old value V a special log record is written outwhen 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 TiNo logging

29、is done in this caseUndo and Redo on Recovering from FailureWhen 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 Note tha

30、t If transaction Ti was undone earlier and the record written to the log, and then a failure occurs, on recovery from failure Ti is redonesuch a redo redoes all the original actions including the steps that restored old valuesKnown as repeating historySeems wasteful, but simplifies recovery greatlyI

31、mmediate DB Modification Recovery Example Below we show the log as it appears at three instances of time.Recovery actions in each case above are:(a) undo (T0): B is restored to 2000 and A to 1000, and log records, , are written out(b) redo (T0) and undo (T1): A and B are set to 950 and 2050 and C is

32、 restored to 700. Log records , are written out.(c) redo (T0) and redo (T1): A and B are set to 950 and 2050 respectively. Then C is set to 600CheckpointsRedoing/undoing all transactions recorded in the log can be very slow processing the entire log is time-consuming if the system has run for a long

33、 timewe might unnecessarily redo transactions which have already output their updates to the database.Streamline recovery procedure by periodically performing checkpointing Output all log records currently residing in main memory onto stable storage.Output all modified buffer blocks to the disk.Writ

34、e a log record onto stable storage where L is a list of all transactions active at the time of checkpoint.All updates are stopped while doing checkpointingCheckpoints (Cont.)During recovery we need to consider only the most recent transaction Ti that started before the checkpoint, and transactions t

35、hat started after Ti. Scan backwards from end of log to find the most recent record Only transactions that are in L or started after the checkpoint need to be redone or undoneTransactions that committed or aborted before the checkpoint already have all their updates output to stable storage.Some ear

36、lier part of the log may be needed for undo operationsContinue scanning backwards till a record is found for every transaction Ti in L.Parts of log prior to earliest record above are not needed for recovery, and can be erased whenever desired.Example of CheckpointsT1 can be ignored (updates already

37、output to disk due to checkpoint)T2 and T3 redone.T4 undoneTcTfT1T2T3T4checkpointsystem failureRecovery Algorithm So far: we covered key concepts Now: we present the components of the basic recovery algorithm Later: we present extensions to allow more concurrencyRecovery AlgorithmLogging (during nor

38、mal operation): at transaction start for each update, and at transaction endTransaction rollback (during normal operation)Let Ti be the transaction to be rolled backScan log backwards from the end, and for each log record of Ti of the form perform the undo by writing V1 to Xj,write a log record such

39、 log records are called compensation log recordsOnce the record is found stop the scan and write the log record Recovery from failure: Two phasesRedo phase: replay updates of all transactions, whether they committed, aborted, or are incompleteUndo phase: undo all incomplete transactionsRedo phase:Fi

40、nd last record, and set undo-list to L.Scan forward from above recordWhenever a record is found, redo it by writing V2 to Xj Whenever a log record is found, add Ti to undo-listWhenever a log record or is found, remove Ti from undo-listRecovery Algorithm (Cont.)Recovery Algorithm (Cont.)Undo phase: S

41、can log backwards from end Whenever a log record 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 Whenever a log record is found where Ti is in undo-list, Write a log record Remove Ti from undo-listStop when undo-

42、list is emptyi.e. has been found for every transaction in undo-listAfter undo phase completes, normal transaction processing can commenceExample of RecoveryLog Record BufferingLog record buffering: log records are buffered in main memory, instead of of being output directly to stable storage.Log rec

43、ords 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 stable storage.Several log records can thus be output using a singl

44、e 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 commit state only when the log record has been output to stabl

45、e 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 speaking WAL only requires undo information to be outputDatabase Buffer

46、ingDatabase 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 diskThe recovery algorithm supports the no-force policy: i.e., updated blocks

47、need not be written to disk when transaction commitsforce policy: requires updated blocks to be written at commitMore expensive commitThe recovery algorithm supports the steal policy:i.e., blocks containing updates of uncommitted transactions can be written to disk, even before the transaction commi

48、tsDatabase Buffering (Cont.)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(Write ahead logging)No updates should be in progress on a block when it is output to disk. Can be ensured as follows.Befo

49、re writing 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.To output a block to diskFirst acquire an exclusive latch on the blockEnsures no update can be in progr

50、ess on the blockThen perform a log flushThen output the block to diskFinally release the latch 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 dr

51、awbacks:Memory is partitioned before-hand between database buffer and applications, limiting 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

52、generally implemented in virtual memory in spite of some drawbacks: When operating system needs to evict a page that has been modified, 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 sp

53、ace on disk and output to the database on disk, resulting in extra I/O! Known as dual paging problem.Ideally when OS needs to evict a page from the buffer, it should pass control to database, which in turn shouldOutput the page to database instead of to swap space (making sure to output log records

54、first), if it is modifiedRelease the page from the buffer, for the OS to useDual paging can thus be avoided, but common operating systems do not support such functionality.Fuzzy CheckpointingTo avoid long interruption of normal processing during checkpointing, allow updates to happen during checkpoi

55、ntingFuzzy checkpointing is done as follows:Temporarily stop all updates by transactionsWrite a log record and force log to stable storageNote list M of modified buffer blocksNow permit transactions to proceed with their actionsOutput to disk all modified buffer blocks in list Mblocks should not be

56、updated while being outputFollow WAL: all log records pertaining to a block must be output before the block is outputStore a pointer to the checkpoint record in a fixed position last_checkpoint on diskFuzzy Checkpointing (Cont.)When recovering using a fuzzy checkpoint, start scan from the checkpoint

57、 record pointed to by last_checkpointLog records before last_checkpoint have their updates reflected in database on disk, and need not be redone.Incomplete checkpoints, where system had crashed while performing checkpoint, are handled safely.Loglast_checkpointFailure with Loss of Nonvolatile Storage

58、So 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 storageNo transaction may be active during the dump procedure; a procedure similar to checkpointing must ta

59、ke 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 log on stable storage.Recovering from Failure of Non-Volatile StorageTo recover from disk failurerestore

60、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 dumpSimilar to fuzzy checkpointingRecovery with Early Lock Release and Logical Undo OperationsRecovery

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論