0% found this document useful (0 votes)
13 views22 pages

Dos 6

Uploaded by

Asmit Patnaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views22 pages

Dos 6

Uploaded by

Asmit Patnaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

DOS 6.

Atomic Transactions in
distributed system
Introduction to Atomic transactions

‘Atomic transaction’.

As an example, consider a process announces that it wants to begin a transaction with one or
more processes. They can add/delete objects or perform tasks for some time. Then the initiator
process wants all other processes to commit themselves to the work done so far. If all of them
agree, the results are made permanent else if any one of them disagree or crashes then the
situation goes back to exactly the state it was before the transaction began.
Consider an online banking application that updates an online database. The
customer needs to withdraw money from one account and deposit it into another
account.

The operation is done in 2 ways:

• Withdraw (amount, account 1)


• Deposit (amount, account 2)

Being able to group these 2 operations in an atomic transaction would solve the
problem. Either both would be completed or none of them. The main thing is to
roll back the transaction to the initial state if the transaction fails to complete.
Transaction model

• RAM memory which is wiped out when power fails or system crashes.
• Disk storage which survive CPU failures but can be lost in disk head crashes.
• Stable storage can survive anything except major calamities like earthquake.
Ø Stable storage can be inplemented with a pair of ordinary disks.

Ø Each block on drive 2 is an exact copy of the corresponding block on drive 1. When a block is updated,
first the block on drive 1 is updated & verified then the block on drive 2 is done.

Ø Suppose the system crashes after drive 1 is updated but before drive 2 is updated. Upon recovery, the
disk can be compared block for block. Whenever 2 corresponding blocks differ, it can be assumed that
drive 1 is the correct one (bcoz drive 1 is always updated before drive 2).

Ø When the recovery process is complete, both drives will be again identical.

Ø Also, a problem happens due to spontaneous decay of the block. Dust or general wear & tear can give a
block sudden checksum error without any warning. When such an error is detected then the bad block
can be regenerated from the corresponding block in drive 1.
Transaction primitives

rollback
determine the
bound of)
Transaction properties
Atomic property

Consistent property

Isolation property

Durability property
Ø When a node synchronizes its clock to that of another node, it is generally a good idea to take previous
measurements into account as well. Why? Also, give an example of how such past readings could be taken
into account.
v The reason is that there may be an error in the current reading. Assuming that clocks need only be gradually
adjusted, one possibility is to consider the last N values and compute a median or average. If the measured
value falls outside a current interval, it is not taken into account (but is added to the list). Likewise, a new
value can be computed by taking a weighted average, or an aging algorithm.

Ø Many distributed algorithms require the use of a coordinating process. To what extent can such algorithms
actually be considered distributed? Discuss.
v In a centralized algorithm, there is often one, fixed process that acts as coordinator. Distribution comes from
the fact that the other processes run on different machines. In distributed algorithms with a nonfixed
coordinator, the coordinator is chosen (in a distributed fashion) among the processes that form part of the
algorithm. The fact that there is a coordinator does not make the algorithm less distributed.
Ø Consider a procedure incr with two integer parameters. The procedure adds one to each parameter. Now
suppose that it is called with the same variable twice, for example, as incr(i, i). If i is initially 0, what value
will it have afterward if call-by-reference is used? How about if copy is used?
v If call by reference is used, a pointer to i is passed to incr. It will be incremented two times, so the final
result will be two. However, with copy, i will be passed by value twice, each value initially 0. Both will be
incremented, so both will now be 1. Now both will be copied back, with the second copy overwriting the
first one. The final value will be 1, not 2

Ø Suppose that in a sensor network measured temperatures are not timestamped by the sensor, but are
immediately sent to the operator. Would it be enough to guarantee only a maximum end-to-end delay?
v Not really if we assume that the operator would still need to know when the measurement took place. In
this case, a timestamp can be attached when the measurement is received.

Ø Consider the behavior of two machines in a distributed system. Both have clocks that are supposed to tick
1000 times per millisecond. One of them actually does, but the other ticks only 990 times per millisecond.
If UTC updates come in once a minute, what is the maximum clock skew that will occur?
v The second clock ticks 990,000 times per second, giving an error of 10 msec per second. In a minute this
error has grown to 600 msec.
Ø Name at least three sources of delay that can be introduced between WWV broadcasting the time and
the processors in a distributed system setting their internal clocks.
v First we have signal propagation delay in the atmosphere. Second we might have collision delay while the
machines with the WWV receivers fight to get on the Ethernet. Third, there is packet propagation delay
on the LAN. Fourth, there is delay in each processor after the packet arrives, due to interrupt processing
and internal queueing delays.

Ø How could you guarantee a maximum end-to-end delay when a collection of computers is organized in a
(logical or physical) ring?
v We let a token circulate the ring. Each computer is permitted to send data across the ring (in the same
direction as the token) only when holding the token. Moreover, no computer is allowed to hold the token
for more than T seconds. Effectively, if we assume that communication between two adjacent computers
is bounded, then the token will have a maximum end-to-end delay for each packet sent.
Nested Transactions

Nested Transactions.

q Problem with sub-transactions:::::::

Assume that a transaction starts many sub-transactions in parallel & one of those commits making its
results visible to the parent transcation. But after further computation, the parent aborts. It thus
restores the entire system to the state it was before the top level transaction started. So, the results of
the sub-transaction must be undone. Hence, this situation applies only to top level transactions.
SINGLE POINT OF FAILURE
Ø When any transaction or sub-transaction starts, it is given a
private copy of all objects in the entire system for it to manipulate.
Ø If it aborts, its private copy vanishes as if it never existed.
Ø If it commits, its private copy replaces its parent copy.
Transactions Implementation issues

v Private workspace
v Writeahead log
Private workspace:::::

1st method is that when a process reads a file but does not modify it there is no need for a private
copy. When a process starts a transaction, it is sufficient to create a private workspace for it that is
empty except for a pointer back to its parent workspace. When the process opens a file for reading, the
back pointers are followed until the file is located in the parent’s workspace. When a process opens a
file for writing, it can be located in the same way as for reading except that now it is copied to the
private workspace.
2nd method removes most of the copying instead only the file’s index is copied into the private
workspace. The index is the data block associated with each file telling where the disk blocks are. Here
when a file block is first modified, a copy of the block is made & the address of the copy is inserted into
the index. The block can then be updated without affecting the original. The new blocks are called
Shadow blocks.
Writeahead log:::::

You might also like