2019-08-28

Aug 28 In-Class Exercise Thread.

Post your solutions to the Aug 28 In-Class Exercise to this thread.
Best, Chris
Post your solutions to the Aug 28 In-Class Exercise to this thread. Best, Chris

-- Aug 28 In-Class Exercise Thread
School example:
If we want to update the average scores of the whole class(process A), we are going to lock everyone's grade; at the same time, we want to compare the previous average scores with one of the student's scores(process B), than average scores will be lock at this time, we need to wait process A to release the student's grade to do the process B, but process A need process B to release average scores first, therefore, they are all waiting for each other to release the lock.
Airline reservation example:
Process A is to add a reservation to the list, therefore, it will lock the list and client's information. Process B is going to update the passport number of the client , therefore, it will lock the reservation list and client's information. Process A is waiting for the reservation list release, and process B is waiting for the client's information release, they won't release until another process completes.
(Edited: 2019-08-28)
School example: If we want to update the average scores of the whole class(process A), we are going to lock everyone's grade; at the same time, we want to compare the previous average scores with one of the student's scores(process B), than average scores will be lock at this time, we need to wait process A to release the student's grade to do the process B, but process A need process B to release average scores first, therefore, they are all waiting for each other to release the lock. Airline reservation example: Process A is to add a reservation to the list, therefore, it will lock the list and client's information. Process B is going to update the passport number of the client , therefore, it will lock the reservation list and client's information. Process A is waiting for the reservation list release, and process B is waiting for the client's information release, they won't release until another process completes.

-- Aug 28 In-Class Exercise Thread
In a school grade table, transaction T1 holds a lock on a row and is waiting to update that row in this grade table. At the same time, transaction T2 holds locks on some other rows in the grade table as well and is also waiting to update the rows in the Student table held by Transaction T1. The deadlock problem happens when Transaction T1 is waiting for T2 to release its lock and transaction T2 is waiting for T1 to release its lock. Both of theses transactions wait.
(Or: To update student A’s final grade on his Math 42, the school need to get his professor’s approval, but his professor is waiting the school to give him the permission to do so. )
Transaction 1 holds a lock in a row from a table to cancel the one ticket to SF, Transaction 2 holds a lock in a row from this table is also trying to cancel the ticket to NY but wait fro 1 to release its lock. But transaction 1 is waiting for 2 to release. So, both are waiting and it is dead!!!!!!
(Edited: 2019-08-28)
In a school grade table, transaction T1 holds a lock on a row and is waiting to update that row in this grade table. At the same time, transaction T2 holds locks on some other rows in the grade table as well and is also waiting to update the rows in the Student table held by Transaction T1. The deadlock problem happens when Transaction T1 is waiting for T2 to release its lock and transaction T2 is waiting for T1 to release its lock. Both of theses transactions wait. (Or: To update student A’s final grade on his Math 42, the school need to get his professor’s approval, but his professor is waiting the school to give him the permission to do so. ) Transaction 1 holds a lock in a row from a table to cancel the one ticket to SF, Transaction 2 holds a lock in a row from this table is also trying to cancel the ticket to NY but wait fro 1 to release its lock. But transaction 1 is waiting for 2 to release. So, both are waiting and it is dead!!!!!!

-- Aug 28 In-Class Exercise Thread
SCHOOL
Transaction 1 (update average GPA for students in a class) started and has a hold on the student table, row for Student A.
Transaction 2 (get the name of a student in the class) started and has a hold on the class table, class CS175A.
T2 is waiting for the lock on the student table, row Student A.
T1 is waiting for the lock on the class table, row CS175A.
AIRLINE
T1 (buying a ticket to Toronto) has started and has a lock on the user table, row client A.
T2 (checking available seats for a user on the Toronto flight) has started an has a lock on the flight table, row Toronto Flight.
T1 is waiting for the lock on the flight table, row Toronto flight.
T2 is waiting for the lock on the user table, row client A.
(Edited: 2019-08-28)
SCHOOL Transaction 1 (update average GPA for students in a class) started and has a hold on the student table, row for Student A. Transaction 2 (get the name of a student in the class) started and has a hold on the class table, class CS175A. T2 is waiting for the lock on the student table, row Student A. T1 is waiting for the lock on the class table, row CS175A. AIRLINE T1 (buying a ticket to Toronto) has started and has a lock on the user table, row client A. T2 (checking available seats for a user on the Toronto flight) has started an has a lock on the flight table, row Toronto Flight. T1 is waiting for the lock on the flight table, row Toronto flight. T2 is waiting for the lock on the user table, row client A.

-- Aug 28 In-Class Exercise Thread
School: A system routine started, updating records of a Student A. A professor tried to update A record at the same time successfully getting a hold of the record, however, could not submit a change to the database since routine is holding A record too.
Airline: Two people go to an airline website. The website holds a ticket to a person that is trying to book it, but timeout of hold is not implemented. If both persons access the site simultaneously and one of the parties is trying to book a ticket, the query will be rejected because another person holds this ticket resource, hence neither of them can book the ticket.
(Edited: 2019-08-28)
School: A system routine started, updating records of a Student A. A professor tried to update A record at the same time successfully getting a hold of the record, however, could not submit a change to the database since routine is holding A record too. Airline: Two people go to an airline website. The website holds a ticket to a person that is trying to book it, but timeout of hold is not implemented. If both persons access the site simultaneously and one of the parties is trying to book a ticket, the query will be rejected because another person holds this ticket resource, hence neither of them can book the ticket.

-- Aug 28 In-Class Exercise Thread
A deadlock occurring in terms of school records is when a student wants to register for a class but the add code provided has been taken by another student.
In terms of writing and reading data from the database of airline reservation, a deadlock occurs when a person wants to fly tomorrow but all flights to the destination are fully booked.
A deadlock occurring in terms of school records is when a student wants to register for a class but the add code provided has been taken by another student. In terms of writing and reading data from the database of airline reservation, a deadlock occurs when a person wants to fly tomorrow but all flights to the destination are fully booked.

-- Aug 28 In-Class Exercise Thread
School records deadlock: A student trying to enroll cs157A, System check for cs146 grade, cs146 grade is not out yet since system need enroll table to do it(for some reason), enroll table cannot complete its trying to update cs157a status. Here a deadlock occurs since "enroll cs157a", "update cs146 grade", "update enroll table" form a triangular, kind of, shape of dependency on each other
------------------- X is buying a ticket to HongKong. there is only one seat left. Y is completing his purchases. X got locked
(Edited: 2019-08-28)
School records deadlock: A student trying to enroll cs157A, System check for cs146 grade, cs146 grade is not out yet since system need enroll table to do it(for some reason), enroll table cannot complete its trying to update cs157a status. Here a deadlock occurs since "enroll cs157a", "update cs146 grade", "update enroll table" form a triangular, kind of, shape of dependency on each other ----------------------- X is buying a ticket to HongKong. there is only one seat left. Y is completing his purchases. X got locked

-- Aug 28 In-Class Exercise Thread
Transaction A: Student account is trying to add CS 157A with an add code but cannot see his/her student ID on the add page. Transaction B: Professor is trying to give the student an add code but needs the student ID.
Transaction A: Passenger needs to buy a ticket that is not torn apart to enter the airport. Transaction B: The air reservation company only sells new tickets in the airport.
Transaction A: Student account is trying to add CS 157A with an add code but cannot see his/her student ID on the add page. Transaction B: Professor is trying to give the student an add code but needs the student ID. Transaction A: Passenger needs to buy a ticket that is not torn apart to enter the airport. Transaction B: The air reservation company only sells new tickets in the airport.

-- Aug 28 In-Class Exercise Thread
SCHOOL RECORDS A student might try to change their email address and it may be locked and waiting for the student to confirm their email through a link. The registration department might try complete a transaction for tuition fees from the same student's account. The registration department cannot complete the transaction until the student confirms their email
AIRLINE RESERVATION A process might be run to calculate/display the amount of available seats on a flight. At the same time, a person might request to buy a ticket for the same flight. The first process has the lock, but can't complete the process until the person buys the ticket
SCHOOL RECORDS A student might try to change their email address and it may be locked and waiting for the student to confirm their email through a link. The registration department might try complete a transaction for tuition fees from the same student's account. The registration department cannot complete the transaction until the student confirms their email AIRLINE RESERVATION A process might be run to calculate/display the amount of available seats on a flight. At the same time, a person might request to buy a ticket for the same flight. The first process has the lock, but can't complete the process until the person buys the ticket

-- Aug 28 In-Class Exercise Thread
School record: On a table containing info about a class, (T1) a teacher is updating the amount of available seats which places a lock on the class record while the TA (T2) wants to update the class length but cannot because (T1) has the lock on the class record.
Airline record: An airline agency has decided to change a flight by changing the amount of stops on a flight record but is unable to because a customer just purchased a ticket on that flight when that flight record only had 1 stop. When the customer purchased the flight with 1 stop, the row was locked.
(Edited: 2019-08-28)
School record: On a table containing info about a class, (T1) a teacher is updating the amount of available seats which places a lock on the class record while the TA (T2) wants to update the class length but cannot because (T1) has the lock on the class record. Airline record: An airline agency has decided to change a flight by changing the amount of stops on a flight record but is unable to because a customer just purchased a ticket on that flight when that flight record only had 1 stop. When the customer purchased the flight with 1 stop, the row was locked.
[ Next ]
X