You are on page 1of 11

dfghjklzxcvbnmqwertyuiopasdfg

hjklzxcvbnmqwertyuiopasdfghjkl
zxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmq
ASSIGNMENT NO 4
Submitted to: Chavi Mam

wertyuiopasdfghjklzxcvbnmqwer
Submitted By:-
Yogesh Gandhi
10808452
RC2801B48

tyuiopasdfghjklzxcvbnmqwertyu
iopasdfghjklzxcvbnmqwertyuiop
asdfghjklzxcvbnmrtyuiopasdfghj
klzxcvbnmqwertyuiopasdfghjklz
xcvbnmqwertyuiopasdfghjklzxcv
bnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwer
tyuiopasdfghjklzxcvbnmqwertyu
iopasdfghjklzxcvbnmqwertyuiop
asdfghjklzxcvbnmqwertyuiopasd
ANS 1
Two Phase Locking Protocol (2PL):

The Two Phase Locking Protocol ensures Serializability. This protocol requires that
each transaction issue lock and unlock requests in two phases:

1. Growing Phase:

A transaction may obtain locks but may not release any lock.

2. Shrinking Phase:

A transaction may release locks but may not obtain any new locks.

A transaction is said to follow Two Phase Locking Protocol if all locking operations
precede the first unlock operation in a transaction. In other words release of locks on all data
items required by the transaction have been acquired both the phases discussed earlier are
monotonic. The number of locks are decreasing in the 2nd phase. Once a transaction starts to
request any further locks.

Transaction T1 shown in Figure 1 below transfers $50 from account B to account A


and transaction T2 in next Figure 2 displays the total amount of money in account A and B.

Figure 1:

T1 : Lock_X (B);

Read (B);

B := B – 50;

Write (B);

Unlock (B);

Lock_X (A);

Read (A);

A := A + 50;

Write (A);

Unlock (A);
Figure 2:

T2: Lock_S (A);

Read (A);

Unlock (A);

Lock_S (B);

Read (B);

Unlock (B);

Display (A + B);

Both the above transaction T1 and T2 do not follow Two Phase Locking Protocol.
However transactions T3 and T4 (shown below) are in two phase.

T3: Lock_X (B);

Read (B);

B := B – 50;

Write (B);

Lock_X (A);

Read (A);

A := A + 50;

Write (A);

Unlock (A);

Unlock (B);

T4: Lock_S (A);

Read (A);

Lock_S (B);

Read (B);
Display (A + B);

Unlock (A);

Unlock (B)

ANS:-2 Timestamp-ordering Protocol

• Suppose Ti executes write(Q)


o If TS(Ti) < R-timestamp(Q), value Q produced by Ti was needed previously
and Ti assumed it would never be produced
 Write operation rejected, Ti rolled back
o If TS(Ti) < W-tiimestamp(Q), Ti attempting to write obsolete value of Q
 Write operation rejected and Ti rolled back
o Otherwise, write executed
• Any rolled back transaction Ti is assigned new timestamp and restarted
• Algorithm ensures conflict serializability and freedom from deadlock

ANS:-3 Deadlock:

A system is in a deadlock state if there exists a set of transactions such that every
transaction in the set in waiting for another transaction in the set.

There exists a set of waiting transactions {T0, T1,…….Tn} such that T0 is waiting for
data item that is held by T1, T1 is waiting for a data item that is held by T2, Tn-1 is waiting
for a data item that is held by Tn, and Tn is waiting for a data item that is held by T0. None of
the transactions can make progress in such a situation.

Deadlock Prevention:

A deadlock can be prevented by following two commonly used schemes:

1. Wait-Die Scheme:

This scheme is based on a non preemptive technique.

When a transaction Ti requests a data item currently held by Tj, Ti is allowed to wait
only if it has a timestamp smaller than that of Tj (i.e. Ti is older than Tj) i.e. if the requesting
transaction is older than the transaction that holds the lock on the requesting transaction is
allowed to wait.
If the requesting transaction is younger than the transaction that holds the lock
requesting transaction is aborted and rolled back.

For example: suppose that transaction T22, T23 and T24 have timestamps 5, 10 and
15 respectively. If T22 requests a data item held by T23, then T22 will wait. If T24 requests a
data item held by T23, then T24 will be rolled back.

T22 Wait T23 Die T24

2. Wound-Wait Scheme:

This scheme is based on a preemptive technique and is a counter part to the wait-die
scheme when transaction Ti requests a data item currently held by Tj, Ti, is allowed to wait
only if it has a timestamp larger than that of Tj (i.e. Ti is younger than Tj). Otherwise, Tj is
rolled back (Tj is wounded by Ti).

i.e. if a younger transaction requests a data item held by an older transaction, the
younger transaction is allowed to wait.

If a younger transaction holds a data item requested by an older one, the younger
transaction is the one that would be aborted and rolled back. (i.e. younger transaction is
wounded by an older transaction and dies)

Considering example given for wait-die scheme, if T22 requests a data itme held by
T23, then the data item will be preempted from T23, and T23 will be rolled back if T24
requests a dta item held by T23, then T24 will wait.

T23
T22

Aborted and Rolled Back


T22 T22

Allowed to wait

Deadlock detection:

A deadlock can be detected by following two common mechanisms:

1. Wait for graph:

A deadlock is said to occur when there is a circular chain of transactions each waiting
for the release of the data item held by the next transaction in the chain. The algorithm to
detect a deadlock is based on the detection of such circular chain in the current system for
Graph.

The wait for graph consist of a pair G = (V, E) where V is a set of vertices which
represents all the transactions in the system.

E is the set of edges where each element is an ordered pair Ti  Tj (which implies
that transaction Ti is waiting for transaction Tj to release a data item that it needs).

A deadlock exists in the system if only if the wait for graph contains a cycle. If there
is no cycle there is no deadlock.

2. TIMEOUT MECHANISM:

If transaction has been waiting for too long for a lock we assume it is in a deadlock.
So this cycle is aborted after a fixed interval of time that is pre set in the system.

ANS:-4 Deferred Database Modification

The deferred-modification technique ensures transaction atomicity by recording all database


modifications in the log, but deferring all write operations of a transaction until the
transaction partially commits (i.e., once the final action of the transaction has been executed).
Then the information in the logs is used to execute the deferred writes. If the system crashes
or if the transaction aborts, then the information in the logs is ignored.

Immediate Database Modification

The immediate-update technique allows database modifications to be output to the database


while the transaction is still in the active state. These modifications are called uncommitted
modifications. In the event of a crash or transaction failure, the system must use the old-value
field of the log records to restore the modified data items.

Checkpoints

When a system failure occurs, we must consult the log to determine those transactions that
need to be redone and those that need to be undone. Rather than reprocessing the entire log,
which is time-consuming and much of it unnecessary, we can use checkpoints:

1. Output onto stable storage all the log records currently residing in main memory.
2. Output to the disk all modified buffer blocks.
3. Output onto stable storage a log record, <checkpoint>.

Now recovery will be to only process log records since the last checkpoint record.

ANS:-5 Shadow Paging

The ideas proposed for implementing transactions are prefectly workable, but such an
approach would not likely be implemented in a modern system. Instead a disk block
transaction technique would more likely be used. This saves much messing around with little
pieces of information, while maintaining disk order and disk clustering.

Disk clustering is when all the data which a query would want has been stored close together
on the disk. In this way when a query is executed the DBMS can simple "scoop" up a few
tracks from the disk and have all the data it needs to complete the query. Without clustering,
the disk may have to move over the whole disk surface looking for bits of the query data, and
this could be hundreds of times slower than being able to get it all at once. Most DBMS
systems perform clustering techniques, either user-directed or automatically.

With shadow paging, transaction logs do not hold the attributes being changed but a copy of
the whole disk block holding the data being changed. This sounds expensive, but actually is
highly efficient. When a transaction begins, any changes to disk follow the following
procedure:

1. If the disk block to be changed has been copied to the log already, jump to 3.
2. Copy the disk block to the transaction log.
3. Write the change to the original disk block.
On a commit the copy of the disk block in the log can be erased. On an abort all the blocks in
the log are copied back to their old locations. As disk access is based on disk blocks, this
process is fast and simple. Most DBMS systems will use a transaction mechanism based on
shadow paging.

Shadow Paging

Shadow paging is an alternative to log-based recovery techniques, which has both advantages
and disadvantages. It may require fewer disk accesses, but it is hard to extend paging to allow
multiple concurrent transactions. The paging is very similar to paging schemes used by the
operating system for memory management.

The idea is to maintain two page tables during the life of a transaction: the current page table
and the shadow page table. When the transaction starts, both tables are identical. The shadow
page is never changed during the life of the transaction. The current page is updated with
each write operation. Each table entry points to a page on the disk. When the transaction is
committed, the shadow page entry becomes a copy of the current page table entry and the
disk block with the old data is released. If the shadow is stored in nonvolatile memory and a
system crash occurs, then the shadow page table is copied to the current page table. This
guarantees that the shadow page table will point to the database pages corresponding to the
state of the database prior to any transaction that was active at the time of the crash, making
aborts automatic.

There are drawbacks to the shadow-page technique:

• Commit overhead. The commit of a single transaction using shadow paging requires
multiple blocks to be output -- the current page table, the actual data and the disk
address of the current page table. Log-based schemes need to output only the log
records.
• Data fragmentation. Shadow paging causes database pages to change locations
(therefore, no longer contiguous.
• Garbage collection. Each time that a transaction commits, the database pages
containing the old version of data changed by the transactions must become
inaccessible. Such pages are considered to be garbage since they are not part of the
free space and do not contain any usable information. Periodically it is necessary to
find all of the garbage pages and add them to the list of free pages. This process is
called garbage collection and imposes additional overhead and complexity on the
system.

ANS:-6

STEPS IN CONCURRENCY CONTROL

1. When this application is called by the main DBMS system (in this case it is called by
Query Processor), an input string is passed to it. This input string is in this form:

T2 , Obj1 , REQ_SHARED , COMMIT


T1 , Obj1 , REQ_EXCLUSIVE , COMMIT

T1 , Obj1 , REQ_SHARED , NO_COMMIT

2. Concurrency control sub-system reads the above mentioned input string and responds
to it. i.e.
a) The first attribute which represents the transaction id.
b) The next attribute (i.e. Obj1) represents the object to be locked.
c) The next attribute (i.e. REQ_LockType) represents the type of lock to be
implemented.
d) And finally the COMMIT tells to release all locks and give control to Query
Processor.

3. Firstly the sub-system will implement the lock requested by the input string.
4. If Share lock is requested it will allot it by checking various conditions for it. If
possible it will grant the request and update the lock table.
5. If Exclusive lock is requested then again it will check for all the conditions associated
with it and then grant it if possible and update the lock table.
6. If the locks cannot be granted it is put in a Lock Queue and recalls the transactions
when the conditions are favourable for it.
7. When the transaction is over and ready to commit it releases all the locks it has taken
and updates the lock table.
8. If the transaction fails i.e. an error occurs it prompts the Query Processor for it and
asks for retransmitting the input queue.
9. The system continuously gets the status of the transactions and locks implemented
from the transaction table which displays the output on the screen continuously.
10. The reload lock table command refreshes the output to the main screen.
11. The updated copy of the lock table is displayed every time a new window is opened or
a new user try to execute some transactions.

Worms, unlike viruses, have self-propagating engines. What this means is while a virus needs
a person to activate it (thus giving it the capability to spread), worms can do this without any
human interaction.
This is how worms cause such a large amount of damage. They spread by themselves and
unleash their payload on every computer they infect. This leads to another question: how do
worms spread themselves???
Excellent question! Worms can do this in a variety of ways. With the worms we have
analyzed (as well as the popular ones you see in the news), they primarily spread in the
following ways:

· Email address harvesting: When a worm infects your system, it will check a
variety of file types on your computer for additional email addresses to send itself to.
The main file types that worms look for in email addresses are files with .doc
(Microsoft Word documents), .txt (Notepad files), .htm and .html (both are
webpages) extensions.
· Same-domain search engine queries: Once a worm infects your system, it will
determine what domain your computer is on. Once it figures this out, the worm will
actually use popular search engines such as Google and Yahoo to search for
additional email addresses that match your domain name.

Want to figure out what domain your computer is on? Do the following:

· Click Start, then Run...


· In the new window that opens, type "cmd" (without the quotes) and click OK
· When the black box opens, type "ipconfig" (without the quotes) and hit Enter
· The value to the right of "Connection-specific DNS Suffix" is the domain your
computer resides on
· Once you discovered the domain your computer is on, type "exit" (without the
quotes) and hit Enter

Think that worms are smart? Unfortunately, they are even smarter than you think. Now, you
would think once worms find additional email addresses to send itself to, it would just send
the exact same email to every email address... we wish that were true. Worms are developed
with what you could consider an email generator. Every email that is sent through the worm
can have a combination of a randomized Sender, Subject, Email Attachment (both the
attachment name and its extension), and Body. Since everything can be randomized except
your email address, it makes it very difficult to spot a worm. Kinda gives you a new
perspective of opening junk mail, doesn't it!

Nobody ever wants to deal with worms, that is obvious (unless you are a malicious software
analyzer or just crazy). Fortunately, the good guys a lot of the time know what to look for in
worms and can quickly produce a remedy for the general public. There are tons of worms that
have had a lifespan of less than an hour because of the rapid releases of security patches from
companies worldwide! How's that for a breath of fresh air!
Want to jump into the fight of preventing worms from spreading? Do the following:

· Keep your computer up-to-date with the latest patches: We can't exaggerate the
importance of this. These patches seal up security holes worms take advantage of, so
it's in your best interest to keep up with the most recent patches available. Not sure if
you have the most up-to-date patches? Look at Microsoft's website and click on the
Microsoft Update link on the left-hand menu. You also have the option of having
critical patches automatically update your machine when available. To set this
option, do the following:
o Click Start, then My Computer
o Under the Other Places menu to the left, click Control Panel
o If you are in Category View, click Security Center and click on the
Automatic Updates section at the bottom of the new window that opened. In
the new window that opened, make sure the Automatic (recommended) is
selected.
o If you are in Classic View, click System. When the new window opens,
click the Automatic Updates tab and make sure the Automatic
(recommended) is selected.

· Have anti-virus software installed with up-to-date virus definitions: Having


anti-virus software with the most up-to-date virus definitions is one of your best
defenses against worms. Not only that, anti-virus software is pretty useless if you
don't keep its virus definitions up-to-date. Have a look at the Checklist section for
more information about anti-virus software.
· Use extreme caution when opening emails from unknown users: This is how
worms like to spread. Always use anti-virus tools to scan emails for worms. Even if
the email looks like it came from someone you know, it never hurts to scan it for
worms. You just never know if a worm got onto a computer of someone you know
and sent its own email to try and infect your system.

You might also like