SlideShare a Scribd company logo
1 of 19
Download to read offline
1/11/2012 1
2. Atomicity & Durability
Using Shadow Paging
CSEP 545 Transaction Processing
for E-Commerce
Philip A. Bernstein
Copyright ©2012 Philip A. Bernstein
1/11/2012 2
Introduction
• To get started on the Java-C# project, you need
to implement atomicity and durability in a
centralized resource manager (i.e. a database).
• We recommend you use shadowing.
• This section provides a quick introduction.
– It’s described in the textbook: Chapter 7, Section 6.
• A more thorough explanation of the overall topic
of database recovery will be presented in a
couple of weeks.
1/11/2012 3
Review of Atomicity & Durability
• Atomicity - a transaction is all-or-nothing
• Durability – the results of a committed
transaction will survive failures
• Problem
– The only hardware operation that is atomic with
respect to failure and whose result is durable is
“write one disk block”
– But the database doesn’t fit on one disk block!
1/11/2012 4
Shadowing in a Nutshell
• The database is a tree whose root is a single disk block
• There are two copies of the tree, the master and shadow
• The root points to the master copy
• Updates are applied to the shadow copy
• To install the updates, overwrite the root so it points to
the shadow, thereby swapping the master and shadow
– Before overwriting the root, none of the transaction’s updates
are part of the disk-resident database
– After overwriting the root, all of the transaction’s updates are
part of the disk-resident database
– Which means the transaction is atomic and durable
1/11/2012 5
More Specifically …
• The database consists of a set of files.
• Each file F consists of a page table FPt and
a set of pages that FPt points to.
• A database root page points to each file’s
master page table.
• To start, assume that
– Transactions run serially.
I.e., at most one transaction runs at any given time.
– For each page table, the transaction has a private
shadow copy in main-memory.
1/11/2012 6
Initial State of Files A and B and
Transaction Ti
APt,i
1
2
3
...
BPt,i
1
2
3
...
a
b
A1APt,m
1
2
3
...
BPt,m
1
2
3
...
A2
B1
B2
Initial
StateD
I
S
K
Main
Memory
For Ti
DB root
1/11/2012 7
Without Recovery Support:
Ti Overwrites A2 and B2
APt,i
1
2
3
...
BPt,i
1
2
3
...
a
b
A1APt,m
1
2
3
...
BPt,m
1
2
3
...
A2, new
B1
B2, new
Initial
StateD
I
S
K
Main
Memory
For Ti
DB root
1/11/2012 8
What Could Go Wrong?
• Atomicity violation: A failure while Ti is running
can leave the disk state as
[A2,new , B2] or [A2 , B2,new]
– Could be a failure of Ti or hardware or the OS
• This could corrupt a multi-page data structure,
making it unintelligible.
• Even if the state is [A2,new , B2,new], readers can’t
tell whether Ti completed.
– If Ti completed, maybe it would have re-written one
of those pages, or have written a third page B3
1/11/2012 9
To Write a Page P
• Transaction writes a shadow copy of page P to
disk (i.e. does not overwrite the master copy).
• Transaction updates its page table for P’s file to
point to the shadow copy of P.
• Transaction marks P’s entry in the page table
(to remember which pages were updated).
1/11/2012 10
After Writing Page B2
APt,i
1
2
3
...
BPt,i
1
2
3
...
a
b
A1APt,m
1
2
3
...
BPt,m
1
2
3
...
A2
B1
B2,old
Initial
StateD
I
S
K
Main
Memory
For Ti
DB root

B2,new
1/11/2012 11
After Writing Page A1
APt,i
1
2
3
...
BPt,i
1
2
3
...
a
b
A1, oldAPt,m
1
2
3
...
BPt,m
1
2
3
...
A2
B1
B2,old
Initial
StateD
I
S
K
Main
Memory
For Ti
DB root

B2,new
A1, new

1/11/2012 12
What if the System Fails?
• Main memory is lost
• The current transaction is effectively aborted
• But the database is still consistent
1/11/2012 13
To Commit Ti
1. First copy APt,i and BPt,i to disk
APt,i
1
2
3
...
BPt,i
1
2
3
...
a
b
A1, oldAPt,m
1
2
3
...
BPt,m
1
2
3
...
A2
B1
B2,old
Initial
StateD
I
S
K
DB root
B2,new
A1, new
1/11/2012 14
To Commit Ti (cont’d)
2. Then overwrite DB root to point to the new Pt’s.
APt,i
1
2
3
...
BPt,i
1
2
3
...
a
b
A1, oldAPt,m
1
2
3
...
BPt,m
1
2
3
...
A2
B1
B2,old
Initial
StateD
I
S
K
DB root
B2,new
A1, new
• This is the atomic hardware operation that commits Ti.
1/11/2012 15
• What if two transactions update different pages of a file?
– If they share their main-memory shadow copy of the page table,
then committing one will commit the other’s updates too!
• One solution: File-grained locking (but poor concurrency).
• Better solution: use a private shadow-copy of each page
table, per transaction. To commit T, do the following
within a critical section :
– For each file F modified by T
• Get a private copy C of last committed value of F’s page tbl.
• Update C’s entries for pages modified by T.
• Store C on disk.
– Write a new master record, which swaps page tables for the files
updated by T, thereby installing just T’s updates.
Shadow Paging with Shared Files
1/11/2012 16
Managing Available Disk Space
• Treat the list of available pages, Avail, like
another file
• The DB root points to the master Avail
• When a transaction allocates a page, update its
shadow Avail list
• When a transaction commits, write a shadow
copy of Avail to disk
• Committing the transaction swaps the master
Avail list and the shadow
1/11/2012 17
Final Remarks
• A transaction doesn’t need to write shadow pages to disk
until it is ready to commit
– Saves disk writes if a transaction writes a page multiple times or
if it aborts
• Main benefit of shadow paging is that doesn’t require
much code
– Was used in the Gemstone OO DBMS (1980’s)
• But it is not good for TPC benchmarks
– How many disk updates per transaction?
– How to do record level locking?
• Most database products use logging.
– Faster execution time, and more functional, but much more code.
1/11/2012 18
Your Project
• You need not use the exact data structure
presented here.
• In particular, you don’t necessarily need a page
abstraction.
• There are design tradeoffs for you to figure out.
1/11/2012 19
References
• Textbook, Section 7.6.
• P. A. Bernstein, V. Hadzilacos, N. Goodman,
Concurrency Control and Recovery in Database
Systems, Chapter 6, Section 7 (pp. 201-204)
– The book is downloadable from
http://research.microsoft.com/pubs/ccontrol/
• Originally proposed by Raymond Lorie in “Physical
Integrity in a Large Segmented Database”ACM
Transactions on Database Systems, March 1977.

More Related Content

Viewers also liked

Centralized vs distrbution system
Centralized vs distrbution systemCentralized vs distrbution system
Centralized vs distrbution system
zirram
 

Viewers also liked (14)

Query Optimisation
Query OptimisationQuery Optimisation
Query Optimisation
 
Query optimisation
Query optimisationQuery optimisation
Query optimisation
 
OLAP Cubes: Basic operations
OLAP Cubes: Basic operationsOLAP Cubes: Basic operations
OLAP Cubes: Basic operations
 
Centralized vs distrbution system
Centralized vs distrbution systemCentralized vs distrbution system
Centralized vs distrbution system
 
Centralised and distributed databases
Centralised and distributed databasesCentralised and distributed databases
Centralised and distributed databases
 
Etl process in data warehouse
Etl process in data warehouseEtl process in data warehouse
Etl process in data warehouse
 
OLAP
OLAPOLAP
OLAP
 
OLAP
OLAPOLAP
OLAP
 
Memory management
Memory managementMemory management
Memory management
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
 
Introduction to ETL and Data Integration
Introduction to ETL and Data IntegrationIntroduction to ETL and Data Integration
Introduction to ETL and Data Integration
 
Memory management
Memory managementMemory management
Memory management
 
OLAP & DATA WAREHOUSE
OLAP & DATA WAREHOUSEOLAP & DATA WAREHOUSE
OLAP & DATA WAREHOUSE
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
 

Similar to 2 shadowing

TokuDB internals / Лесин Владислав (Percona)
TokuDB internals / Лесин Владислав (Percona)TokuDB internals / Лесин Владислав (Percona)
TokuDB internals / Лесин Владислав (Percona)
Ontico
 
Oracle 11g data warehouse introdution
Oracle 11g data warehouse introdutionOracle 11g data warehouse introdution
Oracle 11g data warehouse introdution
Aditya Trivedi
 

Similar to 2 shadowing (20)

Engage 2020 - HCL Notes V11 Performance Boost
Engage 2020 - HCL Notes V11 Performance BoostEngage 2020 - HCL Notes V11 Performance Boost
Engage 2020 - HCL Notes V11 Performance Boost
 
Engage 2020 - HCL Notes V11 Performance Boost
Engage 2020 - HCL Notes V11 Performance BoostEngage 2020 - HCL Notes V11 Performance Boost
Engage 2020 - HCL Notes V11 Performance Boost
 
#dd12 Performance Boost for your IBM Lotus Notes Client
#dd12  Performance Boost for your IBM Lotus Notes Client#dd12  Performance Boost for your IBM Lotus Notes Client
#dd12 Performance Boost for your IBM Lotus Notes Client
 
CollabSphere 2020 - INF105 - HCL Notes 11.0.1 FP1 - Performance Boost Re-Relo...
CollabSphere 2020 - INF105 - HCL Notes 11.0.1 FP1 - Performance Boost Re-Relo...CollabSphere 2020 - INF105 - HCL Notes 11.0.1 FP1 - Performance Boost Re-Relo...
CollabSphere 2020 - INF105 - HCL Notes 11.0.1 FP1 - Performance Boost Re-Relo...
 
CollabSphere 2020 Live - HCL Notes 11.0.1 FP1 - Performance Boost Re-Reloaded
CollabSphere 2020 Live - HCL Notes 11.0.1 FP1 - Performance Boost Re-ReloadedCollabSphere 2020 Live - HCL Notes 11.0.1 FP1 - Performance Boost Re-Reloaded
CollabSphere 2020 Live - HCL Notes 11.0.1 FP1 - Performance Boost Re-Reloaded
 
Percona 服务器与 XtraDB 存储引擎
Percona 服务器与 XtraDB 存储引擎Percona 服务器与 XtraDB 存储引擎
Percona 服务器与 XtraDB 存储引擎
 
CLFS 2010
CLFS 2010CLFS 2010
CLFS 2010
 
TokuDB internals / Лесин Владислав (Percona)
TokuDB internals / Лесин Владислав (Percona)TokuDB internals / Лесин Владислав (Percona)
TokuDB internals / Лесин Владислав (Percona)
 
Zfs Nuts And Bolts
Zfs Nuts And BoltsZfs Nuts And Bolts
Zfs Nuts And Bolts
 
DNUG Webcast: IBM Notes V10 Performance Boost
DNUG Webcast: IBM Notes V10 Performance BoostDNUG Webcast: IBM Notes V10 Performance Boost
DNUG Webcast: IBM Notes V10 Performance Boost
 
RNUG - HCL Notes V11 Performance Boost
RNUG - HCL Notes V11 Performance BoostRNUG - HCL Notes V11 Performance Boost
RNUG - HCL Notes V11 Performance Boost
 
SQL 2005 Disk IO Performance
SQL 2005 Disk IO PerformanceSQL 2005 Disk IO Performance
SQL 2005 Disk IO Performance
 
Oracle 11g data warehouse introdution
Oracle 11g data warehouse introdutionOracle 11g data warehouse introdution
Oracle 11g data warehouse introdution
 
Connect2013: BP105: A Performance Boost for your IBM Lotus Notes Client
Connect2013: BP105: A Performance Boost for your IBM Lotus Notes ClientConnect2013: BP105: A Performance Boost for your IBM Lotus Notes Client
Connect2013: BP105: A Performance Boost for your IBM Lotus Notes Client
 
BP105 - A Performance Boost for your IBM Lotus Notes Client
BP105 - A Performance Boost for your IBM Lotus Notes ClientBP105 - A Performance Boost for your IBM Lotus Notes Client
BP105 - A Performance Boost for your IBM Lotus Notes Client
 
#DNUG45 - IBM Notes and Domino Performance Boost - Reloaded
 #DNUG45 - IBM Notes and Domino Performance Boost - Reloaded #DNUG45 - IBM Notes and Domino Performance Boost - Reloaded
#DNUG45 - IBM Notes and Domino Performance Boost - Reloaded
 
Ccd
CcdCcd
Ccd
 
4 db recovery
4 db recovery4 db recovery
4 db recovery
 
RNUG 2020: HCL Notes 11.0.1 FP2 - Performance Boost Re-Reloaded
RNUG 2020: HCL Notes 11.0.1 FP2 - Performance Boost Re-ReloadedRNUG 2020: HCL Notes 11.0.1 FP2 - Performance Boost Re-Reloaded
RNUG 2020: HCL Notes 11.0.1 FP2 - Performance Boost Re-Reloaded
 
RNUG - HCL Notes 11.0.1 FP2 — Performance Boost Re-Reloaded
RNUG - HCL Notes 11.0.1 FP2 — Performance Boost Re-ReloadedRNUG - HCL Notes 11.0.1 FP2 — Performance Boost Re-Reloaded
RNUG - HCL Notes 11.0.1 FP2 — Performance Boost Re-Reloaded
 

More from ashish61_scs (20)

7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwo
 
Transactions
TransactionsTransactions
Transactions
 
22 levine
22 levine22 levine
22 levine
 
21 domino mohan-1
21 domino mohan-121 domino mohan-1
21 domino mohan-1
 
20 access paths
20 access paths20 access paths
20 access paths
 
19 structured files
19 structured files19 structured files
19 structured files
 
18 philbe replication stanford99
18 philbe replication stanford9918 philbe replication stanford99
18 philbe replication stanford99
 
17 wics99 harkey
17 wics99 harkey17 wics99 harkey
17 wics99 harkey
 
16 greg hope_com_wics
16 greg hope_com_wics16 greg hope_com_wics
16 greg hope_com_wics
 
15 bufferand records
15 bufferand records15 bufferand records
15 bufferand records
 
14 turing wics
14 turing wics14 turing wics
14 turing wics
 
14 scaleabilty wics
14 scaleabilty wics14 scaleabilty wics
14 scaleabilty wics
 
13 tm adv
13 tm adv13 tm adv
13 tm adv
 
11 tm
11 tm11 tm
11 tm
 
10b rm
10b rm10b rm
10b rm
 
10a log
10a log10a log
10a log
 
09 workflow
09 workflow09 workflow
09 workflow
 
08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick
 
06 07 lock
06 07 lock06 07 lock
06 07 lock
 
05 tp mon_orbs
05 tp mon_orbs05 tp mon_orbs
05 tp mon_orbs
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

2 shadowing

  • 1. 1/11/2012 1 2. Atomicity & Durability Using Shadow Paging CSEP 545 Transaction Processing for E-Commerce Philip A. Bernstein Copyright ©2012 Philip A. Bernstein
  • 2. 1/11/2012 2 Introduction • To get started on the Java-C# project, you need to implement atomicity and durability in a centralized resource manager (i.e. a database). • We recommend you use shadowing. • This section provides a quick introduction. – It’s described in the textbook: Chapter 7, Section 6. • A more thorough explanation of the overall topic of database recovery will be presented in a couple of weeks.
  • 3. 1/11/2012 3 Review of Atomicity & Durability • Atomicity - a transaction is all-or-nothing • Durability – the results of a committed transaction will survive failures • Problem – The only hardware operation that is atomic with respect to failure and whose result is durable is “write one disk block” – But the database doesn’t fit on one disk block!
  • 4. 1/11/2012 4 Shadowing in a Nutshell • The database is a tree whose root is a single disk block • There are two copies of the tree, the master and shadow • The root points to the master copy • Updates are applied to the shadow copy • To install the updates, overwrite the root so it points to the shadow, thereby swapping the master and shadow – Before overwriting the root, none of the transaction’s updates are part of the disk-resident database – After overwriting the root, all of the transaction’s updates are part of the disk-resident database – Which means the transaction is atomic and durable
  • 5. 1/11/2012 5 More Specifically … • The database consists of a set of files. • Each file F consists of a page table FPt and a set of pages that FPt points to. • A database root page points to each file’s master page table. • To start, assume that – Transactions run serially. I.e., at most one transaction runs at any given time. – For each page table, the transaction has a private shadow copy in main-memory.
  • 6. 1/11/2012 6 Initial State of Files A and B and Transaction Ti APt,i 1 2 3 ... BPt,i 1 2 3 ... a b A1APt,m 1 2 3 ... BPt,m 1 2 3 ... A2 B1 B2 Initial StateD I S K Main Memory For Ti DB root
  • 7. 1/11/2012 7 Without Recovery Support: Ti Overwrites A2 and B2 APt,i 1 2 3 ... BPt,i 1 2 3 ... a b A1APt,m 1 2 3 ... BPt,m 1 2 3 ... A2, new B1 B2, new Initial StateD I S K Main Memory For Ti DB root
  • 8. 1/11/2012 8 What Could Go Wrong? • Atomicity violation: A failure while Ti is running can leave the disk state as [A2,new , B2] or [A2 , B2,new] – Could be a failure of Ti or hardware or the OS • This could corrupt a multi-page data structure, making it unintelligible. • Even if the state is [A2,new , B2,new], readers can’t tell whether Ti completed. – If Ti completed, maybe it would have re-written one of those pages, or have written a third page B3
  • 9. 1/11/2012 9 To Write a Page P • Transaction writes a shadow copy of page P to disk (i.e. does not overwrite the master copy). • Transaction updates its page table for P’s file to point to the shadow copy of P. • Transaction marks P’s entry in the page table (to remember which pages were updated).
  • 10. 1/11/2012 10 After Writing Page B2 APt,i 1 2 3 ... BPt,i 1 2 3 ... a b A1APt,m 1 2 3 ... BPt,m 1 2 3 ... A2 B1 B2,old Initial StateD I S K Main Memory For Ti DB root  B2,new
  • 11. 1/11/2012 11 After Writing Page A1 APt,i 1 2 3 ... BPt,i 1 2 3 ... a b A1, oldAPt,m 1 2 3 ... BPt,m 1 2 3 ... A2 B1 B2,old Initial StateD I S K Main Memory For Ti DB root  B2,new A1, new 
  • 12. 1/11/2012 12 What if the System Fails? • Main memory is lost • The current transaction is effectively aborted • But the database is still consistent
  • 13. 1/11/2012 13 To Commit Ti 1. First copy APt,i and BPt,i to disk APt,i 1 2 3 ... BPt,i 1 2 3 ... a b A1, oldAPt,m 1 2 3 ... BPt,m 1 2 3 ... A2 B1 B2,old Initial StateD I S K DB root B2,new A1, new
  • 14. 1/11/2012 14 To Commit Ti (cont’d) 2. Then overwrite DB root to point to the new Pt’s. APt,i 1 2 3 ... BPt,i 1 2 3 ... a b A1, oldAPt,m 1 2 3 ... BPt,m 1 2 3 ... A2 B1 B2,old Initial StateD I S K DB root B2,new A1, new • This is the atomic hardware operation that commits Ti.
  • 15. 1/11/2012 15 • What if two transactions update different pages of a file? – If they share their main-memory shadow copy of the page table, then committing one will commit the other’s updates too! • One solution: File-grained locking (but poor concurrency). • Better solution: use a private shadow-copy of each page table, per transaction. To commit T, do the following within a critical section : – For each file F modified by T • Get a private copy C of last committed value of F’s page tbl. • Update C’s entries for pages modified by T. • Store C on disk. – Write a new master record, which swaps page tables for the files updated by T, thereby installing just T’s updates. Shadow Paging with Shared Files
  • 16. 1/11/2012 16 Managing Available Disk Space • Treat the list of available pages, Avail, like another file • The DB root points to the master Avail • When a transaction allocates a page, update its shadow Avail list • When a transaction commits, write a shadow copy of Avail to disk • Committing the transaction swaps the master Avail list and the shadow
  • 17. 1/11/2012 17 Final Remarks • A transaction doesn’t need to write shadow pages to disk until it is ready to commit – Saves disk writes if a transaction writes a page multiple times or if it aborts • Main benefit of shadow paging is that doesn’t require much code – Was used in the Gemstone OO DBMS (1980’s) • But it is not good for TPC benchmarks – How many disk updates per transaction? – How to do record level locking? • Most database products use logging. – Faster execution time, and more functional, but much more code.
  • 18. 1/11/2012 18 Your Project • You need not use the exact data structure presented here. • In particular, you don’t necessarily need a page abstraction. • There are design tradeoffs for you to figure out.
  • 19. 1/11/2012 19 References • Textbook, Section 7.6. • P. A. Bernstein, V. Hadzilacos, N. Goodman, Concurrency Control and Recovery in Database Systems, Chapter 6, Section 7 (pp. 201-204) – The book is downloadable from http://research.microsoft.com/pubs/ccontrol/ • Originally proposed by Raymond Lorie in “Physical Integrity in a Large Segmented Database”ACM Transactions on Database Systems, March 1977.