Databases Reference
In-Depth Information
A record in this separate file might indicate, for example, that Premiere Products received a $100 pay-
ment from customer 282 on a certain date. Periodically, usually once a day, a single update program reads the
batch of records in this file one at a time and performs the appropriate updates to the database; this process-
ing technique is called batch processing . Because this program is the only way to update the database, you
eliminate the problems associated with concurrent update.
Although this alternative approach avoids the lost update problem, it creates another problem. From the
time users start updating (adding records to the special batch file) until the time the batch-processing pro-
gram actually updates the database, the data in the database is out of date. If a customer's balance in the data-
base is $4,500, the true balance is $5,500 if a user had entered an order for this customer that increased its
balance by $1,000. If the customer has a $5,000 credit limit, the customer is now over its credit limit by $500.
The batch-processing alternative does not work in any situation that requires the data in the database to
be current. These situations include credit card processing, banking, inventory control, and airline
reservations. Other simple alternative solutions to the concurrent update problem, such as permitting only
one user to update the database, also will not work in these situations because many users need to update the
database in a timely way.
233
Two-Phase Locking
In most situations, you can't solve the concurrent update problem by avoiding it; you need the DBMS to have
a strategy for dealing with it. One such strategy is for the DBMS to process an update completely before it
begins processing the next update. For example, the DBMS can prevent Elena from beginning her update to the
Brookings Direct data until the DBMS completes Ryan's update to that data, or vice versa.
To accomplish such a serial processing of updates, many DBMSs use locking. Locking denies other users
access to data while the DBMS processes one user's updates to the database. An example of locking using
Ryan's and Elena's updates appears in Figure 7-8. After the DBMS reads the data in the database for Ryan's
update, the DBMS locks the data, denying access to the data by Elena and any other user. The DBMS retains
the locks until Ryan completes his change; then the DBMS updates the database. For the duration of the locks,
the DBMS rejects all attempts by Elena to access the data and it notifies Elena that the data is locked. If she
chooses to do so, she can keep attempting to access the data until the DBMS releases the locks, at which
time the DBMS can process her update. In this simple case at least, the locking technique appears to solve the
lost update problem.
 
Search WWH ::




Custom Search