SlideShare a Scribd company logo
1 of 14
Download to read offline
Assignment 7 - Solution
Problem 1
Consider a system that uses persistent queues for requests and
replies, but where the queues do not support transactions.
Each queue simply supports the atomic operations:
• Enqueue(r)
• Dequeue(r)
• ReadTop(r) - non-destructive read of first element in queue.
Suppose the system adopts the three-transaction request-
processing model
• Txn1 enqueues a request,
• Txn2 executes a request and enqueues a reply,
• Txn3 dequeues a reply.
1
Problem 1A
Suggest an implementation of Txn2 such that each request
executes at least once.
1. Call ReadTop(r) to read request at top of queue
2. Run a transaction to process r.
3. After processing r, Dequeue it.
If the system stays up long enough, the top request will be
processed at least once. If there's a failure after the ReadTop and
before the Dequeue, then after recovery the request will be
processed a second time giving at-least-once semantics.
2
Problem 1B
Suggest another implementation of Txn2 such that each request
executes at most once.
1. Dequeue(r)
2. Run a transaction to process r.
If there's a failure that causes the latter transaction to abort, then
r may not be processed. But since it's dequeued only once, it will
be processed at most once.
3
Problem 1C
Suggest another implementation of Txn2 such that each request
executes exactly once, under the assumption that each
transaction executed by Txn2 is testable.
Call ReadTop(r).
IF r has already executed
(we can find out because the
transaction executed for r is testable),
THEN
dequeue(r),
ELSE
run a transaction to process r.
After transaction commits, dequeue(r).
4
Problem 2
Consider a system that uses persistent queues that do not support
transactions.
Each queue supports the atomic operations :
• Enqueue(r, qn) – enqueue r to end of queue qn,
• Dequeue(r, qn) – dequeue top from queue qn & return it in r,
• ReadTop(r, qn) - a non-destructive read of the first element in qn.
Suppose there is one single-threaded server that processes
requests from the request queue.
5
While (true) do {
Write(Last = 0);
// 0 is a value that is different from any request
StartTransaction;
ReadTop(r, RequestQueue);
s = ProcessRequest(r);
Write(Last = r);
Write(Reply = s);
Commit;
Enqueue(Reply, ReplyQueue);
Dequeue(x, RequestQueue);
}
6
In the above server program, Last and Reply are transactional data
items in stable storage.
Write operations on them are undone if the transaction that invokes
them aborts.
If the server fails, the values of local variables r, s, and x are lost.
After the server recovers, before restarting execution of the above
program it runs the following recovery program:
ReadTop(r, RequestQueue)
IF Last = r
THEN {
Dequeue(x, RequestQueue);
Enqueue(Reply, ReplyQueue)
}
7
Although the server fails occasionally, it is highly available.
Assume that ProcessRequest() supports transactions.
If its transaction aborts, it is undone as if it was never called.
8
Problem 2A.
The above programs ensure that for each request r, it is
processed exactly once, even in the presence of server failures
(assuming no other kinds of failures).
True.
If the containing transaction commits, ProcessRequest() is
executed and its reply is durable.
Recovery code ensures that it is not executed again.
If the containing transaction aborts, ProcessRequest() is
undone.
9
Problem 2B.
The above programs ensure that each reply is enqueued at
least once, even in the presence of server failures (assuming no
other kinds of failures).
False.
If the server fails during recovery after it dequeues x and before
it enqueues reply, it will never enqueue a reply.
Replies may be lost.
10
Problem 2C.
Atomic operation EnqueueDequeue(r, qn1, s, qn2) which
enqueues r on qn1 and dequeues top of qn2 and returns it in s.
In the server program, replace the last two lines by
EnqueueDequeue(s, ReplyQueue, x, RequestQueue).
In the recovery program, replace the then-clause by
EnqueueDequeue(Reply, ReplyQueue, x, RequestQueue).
Each reply is enqueued exactly once, even in the presence of
server failures (assuming no other kinds of failures).
True. Adding a reply is coupled with removing the
corresponding request in an atomic operation.
Exactly one reply is enqueued when the request dequeued.
11
Problem 3.
ProcessRequest() has side effects, and does not execute
atomically.
Problem 3A.
The above programs ensure that for each request r, it is
processed exactly once, even in the presence of server failures
(assuming no other kinds of failures).
False.
If the transaction containing ProcessRequest() aborts after the
call (for example we run out of disk space or hit a software
bug), and then the server crashes, then ProcessRequest() will
be called again after recovery.
12
Problem 3B.
The above programs ensure that each reply is enqueued at
least once, even in the presence of server failures (assuming no
other kinds of failures).
Same as problem 2B.
False.
If the server fails during recovery after it dequeues x and before
it enqueues reply, it will never enqueue a reply.
Replies may be lost.
13
Problem 3C.
Atomic operation EnqueueDequeue(r, qn1, s, qn2).
In the server program,
EnqueueDequeue(s, ReplyQueue, x, RequestQueue).
In the recovery program, replace the then-clause by
EnqueueDequeue(Reply, ReplyQueue, x, RequestQueue).
Each reply is enqueued exactly once, even in the presence of
server failures (assuming no other kinds of failures).
True.
Adding a reply is coupled with removing the corresponding
request in an atomic operation. Failures may cause a request to
be executed several times in ProcessRequest(r) generating
multiple replies. But exactly one reply is enqueued when the
request is dequeued.
14

More Related Content

What's hot

What's hot (19)

Operating System Process Synchronization
Operating System Process SynchronizationOperating System Process Synchronization
Operating System Process Synchronization
 
Distributed System Management
Distributed System ManagementDistributed System Management
Distributed System Management
 
OSCh7
OSCh7OSCh7
OSCh7
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Operating system NachOS
Operating system NachOSOperating system NachOS
Operating system NachOS
 
Unit iv: Deadlocks
Unit iv: DeadlocksUnit iv: Deadlocks
Unit iv: Deadlocks
 
p2 p grid
 p2 p grid  p2 p grid
p2 p grid
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
ExecuteAndWait Interceptor
ExecuteAndWait InterceptorExecuteAndWait Interceptor
ExecuteAndWait Interceptor
 
L09
L09L09
L09
 
Locks In Disributed Systems
Locks In Disributed SystemsLocks In Disributed Systems
Locks In Disributed Systems
 
Operating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphoresOperating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphores
 
Architecture
ArchitectureArchitecture
Architecture
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronization
 
Operating system Q/A
Operating system Q/AOperating system Q/A
Operating system Q/A
 
BIG DATA ANALYTICS
BIG DATA ANALYTICSBIG DATA ANALYTICS
BIG DATA ANALYTICS
 
Cpu scheduling qusetions
Cpu scheduling qusetionsCpu scheduling qusetions
Cpu scheduling qusetions
 
Analytical approximations of real-time systems with a single joint queue and ...
Analytical approximations of real-time systems with a single joint queue and ...Analytical approximations of real-time systems with a single joint queue and ...
Analytical approximations of real-time systems with a single joint queue and ...
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
 

Viewers also liked

Viewers also liked (11)

08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick
 
3 concurrency controlone_v3
3 concurrency controlone_v33 concurrency controlone_v3
3 concurrency controlone_v3
 
Project description2012
Project description2012Project description2012
Project description2012
 
10b rm
10b rm10b rm
10b rm
 
17 wics99 harkey
17 wics99 harkey17 wics99 harkey
17 wics99 harkey
 
9 queuing
9 queuing9 queuing
9 queuing
 
16 greg hope_com_wics
16 greg hope_com_wics16 greg hope_com_wics
16 greg hope_com_wics
 
2 shadowing
2 shadowing2 shadowing
2 shadowing
 
20 access paths
20 access paths20 access paths
20 access paths
 
1 introduction
1 introduction1 introduction
1 introduction
 
14 scaleabilty wics
14 scaleabilty wics14 scaleabilty wics
14 scaleabilty wics
 

Similar to Solution7.2012

Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
 
MapReduce.pptx
MapReduce.pptxMapReduce.pptx
MapReduce.pptxSheba41
 
Multi-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketMulti-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketStéphane Maldini
 
Priority based K-Erlang Distribution Method in Cloud Computing
Priority based K-Erlang Distribution Method in Cloud ComputingPriority based K-Erlang Distribution Method in Cloud Computing
Priority based K-Erlang Distribution Method in Cloud Computingidescitation
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesNirmalavenkatachalam
 
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxOS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxGovindJha93
 
Study Notes: Google Percolator
Study Notes: Google PercolatorStudy Notes: Google Percolator
Study Notes: Google PercolatorGao Yunzhong
 
Deadlock and Banking Algorithm
Deadlock and Banking AlgorithmDeadlock and Banking Algorithm
Deadlock and Banking AlgorithmMD.ANISUR RAHMAN
 
os distributed system theoretical foundation
os distributed system theoretical foundationos distributed system theoretical foundation
os distributed system theoretical foundationAnonymous9etQKwW
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OSC.U
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questionsESWARANM92
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questionsESWARANM92
 
Recursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & StructureRecursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & Structurecogaxor346
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)Rick Hightower
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)Rick Hightower
 

Similar to Solution7.2012 (20)

Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
MapReduce.pptx
MapReduce.pptxMapReduce.pptx
MapReduce.pptx
 
3 recursion
3 recursion3 recursion
3 recursion
 
3-Recursion.ppt
3-Recursion.ppt3-Recursion.ppt
3-Recursion.ppt
 
Multi-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketMulti-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocket
 
Priority based K-Erlang Distribution Method in Cloud Computing
Priority based K-Erlang Distribution Method in Cloud ComputingPriority based K-Erlang Distribution Method in Cloud Computing
Priority based K-Erlang Distribution Method in Cloud Computing
 
Sample final report
Sample final reportSample final report
Sample final report
 
Salesforce asynchronous apex
Salesforce asynchronous apexSalesforce asynchronous apex
Salesforce asynchronous apex
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxOS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
 
Study Notes: Google Percolator
Study Notes: Google PercolatorStudy Notes: Google Percolator
Study Notes: Google Percolator
 
Deadlock and Banking Algorithm
Deadlock and Banking AlgorithmDeadlock and Banking Algorithm
Deadlock and Banking Algorithm
 
os distributed system theoretical foundation
os distributed system theoretical foundationos distributed system theoretical foundation
os distributed system theoretical foundation
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OS
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
 
Recursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & StructureRecursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & Structure
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
 

More from ashish61_scs

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
 
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
 
15 bufferand records
15 bufferand records15 bufferand records
15 bufferand records
 
14 turing wics
14 turing wics14 turing wics
14 turing wics
 
13 tm adv
13 tm adv13 tm adv
13 tm adv
 
11 tm
11 tm11 tm
11 tm
 
10a log
10a log10a log
10a log
 
09 workflow
09 workflow09 workflow
09 workflow
 
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
 
04 transaction models
04 transaction models04 transaction models
04 transaction models
 
03 fault model
03 fault model03 fault model
03 fault model
 
02 fault tolerance
02 fault tolerance02 fault tolerance
02 fault tolerance
 
01 whirlwind tour
01 whirlwind tour01 whirlwind tour
01 whirlwind tour
 
Solution5.2012
Solution5.2012Solution5.2012
Solution5.2012
 
Solution6.2012
Solution6.2012Solution6.2012
Solution6.2012
 

Solution7.2012

  • 1. Assignment 7 - Solution Problem 1 Consider a system that uses persistent queues for requests and replies, but where the queues do not support transactions. Each queue simply supports the atomic operations: • Enqueue(r) • Dequeue(r) • ReadTop(r) - non-destructive read of first element in queue. Suppose the system adopts the three-transaction request- processing model • Txn1 enqueues a request, • Txn2 executes a request and enqueues a reply, • Txn3 dequeues a reply. 1
  • 2. Problem 1A Suggest an implementation of Txn2 such that each request executes at least once. 1. Call ReadTop(r) to read request at top of queue 2. Run a transaction to process r. 3. After processing r, Dequeue it. If the system stays up long enough, the top request will be processed at least once. If there's a failure after the ReadTop and before the Dequeue, then after recovery the request will be processed a second time giving at-least-once semantics. 2
  • 3. Problem 1B Suggest another implementation of Txn2 such that each request executes at most once. 1. Dequeue(r) 2. Run a transaction to process r. If there's a failure that causes the latter transaction to abort, then r may not be processed. But since it's dequeued only once, it will be processed at most once. 3
  • 4. Problem 1C Suggest another implementation of Txn2 such that each request executes exactly once, under the assumption that each transaction executed by Txn2 is testable. Call ReadTop(r). IF r has already executed (we can find out because the transaction executed for r is testable), THEN dequeue(r), ELSE run a transaction to process r. After transaction commits, dequeue(r). 4
  • 5. Problem 2 Consider a system that uses persistent queues that do not support transactions. Each queue supports the atomic operations : • Enqueue(r, qn) – enqueue r to end of queue qn, • Dequeue(r, qn) – dequeue top from queue qn & return it in r, • ReadTop(r, qn) - a non-destructive read of the first element in qn. Suppose there is one single-threaded server that processes requests from the request queue. 5
  • 6. While (true) do { Write(Last = 0); // 0 is a value that is different from any request StartTransaction; ReadTop(r, RequestQueue); s = ProcessRequest(r); Write(Last = r); Write(Reply = s); Commit; Enqueue(Reply, ReplyQueue); Dequeue(x, RequestQueue); } 6
  • 7. In the above server program, Last and Reply are transactional data items in stable storage. Write operations on them are undone if the transaction that invokes them aborts. If the server fails, the values of local variables r, s, and x are lost. After the server recovers, before restarting execution of the above program it runs the following recovery program: ReadTop(r, RequestQueue) IF Last = r THEN { Dequeue(x, RequestQueue); Enqueue(Reply, ReplyQueue) } 7
  • 8. Although the server fails occasionally, it is highly available. Assume that ProcessRequest() supports transactions. If its transaction aborts, it is undone as if it was never called. 8
  • 9. Problem 2A. The above programs ensure that for each request r, it is processed exactly once, even in the presence of server failures (assuming no other kinds of failures). True. If the containing transaction commits, ProcessRequest() is executed and its reply is durable. Recovery code ensures that it is not executed again. If the containing transaction aborts, ProcessRequest() is undone. 9
  • 10. Problem 2B. The above programs ensure that each reply is enqueued at least once, even in the presence of server failures (assuming no other kinds of failures). False. If the server fails during recovery after it dequeues x and before it enqueues reply, it will never enqueue a reply. Replies may be lost. 10
  • 11. Problem 2C. Atomic operation EnqueueDequeue(r, qn1, s, qn2) which enqueues r on qn1 and dequeues top of qn2 and returns it in s. In the server program, replace the last two lines by EnqueueDequeue(s, ReplyQueue, x, RequestQueue). In the recovery program, replace the then-clause by EnqueueDequeue(Reply, ReplyQueue, x, RequestQueue). Each reply is enqueued exactly once, even in the presence of server failures (assuming no other kinds of failures). True. Adding a reply is coupled with removing the corresponding request in an atomic operation. Exactly one reply is enqueued when the request dequeued. 11
  • 12. Problem 3. ProcessRequest() has side effects, and does not execute atomically. Problem 3A. The above programs ensure that for each request r, it is processed exactly once, even in the presence of server failures (assuming no other kinds of failures). False. If the transaction containing ProcessRequest() aborts after the call (for example we run out of disk space or hit a software bug), and then the server crashes, then ProcessRequest() will be called again after recovery. 12
  • 13. Problem 3B. The above programs ensure that each reply is enqueued at least once, even in the presence of server failures (assuming no other kinds of failures). Same as problem 2B. False. If the server fails during recovery after it dequeues x and before it enqueues reply, it will never enqueue a reply. Replies may be lost. 13
  • 14. Problem 3C. Atomic operation EnqueueDequeue(r, qn1, s, qn2). In the server program, EnqueueDequeue(s, ReplyQueue, x, RequestQueue). In the recovery program, replace the then-clause by EnqueueDequeue(Reply, ReplyQueue, x, RequestQueue). Each reply is enqueued exactly once, even in the presence of server failures (assuming no other kinds of failures). True. Adding a reply is coupled with removing the corresponding request in an atomic operation. Failures may cause a request to be executed several times in ProcessRequest(r) generating multiple replies. But exactly one reply is enqueued when the request is dequeued. 14