1. What is a transaction? What are its properties? Why are transactions
important units of operation in a DBMS? As defines by the Elmasri and Navathe, Transaction is a sequence of operations that performs logical unit of operations on a database which include one or more operations as insert, delete, update and modification, Transaction is a executing program, the boundaries of a transaction is define as the explicit begin of transaction and end of transaction. Read-only transaction performs only retrieve data from the database and the Read- write operation includes both retrieving and updating transactions. (Elmasri and Navathe 2010 p.745) The properties of a transaction is define as ACID properties as below, Atomicity, Consistency, Isolation and Durability Transaction is the executing program that executes the operations on the database as read(x), write (x) ,so the transactions plays a vital role among database operations.
2. Draw a state diagram and discuss the typical states that a transaction goes through during execution.
Figure1. State Diagram of a Transaction Source: Author Begin transaction: This indicates the beginning of a transaction Active phase: in this phase the running of the database operations or write sql queries for perform the tasks is done Partially committed: After performs the needed operations the transaction indicates end state and come to the phase partially committed and store in the buffer but not permanently. Committed: If the transaction was successfully executed it comes to the commit state and indicates the database that the operation was success. Page 2
Fail : if any failure occur during the transaction before committed it comes to the fail state. The system failures can occur as transaction, system and media failures. Terminate: after successfully committed or the rollback after the failures finally it indicate the transaction is over. (Elmasri and Navathe 2010 p.751)
3. How does the DBMS ensure that the transactions are executed properly? DBMS ensure the successfully termination of an operation by the commit point. After the transaction indicates the commit state all transaction logs are permanently recorded in the log. The commit point indicate the successfully access of the database operations with the DBMS. (Elmasri and Navathe 2010 p.754)
4. What is consistent database state and how is it achieved? Consistency or the consistency preserving is a major concept of the DBMS. Consistent state indicates in the sequence of database operations step to step it should be confirmed the successfully executing the last operations before skip to the next state. In order to successfully achieve the consistent database transactions in a one stage should successfully complete before skip to the next phase. (Demetris Zeinalipour 2005)
5. What is transaction log? What are its functions? Transaction log is holds the track of all operations performs in the transactions on the DBMS. This log file is stored in the disk as an appended file which has been recorded sequential operations. When a transaction is processing the log records first kept in the memory buffer, then finally transaction log records in the memory buffer is added as appended with the end of the log records. Transaction log files will not be affected by the system failures except fault of the disk. (Krzyzanowski 2009) Function of a log file is it helps to recover from catastrophic failures.
6. What are the typical kinds of records in a transaction log? What are transaction commit points and why are they important?
Start transaction: This indicates the beginning of a transaction Write item: Indicates that old value of an item has been changed to a new value Read item: indicates that transaction have read the value of the item stored in the DBMS Commit: indicates transaction is successfully completed and can be stored Permanently. Abort: Transaction is terminated. Page 3
Commit point helps to DBMS to ensure the successfully termination of an operation by the commit point. After the transaction indicates the commit state all transaction logs are permanently recorded in the log. The commit point indicate the successfully access of the database operations with the DBMS. The most importance of the Commit statement is to ensure whether the transaction is successfully completed.
7. What is a schedule? What does it do? Schedule is defined as sequence of operations of set of transactions that coordinated the sequence order of executing transaction. The objectives are Schedule determines the flow of the transaction and the time it should start and terminate and the order of executing 8. What is concurrency control? What are its objectives? Concurrency control is a mechanism which allows and control and coordinate multiple transaction to access the DBMS in simultaneous manner to ensure serializability. The objectives of Concurrency control is to enhance the resource utilization by allowing multiple operation to occur in the same time and to ensure the serializability of transactions in a multiple user access DBMSs and to prevent from problems like dirty read, lost updates and inconsistent retrievals. Reduce the response time for the operations and Get the maximum use of the disk access by performing operations continuously. (Singh, Elmasiri and Connoly 2006 p.12)
9. What do you understand by the concurrent execution of database transactions in a multi-user environment? Multi user environment means that a particular system will be accessed or used by more than one user or multiple users at the same time. So in a multiple user environment concurrent execution of transaction defines that it will be allowed to access the database for several users in the meantime or same time while coordinating and detecting occurring failures. This ensures the serializability access.
Page 4
10. What are transaction states? There are initial 6 states in a transaction
Begin transaction: This indicates the beginning of a transaction Active phase: in this phase the running of the database operations or write sql queries for perform the tasks is done.
Partially committed: After performs the needed operations the transaction indicates end state and come to the phase partially committed and store in the buffer but not permanently. Committed: If the transaction was successfully executed it comes to the commit state and indicates the database that the operation was success. Fail: if any failure occur during the transaction before committed it comes to the fail state. The system failures can occur as transaction, system and media failures. Terminate: after successfully committed or the rollback after the failures finally it indicate the transaction is over. 11. Explain ACID properties with examples for each. ACID properties are Atomicity, Consistency, Isolation and Durability
Atomicity When performing a transaction either it should be completely perform and terminated or abort the process. As an example in a transaction of borrowing money from a ATM machine during the process if any failure occurs due to a system problem either system should completely abort the process and restart or should be discontinued the operation. Consistency When go through a process before shift to the one state form to another in the operation the previous state should ensure the particular operations for that state were successfully completed in that state. Otherwise the operation will not be continued. In ATM operation the operation of borrowing money will not be completed until the all records were added to the database. Isolation When multiple transactions occur simultaneously. Occurring of one transaction will not be interfering the other transaction. That is a property of a DBMS. So that it will never conflict two transactions which occurs simultaneously. As an example if two transaction are performs on a database at the same time one transaction will not be blocked by the other transaction. Page 5
Durability or Permanency In the DBMS operations for the purpose of archiving the efficiency the records are holds in the memory buffer not in the main memory. So the after committed a transaction it should be permanently record the all records related to operations and because of any failure that records should not be loss. As an example in a ATM machine after completed the transaction it will come to the commit state and all records happened in the operations will be permanent stored in the disk of the DBMS.
12. A hospital blood bank transaction system is given which records the following information:
Deliveries of different blood products in standard units. Issues of blood products to hospital wards, clinics, and Operation Theaters. Assume that each issue is for an identified patient and each unit is uniquely identified. Returns of unused blood products from hospital wards.
Describe a concurrency control scheme for this system which allows maximum concurrency, always allow Read access to the stock and accurately records the blood products used by each patient.
T1 is the delivering of different blood products in different units T2 is issuing blood products to the wards, clinics, T3 is retuning of unused blood products When it is needed to deliver a blood product that item (x) will be read and then write after terminating the process. When issuing the blood products it will read that item (y) and will do updates on that data item then those data will again updated at data item( x) in order to confirm about the issuing the blood product. When unused blood products records to the database, it will first read item(z) and then update that information and those information will be recorded in the databas
13. What a r e ACI D pr o pe r t i e s o f a da t a ba s e t r a ns a c t i o n ? Discuss e a c h o f t he s e properties and how they relate to the concurrency control. Give example to illustrate your answer. ACID properties are Atomicity, Consistency, Isolation and Durability
Atomicity When performing a transaction either it should be completely perform and terminated or abort the process. As an example in a transaction of borrowing money from a ATM machine during the process if any failure occurs due to a system problem either system should completely abort the process and restart or should be discontinued the operation. Consistency When go through a process before shift to the one state form to another in the operation the previous state should ensure the particular operations for that state were successfully completed in that state. Otherwise the operation will not be continued. In ATM operation the operation of borrowing money will not be completed until the all records were added to the database. Isolation When multiple transactions occur simultaneously. Occurring of one transaction will not be interfering the other transaction. That is a property of a DBMS. So that it will never conflict two transactions which occurs simultaneously. As an example if two transaction are performs on a database at the same time one transaction will not be blocked by the other transaction. Page 7
Durability or Permanency In the DBMS operations for the purpose of archiving the efficiency the records are holds in the memory buffer not in the main memory. So the after committed a transaction it should be permanently record the all records related to operations and because of any failure that records should not be loss. As an example in an ATM machine after completed the transaction it will come to the commit state and all records happened in the operations will be permanent stored in the disk of the DBMS. (Elmasri and Navathe 2010 p.) 14. Explain the concept of serial, non-serial and serializable schedules. State the rules for rules for equivalence of schedules. Serial schedule is known for the transaction which continuous until it aborts or terminate another transaction will not interfere until the first one come to the commit, abort or terminate state. The problem with this serial schedule is it will limit the concurrency.
Figure 3. Serial schedule Source: Elmasri navathe( p.760)
Above figure 3 illustrate the serial schedule, the transaction T 2 will not start until the transaction T 1 terminate. In serial schedule transaction will occur one after another. Non Serial schedule is known for, one transaction which not continuous along until terminate and another transaction can interleave while occur the first one, in below figure 3 it is illustrated a non-serial schedule .Some operations of the T 2 transaction is perform before terminate the transaction T 1.
Page 8
Figure 4. Non Serial schedule Source: Elmasri navathe( p.760) Serializabal schedule is define as the schedules that allows transaction to concurrent access the system but the final result will same as the result of serial schdule Rules for equivalence of the schedules are Result equivalence: the final outcome of the distinct schedule will be same. Conflict equivalence: The order of two distinct transactions is same. View equivalence: if all the transaction have same set of transaction, it is called view equivalence 15. Explain the distinction between the terms serial schedule and serializable schedule. Serial schedule is known for the transaction which continuous until it aborts or terminate another transaction will not interfere until the first one come to the commit, abort or terminate state. The problem with this serial schedule is it will limit the concurrency.it will not provide the opportunity to another transaction to hold the database item need to process until the first one terminate. It means that if there are two transactions as T 1, T2. T2 will execute after performed the all actions of the T 1 transaction. Serializability schedule is defined as the schedules execute concurrently but the final result totally same as the result of the serial schedule. So the final outcome of the transaction will not be incorrect.
Page 9
16. Discuss the actions taken by Read_item and Write_item operations on a database. In the Read_Item operation the transaction will access the item and only it will be read. No changes of the value is not happen, if there is an item (x) the value before read the (x) will same at the end of reading the (x) value. In the Write_Item operation the transaction will access the item and it will be change the value or re write the value, if there is an item (x) the value before write the (x) will differ at the end of reading the (x) value.
17. Describe the four levels of transaction concurrency The four levels of transaction concurrency level are known as Four levels of isolation As followings Read committed Read uncommitted Repeatable read Serializable
Read uncommitted that multiple transaction accessed on a system are not isolated from each other transaction, but those will not interferer among transactions it will usually allow privileges to only read( ) for the transaction running on this level
Read committed that always transaction will read the committed data of the other transaction, it will not read uncommitted data or partially committed data so this will helps to prevent from dirty read like problems. So one transaction will wait until the other one release the lock
Repeatable read that transaction will avoid form any non-repeatable read, one transaction will wait to access the data items until executing transaction release the lock. When one transaction need to access data item it will lock that then it will do all the update, insert operations and after terminate the operations or committed it will release the lock. So after that no operation will be done on that data item. It will not repeat the same operation again and again.
Serializable that it will allow multiple transaction to access on the system but the final output given by the all schedules should be same so maintaining these kind of schedules is essential.
Page 10
18. Define the violations caused by the following: i. Lost updates. ii. Dirty read (or uncommitted data). iii. Unrepeatable read (or inconsistent retrievals). Lost update. This problem occurs when two transaction access the same item of the database at the same time, so in this conflict the value of the item will be changed or update in an incorrect manner. So this will be lead to the providing incorrect results. Example: 500 items are available in a store and t 1 transaction request for 400 items, so the transaction will continue and meanwhile t 2 transaction request 200 items, still t 1 not have committed the deducted value as 100, so the t 2 see the value as 500 still and confirm the order and both t 1 and t 2 update the final value as 100 and 300. But this is not the real value. Dirty Read. Dirty read occurs due to the access of uncommitted data of a one transaction by another transaction. Assume that error is occurring in the middle While a transaction is going on still not have been committed the final value permanently. If another transaction access the exist value so it is incorrect and dirty read will occur. Example: 500 items are available in a store and t 1 transaction request for 400 items now the deducted value is 100, in the middle error occurs or order for t 1 is rejected. still this t 1 is not aborted and rollback, meanwhile t 2 access foe order 300 items and it reads the remain value as 100,but actual remain value is 500 due the t 1 not completed, but t 2 happen to be cancelled due to read incorrect value. Unrepeatable read This problem occurs due to the simultaneous access of same data item by two transactions as one transaction is updating data while the other one is aggregate calculating data. The calculating value will be incorrect as the first one is still updating the value.
19. What is seralizability? What is its objective? Serializability means that when there are multiple transaction in queue those will be allow to concurrent execution without giving up any correctness. The two transactions can interleaving and perform their operations. The objective of Serializability is to allow concurrent execution of the transaction without conflicting and interfering each others. (Elmasri and Navathe 2010 p.765)
Page 11
20. Discuss how seralizability is used to enforce concurrency control in a database system. Why is seralizability sometimes considered too restrictive as a measure of correctness for schedules? A concurrency control is said to be serializable if the final result of that schedule is totally same as the final result given by the serial schedule. So in executing transaction it will be allow to access multiple transaction with the DBMS in orders to enhance the efficiency and the maximum usability of the resources. But it should give the same result for particular transaction, otherwise it is useless. So through serializability it will lead to the same final outcome by using the schedules, But it is called serializability sometimes too restrictive as because the in serializability it is used locking mechanisms so using locking mechanism me lead to the occurring deadlocks and abort the transaction. This is the reason for called serializability is sometimes too restrictive.
21. What is locking? What is the relevance of lock in database in database management system? How does a lock work? Locking is the process of defining variable with the data items of the database in order to control the access mechanism with respect to the particular operation, by locking it will be controlled and coordinate the process of access items in the database in a sequence manner. In the locking mechanism, Data items will be given values as lock(x) =1 or unlock(x) =0. When a one transaction need to access data item it will check the status. If it is (x) =1 it indicates that data item is still using by another transaction so the request will be abort and retry. If the value is (x) =0 the transaction will access the data item. Then change the status as (x) =1 for the purpose of indicating other transaction not to be access that data item. (Elmasri and Navathe 2010 p.765) After doing the particular operation data item will be unlocked (x) =0 and terminate.
22. What are the different types of locks? Binary locks. Binary locks have only two states as (x) =1 for indicate lock and (x) =0 for indicates unlock. When a transaction need to access a data item it will check the states and determine access of the database .if (x) =1 it will not be access and wait, if (x) =1 it will access and will perform the operation.
next
Page 12
Shared/Exclusive (or Read/Write) Locks. In the binary locking mechanism it will not allow to access the same data item simultaneously. But in Exclusive mechanism there are 3 statuses as Read_lock, Write_lock and Unlock .while one transaction is already access the data item if another transaction need to access that data item only for read it will allow to access but not to change the value. In shared lock it will allow any transaction to only read a data item any time but not to write on it. But using exclusive locks it will totally prvent from allowing other transaction to read and write on a data item. (Elmasri and Navathe 2010 p .766)
23. What is deadlock? How can a deadlock be avoided? Deadlock occurs in a situation while multiple T n transaction are waiting considerable time to access data item locked by current T y transaction. Sometimes T y will not release the lock as the other T n are waiting, So transaction will not be able to access the data item and those will be abort. This is called a deadlock. Deadlocks can be avoid form using Two phase locking This mechanism will consist of two mechanisms, in one mechanism it obtain all the locks for particular data item and in the next phase it will do operation on that data item and unlock and release for access of the other transactions
Deadlock detection systems as wait-for-graph. In order to prevent from deadlocks it can be used wait-for-graph. In the wait for graph, when a t 2 transaction wait for to access a data item locked by the transaction t 2,
the wait for graph will create direct edge between these two and soon after the t 1 terminate the process it will be given the priority for t 2 to access the database item.
Timeout In this method the system will determine particular time period for proceed a transaction if the transaction cannot proceed within that time period the particular transaction will abort and give the priority to another.
24. Discuss the problems of deadlock and the different approaches to dealing with these problems. Starvation is a one problem can be seen in the locking. In the starvation a transaction will not be able to proceed the operation within the particular time period while other transaction continuous in normal manner. This occurs because the waiting time for that particular operation is unfair. The solution for starvation problem is that using of first come first serve method that which allows the transaction to access in the order that they access the system. Page 13
Different methods for avoid the deadlock problems are using Deadlock detection In order to prevent from deadlocks it can be used wait-for-graph. In the wait for graph, when a t 2 transaction wait for to access a data item locked by the transaction t 2,
the wait for graph will create direct edge between these two and soon after the t 1 terminate the process it will be given the priority for t 2 to access the database item. Timeout In this method the system will determine particular time period for proceed a transaction if the transaction cannot proceed within that time period the particular transaction will abort and give the priority to another. first come first serve method Allows the transaction to access in the order that they access the system. 25 Add lock items for two Transaction
Figure 5 locking mechanism Source: Author Yes this two transaction can lead to the deadlocks because as these two transaction use exclusive locks until they release other transaction has to be waited. So this can be lead to a dead lock if other transaction failure or abort due to the impossible to access the data item in the fair time period.
26 Describe the wait-die and wound-wait techniques for deadlock prevention. Wait-die techniques use the concept of timestamp. Timestamp concept coordinates sthe prioritization of the transaction, In the wait die when exists two transactions as t 1 and t 2 , if the t 1 access the system first and t 2 then request the data item at the mean time the wait-die technique will give prioritization for the t 1 as it first access with the database or the system. In simply the older transaction will be allow to continue the process and younger transaction will required to wait abort and restart. T1: Lock-S (A) Read (A) Lock-X (B) Read (B) If (A=0) then B=B+1; Write (B) Unlock (A) Unlock (B)
T2: Lock-S (B) Read (B) Lock-X (A) Read (A) If (B=0) then A=A+1; Write (A) Unlock (B) Unlock (A)
Page 14
Wound-wait techniques also use the concept of timestamp. In the wound-wait when there are two transactions if the younger transaction is processing and meanwhile the if older transaction request from the particular data item the younger transaction will be request to wait or abort and restart transaction until older one perform the required operation. (Elmasri and Navathe 2010 p. 786) 27. What is a timestamp? How does the system generate timestamp? Timestamp can be defined as an type of identifier used for identify the order of the Transaction to be executed or the prioritize the transaction as they access the system. Timestamp is deadlock free as does not use the locks. System generates timestamps according to the sequence of order transaction are accessed the system. There are many ways of generating transaction one way is, Using a counter that increments the value as the transactions access the system, this will maintain the counting as 1, 2, 3. As the system has finite or maximum value of counting this counter must be time to time reset the value to zero at the time transaction are not possible. And the other way is using the date/ time of the system at the transaction are access or submitted the system. This should be ensuring not to check two different transaction to at the same time of the system. (Demetris Zeinalipour 2005) 28. Discuss the timestamp ordering techniques for concurrency Time stamp ordering defines giving the privileges to transaction according to the timestamps have been allocated. In timestamp ordering also it ensures the schedule to be serialized as corresponding schedule. In order to avoid from the conflict of violating of the order of executing transaction, it is uses two timestamp values as. Read_TS (x) and Write_TS (x). TS is defined as Timestamp.
Techniques for Timestamp ordering
One technique used for timestamp ordering is Basic Timestamp ordering in here, When transaction need to execute transaction values Read_TS (x) or Write_TS (x) it is compared the order of executing these values in order to prevent from conflicting the transaction steps. If any conflict or violation occurs the transaction will abort and rollback and restart with a new timestamp. But in here a problem called the cascading rollback. Any other number of transactions depend on or read values of the rollback transaction will be also abort if the most first transaction get aborted.
So in Basic timestamp ordering when it is requested Write_TS (x) in a situation another TS(T) exists where the TS(x) older, TS(T) will aborted and requested to be restart or wait as if TS(T) read values of the particular data item it will violate the TS ordering technique,
And also Basic timestamp ordering when it is requested Read_TS (x) in a situation another TS(T) exists where the TS(x) older, TS(T) will aborted and requested to be Page 15
restart or wait as if TS(T) read values of the particular data item it will violate the TS ordering technique,
Strict Timestamp Ordering is another technique, this timestamp order mechanisms ensure to schedules to be strict and serializabal, in a situation transaction T that issues a read_item (x) or write_item(x) such that TS(T) is older than write_TS(X) has its read or write operation is delayed until the transaction T that wrote the value of X is committed or aborted . In here is used lock mechanisms, but prevent from the deadlocks Thomass Write Rule. is also another technique used for timestamp order, In this technique it prevented from modifying the conflicting of serializability by modifying the write_item() value. In a situation read_TS(x) is older than TS(T) the transaction(T) will be terminated or abort to prevent form conflicting the schdules. And also in a situation I write_TS(x) is older than TS(T), then it will do not execute the write operation but continue processing.
29. When a transaction is rolled back under timestamp ordering, it is assigned a New timestamp. Why can it not simply keep its old timestamp? The objective or the purpose of using timestamp ordering is to provide mechanisms for access the transaction with the system in a sequence of order that they access the system. It is used counting value mechanisms or using the date and time for determine the way of ordering the timestamps, If a transaction t 1 rollback it should be given priority for the other tractions t n to be executed otherwise a deadlock can be occur. So if the rollback transaction t 1 will be given the older timestamp again other waiting transactions t n will not be able to execute as the transactions are occur as time stamp ordering, so that if transaction is roll back it will be given new timestamp and given the opportunity to executing as the sequence of order. 30. How does optimistic concurrency control method differ from other concurrency control methods? Why they are also called validation or certification methods? In all concurrency control mechanisms it can be seen a common way of executing the transaction, it is the checking , before any transaction to be executed it comes to the phase of checking and execute the other steps, But, In the Optimistic concurrency Control phase called check cannot be seen, that, while executing a transaction the updates occur time to time will not be applied at the database items while the complete transaction is executed. So this temporary updates will be applied local copies of transaction keep for transactions. In the end it will be ensure whether any violation of the transaction happened.in optimistic concurrency all the checkings are done in one time. The reason for using term validation is as because at the end of the transaction a phase called validation is executed to ensure whether any violation of serializability is happened. Page 16
The reason for using term certification is as in the over roll process it is certified the execution of the complete transaction by validation like processes. (Demetris Zeinalipour 2005)
31 Using an example, illustrate how two-phase locking works. A transaction is considered that it is using the two phase locking protocol mechanism if read () and write() operations is done before the release the lock ,unlock(). There are two Phases as Growing phase and shrinking phase in two phase locking, In growing phase it will obtain all the locks and will not release but in the shrinking Phase it will terminate the operations and release the data items. The following figure Illustrate how it has been violate the two phase locking system.
Figure 6. Violation of TP locking Source: Elmasri navathe( p.784)
In above example T 1 do read and write operations on data item Y and release that data item and unlock the Y. but there after in transaction T 2 again it lock the item why and write on it. But in the two phase locking after release the lock it cannot be again lock that data item. So this example says how it violates the two phase locking. Below example will illustrate how a transaction follow two phase locking mechanism. (Demetris Zeinalipour 2005)
Page 17
Figure 7 Two Phase locking Source: Elmasri navathe( p.760) In the above example it can be seen T / 1 will never has written on the data item Y after it release the data item Y or unlock the Y. and all operations on data item X have been done before the unlock X. Same as T / 2 will never has written on the data item Y after it release the data item Y or unlock the Y. and all operations on data item X have been done before the unlock X. So this not violate the two phase locking mechanism.
Page 18
Reference Elmasri, R. and Navathe, S. (2010) Fundementals of Database Systems 6 th edition
Elmasiri, R. Singhand Connoly (2006) Database Management systems II
Krzyzanowski, P. (2009) Lectures on distributed systems Concurrency Control http://www.cs.rutgers.edu/~pxk/rutgers/notes/content/concurrency.pdf
Zeinalipour, D.( 2005) Concurrency Control with Timestamps, university of Cyprus http://www2.cs.ucy.ac.cy/~dzeina/
Modern Web Applications with Next.JS: Learn Advanced Techniques to Build and Deploy Modern, Scalable and Production Ready React Applications with Next.JS