Page 197 - DCAP402_DCAO204_DATABASE MANAGEMENT SYSTEM_MANAGING DATABASE
P. 197

Database Management Systems/Managing Database




                    Notes          forwards from the <checkpoint L> record till the end of the log. During the scan, perform redo
                                   for each log record that belongs to a transaction on redo-list.
                                   SQL does not  have  very  specific commands  for recovery  but, it  allows explicit  COMMIT,
                                   ROLLBACK and other related commands.

                                   11.7 Buffer Management

                                   When the database is updated, a lot of records are changed in the buffers allocated to the log
                                   records, and database records. Although buffer management is the job of the operating system,
                                   however, some times the DBMS prefer buffer management policies of their own.

                                   Log Record Buffering

                                   Log records are buffered in  the main  memory, instead  of being output directly to a stable
                                   storage media. Log records are output to a 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 single output operation, reducing the I/O cost.
                                   The rules below must be followed if log records are buffered:
                                   1.  Log records are output to stable storage in the order in which they are created.

                                   2.  Transaction T  enters the commit state only when the log record <T  commit> has been
                                                   i                                           i
                                       output to stable storage.
                                   3.  Before a block of data in the main  memory is  output to the database,  all log  records
                                       pertaining to data in that block must be output to a stable storage.
                                   These rules are also called the write-ahead logging scheme.

                                   Database Buffering

                                   The database maintains an in-memory buffer of data blocks, when a new block is needed, if the
                                   buffer is full, an existing  block needs to be removed from the buffer. If the block chosen for
                                   removal has been updated, even then it must be output to the disk. However, as per write-ahead
                                   logging scheme, a block with uncommitted updates is output to disk, log records with undo
                                   information for the updates must be output to the log on a stable storage. No updates should be
                                   in progress on a block when it is output to disk. This can be ensured as follows:
                                   1.  Before writing a data item, the transaction acquires exclusive lock on block containing the
                                       data item.

                                   2.  Lock can be released once the write is completed. (Such locks held for short duration are
                                       called latches).
                                   3.  Before  a block is output to disk, the system acquires an  exclusive latch  on the  block
                                       (ensures no update can be in progress on the block).
                                   A database buffer can be implemented either, in an area of real main-memory reserved for the
                                   database,  or in  the  virtual  memory.  Implementing  buffer  in  reserved  main-memory  has
                                   drawbacks. Memory is partitioned before-hand between database buffer and applications, thereby,
                                   limiting flexibility. Although the operating system knows how memory should be divided at
                                   any time, it cannot change the partitioning of memory.







          190                               LOVELY PROFESSIONAL UNIVERSITY
   192   193   194   195   196   197   198   199   200   201   202