Database Reference
In-Depth Information
User A
User B
1. Read item 100.
2. Change item 100.
3. Write item 100.
1. Read item 200.
2. Change item 200.
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.
4. Write item 100 for A.
5. Change item 200 for B.
6. Write item 200 for B.
Figure 9-4
Concurrent-Processing
Example
switching among tasks is done so quickly that two people seated at browsers side by side,
processing the same database, may believe that their two transactions are completed simul-
taneously; in reality, however, the two transactions are interleaved.
Figure 9-4 shows two concurrent transactions. User A's transaction reads Item 100,
changes it, and rewrites it in the database. User B's transaction takes the same actions, but on
Item 200. The CPU processes User A's transactions until it encounters an I/O interrupt or some
other delay for User A. The operating system shifts control to User B. The CPU now processes
User B's transactions until an interrupt, at which point the operating system passes control
back to User A. To the users, the processing appears to be simultaneous, but it is interleaved,
or concurrent.
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,
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
User A
User B
Figure 9-5
Lost Update Problem
1. Read item 100
(item count is 10).
2. Reduce count of items by 5.
3. Write item 100.
1. Read item 100
(item count is 10).
2. Reduce count of items by 3.
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.
 
Search WWH ::




Custom Search