Lost Update Example: Two people are editting the same file. The person who saves his file last overwrites the changes made by the first person. The first person's updates are lost.
Inconsistent Read: You are counting the total number of files in two directories. Let's say there are 20 files in the honeymoon folder and 30 files in the wedding folder to start. You list the number of files in the wedding folder, then you take a break. In the meantime, your wife adds 5 pictures to the honeymoon folder an 3 pictures to the wedding folder. You come back and count 33 pictures in the wedding folder. Your total is 20 + 33 = 55. Before your wife added the additional pictures, the total was 50, and afterward the total was 58, so 55 is an incosistent read caused by the concurrently reading from a folder while someone else is writing to that folder.
A pessimistic lock requires each process to lock data while it is being modified.
With a pick list of products, it doesn't matter if a new product appears in it after you start making changes, but a list of charges you're summarizing for a bill may be more important. In some cases, careful analysis of how the data is used is required. For example, a zip code may seem unimportant, but if where a person lives determines a tax calculation, then the address has to be controlled for concurrency.
Read/Write Lock
Temporal Reads
Deadlocks
ACID
The four isolation levels and the corresponding behaviors are described below:
| Dirty Read | Non-Repeatable Read | Phantom Read | |
|---|---|---|---|
| Read Uncommitted | Possible | Possible | Possible |
| Read Committed | Not Possible | Possible | Possible |
| Repeatable Read | Not Possible | Not Possible | Possible |
| Serializable | Not Possible | Not Possible | Not Possible |
With Repeatable Read, we know that a value that is read at the beginning of a transaction will be the same no matter how many times it is subsequently re-read during the course of that transaction, even if another transaction commits a change to that value (or for that matter deletes it). However, newly committed insertions may still cause inconsistent reads. Suppose transaction R executes a query that looks for all the red cars in a given table. Initially this query may return, say 3 records. The values of those records won't change if the transaction re-reads those records, and if another transaction deletes some of them, a re-read will still not be affected -- all 3 records will still show up. However, there is still a potential for inconsistent reads. If transaction W commits two more red cars, then re-running the query in R will now return 5 cars instead of 3! These extra two records are called phantoms, because as far as the R transaction is concerned, there should still only be 3 cars.
Optimisitic Offline Lock
Pessimistic Offline Lock
Coarse Grained Lock