ADBMsFirstDay Classs
ADBMsFirstDay Classs
File System manages data using files on a hard disk. Users are allowed
to create, delete, and update the files according to their requirements.
Let us consider the example of file-based University Management
System.
Data of students is available to their respective Departments, Academics
Section, Result Section, Accounts Section, Hostel Office, etc. Some of
the data is common for all sections like Roll No, Name, Father Name,
Address, and Phone number of students but some data is available to a
particular section only like Hostel allotment number which is a part of
the hostel office.
…
Let us discuss the issues with this system:
• Redundancy of data: Data is said to be redundant if the same data is
copied at many places. If a student wants to change their Phone
number, he or has to get it updated in various sections. Similarly, old
records must be deleted from all sections representing that student.
• Inconsistency of Data: Data is said to be inconsistent if multiple
copies of the same data do not match each other. If the Phone number
is different in Accounts Section and Academics Section, it will be
inconsistent. Inconsistency may be because of typing errors or not
updating all copies of the same data.
…
• Difficult Data Access: A user should know the exact location of the
file to access data, so the process is very cumbersome and tedious. If
the user wants to search the student hostel allotment number of a
student from 10000 unsorted students’ records, how difficult it can be.
• Unauthorized Access: File Systems may lead to unauthorized access
to data. If a student gets access to a file having his marks, he can
change it in an unauthorized way.
…
• No Concurrent Access: The access of the same data by multiple users
at the same time is known as concurrency. The file system does not
allow concurrency as data can be accessed by only one user at a time.
• No Backup and Recovery: The file system does not incorporate any
backup and recovery of data if a file is lost or corrupted.
Advantages of DBMS over File system
consistent consistent
transaction
state state
database requests
What is a Transaction?
What Is a Transaction?
Figure 9.2
What Is a Transaction?
• Transaction Properties
• Atomicity
• All transaction operations must be completed
• Incomplete transactions aborted
• Consistency
permanence of the database’s consistent state.
• Isolation
means that the data used during the execution of a transaction cannot be
used by a second transaction until the first one is completed.
What Is a Transaction?
• Transaction Properties
• Durability
once transaction changes are done (committed), they cannot be
undone.
• Serializability
• concurrent transactions are treated as though they were executed in
serial order (one after another).
• Ensures that the concurrent execution of several transactions yields
consistent results
• important in multi-user and distributed databases.
What Is a Transaction?
• Transaction Management with SQL
• Transaction support is provided
• COMMIT
• ROLLBACK
• When a transaction sequence is initiated,
it must continue through all succeeding SQL statements until one
of the following four events occurs:
• A COMMIT statement is reached.
The COMMIT statement automatically ends the SQL transaction.
• A ROLLBACK statement is reached.
• The end of a program is successfully reached ( = COMMIT).
• The program is abnormally terminated ( = ROLLBACK).
What Is a Transaction?
• Transaction Management with SQL
• Example:
UPDATE PRODUCT
SET PROD_QOH = PROD_QOH - 2
WHERE PROD_CODE = ‘1558-QW1’;
UPDATE CUSTOMER
SET CUST_BALANCE = CUST_BALANCE + 87.98
WHERE CUST_NUMBER = ‘10011’;
COMMIT;
• Concurrency control
coordinates simultaneous execution of transactions in a
multiprocessing database.
• The objective of concurrency control is to
ensure the serializability of transactions in a multi-user database
environment.
Concurrency Control
TRANSACTION COMPUTATION
T1: Purchase 100 units PROD_QOH = PROD_QOH + 100
T2: Sell 30 units PROD_QOH = PROD_QOH - 30
TABLE 10.3
Concurrency Control
• Uncommitted Data
• Data are not committed when
two transactions T1 and T2 are executed concurrently and the
first transaction is rolled back after
the second transaction has already accessed the uncommitted
data –
thus violating the isolation property of the transaction.
TRANSACTION COMPUTATION
T1: Purchase 100 units PROD_QOH = PROD_QOH + 100 (Rolled back)
T2: Sell 30 units PROD_QOH = PROD_QOH - 30
TABLE 10.4
TABLE 10.5
Concurrency Control
• Inconsistent Retrievals
• Inconsistent retrievals occur when a transaction calculates some summary
(aggregate) functions over a set of data while other transactions are
updating the data.
• Example:
• T1 calculates the total quantity on hand of the products stored in the PRODUCT table.
• At the same time, T2 updates the quantity on hand (PROD_QOH) for two of the
PRODUCT table’s products.
Retrieval During Update
TABLE
10.6 T2
T1
Transaction Results:
Data Entry Correction
TABLE
10.7
Inconsistent
TABLE
Retrievals
10.8
Concurrency Control
• The Scheduler
• The scheduler establishes the order in which the operations
within concurrent transactions are executed.
• The scheduler interleaves the execution of database
operations to ensure serializability and isolation.
• To determine the appropriate order, the scheduler bases its
actions on concurrency control algorithms, such as locking or
time stamping methods.
• The scheduler also makes sure that the computer’s CPU is
used efficiently.
Read/Write Conflict Scenarios:
Conflicting Database Operations Matrix
TABLE
10.9
FIGURE 10.3
An Example Of A Table-Level Lock
•T1 and T2 cannot access the same table concurrently,
even if they use different rows.
FIGURE 10.4
An Example Of A Page-Level Lock
•T1 and T2 cannot access the same page concurrently,
even if they use different rows.
• the most frequently used multiuser DBMS locking methods.
FIGURE 10.5
An Example Of A Row-Level Lock
• Although it improves the availability of data,
its management requires high overhead cost.
row
FIGURE 10.6
Concurrency Control with
Locking Methods
• Lock types
• Binary Locks
• Shared/Exclusive Locks
• Binary Locks
• A binary lock has only two states:
locked (1) or unlocked (0).
• If an object is locked by a transaction,
no other transaction can use that object.
• If an object is unlocked, any transaction can lock the object for its
use.
• A transaction must unlock the object
after its termination.
Binary Lock
Concurrency Control with Locking Methods
• Shared/Exclusive Locks
(1)Exclusive Locks
• An exclusive lock exists when access is specially reserved for
the transaction that locked the object.
• The exclusive lock must be used
when the potential for conflict exists.
(2)Shared Locks
• A shared lock exists
when concurrent transactions are granted READ access on the basis
of a common lock.
• A shared lock produces no conflict as long as the concurrent
transactions are read only.
• Shared/Exclusive Locks
Although the possibility of shared locks renders data access more
efficient,
a shared/exclusive lock schema increases the lock manager’s
overhead.
• Three lock operations needed:
• READ_LOCK(check the type of lock)
• WRITE_LOCK(issue the lock)
• UNLOCK(release the lock)
Concurrency Control with Locking Methods
• Shared/Exclusive Locks
Current
Shared Exclusive
Unlock
Want to Lock Lock
Shared Shared
Read Wait
Lock Lock
Exclusive
Write Wait Wait
Lock
Concurrency Control with Locking Methods
• Two-Phase Locking
• The two-phase locking protocol defines how transactions
acquire and relinquish locks.
It guarantees serializability,
but it does not prevent deadlocks.
• In a growing phase,
a transaction acquires all the required locks without
unlocking any data.
Once all locks have been acquired,
the transaction is in its locked point.
• In a shrinking phase,
a transaction releases all locks and cannot obtain any
new locks.
Concurrency Control with Locking Methods
Table 9.11
Four Conditions for Deadlock
All four of these conditions must be present :
1. Mutual exclusion condition
•
each resource assigned to 1 process or is available
2. Hold and wait condition
•
process holding resources can request additional
3. No preemption condition
•
previously granted resources cannot forcibly taken away
4. Circular wait condition
• must be a circular chain of 2 or more processes
• each is waiting for resource held by next member of the
chain
Concurrency Control with Locking Methods
• Problems
1. may not know required resources at start of run
2. Resources will not be used optimally.
• Variation:
• process must give up all resources it currently holds
then request all at once
(3) Attacking the No Preemption Condition
(a) (b)
Concurrency Control with
Time Stamping Methods
• Wound/wait (Older)
• Older transaction rolls back the younger transaction and reschedules it
Requesting Owning
Wait/Die Wound/Wait
Lock Lock
T1 preempts
T1(Older) T2(Younger) T1 Wait
T2
T2(Younger) T1(Older) T2 Dies T2 Waits
Wait/Die and Wound/Wait
Concurrency Control Schemes
Concurrency Control with Optimistic Methods
• Optimistic Methods
• It is based on the assumption
that the majority of the database operations do not conflict.
• A transaction is executed without restrictions
until it is committed.
Database• Recovery
Recovery Management
restores a database
from a given state, usually inconsistent,
to a previously consistent state.
• Recovery techniques are based on the atomic transaction
property:
All portions of the transaction must be applied and
completed to produce a consistent database.
If, for some reason, any transaction operation cannot be
completed, the transaction must be aborted, and any
changes to the database must be rolled back.
Database Recovery Management
• Levels of Backup
• Full backup of the database
It backs up or dumps the whole database.
• Write-through/Immediate-update
The database is immediately updated by transaction operations during
the transaction’s execution, even before the transaction reaches its
commit point.
The transaction log is also updated.
If a transaction fails, the database uses the log information to roll back
the database.