The Lost Update Problem

The Lost Update Problem

The concurrent processing illustrated in Figure 9-4 poses no problems because the users are processing different data. But suppose that both users want to process Item 100. For example,

Figure 9-3

Need for Transaction Processing

CNum OrderNum Description

CNum OrderNum Description AmtDue 123

AmtDue

1. Add new-order data to

2. Add new-order data to

Total-

Name

Sales Commission Due JONES

Sales Commission Due

3. Insert new ORDER.

(a) Errors Introduced Without Transaction

(continued)

Figure 9-3

Begin Transaction

CUSTOMER

Change CUSTOMER data

CNum OrderNum Description

CNum OrderNum Description AmtDue 123

AmtDue

Change SALESPERSON data

Insert ORDER data

If no errors then Commit Transactions Else

SALESPERSON

Rollback Transaction

Sales Commission Due JONES

Sales Commission Due

(b) Atomic Transaction Prevents Errors

Chapter 9 Managing Multiuser Databases

User A

User B

1. Read item 100.

1. Read item 200.

2. Change item 100.

2. Change item 200.

3. Write item 100.

3. Write item 200.

Order of processing at database server 1. Read item 100 for A.

2. Read item 200 for B. 3. Change item 100 for A.

Figure 9-4

4. Write item 100 for A. 5. Change item 200 for B.

Concurrent-Processing

6. Write item 200 for B.

Example

User A wants to order five units of Item 100, and User B wants to order three units of the same item. Figure 9-5 illustrates the problem.

User A reads a copy of Item 100’s record into memory. According to the record, there are

10 items in inventory. Then User B reads another copy of Item 100’s record into a different section of memory. Again, according to the record, there are 10 items in inventory. Now User A takes five, decrements the count of items in its copy of the data to five, and rewrites the record for Item 100. Then User B takes three, decrements the count in its copy of the data to seven, and rewrites the record for Item 100. The database now shows, incorrectly, that there are seven Item 100s in inventory. To review: We started with 10 in inventory, User A took 5, User B took 3, and the database shows that 7 are in inventory. Clearly, this is a problem.

Both users obtained data that were correct at the time they obtained them. But when User B read the record, User A already had a copy that it was about to update. This situation is called the lost update problem, or the concurrent update problem. A similar problem is the inconsistent read problem. With this problem, User A reads data that have been processed by a portion of a transaction from User B. As a result, User A reads incorrect data.

One remedy for the inconsistencies caused by concurrent processing is to prevent multiple applications from obtaining copies of the same record when the record is about to be changed. This remedy is called resource locking.

Figure 9-5

User B Lost Update Problem

User A

1. Read item 100

1. Read item 100

(item count is 10).

(item count is 10).

2. Reduce count of items by 5.

2. Reduce count of items by 3.

3. Write item 100.

3. Write item 100.

Order of processing at database server 1. Read item 100 (for A).

2. Read item 100 (for B). 3. Set item count to 5 (for A). 4. Write item 100 for A. 5. Set item count to 7 (for B). 6. Write item 100 for B.

Note: The change and write in steps 3 and 4 are lost.

Part 4 Multiuser Database Processing