0% found this document useful (0 votes)
68 views9 pages

Experiment No. 3 ADBMS

The document describes implementing a deadlock detection algorithm for a distributed database using a wait-for graph. It inserts transaction and lock data into a table, then uses PL/SQL procedures to analyze the data and detect deadlocks between transactions by identifying cycles in the wait-for graph. The result is that deadlocks can be detected by analyzing the locks held by transactions running on different database sites.

Uploaded by

Priyu Sakhare
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)
68 views9 pages

Experiment No. 3 ADBMS

The document describes implementing a deadlock detection algorithm for a distributed database using a wait-for graph. It inserts transaction and lock data into a table, then uses PL/SQL procedures to analyze the data and detect deadlocks between transactions by identifying cycles in the wait-for graph. The result is that deadlocks can be detected by analyzing the locks held by transactions running on different database sites.

Uploaded by

Priyu Sakhare
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/ 9

Aim - Implement the deadlock detection Algorithm for distributed database using wait- for

graph.
Requirement – ORACLE 10g
Theory -
There are five transactions T1, T2, T3, T4 and T5 with

• T1 initiated at site S1 and spawning an agent at site S2


• T2 initiated at site S3 and spawning an agent at site S1
• T3 initiated at site S1 and spawning an agent at site S3
• T4 initiated at site S2 and spawning an agent at site S3
• T5 initiated at site S3
CODINGS:
Connected to: Oracle9i Release 9.0.1.1.1 - Production
SQL> create table dd1(trans varchar(20),loc varchar2(10),wait varchar2(10),site varchar2(10));
Table created.
SQL> insert into dd1 values('t1','x1','x8','s1');
1 row created.
SQL> insert into dd1 values('t1','x6','x2','s2');
1 row created.
SQL> insert into dd1 values('t2','x4','x7','s2');
1 row created.
SQL> insert into dd1 values('t2','x5',' ','s3');
1 row created.
SQL> insert into dd1 values('t3','x2','x7','s1');
1 row created.
SQL> insert into dd1 values('t4','x7',' ','s2');
1 row created.
SQL> insert into dd1 values('t4','x8','x5','s3');
1 row created.
SQL> insert into dd1 values('t5','x3','x7','s3');
1 row created.
SQL> select * from dd1;

8 rows selected.
SQL> ed dd1;
SQL> set serveroutput on;
SQL> @dd1;
SQL> ed dd1;
SQL> @dd1;
42 /

PL/SQL procedure successfully completed.


SQL> ed dd2;
SQL> @dd2;
37 /

PL/SQL procedure successfully completed.


SQL> ed dd3;
SQL> ed dd3;
SQL> @dd3;
41/
TRANS Lock wait
t1 x6 x2
t2 x4 x7
t4 x7
x7<-x7deadlock occurred
no deadlock
PL/SQL procedure successfully completed.
SQL> ed dd1;
SQL> @dd1;
42 /
TRANS Lock wait
t1 x1 x8
t1 x6 x2
t2 x4 x7
t2 x5
t3 x2 x7
t4 x7
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occurred
x2<-x2deadlock occurred
x7<-x7deadlock occurred
x7<-x7deadlock occurred
x7<-x7deadlock occurred
x8<-x8deadlock occurred
PL/SQL procedure successfully completed.

SQL> DD1 :
declare
cursor c1 is
SELECT trans, loc, wait
FROM dd1;
type c_list is varray(20) of dd1.loc%type;
ll c_list:=c_list();
type c_list1 is varray(20) of dd1.wait%type;
l2 c_list1:=c_list1();
type c_list2 is varray(20) of dd1.trans%type;
t c_list:=c_list(); c integer := 0;
d integer :=0; f integer :=0;
ss c1%rowtype;
begin open c1;
dbms_output.put_line('TRANS '||' '||'Lock'||' '||'wait');
loop fetch c1 into ss; exit when c1%notfound;
c := c+1; ll.extend; ll(c) := ss.loc;
f := f+1;t.extend;
t(f) := ss.trans;
d :=d+1; l2.extend;
l2(d) := ss.wait;
dbms_output.put_line(ss.trans||' '||ss.loc||' '||ss.wait);
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if ( ll(i) = l2(j)) then
if(ll(i) != '-')then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end if;
end loop;
end loop;
end;

SQL>DD2:
declare
cursor c1 is
SELECT trans, loc, wait
FROM dd1
WHERE Site='s1';
type c_list is varray(10) of dd1.loc%type;
ll c_list:=c_list();
type c_list1 is varray(10) of dd1.wait%type;
l2 c_list1:=c_list1();
type c_list2 is varray(20) of dd1.trans%type;
t c_list:=c_list();
c integer := 0;
d integer :=0;
ss c1%rowtype;
begin open c1;
dbms_output.put_line('TRANS '||' '||'Lock'||' '||'wait');
loop fetch c1 into ss;
exit when c1%notfound;
dbms_output.put_line(ss.trans||' '||ss.loc||' '||ss.wait);
c := c+1; ll.extend;
ll(c) := ss.loc;
d :=d+1; l2.extend; l2(d) := ss.wait;
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if ( ll(i) = l2(j)) then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
end loop;
end;

SQL>DD3:
declare
cursor c1 is
SELECT trans, loc, wait
FROM dd1
WHERE Site='s2';
type c_list is varray(10) of dd1.loc%type;
ll c_list:=c_list();
type c_list1 is varray(10) of dd1.wait%type;
l2 c_list1:=c_list1();
type c_list2 is varray(20) of dd1.trans%type;
t c_list:=c_list();
c integer := 0;
d integer :=0;
e integer :=0;
ss c1%rowtype;
begin open c1;
dbms_output.put_line('TRANS '||' '||'Lock'||' '||'wait');
loop fetch c1 into ss;
exit when c1%notfound;
dbms_output.put_line(ss.trans||' '||ss.loc||' '||ss.wait);
c := c+1;
ll.extend; ll(c) := ss.loc; d :=d+1; l2.extend;
l2(d) := ss.wait;
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if ( ll(i) = l2(j)) then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
end loop;
if (e = 0) then
dbms_output.put_line('no deadlock ');
end if;
end;

SQL>DD4:
declare
cursor c1 is
SELECT trans, loc, wait
FROM dd1
WHERE Site='s3';
type c_list is varray(10) of dd1.loc%type;
ll c_list:=c_list();
type c_list1 is varray(10) of dd1.wait%type; l2 c_list1:=c_list1();
type c_list2 is varray(20) of dd1.trans%type;
t c_list:=c_list();
c integer := 0; d integer :=0;
ss c1%rowtype; begin open c1;
dbms_output.put_line('TRANS '||' '||'Lock'||' '||'wait');
loop fetch c1 into ss;
exit when c1%notfound;
dbms_output.put_line(ss.trans||' '||ss.loc||' '||ss.wait);
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait; end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if ( ll(i) = l2(j)) then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;

Result – Thus ,we implemented the deadlock detection Algorithm for distributed database using
wait- for graph.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy