NoSQL Module 2
NoSQL Module 2
21CS745
Module -2
• Distribution Models:
• Single Server, Sharding, Master-Slave Replication, Peer-to-Peer Replication,
• Consistency:
• Update Consistency, Read Consistency, Relaxing Consistency, The CAP
Theorem, Relaxing Durability, Quorums.
• Version Stamps
• Business and System Transactions, Version Stamps on Multiple Nodes
• When the writes reach the server, the server will serialize them—
decide to apply one, then the other.
• But how????
• Server first picks for ABC –as first update and then XYZ
• When XYZ’s update would be applied and immediately overwritten by ABC’s.
In this case ABC’s is a lost update
• This is an example for failure consistency
Solution :pessimistic or optimistic
• A pessimistic approach works by preventing conflicts from occurring;
• An optimistic approach lets conflicts occur, but detects them and takes
action.
• For update conflicts, the most common pessimistic approach is to have
write locks, so that in order to change a value you need to acquire a
lock, and the system ensures that only one client can get a lock at a
time.
• In the previous example, ABC ( say) acquired write lock and perform
update. Then XYZ decide whether to update or not.
optimistic approach is a conditional update
• Optimistic approach is a conditional update where any client that
does an update tests the value just before updating it to see if it’s
changed since his last read.
• In our example ,ABC’s update would succeed but XYZ’s would fail.
• The error would let XYZ know that he should look at the value again
and decide whether to attempt a further update.
• write-write conflict—save both updates and record that they are in
conflict.
• This approach is familiar to many programmers from version control
systems, particularly distributed version control systems
• Replication makes it much more likely to run into write-write conflicts.
• If different nodes have different copies of some data which can be
independently updated, then you’ll get conflicts unless you take specific
measures to avoid them.
• Using a single node as the target for all writes for some data makes it
much easier to maintain update consistency
Read Consistency- inconsistent read or
read-write conflict or logical consistency
• Update consistency is one thing, but it doesn’t guarantee that readers
of that data store will always get consistent responses to their
requests.
• NoSQL (aggregate oriented ) does not support transaction but graph
support ACID transaction .
• Aggregate-oriented databases do support atomic updates, but only
within a single aggregate not between two aggregate .
• We can avoid running into that inconsistency if the order, the delivery
charge, and the line items are all part of a single order aggregate.
• How problem comes?
• Not all data can be put in the same aggregate, so any update that
affects multiple aggregates leaves open a time when clients could
perform an inconsistent read.
• The length of time an inconsistency is present is called the
inconsistency window.
Example on inconsistency
• The hotel reservation system runs on many nodes.
• Martin and Cindy are a couple considering this room, but they are
discussing this on the phone because Martin is in London and Cindy is in
Boston and Pramod, who is in Mumbai, goes and books that last room.
• That updates the replicated room availability, but the update gets to
Boston quicker than it gets to London.
• When Martin and Cindy fire up their browsers to see if the room is
available, Cindy sees it booked and Martin sees it free.
• This is another inconsistent read—but it’s a breach of a different form of
consistency we call replication consistency: ensuring that the same data
item has the same value when read from different replicas
• Replication consistency: ensuring that the same data item has the same
value when read from different replicas.
• The updates will propagate fully, and Martin will see the room is fully
booked.
• Therefore this situation is generally referred to as eventually consistent,
meaning that at any time nodes may have replication inconsistencies but, if
there are no further updates, eventually all nodes will be updated to the
same value.
• In NoSQL databases, consistency is more eventual than strong. This means that
replicas may temporarily show inconsistencies, but will eventually converge to
the same state with further updates
The CAP Theorem
Relaxing Durability
• The key to Consistency is serializing requests by forming Atomic,
Isolated work units.
• Each time a node has an internal update, it updates its own counter, so an
update in the green node would change the vector to [blue: 43, green: 55,
black: 12].
• Whenever two nodes communicate, they synchronize their vector stamps.
• vector clocks and version vectors—these are specific forms of vector
stamps to synchronize.
• By using vector clocks scheme you can tell if one version stamp is newer
than another because the newer stamp will have all its counters greater
than or equal to those in the older stamp.
• So [blue: 1, green: 2, black: 5] is newer than [blue:1, green: 1, black 5] since
one of its counters is greater.
• If both stamps have a counter greater than the other, e.g. [blue: 1, green: 2,
black: 5] and [blue: 2, green: 1, black: 5], then you have a write-write
conflict.
• There may be missing values in the vector, in which case we use treat the
missing value as 0. So [blue: 6, black: 2] would be treated as [blue: 6,
green: 0, black: 2].