Database Systems Instructr: Ha-Hua Chu Fall Semester, 2004 Assignment 10: Transactin Simulatin & Crash Recvery Deadline: 23:59 Jan. 5 (Wednesday), 2005 This is a grup assignment, and at mst 2 students per grup are allwed. Cheating Plicy: If yu are caught cheating, yur grade is 0. Late Plicy: Yu may hand in yur late assignment befre 23:59 n Thursady (1/6/2005) fr 80% f riginal grade, r befre 23:59 n Friday (1/7/2005) fr 70%. We will nt accept any assignment submissins after Friday (1/7/2005). Dem Time: 1/12 (Wednesday) 10:00 ~ 11:30, 1/14 (Friday) 13:30~14:30 If yu are nt available n thse time perid, please let me knw. I will annunce anther time perid. The deadline f this dem will be n 1/17 befre 17:00. 1. Intrductin In this assignment yu will cmplete certain parts f a database engine. The database is mdeled very simply, and runs by executing a series f transactin peratins given t it by the user. Each transactin perfrms a series f reads and writes n the pages f the database, and can cmmit r abrt at any time. The simulatr keeps a recvery manager mdule that keeps a lg f the database's activity. At any pint in time, the database may crash (specifically, when it encunters a special cmmand t induce a crash). The recvery manager then perfrms a restart t restre the database t a crrect state, using the Aries recvery algrithm.
2. The Transactin Simulatr The transactin simulatr wrks just like a mini-database. There is a series f pages stred in a file n disk, accessed thrugh a buffer. Transactins are mdeled as a sequence f reads and writes t the pages f the database. A lg is kept f all changes t database pages, with WAL used t insure that cmmitted transactins are fully represented by the lg as written t stable strage. Checkpints can be inserted at will. This assignment uses an applicatin called MARS which is a GUI fr testing the simulatr. The input cmes frm.mars files that can be fund in the flder Tests. These files can be edited using any simple text editr. The syntax fr cmmands t the simulatr is discussed in Getting Started with the Simulatr. A breakdwn f the majr cmpnents fllws: BufMgr - This mdule perates much like the buffer yu implemented fr prject 1. When a page is t be read r written t, a pinpage() request is made, and the page is, if nt already present, laded int the buffer pl. On request, ne r all pages can be flushed. Pages are released with an unpinpage() call. The buffer fr this prject is smewhat small, being intended t illustrate the rle f the buffer in crash recvery. Xactin_table - This keeps track f all the transactins currently active in the database. It als keeps infrmatin n each active transactin, namely the ldest and mst recent lg sequence numbers (LSN's) fr each transactin. The lg subsystem: lg - This is the lg that is used in WAL while the transactins are executing. It prvides simple sequential access t the lg files fr reading purpses, and can append new recrds t the end f the lg. The lg recrds are f unifrm size, and the lg des nt cncern itself with the type f lg being written. lgrecrd - This represents a single lg entry. A special field is kept in each recrd t identify the variety f lg recrd (cmmit, update, etc.) that it is. It cntains a generic data buffer, which hlds the infrmatin specific t each type f lg recrd. masterlg - This keeps track f the checkpinting, s that the recvery prcess will nt need t g back t far t recnstruct the database at the time f the crash.
LgData structures - These classes represent each type f update, and the infrmatin assciated with it like prevlsn, xactin_id, and the page affected. Each Lg Data structure is stred in the data field f a lg recrd, and shuld be accessed by typecasting that data t the apprpriate LgData type (UPD, CLR, ABORT). Recvery Manager - cnsists f several related mdules fr lgging & recvery prcedures. While the database is running, each transactin has its wn recvery manager that is respnsible fr lgging its actins. Only ne recvery mdule, thugh, is necessary fr perfrming crash recvery. The pieces f the manager are: The lgging functinality (lgfunc.cpp) - This translates write requests by transactins int Update recrds that are written t the lg, and creates CLR recrds whenever a prcess abrts n its wn. rllback.cpp - This perfrms a rllback n a prcess that has just abrted n its wn, unding the changes and making sure that nne f them persist even after a crash. restart.cpp - This is the part respnsible fr bringing the database up t a cnsistent state fllwing a crash. It perfrms the three phases f the Aries recvery algrithm based n the infrmatin written t the lg. Checkpint - This generates checkpints and writes them t the lg, extracting the infrmatin frm the Xactin table and getting the Dirty Page Table frm the Buffer. Recvery DirtyPageTable - this is the list f pssibly dirty pages that is built during the analysis phase f recvery. Recvery XactTable - this is the list f active transactins that is built during the analysis phase f recvery. The recmgr_tab.c mdule is respnsible fr parsing the input. It is cmputer generated, and nt very fit fr mdificatin. Dn't wrry t much abut what it des; just knw that it takes ne cmmand at a time frm the standard input (which we might have redirected t pint t a file) and cnverts it int a database peratin. The handle.cpp mdule cntains the standalne functins fr perfrming the cmmands. There's ne fr each peratin, and are the "tp-level" functins that are first called when an peratin is dne. The functins in handle.cpp are the functins that will call the Recvery Manager functins that yu will be finishing, and will pass in the relevant data abut the peratins.
The cmplete cde is available in the \\gse\cs432-fall99\a7 and it cnsists f the cmplete prject file. Yu can pen it by duble clicking the Mars.dsw file. All yu need t d is fill in gaps inside tw surce files (lgfunc.cpp and restart.cpp) in the prject. When yu have included yur mdificatin and are ready t test yur cde, yu can run the Mars.exe file generated by visual studi when yu cmpile the prject. When yu are generating the Mars.exe file it is recmmended that yu build the release versin f the prject. This can be dne by pening the Build menu, selecting "Set Active Cnfiguratin", and chse "Release". The.exe file can then be fund in the "Release" flder. Simply duble click it t start the transactin manager. 3. Yur Task Yu will implement varius pieces f the recvery mdule. Specifically, yu will implement the functinality t handle the mst basic and cmmn f transactins, the write (WriteUpdateLg()). Yu must add cde t the lgging mechanism s that writes (als called updates) t the pages f the DB are reflected in the lg, and then implement thse parts f the restart mechanism that deal specifically with thse lg entries t restre the database t a cnsistent state. The cde yu will write belngs in these mdules: lgfunc.cpp - Yu shuld cmplete this functin: WriteUpdateLg() - Given the infrmatin abut a given update, generate an update lg recrd, and update all affected infrmatin in the rest f the database. restart.cpp - Yu shuld cmplete these fur main functins: restart_analysis - This scans the lg recrd frward frm the last checkpint, building up infrmatin abut the database at the time f the crash. Fill in the cde executed when the recrd being lked at is an update recrd, updating the Recvery Xactin table and Recvery Dirty Page Table being rebuilt. red_update - This is the functin fr reding a single actin. Add the cde fr reding an update (UPD) recrd, extracting the necessary infrmatin frm the lg recrd data and perfrming the update.
restart_red - This is the secnd phase f recvery, and restres the database t its pre-crash state. Yu shuld implement the cde that handles each update recrd, calling red_update if the actin needs t be retaken. Yu shuld cnsider the pagelsn stred with each page t determine the necessity f repeating the actin, and update the Recvery Dirty Page Table where necesary. restart_und - This third phase f recvery abrts all transactins active at the time f the crash, scanning the lg backwards and unding the actins f that transactin. Implement the cde that handles the case fr unding an update recrd. Yu'll need t wrk with the Recvery Xactin table, and yu shuld generate a CLR t be written t the lg. Hint: This is essentially a rllback f the transactin, s lk at the cde that nrmally handles a rllback when a transactin abrts. Yu shuld als finish three small methds cncerning the cntrl f the recvery prcess: findredlsn() - identifying the earliest lsn frm which the red prcess shuld start. keepperfrmingund() - determining when t stp the und prcess. findnextundlsn() - identifying the next lg recrd t be undne in the und prcess. 4. Reference Yu culd find the executable file in Exe_4_Test. The fllwing pages prvide mre detailed explanatins abut the classes and types that will be useful fr this assignment. Class lg Class lsn_t Class lgrecrd type LOG_TYPE Class UpdateLgRec Class CLRLgRec Class CmmitLgRec Class AbrtLgRec
Class CkptBeginLgRec Class CkptEndLgRec Class RecveryMgr Class Xactin_table 5. Submissin Submit yur prgram (lgfunc.cpp and restart.cpp) per grup via email t TA, yfhuang@csie.ntu.edu.tw. The email subject must be [DBMS] ASS10 members ID. Yu can submit yur prgram many times, and TA will use that latest ne t grade. In additin, each grup has t hand in a ne-page reprt t illustrate hw yu implement this assignment.