Consistency and Replication Lecture
Consistency and Replication Lecture
Replication of data
Why?
• To enhance reliability
• To improve performance in a large scale system
However;
• Replicas must be consistent
• Modifications have to be carried out on all copies
• Problems with network performance
It is needed to handling concurrency…
Loose Consistency
read or
write
• The general organization of a logical data store, physically distributed and replicated
across multiple machines.
• Each process that can access the data has its own local copy
• Write operations are propagated to the other copies
Strict Consistency
Any read on a data item x returns a value of the last write operation on x
Two operations in the same time interval are said to conflict if they operate on the same data and one of them is a
write operation
This behavior implies a globally consistent view of data that requires synchronization across all replicas
The result of any execution is the same as if the read and write operations by all
processes on the data store were executed in some sequential order and the
operations of each individual process appear in this sequence in the order specified
by its program
All processes see the same interleaving of operations
a) A sequentially consistent data store. كل عمليات القراءة ترى آخر قيمة مكتوبة،
b) A data store that is not sequentially consistent.
z = 1;
x = 1; y = 1; write
print ( y, z); print (x, z); print (x, y);
read
Example : three concurrently executing processes; (x, y, z) are data store shared items
Various (90) interleaved execution sequences are possible
Linearizability and Sequential Consistency (3)
x = 1; x = 1; y = 1; y = 1;
print (y, z); y = 1; z = 1; x = 1;
y = 1; print (x, z); print (x, y); z = 1;
print (x, z); print(y, z); print (x, z); print (x, z);
z = 1; z = 1; x = 1; print (y, z);
print (x, y); print (x, y); print (y, z); print (x, y);
Not all signature pattern are allowed : 00 00 00 not permitted, 00 10 01 not permitted.
An invalid ordering would be when after assigning a value to a variable we still print a 0. Another scenario might be if we do not agree to
program order.
Constraints:
• Program order must be maintained
• Data coherence must be respected
Data coherence : any read must return the most recently written value of the data (relatively to the single data item, without regard to other data)
Causal Consistency (1)
When there is a read followed by a write, the two events
are potentially causally related
Operation not causally related are said concurrent
Necessary condition:
Writes that are potentially causally related must be seen
by all processes in the same order. Concurrent writes
may be seen in a different order on different machines.
Causal Consistency (2)
This sequence is allowed with a causally-consistent store, but not with sequentially or strictly
consistent store.
Note that the writes W2(x)b and W1(x)c are concurrent
Causal consistency requires keeping records and tracks of the writes seen or processed by each
process or node in the distributed system.
Causal Consistency (3)
Necessary Condition:
Writes done by a single process are seen by all other processes in the
order in which they were issued, but writes from different processes
may be seen in a different order by different processes.
A valid sequence of events of FIFO consistency. It is not valid for causal consistency
FIFO Consistency (3)
Process P1 Process P2 Process P3
x = 1; y = 1; z = 1; write
print ( y, z); print (x, z); print (x, y); read
x = 1; x = 1; y = 1;
print (y, z); y = 1; print (x, z);
y = 1; print(x, z); z = 1;
print(x, z); print ( y, z); print (x, y);
z = 1; z = 1; x = 1;
print (x, y); print (x, y); print (y, z);
The statements in bold are the ones that generate the output shown. Their
concatenated output is 001001, that is incompatible with sequential consistency
FIFO Consistency (4)
Different processes can see the operations in different
order
Process P1 Process P2
x = 1; y = 1;
if (y == 0) kill (P2); if (x == 0) kill (P1);
The result of this two concurrent processes can be also that both processes are killed.
Weak Consistency
We can release the requirements of writes within the same process
seen in order everywhere introducing a synchronization variable.
A synchronization operation synchronize all local copies of the data
store.
Properties of weak consistency:
• Accesses to synchronization variables associated with a data store
are sequentially consistent
• No operation on a synchronization variable is allowed to be
performed until all previous writes have been completed
everywhere
• No read or write operation on data items are allowed to be
performed until all previous operations to synchronization
variables have been performed.
It forces consistency on a group of operations, not on individual write
and read
It limits the time when consistency holds, not the form of consistency.
Weak Consistency
A valid event sequence for entry consistency. Lock are associated with each data item
Summary of Consistency Models
Consistency Description
Strict Absolute time ordering of all shared accesses matters.
All processes must see all shared accesses in the same order. Accesses are
Linearizability
furthermore ordered according to a (nonunique) global timestamp
All processes see all shared accesses in the same order. Accesses are not ordered in
Sequential
time
Causal All processes see causally-related shared accesses in the same order.
All processes see writes from each other in the order they were used. Writes from
FIFO
different processes may not always be seen in that order
(a)
Consistency Description
Weak Shared data can be counted on to be consistent only after a synchronization is done
Release Shared data are made consistent when a critical region is exited
Entry Shared data pertaining to a critical region are made consistent when a critical region is
entered.
(b)
a) Consistency models not using synchronization operations.
b) Models with synchronization operations.