Database Reference
In-Depth Information
their living room. The mixing room is very small, and only one person can enter at a time.
Now anyone can enter the room in any order. After all of them mix the colors red, blue
and green in the correct proportion, the family will get the white paint. We don't have any
problem in this case.
Consider another scenario where we need black paint. As mentioned in the CMYK color
chart , if we need black then we must mix cyan, magenta, and yellow in equal proportions.
Therefore now we have two mixing rooms. The first mixing room is used to produce the
colors cyan, magenta, and yellow, and the second mixer room is used to mix these colors
to get the color black. Therefore, the first mixing room should have three containers. Each
family member holding a primary color (red, green, and blue) should mix their color in
exactly two containers. For example, to get cyan, we need to mix blue and green. If the
person holding red mixes his color with the container that always has cyan, then it will
turn white, which makes the whole process fail. So there should be some locking, which is
made available.
Let us assume that the father and mother have the colors red and blue with them and have
done their work by mixing the paints in the correct containers. So, as of now, one contain-
er will have magenta (R+B), the other will have red, and the last container will have blue.
Then their elder son enters with green paint and mixes it in the second container, which
turns into yellow (R+G). He then realizes that he doesn't have any paint left to mix with
the third container which is still blue. So, he moves out to collect the paint. The younger
daughter doesn't have any idea about it. So, she comes and collects all three containers
and mixes them. Do you think she might have looked at the color black? The answer is
no, and in fact, she will look at magenta. Y+M gives red and R+B gives magenta.
The question is, what might have prevented this error? First, it is the responsibility of the
elder son to notify the family members that he is not yet done with his work and he should
have put a lock on that room, not letting anyone (including his sister) mix those paints
prematurely. But, he didn't do that. This is the reason why we should have a lock over
something (here the DynamoDB database table) when more than one person has access to
the shared data. Even though it is a bigger illustration, I hope that it answers the primary
question about the use of locking.
Tip
The preceding image is available as a colored image for download from ht-
tps://www.packtpub.com/sites/default/files/downloads/1897OT_07_01.png .
Search WWH ::




Custom Search