Experiment No. 3 ADBMS
Experiment No. 3 ADBMS
graph.
Requirement – ORACLE 10g
Theory -
There are five transactions T1, T2, T3, T4 and T5 with
8 rows selected.
SQL> ed dd1;
SQL> set serveroutput on;
SQL> @dd1;
SQL> ed dd1;
SQL> @dd1;
42 /
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.