SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Scalable Socket Server by Aryo
Scalable Socket Server by AryoScalable Socket Server by Aryo
Scalable Socket Server by Aryo
Agate Studio
 
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
 

Was ist angesagt? (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
 

Andere mochten auch

Dynamic Power of QFT - Copy
Dynamic Power of QFT - CopyDynamic Power of QFT - Copy
Dynamic Power of QFT - Copy
Jacques Benoit
 
UPDATED INTERVIEW GUIDE
UPDATED INTERVIEW GUIDEUPDATED INTERVIEW GUIDE
UPDATED INTERVIEW GUIDE
Khang Vang
 

Andere mochten auch (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
 

Mehr von 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
 

Kürzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Kürzlich hochgeladen (20)

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
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
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
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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...
 

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