Information Technology Reference
In-Depth Information
Algorithm 3.1 Procedure insert-into-page .T;p;x; v /
insert .x; v / into data page p
n 0 U NDO -N EXT -LSN.T /
log .n;hT; I; p; x; v ;n 0 i/
P AGE -LSN.p/ n
U NDO -N EXT -LSN.T / n
Algorithm 3.2 Procedure delete-from-page .T;p;x/
delete the tuple .x; v / with key x from data page p
n 0 U NDO -N EXT -LSN.T /
log .n;hT; D; p; x; v ;n 0 i/
P AGE -LSN.p/ n
U NDO -N EXT -LSN.T / n
3.7
Write-Ahead Logging
The entry-sequenced file that stores the log is kept in stable storage ,thatis,a
permanent memory that is as reliable as possible. In practice, stable storage must
be approximated with mirrored files stored on different disk drives. The log records
are packed into buffer pages that are taken to the log file on disk when necessary.
To make the log file on stable storage reflect the state of the database as exactly as
possible, modified pages of the log file should be flushed from the buffer onto disk
immediately after writing a new log record. However, this would cause a disk access
for every update, which is very inefficient. In practice, the log is forced to disk only
when a transaction commits or completes its rollback or when the buffering policy
requests it.
Whenever a transaction updates (by one of the actions I , D, W , I 1 , D 1 ,
or W 1 ) a database page p in the buffer, the LSN of the log record generated for
this update is stamped into the P AGE -LSN field in the header of page p. Similarly is
the LSN for a structure modification stamped into the P AGE -LSN fields of all those
pages that are modified in the structure modification. For example, in Example 3.3
the LSN n 2 of the log record h allocate-page-for-heap ;s;f;p;q i is stamped into the
P AGE -LSN fields of all the four affected pages: s, f , p,andq.
Before page p can be flushed from the buffer onto disk, the log manager must
flush from the log buffer onto the log disk all log records whose LSN s are less than
or equal to the P AGE -LSN of page p. This is called the WA L protocol.
In the event of a system failure, the contents of main memory are lost. Thus,
the buffer versions of updated database pages as well as the log records in the log
buffer are gone. What remains are the disk versions of the database pages and the
log records that were flushed onto the log disk before the failure.
The protocol for page updating, which includes that the page must be kept write-
latched during the generation of the log record and the stamping of its LSN into the
P AGE -LSN of the page, guarantees that the log always “runs side by side” with the
current version of the database, when no process failures or system crashes occur.
 
Search WWH ::




Custom Search