Example
A store has 50 units of Product A in inventory and two people order Product A simultaneously, reducing the inventory
① Places order for 15
units of Product A
② Places order for 20
units of Product A
A
B
User A
User B
Product A inventory
:Reference
:Update
Exclusive
lock
50−15=35
×:Reference
50 units
:Reference
35 units
15 units
35−20=15
:Update
User B
acquires
exclusive
lock
Chapter 9
Exclusive
lock
Acquire exclusive lock
to prevent
referencing/updating
by others
User B is
made to
wait during
this time
Technology element
Acquire exclusive lock
to prevent
referencing/updating by
others
(2)Transaction
A “transaction” is a set of operations that should be completed as one
unit. For example, the process of “placing an order for 15 units of Product A” is a transaction.
Transactions are either accepted and completely processed, or rejected and
not processed at all. If a transaction is completed successfully, the database
is updated. However, if a transaction is interrupted and gets aborted, the
database is not updated. This system maintains database consistency.
2
Backups in the event of failure
The database management system automatically writes updated information to a “log file” when an update process is executed on the database.
The database and log file should be backed up regularly just in case hardware failure occurs. If hardware failure does occur, a backup makes it possible to exchange the hardware and restore the database up to the point
where the log file was last backed up.
Reference
Log file
A “log file” is a file that records activities
that occur on a computer. It can be used
to check who accessed the data on a
server, when it was accessed, and what
was done to it.
256