Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concurrency Control. R/RR/W W/W User 2 ReadWrite User 1 Read Write R/W: Inconsistent Read problem. W/W: Lost Update problem.

Similar presentations


Presentation on theme: "Concurrency Control. R/RR/W W/W User 2 ReadWrite User 1 Read Write R/W: Inconsistent Read problem. W/W: Lost Update problem."— Presentation transcript:

1 Concurrency Control

2 R/RR/W W/W User 2 ReadWrite User 1 Read Write R/W: Inconsistent Read problem. W/W: Lost Update problem.

3 Example Husband/Wife joint account with $1000 balance. Transactions: –Husband: Withdraw 800 –Wife: Withdraw 100 Processing: –Read Balance, Calculate New Balance, Write New Balance

4 Husband:ReadBalanceCalNewBalanceWriteNewBalance (In memory)(On disk) 1000New=1000-800200 Wife:ReadBalanceCalNewBalance WriteNewBalance 1000New=1000-100900

5 Serializable Schedule Serial Schedule: The operations of each concurrent transaction are executed consecutively without any interleaved operations from other transactions. Nonserial Schedule: The operations from a set of concurrent transactions are interleaved. –Maximizing database availability Serializable schedule: If a set of transactions executes concurrently, the nonserial schedule is called serializable if it produces the same results as a serial schedule.

6 Locking Locking is the most widely used approach to ensure serializability of concurrent transactions. Shared lock: read only access Exclusive lock: for both read and write access.

7 Two-Phase Locking A transaction must acquire a lock (read or write) on an item before operating on the item. Once the transaction releases a lock, it cannot acquire any new locks. All locking operations precede the first unlock operation in the transaction: –Growing phase –Shrinking phase

8 Lock Granularity The size of data items protected by a lock. –Entire database –Entire table –A page –A record –A Field The coarser the data item size, the lower the degree of concurrency permitted.

9 Dead Lock Two transactions wait for locks on items held by the other. T1T2 DataItem 1 DataItem 2 Lock Wait For Lock

10 Transaction An unit of work on database that is either completed in its entirety or is not performed at all. ACID Properties: –Atomicity: All or nothing –Consistency: A transaction transforms a database from one consistent state to another consistent state. –Isolation: Transactions execute independently of one another. Serializability –Durability: The effects of a successfully completed transaction are permanently recorded in the database and must not be lost.

11 Begin Transaction Active State Read/ Write Partially Committed Failed aborted Abort Commit

12 Transaction Commands Begin Transaction Update commands Commit RollBack End Transaction

13 Log File (Journal) A file that contains all information about all updates to the database. It may contain the following data: –Transaction records: Transaction ID Type of action: –Begin, Insert,Delete, Modify, Commit, Rollback, End Before-image After-image –Checkpoint records The point of synchronization between the database and the transaction log file.

14 Completed Transaction All calculations done by the transaction in its work space (RAM) must have finished, and a copy of the results of the transaction must have been written in a secure place (log file). The action of committing the transaction must also be written in the log.

15 Two Phase Commit A transaction cannot commit until it has recorded all its changes in the log. A transaction cannot write into the database until it has committed.

16 Recovery Technique Using Deferred Update When a transaction starts, write a Transaction Start record to the log. When any write operation is performed, write a log record containing the after-image of the update. When a transaction is about to commit: –write a Transaction Commit log record, –write all the log records for the transaction to disk, then –Use the log records to perform the actual updates to the database. If a transaction aborts, write a Transaction Abort log record and do not perform the writes. –A transaction without a Transaction Abort record is also aborted.

17 To Recover In the event of a failure, examine the log startng from the most recent checkpoint record. Any transaction with Transaction Start and Transaction Commit records should be redone: –Perform all the writes to the database using the after-image log records in the order in which they were written to the log.

18 DefiningTransaction in An Application Truck Rental System: –Vehicle Table:VID, VType, VStatus » V1PickUp Available » V2TowTruck Booked –VReservation:RID, VID, Date » R1V21/2/04

19 Transaction Example Sub Rent(RID, VID, RDate) Begin Transaction Insert (RID, VID, RDate) into VReservation table If No Error Then Update Vehicle Status If No Error Then Commit Transaction Else Roll Back End if Else Roll Back End if End Sub

20 Database Security

21 Theft and fraud; Loss of confidentiality; –Data critical to the organization Loss of privacy; Loss of integrity; Loss of availability.

22 Potential Threats Hardware: physical damages Software: –DBMS: security mechanism, privilege –Application software: program alteration People: –Users: using another person’s means of access, viewing unauthorized data, introduction of viruses –Programmers/Operators –Database administrator: Inadequate security policy Database –Theft, unauthorized update/copy

23 Countermeasures to Threats Authorization –Authentication Access controls: privileges Database views BackUp and Recovery Enforcing integrity rules Encryption –Symmetric encryption:use same key for encryption and decryption –Asymmetric encryption: Public key: for encryption Private key: decryption RAID

24 SQL Injection Exploits applications that use external input for database commands. In the textbox, enter: –‘ OR 1=1 OR CID = ‘

25 Demo ( demoweb112/webform9) Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\salesDB.mdb" Dim objConn As New OleDbConnection(strConn) Dim strSQL As String = "select * from customer where cid = '" & TextBox1.Text & "'" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() DataGrid1.DataSource = objDataReader DataGrid1.DataBind()


Download ppt "Concurrency Control. R/RR/W W/W User 2 ReadWrite User 1 Read Write R/W: Inconsistent Read problem. W/W: Lost Update problem."

Similar presentations


Ads by Google