数据库代写 | CSCI235/CSCI835 Database Systems Assignment 2
这个作业是完成与数据库事务的实现有关的任务
CSCI235/CSCI835 Database Systems
Assignment 2
27 April 2020
Scope
This assignment includes the tasks related to implementation of database transactions.
The outcomes of the laboratory work are due by Saturday 16 May, 2020, 7.00 pm
(sharp).
Please read very carefully information listed below.
This laboratory contributes to 20% of the total evaluation in a subject CSCI235 and it
contributes to 17% of the total evaluation in a subject CSCI835.
A submission procedure is explained at the end of specification.
This assignment consists of 4 tasks and specification of each task starts from a new page.
It is recommended to solve the problems before attending the laboratory classes in order
to efficiently use supervised laboratory time.
A submission marked by Moodle as “late” is treated as a late submission no matter how
many seconds it is late.
A policy regarding late submissions is included in the subject outline.
A submission of compressed files (zipped, gzipped, rared, tared, 7-zipped, lhzed, … etc)
is not allowed. The compressed files will not be evaluated.
All files left on Moodle in a state “Draft(not submitted)” will not be evaluated.
An implementation that does not compile due to one or more syntactical errors scores no
marks.
It is expected that all tasks included within Assignment 2 will be solved individually
without any cooperation with the other students. If you have any doubts, questions, etc.
please consult your lecturer or tutor during lab classes or office hours. Plagiarism will
result in a FAIL grade being recorded for the assessment task.
Prologue
Download the files dbcreate.sql and dbdrop.sql included in a section SAMPLE
DATABASE. To drop a sample database, process a script dbdrop.sql. To create a
sample database, process as script dbcreate.sql. It is strongly recommended to drop
a sample database and to re-create it before each implementation task. No report is
expected from Prologue.
Tasks
Task 1 (4 marks)
View serializability versus conflict serializability
Assume, that a sample database contains three data items x, y, and z and that the values
of the data items are the following x = 10, y = 20, and z = 30.
Consider three database transactions T1 , T2 , and T3 given below.
T1 T2 T3
read(x) read(x) read(x)
write(x, x+10) read(y) read(z)
write(y, x) write(y,x+y) write(z, z+x)
Show a sample concurrent execution of the transaction T1 , T2 , and T3 that is view
serializable and that is not conflict serializable.
Present a concurrent execution of the transaction T1, T2, and T3 that is view
serializable and that is not conflict serializable in a two-dimensional table with three
columns such that each column contains a sequence of operations processed by one
transaction and with nine rows such that each row contains an operation processed by one
transaction.
A sample two-dimensional table that contains a concurrent execution of three database
transaction is available in a presentation Introduction to Transaction
Processing (2), slide 11.
Make sure that two-dimensional table that contains your solutions does not contain a row
with two operations processed by two or more different transactions.
Save your solution in a file solution1.pdf.
Deliverables
A file solution1.pdf a sample concurrent execution of the transaction T1 , T2 , and
T3 given above that is view serializable and that is not conflict serializable
Task 2 (5 marks)
Serialization graph testing, 2PL and timestamp ordering schedulers.
Consider the following concurrent execution of three database transactions T1, T2, and
T3.
T1 T2 T3
read(x)
read(x)
write(x,x+10)
read(u)
read(y)
write(y,y+1)
read(z)
read(z)
write(z,z+1)
write(x,u+2)
read(z)
read(v)
write(v,v+z)
write(v,y+z)
read(x)
write(x,x+z)
In a concurrent execution above, the transactions interleaved their operations and no
controller (scheduler) has been used to control the processing of the transactions. A
transaction T1 started first, followed by a transaction T2 and finally a transaction T3
started as the last one. Therefore, timestamp(T1) < timestamp(T2) <
timestamp(T3).
(1) Draw a conflict serialization graph for the concurrent execution of database
transactions given above. (1 mark)
(2) Show a history of concurrent execution when the database transactions T1, T2, and
T3 interleave their operations in the same way as above and the concurrent
processing is controlled by a 2PL protocol scheduler. (2 marks)
Assume, that it is up to you, which transaction resumes execution when a lock on a
data item is released.
A sample processing of database transactions controlled by a 2PL protocol
scheduler can be found in the lectures slides.
When presenting your solution, apply the same two-dimensional tabular
visualisation of concurrent execution of database transactions as above.
(3) Show a history of concurrent processing when the database transactions T1, T2,
and T3 interleave their operations in the same way as above and the concurrent
processing is controlled by a timestamp ordering protocol scheduler. (2 marks)
Assume, that it is up to you, which transaction is aborted when incorrect order of
timestamps is detected.
A sample processing of database transactions controlled by a timestamp ordering
protocol scheduler can be found in the lectures slides.
When presenting your solution, apply the same two-dimensional tabular
presentation of concurrent database transactions as above.
Deliverables
A file solution2.pdf with conflict serialization graph (step 1), a history of
concurrent execution of database transactions when controlled by a 2PL protocol (step 2),
and a history of concurrent execution of database transactions controlled by a timestamp
ordering protocol (step 3).
Task 3 (5 marks)
Deadlocks
Connect to your Oracle account, restore the contents of a sample database to its original
state, and disconnect.
Next, open three terminal windows and in each window start SQLcl client and connect
to your account (note, that because you have only 3 connections available, termination of
a connection that restores a sample database is very important ! ).
Three SQLcl command line client connections simulate 3 different users concurrently
change the contents of a sample database.
All three users plan to update the relational tables EMPLOYEE, CUSTOMER, and
ORDERS. All details of the updates are up to you.
Process in three SQLcl command line connections the UPDATE statements on the tables
EMPLOYEE, CUSTOMER, and ORDERS such that simulated concurrent processing leads
to a deadlock that involves all three users/transactions.
UPDATE statements can be processed in any order within SQLcl command line
connections. As it has been already mentioned, all other details of the updates are up to
you. Note, that the details and the orders of UPDATE statements will be used to evaluate
originality of your solution.
You can find a sample solution of a very similar problem in Cookbook, Recipe 8.3,
How to process transactions at SERIALIZABLE isolation level
? Step 4 How to check if SERIALIZABLE transactions get into
a deadlock situation ?
When ready, i.e. when the simulated processing of three transactions ends up in a
deadlock copy and paste the contents of three windows with SQLcl connections and save
one by one in a file solution3.lst. Do not forget to save an evidence that actually a
deadlock has happened.
Deliverables
A file solution3.lst with a report from the simulated processing of three
transactions that ends up in a deadlock
Task 4 (6 marks)
READ COMMITTED versus SERIALIZABLE isolation levels
Assume that the structures and the contents of a sample database have been changed in
the following way.
ALTER TABLE CUSTOMER ADD (TOTAL_ORDERS NUMBER(7));
UPDATE CUSTOMER
SET TOTAL_ORDERS = ( SELECT count(*)
FROM ORDERS
WHEREORDERS.CUSTOMER_CODE = CUSTOMER.CUSTOMER_CODE );
A database developer implemented the following stored procedure.
CREATE OR REPLACE PROCEDURE INSERT_ORDER(oid IN NUMBER,
ccode IN VARCHAR,
eid IN NUMBER) IS
total CUSTOMER.TOTAL_ORDERS%TYPE;
BEGIN
INSERT INTO ORDERS VALUES(oid, ccode, eid, sysdate, sysdate + 5, sysdate + 1,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
SELECT TOTAL_ORDERS
INTO total
FROM CUSTOMER
WHERE CUSTOMER.CUSTOMER_CODE = ccode;
total := total + 1;
UPDATE CUSTOMER
SET TOTAL_ORDERS = total
WHERE CUSTOMER.CUSTOMER_CODE = ccode;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE( SQLERRM );
ROLLBACK;
END;
/
The procedure INSERT_ORDER can be used to insert information about a new order
submitted by a customer. Assume that the procedure INSERT_ORDER can be processed
concurrently by many different users.
Your task is to decided what isolation level the procedure INSERT_ORDER should be
processed and to justify your decision.
You have the following two options: READ COMMITTED or SERIALIZABLE. I am
sure that there is no need to explain why the procedure cannot be processed at READ
ONLY isolation level.
If you decide that the procedure can be processed at READ COMMITTED level then as
justification of your decision provide a proof that any concurrent processing of the
procedure at READ COMMITTED level does not corrupt a sample database.
If you decide that the procedure can be processed at SERIALIZABLE level then as a
justification provide a concurrent processing of the procedure at READ COMMITTED
level that corrupts a database. You can apply two-dimensional visualisation of concurrent
execution of database transactions as it has been already used in this assignment.
Deliverables
A file solution4.pdf with a decision what isolation level a stored procedure
INSERT_ORDER should be processed at and with comprehensive justification of the
decision. Note, that a decision without justification, i.e. “educated guess” scores no
marks.
Submission
Submit the files solution1.pdf, solution2.pdf, solution3.lst and
solution4.pdf through Moodle in the following way:
(1) Access Moodle at http://moodle.uowplatform.edu.au/
(2) To login use a Login link located in the right upper corner the Web page or in
the middle of the bottom of the Web page
(3) When logged select a site CSCI835/CSCI235 (S120) Database
Systems
(4) Scroll down to a section SUBMISSIONS
(5) Click at a link In this place you can submit the outcomes of
Assignment 2
(6) Click at a button Add Submission
(7) Move a file solution1.pdf into an area You can drag and drop
files here to add them. You can also use a link Add…
(8) Repeat a step (7) for the files solution2.pdf, solution3.pdf, and
solution4.pdf.
(9) Click at a button Save changes
(10)Click at a button Submit assignment
(11)Click at the checkbox with a text attached: By checking this box, I
confirm that this submission is my own work, … in order to
confirm the authorship of your submission.
(12)Click at a button Continue
End of specification