|INSS 651 Ch 10
Transaction Management and concurrency control
a sequence of logical steps that will accomplish a single task (or
what seems like a single task)
add an employee
enter an order
enroll a student in a course
A single task may require MANY changes to the database.
If all changes are NOT made database integrity will be lost
ex: Enroll a student
MARY to INSS651
1.check to see if student "MARY" exists…read only
2.check to see if class "INSS651" exists..read only
3. access enrollment table ..read only
update enrollment table ..make changes (update)
4. access student record/table ..read only
update student table ..make changes (update)
5. access class record/table
update class table
all phases (steps) must be completed, if not abort the trans.
permanence of DB consistent state achieved only when transaction is complete
Be able to serialize concurrent trans.
Be able to isolate data and can not be used by other trans.
if aborted for any reasons, ROLLBACK,
i.e., change back to previous commit
create backup and use it to reconstruct DB
Transaction Log(Journal): (p 402)
Keeps track of all transactions that update the DB
Info kept in a typical log:
time of trans.
type of trans.
object of action
this allows for FORWARD & BACKWARD recovery
add student xyz to inss651
transaction ID transaction description
ST1 get student table (check to see if student xyz exists
get class table (check to see if inss651 exists)
get enrollment table
enroll student XYZ in inss651
update student record (ie total number of hours)
update class record (i.e., total number of students)
a log may look like:
TRANS ID TIME ACTION OBJECT OF ACTION BEFORE AFTER
ST1 8:00 START
ST1 8:04 INSERT ENROLLMENT(XYZ,INSS651..) NEW VALUE
ST1 8:16 MODIFY STUDENT (XYZ,..) OLD VALUE NEW VALUE
ST1 8:20 MODIFY CLASS(INSS651..) OLD VALUE NEW VALUE
ST1 8:30 COMMIT
Recovery Management (page 416)
if ALL or PART of the database has been destroyed then start
with most recent backup and update it using AFTER images from COMMITTED
transactions to this copy.
if DB is not actually destroyed but trans. was not completed,
then we need to bring Db back to consistent state.
start with current DB and UNDO changes using BEFORE values of uncommitted trans.
which is most recent correct state?
with large users/transaction it is not clear what is the correct database state.
do we go back to archives?
most systems have CHECKPOINT.
Periodically system will refuse any new requests and will complete transactions
in progress. Usually done every 15 min. or so to match log and DB
Recovery THRU OFFsetting trans.
GIGO, a trans. Is entered incorrectly & commit is done.
ROLLBACK is NOT effective
create a DUMMY offsetting trans RECORD
IF WE WANT TO REDUCE BALACE BY $30 BUT BY MISTAKE WE PUT $50, an offsetting transaction would require a “dummy” transaction of $20 to ADD to the account
DB is not updated directly, but a DIFFERENTIAL file containing the
changes is created
DB are periodically updated in batch mode. Similar to accounting systems
two users trying to update a data item
ex: TOM needs to increase product A by $35 and MARY needs to
decrease it by 35
Initial value is 642.50
TOM reads information
from DB($642.50)step 1TOM updates data in
his work area $677.50
Value is 677.50
TOM updates DB
MARY reads info from
MARY updates data in her work
Mary updates database $642.50
A Different scenario
TOM reads information
Mary read from DB($642.50)
TOM updates it to $677.50 Mary updates it
TOM updates DB $677.50
Mary updates DB
An INCORRECT update!!!!
LOST updates: when we lose one of the updates
CONCURRENCY CONTROL with LOCKING (page 408)
Guarantees EXCLUSIVE use of data item to a CURRENT trans.LOCK GRANULARITY:level of lock usage
more overhead as we go from DB to field LOCK types:
Shared lock allows users to access data for "READ" only mode
Exclusive lock does not allow data access until user releases
data item thru commit, used for updates
exclusive lock is granted iff there are no other locks on the
TOM has finished five steps of a six step transaction, but data
needed for sixth step is locked...
a trans. acquires all the locks needed for that transaction
transaction releases ALL locks
two users are waiting for data that is locked by each other
if a user cannot get all the locks, they are not provided ANY
break the deadlock by rolling back one user's transactions