SlideShare a Scribd company logo
1 of 5
Download to read offline
lastTrans = 1;
int start()
{
if (lastTrans < 0) { return -1 }
else
{
lastTrans = -(++lastTrans);
return lastTrans
}
}
Assignment 1, Code
• As background to review the solution
1/11/2012 CSEP 545 1
int read(int diskBlockAddr, int tId, int *memBlock)
{
/* find the cache element e containing the block whose
disk address is diskBlockAddr */
if (there is such a cache element e) {
/* the disk block at diskBlockAddr is in cache */
Cache(e).tId = tId;
memBlock = &Cache(e).newBlock;
/* &Cache(e).newBlock = address of Cache(e).newBlock */
return 0
}
else {
/* pick a cache entry e, where Cache(e).tId = 0.
If there is no such entry, then return -1 */
status = diskRead(diskBlockAddr, &Cache(e).oldBlock);
if(status != 0) {return -1};
Cache(e).newBlock = Cache(e).oldBlock;
memBlock = &Cache(e).newBlock;
Cache(e).diskBlockAddr = diskBlockAddr;
Cache(e).tId = tId;
return 0
}
}1/11/2012 CSEP 545 2
/* A transaction should call
write(&Cache(e).newBlock, tId)
after it updates Cache(e).newBlock. */
int write(int diskBlockAddr, int tId)
{
/* find cache entry e for block diskBlockAddr */
if (there is no such entry) { return 0 }
else
{
Cache(e).tId = tId;
return 1
}
}
1/11/2012 CSEP 545 3
int commit(int tId)
{
for (each cache entry e where Cache(e).tId == tId)
{
status = diskWrite(Cache(e).diskBlockAddr,
&Cache(e).newBlock);
Cache(e).tId = - tId;
if (status == -1) {
Abort(tId);
return -1
}
Cache(e).oldBlock = Cache(e).newBlock
}
for (each cache entry e where Cache(e).tId == -tId){
Cache(e).tId = 0
}
lastTrans = -lastTrans;
return 0
}
1/11/2012 CSEP 545 4
int abort(int tId)
{
for (all cache entries e, where Cache(e).tId == -tId)
{
repeat
{
status = diskWrite(Cache(e).diskBlockAddr,
&Cache(e).oldBlock)
} until (status == 0);
/* Of course, this will not terminate if diskWrite
keeps failing, but ignore that issue */
Cache(e).newBlock = Cache(e).oldBlock
}
for (all cache entries e) {
Cache(e).tId = 0
}
lastTrans = -lastTrans;
return 0
}
1/11/2012 CSEP 545 5

More Related Content

What's hot

Correcting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await MistakesCorrecting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await MistakesBrandon Minnick, MBA
 
Scalable Socket Server by Aryo
Scalable Socket Server by AryoScalable Socket Server by Aryo
Scalable Socket Server by AryoAgate Studio
 
ReactiveMongo - non blocking and asynchronous I/O operations
ReactiveMongo - non blocking and asynchronous I/O operationsReactiveMongo - non blocking and asynchronous I/O operations
ReactiveMongo - non blocking and asynchronous I/O operationsDavid Pichsenmeister
 
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session 병완 임
 
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Arian Gutierrez
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisKnoldus Inc.
 
Reactive Quarkus – A Java Mutiny! | DevNation Tech Talk
Reactive Quarkus – A Java Mutiny! | DevNation Tech TalkReactive Quarkus – A Java Mutiny! | DevNation Tech Talk
Reactive Quarkus – A Java Mutiny! | DevNation Tech TalkRed Hat Developers
 
The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180Mahmoud Samir Fayed
 
Node.js and angular js
Node.js and angular jsNode.js and angular js
Node.js and angular jsHyungKuIm
 
The Ring programming language version 1.6 book - Part 71 of 189
The Ring programming language version 1.6 book - Part 71 of 189The Ring programming language version 1.6 book - Part 71 of 189
The Ring programming language version 1.6 book - Part 71 of 189Mahmoud Samir Fayed
 
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki LinnakangasPG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangaspgdayrussia
 

What's hot (16)

Correcting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await MistakesCorrecting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await Mistakes
 
Scalable Socket Server by Aryo
Scalable Socket Server by AryoScalable Socket Server by Aryo
Scalable Socket Server by Aryo
 
ReactiveMongo - non blocking and asynchronous I/O operations
ReactiveMongo - non blocking and asynchronous I/O operationsReactiveMongo - non blocking and asynchronous I/O operations
ReactiveMongo - non blocking and asynchronous I/O operations
 
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
 
MIDP: Persistant Storage
MIDP: Persistant StorageMIDP: Persistant Storage
MIDP: Persistant Storage
 
Ac2
Ac2Ac2
Ac2
 
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
 
Circuit breaker
Circuit breakerCircuit breaker
Circuit breaker
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Reactive Quarkus – A Java Mutiny! | DevNation Tech Talk
Reactive Quarkus – A Java Mutiny! | DevNation Tech TalkReactive Quarkus – A Java Mutiny! | DevNation Tech Talk
Reactive Quarkus – A Java Mutiny! | DevNation Tech Talk
 
The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180
 
Node.js and angular js
Node.js and angular jsNode.js and angular js
Node.js and angular js
 
Vcs24
Vcs24Vcs24
Vcs24
 
The Ring programming language version 1.6 book - Part 71 of 189
The Ring programming language version 1.6 book - Part 71 of 189The Ring programming language version 1.6 book - Part 71 of 189
The Ring programming language version 1.6 book - Part 71 of 189
 
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki LinnakangasPG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
 
Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 

Viewers also liked

Viewers also liked (13)

05 tp mon_orbs
05 tp mon_orbs05 tp mon_orbs
05 tp mon_orbs
 
10a log
10a log10a log
10a log
 
Transactions
TransactionsTransactions
Transactions
 
Dynamic Power of QFT - Copy
Dynamic Power of QFT - CopyDynamic Power of QFT - Copy
Dynamic Power of QFT - Copy
 
21 domino mohan-1
21 domino mohan-121 domino mohan-1
21 domino mohan-1
 
03 fault model
03 fault model03 fault model
03 fault model
 
MarkH-CV 2015
MarkH-CV 2015MarkH-CV 2015
MarkH-CV 2015
 
pics
picspics
pics
 
4G MOBILE COMMUNICATION SYSTEM
4G MOBILE COMMUNICATION SYSTEM4G MOBILE COMMUNICATION SYSTEM
4G MOBILE COMMUNICATION SYSTEM
 
Solution5.2012
Solution5.2012Solution5.2012
Solution5.2012
 
15 bufferand records
15 bufferand records15 bufferand records
15 bufferand records
 
UPDATED INTERVIEW GUIDE
UPDATED INTERVIEW GUIDEUPDATED INTERVIEW GUIDE
UPDATED INTERVIEW GUIDE
 
Emerging Trends and Tech
Emerging Trends and TechEmerging Trends and Tech
Emerging Trends and Tech
 

More from ashish61_scs

More from ashish61_scs (20)

7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwo
 
22 levine
22 levine22 levine
22 levine
 
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
 
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
 
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
 
04 transaction models
04 transaction models04 transaction models
04 transaction models
 
02 fault tolerance
02 fault tolerance02 fault tolerance
02 fault tolerance
 
01 whirlwind tour
01 whirlwind tour01 whirlwind tour
01 whirlwind tour
 
Solution6.2012
Solution6.2012Solution6.2012
Solution6.2012
 
Solution7.2012
Solution7.2012Solution7.2012
Solution7.2012
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
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...christianmathematics
 
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.pdfAdmir Softic
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
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...
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

Assignment1.2012

  • 1. lastTrans = 1; int start() { if (lastTrans < 0) { return -1 } else { lastTrans = -(++lastTrans); return lastTrans } } Assignment 1, Code • As background to review the solution 1/11/2012 CSEP 545 1
  • 2. int read(int diskBlockAddr, int tId, int *memBlock) { /* find the cache element e containing the block whose disk address is diskBlockAddr */ if (there is such a cache element e) { /* the disk block at diskBlockAddr is in cache */ Cache(e).tId = tId; memBlock = &Cache(e).newBlock; /* &Cache(e).newBlock = address of Cache(e).newBlock */ return 0 } else { /* pick a cache entry e, where Cache(e).tId = 0. If there is no such entry, then return -1 */ status = diskRead(diskBlockAddr, &Cache(e).oldBlock); if(status != 0) {return -1}; Cache(e).newBlock = Cache(e).oldBlock; memBlock = &Cache(e).newBlock; Cache(e).diskBlockAddr = diskBlockAddr; Cache(e).tId = tId; return 0 } }1/11/2012 CSEP 545 2
  • 3. /* A transaction should call write(&Cache(e).newBlock, tId) after it updates Cache(e).newBlock. */ int write(int diskBlockAddr, int tId) { /* find cache entry e for block diskBlockAddr */ if (there is no such entry) { return 0 } else { Cache(e).tId = tId; return 1 } } 1/11/2012 CSEP 545 3
  • 4. int commit(int tId) { for (each cache entry e where Cache(e).tId == tId) { status = diskWrite(Cache(e).diskBlockAddr, &Cache(e).newBlock); Cache(e).tId = - tId; if (status == -1) { Abort(tId); return -1 } Cache(e).oldBlock = Cache(e).newBlock } for (each cache entry e where Cache(e).tId == -tId){ Cache(e).tId = 0 } lastTrans = -lastTrans; return 0 } 1/11/2012 CSEP 545 4
  • 5. int abort(int tId) { for (all cache entries e, where Cache(e).tId == -tId) { repeat { status = diskWrite(Cache(e).diskBlockAddr, &Cache(e).oldBlock) } until (status == 0); /* Of course, this will not terminate if diskWrite keeps failing, but ignore that issue */ Cache(e).newBlock = Cache(e).oldBlock } for (all cache entries e) { Cache(e).tId = 0 } lastTrans = -lastTrans; return 0 } 1/11/2012 CSEP 545 5