CH 7 Part 2 Distributed System
CH 7 Part 2 Distributed System
CH 7 Part 2 Distributed System
com
Chapter 6
www.getmyuni.com
Object Replication
• There are two approaches for object sharing:
– The object itself can handle concurrent invocation.
• A Java object can be constructed as a monitor by declaring
the object’s methods to be synchronized.
– The object is completely unprotected against
concurrent invocations, but the server in which the
object resides is made responsible for concurrency
control.
• In particular, use an appropriate object adapter.
www.getmyuni.com
Object Replication
Object Replication
• There are two approaches for object replication:
– The application is responsible for replication.
• Application needs to handle consistency issues.
– The system (middleware) handles replication.
• Consistency issues are handled by the middleware.
• It simplifies application development but makes object-
specific solutions harder.
www.getmyuni.com
Object Replication
Object Replication
Linearizability
• Definition: 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. In addition, if TSop1(x) < TSop2(y),
then operation OP1(x) should precede OP2(y) in this
sequence.
• In this model, operations are assumed to receive a timestamp
using a globally available clock with finite precision.
• A linearizable data store is also sequentially consistent, but it is
more expensive to implement than sequential consistency
• Linearizability is primarily used to assist formal verification of
concurrent programs,
Analysis of Sequential Consistency
www.getmyuni.com
Four valid execution sequences for the processes of the previous slide.
www.getmyuni.com
Causal Consistency
• Causal consistency requires a total order of causally
related write operations only.
1. A read is causally related to the write that provided the data
the read got.
2. A write is causally related to a read that happened before this
write in the same process.
3. If write1 read, and read write2, then write1 write2.
• Necessary condition for causal consistency:
Writes that are potentially casually related must be seen
by all processes in the same order. Concurrent writes
may be seen in a different order on different machines.
www.getmyuni.com
Casual Consistency
Casual Consistency
FIFO Consistency
• 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.
FIFO Consistency
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);
FIFO Consistency
Process P1 Process P2
x = 1; y = 1;
if (y == 0) kill (P2); if (x == 0) kill (P1);
Weak Consistency
• 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.
• You don't care that reads and writes of a series of
operations are immediately known to other
processes. You just want the effect of the series
itself to be known.
www.getmyuni.com
Weak Consistency
int a, b, c, d, e, x, y; /* variables */
int *p, *q; /* pointers */
int f( int *p, int *q); /* function prototype */
a = x * x; /* a stored in register */
b = y * y; /* b as well */
c = a*a*a + b*b + a * b; /* used later */
d = a * a * c; /* used later */
p = &a; /* p gets address of a */
q = &b /* q gets address of b */
e = f(p, q) /* function call */
Weak Consistency
• 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.
• You don't care that reads and writes of a series of
operations are immediately known to other
processes. You just want the effect of the series
itself to be known.
www.getmyuni.com
Weak Consistency
Release Consistency
• Divide access to a synchronization variable into
two parts: an acquire and a release phase. Acquire
forces a requester to wait until the shared data can
be accessed; release sends requester's local value
to other servers in data store.
Release Consistency
• Rules:
– Before a read or write operation on shared data is
performed, all previous acquires done by the
process must have completed successfully.
– Before a release is allowed to be performed, all
previous reads and writes by the process must
have completed
– Accesses to synchronization variables are FIFO
consistent (sequential consistency is not required).
www.getmyuni.com
Entry Consistency
• Conditions:
– An acquire access of a synchronization variable is not
allowed to perform with respect to a process until all updates
to the guarded shared data have been performed with respect
to that process.
– Before an exclusive mode access to a synchronization
variable by a process is allowed to perform with respect to
that process, no other process may hold the synchronization
variable, not even in nonexclusive mode.
– After an exclusive mode access to a synchronization variable
has been performed, any other process's next nonexclusive
mode access to that synchronization variable may not be
performed until it has performed with respect to that
variable's owner.
www.getmyuni.com
Entry Consistency
Eventual Consistency
Monotonic Reads
• If a process reads the value of a data item x, any
successive read operation on x by that process will
always return that same or a more recent value.
• Example: Automatically reading your personal
calendar updates from different servers. Monotonic
Reads guarantees that the user sees all updates, no
matter from which server the automatic reading takes
place.
• Example: Reading (not modifying) incoming mail
while you are on the move. Each time you connect to a
different email server, that server fetches (at least) all
the updates from the server you previously visited.
www.getmyuni.com
Monotonic Reads
Monotonic Writes
• If a A write operation by a process on a data item x is
completed before any successive write operation on x
by the same process.
• Example: Updating a program at server S2 , and
ensuring that all components on which compilation
and linking depends, are also placed at S2 .
• Example: Maintaining versions of replicated files in
the correct order everywhere (propagate the previous
version to the server where the newest version is
installed).
www.getmyuni.com
Monotonic Writes
Replica Placement
• The effect Model: We consider objects (and don't
worry whether they contain just data or code, or both)
• Distinguish different processes: A process is capable
of hosting a replica of an object or data:
– Permanent replicas: Process/machine always having a
replica
– Serverinitiated replica: Process that can dynamically host a
replica on request of another server in the data store
– Clientinitiated replica: Process that can dynamically host a
replica on request of a client (client cache)
www.getmyuni.com
Replica Placement
Server-Initiated Replicas
• The Keep track of access counts per file,
aggregated by considering server closest to
requesting clients
• Number of accesses drops below threshold D
drop file
• Number of accesses exceeds threshold R
replicate file
• Number of access between D and R migrate file
www.getmyuni.com
Server-Initiated Replicas
Update Propagation
• There are three possibilities of propagation update:
– The Propagate only notification/invalidation of update (often
used for caches)
– Transfer data from one copy to another (distributed
databases)
– Propagate the update operation to other copies (also called
active replication)
• No single approach is the best, but depends highly on
available bandwidth and readtowrite ratio at replicas.
www.getmyuni.com
Messages sent Update (and possibly fetch update later) Poll and update
Response time at
Immediate (or fetch-update time) Fetch-update time
client
Epidemic Algorithms
• Basic idea: Assume there are no write--write conflicts:
– Update operations are initially performed at one or only a
few replicas
– A replica passes its updated state to a limited number of
neighbors
– Update propagation is lazy, i.e., not immediate
– Eventually, each update should reach every replica
• Antientropy: Each replica regularly chooses another
replica at random, and exchanges state differences,
leading to identical states at both afterwards
• Gossiping: A replica which has just been updated (i.e.,
has been contaminated), tells a number of other
replicas about its update (contaminating them as well).
www.getmyuni.com
System Model
• We consider a collection servers, each storing a
number of objects
• Each object O has a primary server at which
updates for O are always initiated (avoiding
writewrite conflicts)
• An update of object O at server S is always
timestamped; the value of O at S is denoted
VAL (O, S)
• T (O, S) denotes the timestamp of the value of
object O at server S
www.getmyuni.com
Consistency Protocols
• Consistency protocol: describes the implementation of
a specific consistency model. We will concentrate only
on sequential consistency.
– Primary-based protocols
– Replicated-write protocols
– Cache-coherence protocols
www.getmyuni.com
Consistency Protocols
• Examples of primarybased protocols
– Used in traditional clientserver systems that do not support
replication.
– Traditionally applied in distributed databases and file
systems that require a high degree of fault tolerance.
Replicas are often placed on same LAN.
– Establishes only a fully distributed, nonreplicated data store.
Useful when writes are expected to come in series from the
same client (e.g., mobile computing without replication)
– Distributed shared memory systems, but also mobile
computing in disconnected mode (ship all relevant files to
user before disconnecting, and update later on).
www.getmyuni.com
Remote-Write Protocols
Remote-Write Protocols
Local-Write Protocols
Local-Write Protocols
ReplicatedWrite Protocols
• Active replication: Updates are forwarded to multiple
replicas, where they are carried out. There are some
problems to deal with in the face of replicated
invocations.
• Replicated invocations: Assign a coordinator on each
side (client and server), which ensures that only one
invocation, and one reply is sent.
• Quorumbased protocols: Ensure that each operation
is carried out in such a way that a majority vote is
established: distinguish read quorum and write
quorum.
www.getmyuni.com
Active Replication
Active Replication
Quorum-Based Protocols
Orca
OBJECT IMPLEMENTATION stack;
top: integer; # variable indicating the top
stack: ARRAY[integer 0..N-1] OF integer # storage for the stack
OPERATION push (item: integer) # function returning nothing
BEGIN
GUARD top < N DO
stack [top] := item; # push item onto the stack
top := top + 1; # increment the stack pointer
OD;
END;
OPERATION pop():integer; # function returning an integer
BEGIN
GUARD top > 0 DO # suspend if the stack is empty
top := top – 1; # decrement the stack pointer
RETURN stack [top]; # return the top item
OD;
END;
BEGIN
top := 0; # initialization
END;