Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe
CHAPTER 20 Itroductio to Trasactio Processig Cocepts ad Theory Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe
Itroductio Trasactio Describes local uit of database processig Trasactio processig systems Systems with large databases ad hudreds of cocurret users Require high availability ad fast respose time Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-3
20.1 Itroductio to Trasactio Processig Sigle-user DBMS At most oe user at a time ca use the system Example: home computer Multiuser DBMS May users ca access the system (database) cocurretly Example: airlie reservatios system Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-4
Itroductio to Trasactio Processig (cot d.) Multiprogrammig Allows operatig system to execute multiple processes cocurretly Executes commads from oe process, the suspeds that process ad executes commads from aother process, etc. Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-5
Itroductio to Trasactio Processig (cot d.) Iterleaved processig Parallel processig Processes C ad D i figure below Figure 20.1 Iterleaved processig versus parallel processig of cocurret trasactios Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-6
Trasactios Trasactio: a executig program Forms logical uit of database processig Begi ad ed trasactio statemets Specify trasactio boudaries Read-oly trasactio Read-write trasactio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-7
Database Items Database represeted as collectio of amed data items Size of a data item called its graularity Data item Record Disk block Attribute value of a record Trasactio processig cocepts idepedet of item graularity Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-8
Read ad Write Operatios read_item(x) Reads a database item amed X ito a program variable amed X Process icludes fidig the address of the disk block, ad copyig to ad from a memory buffer write_item(x) Writes the value of program variable X ito the database item amed X Process icludes fidig the address of the disk block, copyig to ad from a memory buffer, ad storig the updated disk block back to disk Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-9
Read ad Write Operatios (cot d.) Read set of a trasactio Set of all items read Write set of a trasactio Set of all items writte Figure 20.2 Two sample trasactios (a) Trasactio T1 (b) Trasactio T2 Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-10
DBMS Buffers DBMS will maitai several mai memory data buffers i the database cache Whe buffers are occupied, a buffer replacemet policy is used to choose which buffer will be replaced Example policy: least recetly used Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-11
Cocurrecy Cotrol Trasactios submitted by various users may execute cocurretly Access ad update the same database items Some form of cocurrecy cotrol is eeded The lost update problem Occurs whe two trasactios that access the same database items have operatios iterleaved Results i icorrect value of some database items Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-12
The Lost Update Problem Figure 20.3 Some problems that occur whe cocurret executio is ucotrolled (a) The lost update problem Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-13
The Temporary Update Problem Figure 20.3 (cot d.) Some problems that occur whe cocurret executio is ucotrolled (b) The temporary update problem Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-14
The Icorrect Summary Problem Figure 20.3 (cot d.) Some problems that occur whe cocurret executio is ucotrolled (c) The icorrect summary problem Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-15
The Urepeatable Read Problem Trasactio T reads the same item twice Value is chaged by aother trasactio T betwee the two reads T receives differet values for the two reads of the same item Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-16
Why Recovery is Needed Committed trasactio Effect recorded permaetly i the database Aborted trasactio Does ot affect the database Types of trasactio failures Computer failure (system crash) Trasactio or system error Local errors or exceptio coditios detected by the trasactio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-17
Why Recovery is Needed (cot d.) Types of trasactio failures (cot d.) Cocurrecy cotrol eforcemet Disk failure Physical problems or catastrophes System must keep sufficiet iformatio to recover quickly from the failure Disk failure or other catastrophes have log recovery times Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-18
20.2 Trasactio ad System Cocepts System must keep track of whe each trasactio starts, termiates, commits, ad/or aborts BEGIN_TRANSACTION READ or WRITE END_TRANSACTION COMMIT_TRANSACTION ROLLBACK (or ABORT) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-19
Trasactio ad System Cocepts (cot d.) Figure 20.4 State trasitio diagram illustratig the states for trasactio executio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-20
The System Log System log keeps track of trasactio operatios Sequetial, apped-oly file Not affected by failure (except disk or catastrophic failure) Log buffer Mai memory buffer Whe full, appeded to ed of log file o disk Log file is backed up periodically Udo ad redo operatios based o log possible Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-21
Commit Poit of a Trasactio Occurs whe all operatios that access the database have completed successfully Ad effect of operatios recorded i the log Trasactio writes a commit record ito the log If system failure occurs, ca search for trasactios with recorded start_trasactio but o commit record Force-writig the log buffer to disk Writig log buffer to disk before trasactio reaches commit poit Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-22
DBMS-Specific Buffer Replacemet Policies Page replacemet policy Selects particular buffers to be replaced whe all are full Domai separatio (DS) method Each domai hadles oe type of disk pages Idex pages Data file pages Log file pages Number of available buffers for each domai is predetermied Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-23
DBMS-Specific Buffer Replacemet Policies (cot d.) Hot set method Useful i queries that sca a set of pages repeatedly Does ot replace the set i the buffers util processig is completed The DBMIN method Predetermies the patter of page refereces for each algorithm for a particular type of database operatio Calculates locality set usig query locality set model (QLSM) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-24
20.3 Desirable Properties of Trasactios ACID properties Atomicity Trasactio performed i its etirety or ot at all Cosistecy preservatio Takes database from oe cosistet state to aother Isolatio Not iterfered with by other trasactios Durability or permaecy Chages must persist i the database Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-25
Desirable Properties of Trasactios (cot d.) Levels of isolatio Level 0 isolatio does ot overwrite the dirty reads of higher-level trasactios Level 1 isolatio has o lost updates Level 2 isolatio has o lost updates ad o dirty reads Level 3 (true) isolatio has repeatable reads I additio to level 2 properties Sapshot isolatio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-26
20.4 Characterizig Schedules Based o Recoverability Schedule or history Order of executio of operatios from all trasactios Operatios from differet trasactios ca be iterleaved i the schedule Total orderig of operatios i a schedule For ay two operatios i the schedule, oe must occur before the other Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-27
Characterizig Schedules Based o Recoverability (cot d.) Two coflictig operatios i a schedule Operatios belog to differet trasactios Operatios access the same item X At least oe of the operatios is a write_item(x) Two operatios coflict if chagig their order results i a differet outcome Read-write coflict Write-write coflict Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-28
Characterizig Schedules Based o Recoverability (cot d.) Recoverable schedules Recovery is possible Norecoverable schedules should ot be permitted by the DBMS No committed trasactio ever eeds to be rolled back Cascadig rollback may occur i some recoverable schedules Ucommitted trasactio may eed to be rolled back Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-29
Characterizig Schedules Based o Recoverability (cot d.) Cascadeless schedule Avoids cascadig rollback Strict schedule Trasactios ca either read or write a item X util the last trasactio that wrote X has committed or aborted Simpler recovery process Restore the before image Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-30
20.5 Characterizig Schedules Based o Serializability Serializable schedules Always cosidered to be correct whe cocurret trasactios are executig Places simultaeous trasactios i series Trasactio T 1 before T 2, or vice versa Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-31
Figure 20.5 Examples of serial ad oserial schedules ivolvig trasactios T1 ad T2 (a) Serial schedule A: T1 followed by T2 (b) Serial schedule B: T2 followed by T1 (c) Two oserial schedules C ad D with iterleavig of operatios Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-32
Characterizig Schedules Based o Serializability (cot d.) Problem with serial schedules Limit cocurrecy by prohibitig iterleavig of operatios Uacceptable i practice Solutio: determie which schedules are equivalet to a serial schedule ad allow those to occur Serializable schedule of trasactios Equivalet to some serial schedule of same trasactios Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-33
Characterizig Schedules Based o Serializability (cot d.) Result equivalet schedules Produce the same fial state of the database May be accidetal Caot be used aloe to defie equivalece of schedules Figure 20.6 Two schedules that are result equivalet for the iitial value of X = 100 but are ot result equivalet i geeral Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-34
Characterizig Schedules Based o Serializability (cot d.) Coflict equivalece Relative order of ay two coflictig operatios is the same i both schedules Serializable schedules Schedule S is serializable if it is coflict equivalet to some serial schedule S. Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-35
Characterizig Schedules Based o Serializability (cot d.) Testig for serializability of a schedule Algorithm 20.1 Testig coflict serializability of a schedule S Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-36
Characterizig Schedules Based o Serializability (cot d.) Figure 20.7 Costructig the precedece graphs for schedules A to D from Figure 20.5 to test for coflict serializability (a) Precedece graph for serial schedule A (b) Precedece graph for serial schedule B (c) Precedece graph for schedule C (ot serializable) (d) Precedece graph for schedule D (serializable, equivalet to schedule A) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-37
How Serializability is Used for Cocurrecy Cotrol Beig serializable is differet from beig serial Serializable schedule gives beefit of cocurret executio Without givig up ay correctess Difficult to test for serializability i practice Factors such as system load, time of trasactio submissio, ad process priority affect orderig of operatios DBMS eforces protocols Set of rules to esure serializability Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-38
View Equivalece ad View Serializability View equivalece of two schedules As log as each read operatio of a trasactio reads the result of the same write operatio i both schedules, the write operatios of each trasactio must produce the same results Read operatios said to see the same view i both schedules View serializable schedule View equivalet to a serial schedule Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-39
View Equivalece ad View Serializability (cot d.) Coflict serializability similar to view serializability if costraied write assumptio (o blid writes) applies Ucostraied write assumptio Value writte by a operatio ca be idepedet of its old value Debit-credit trasactios Less-striget coditios tha coflict serializability or view serializability Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-40
20.6 Trasactio Support i SQL No explicit Begi_Trasactio statemet Every trasactio must have a explicit ed statemet COMMIT ROLLBACK Access mode is READ ONLY or READ WRITE Diagostic area size optio Iteger value idicatig umber of coditios held simultaeously i the diagostic area Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-41
Trasactio Support i SQL (cot d.) Isolatio level optio Dirty read Norepeatable read Phatoms Table 20.1 Possible violatios based o isolatio levels as defied i SQL Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-42
Trasactio Support i SQL (cot d.) Sapshot isolatio Used i some commercial DBMSs Trasactio sees data items that it reads based o the committed values of the items i the database sapshot whe trasactio starts Esures phatom record problem will ot occur Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-43
20.7 Summary Sigle ad multiuser database trasactios Ucotrolled executio of cocurret trasactios System log Failure recovery Committed trasactio Schedule (history) defies executio sequece Schedule recoverability Schedule equivalece Serializability of schedules Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 20-44