SlideShare a Scribd company logo
Subject: Distributed systems
Department of computer science and
Engineering
Prof. S. Anbu
Sep’10, 2021
 This algorithm is used to determine the partial ordering of
events in a distributed system and also to detect causality
violations.
 Assume the processes are running P0,P1 and
P2.
 At 1’o clock, The first process P0 send a message to P1. This message
reaches P1 only at 6 pm in the evening.
 At 2’0 clock, the first process P0 send an another message to the
process p3. It reaches P3 at 3 pm.
 The processPp3 also sends one message to process P2 at 4 ‘o clock.
This message reaches P1 at 5 pm.
 The important thing about this situation is that , the message from P2
arrives at P1, before the first message from P0 reaches p1 i.e the
first message arrives only at 6 pm. ( late arrival)
 This timing problem should be solved .
Vector clock algorithm
 The process P0 gives one apple to P1.
 Immediately P0 sends a message to P2 that P1 has one apple
 So P2 sends a message to P1 to eat that apple.
 But the real situation is, P1 not yet received that apple. So how does
he eat it?
 This example illustrates a causality violation.
 A causality violation occurs when a message ordering problem results
in one host taking an action based on information that another host
should have received, but not yet received.
 In this case , P2 is trying to invoke a method ( eat( ) ) on P1, because
P2 wrongly assumes that P1 has an apple.
 Each process in a system should have knowledge of other processes
running in the system to find the causality violations. i.e An array of
knowledge is needed by each process.
 Lamport logical lock is not sufficient to solve this problem, because it
tracks only the total number of events in the system
 So a new communication mechanism is needed to solve this causality
violation problem. What is that mechanism?
 Vector clocks .
 Vector Clocks are used in a distributed systems to determine whether
pairs of events are causally related or not.
 Using Vector Clocks, timestamps are generated for each event in the
system, and their causal relationship is determined by comparing those
timestamps.
 Vector clock of a system of N processes is an array of N logical clocks,
i.e one clock per process.

 So for N given processes, there will be a vector/ array of size N.
[ 1….N]
 As with Lamport logical time, each process maintains its own
view of the local time and updates it using the timestamps
placed by the sender onto messages.
 But with vector logical time, the time contains more information
i.e it contains a vector representing the state of each process
running in the distributed system.
 In other words, this vector not only contains the event count for
the process itself, it also contains the last-known event counts on
each and every other process .
 Initially, all the clocks are set to zero.
 Every time, an Internal event occurs in a process, the value of the
processes' logical clock in the vector is incremented by 1
Two rules
 Rule 1: ( Local update rule) Every time a process sends a message, the
value of the processes' logical clock in the vector is incremented by 1 and
and then send a copy of its own vector.
 Rule 2: (message rule) Every time, a process receives a message, the
value of the processes' logical clock in the vector is incremented by 1.
Moreover, each element is updated by taking the maximum of the value
in its own vector clock and the value in the vector in the received message
.
 As a result, when a process receives a message, it merges its own time
vector and the timestamp sent with the message -- it selects the higher
of the values for each element.
 This ensures that the sender has information that is at least as up-to-
date as the receiver.
Vector clock algorithm
 Assume, N = 3. i.e 3 processes are running p1, p2 and p3.
Apply rule 1 ( Local update rule)
 The event a occurs in p1. So it increments its own logical clock in the
vector by 1. ( 1,0,0)
 The event d occurs in p2. So it increments its own logical clock in
the vector by 1. ( 0,1,0)
 The event g occurs in p3. So it increments its own logical clock in
the vector by 1. ( 0,0,1)
 Now , event b occurs in process p1. So again apply rule 1 (local update
rule). Process p1 increments its clock in the vector by 1. ( 2,0,0).
 The event b of process p1 sends a message to the event e in process
p2. Also sends a copy of its own vector to p2( By piggybacking. i.e
sends vector elements on the shoulder of message).
 Now what will be the status of the vector clocks ?.
 Apply rule 2
( Every time, a process receives a message, the value of the processes'
logical clock in the vector is incremented by 1. Moreover, each element is
updated by taking the maximum of the value in its own vector clock and
the value in the vector in the received message (for every element) ) .
First, Increment VC of p2 by 1 as per the rule. So ( 0,1,0) becomes
( 0,2,0) .
Vector clock values in the received message are ( 2, 0, 0). ( Already
sent by p1)
Take maximum of these two vector clock values
Time stamps
-----------
0, 2, 0 0 and 2 . maximum is 2
2, 0, 0 2 and 0 . maximum is 2
-----------
2, 2, 0
----------
Vector clock algorithm
 Now, many events occur in all the processes
 Event h occurs in process p3. So VCs become ( 0, 0, 2)
 Event c occurs in process p1. Now, VCs become ( 3, 0, 0)
 Event f occurs in process p2. Now, VCs become ( 2, 3, 0)
 Event i occurs in process p3.
Vector clock algorithm
Vector clock algorithm
 Now what will be the status of the vector clocks now ?.
 Apply rule 2
 first, Increment VC of p3 by 1 as per the rule
 So ( 0, 0, 2) becomes ( 0, 0, 3 )
 Vector clock values in the received message are ( Already sent by p2)
 ( 2, 3, 0).
 Take maximum of these two vector clock values
 Time stamps
 ------------
 0, 0, 3 take maximum values
 2, 3, 0
 -----------
 2, 3, 3
 ----------

Vector clock algorithm
 Vector clocks easily captures the causality between inter-process
communications. Partial order (→) between a and i.
 If two events are not comparable, we say these events are concurrent. But
Lamport logical clock mechanism can not find whether the events are
concurrent or not. This problem is solved by the vector clock mechanism
 Using vector clock, timestamps are created for each event in the
distributed system and their relationship is determined by comparing
those timestamps. Whether they are concurrent or in a casual relationship.
 Vector clock timestamps precisely capture happens-before relation
 Vector Clocks guarantee strong clock consistency as they are an
extension of Lamport Timestamps.
 .
Thank you
Ad

More Related Content

What's hot (20)

Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
SHATHAN
 
Distributed Systems Naming
Distributed Systems NamingDistributed Systems Naming
Distributed Systems Naming
Ahmed Magdy Ezzeldin, MSc.
 
Message passing in Distributed Computing Systems
Message passing in Distributed Computing SystemsMessage passing in Distributed Computing Systems
Message passing in Distributed Computing Systems
Alagappa Govt Arts College, Karaikudi
 
Computer Network-Data Link Layer-Module-2.pdf
Computer Network-Data Link Layer-Module-2.pdfComputer Network-Data Link Layer-Module-2.pdf
Computer Network-Data Link Layer-Module-2.pdf
Sweta Kumari Barnwal
 
Distributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithmsDistributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithms
MNM Jain Engineering College
 
Message and Stream Oriented Communication
Message and Stream Oriented CommunicationMessage and Stream Oriented Communication
Message and Stream Oriented Communication
Dilum Bandara
 
CS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMSCS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMS
Kathirvel Ayyaswamy
 
program partitioning and scheduling IN Advanced Computer Architecture
program partitioning and scheduling  IN Advanced Computer Architectureprogram partitioning and scheduling  IN Advanced Computer Architecture
program partitioning and scheduling IN Advanced Computer Architecture
Pankaj Kumar Jain
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
Dr Sandeep Kumar Poonia
 
File replication
File replicationFile replication
File replication
Klawal13
 
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit ProtocolsDistributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Sachin Chauhan
 
Chapter 14 replication
Chapter 14 replicationChapter 14 replication
Chapter 14 replication
AbDul ThaYyal
 
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...
Sagar Rai
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
Md. Mahedi Mahfuj
 
Chapter 6-Consistency and Replication.ppt
Chapter 6-Consistency and Replication.pptChapter 6-Consistency and Replication.ppt
Chapter 6-Consistency and Replication.ppt
sirajmohammed35
 
Transport services
Transport servicesTransport services
Transport services
Navin Kumar
 
Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)
Sri Prasanna
 
Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)
Sri Prasanna
 
Case Study - SUN NFS
Case Study - SUN NFSCase Study - SUN NFS
Case Study - SUN NFS
Ashish KC
 
Lamport’s algorithm for mutual exclusion
Lamport’s algorithm for mutual exclusionLamport’s algorithm for mutual exclusion
Lamport’s algorithm for mutual exclusion
Neelamani Samal
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
SHATHAN
 
Computer Network-Data Link Layer-Module-2.pdf
Computer Network-Data Link Layer-Module-2.pdfComputer Network-Data Link Layer-Module-2.pdf
Computer Network-Data Link Layer-Module-2.pdf
Sweta Kumari Barnwal
 
Message and Stream Oriented Communication
Message and Stream Oriented CommunicationMessage and Stream Oriented Communication
Message and Stream Oriented Communication
Dilum Bandara
 
program partitioning and scheduling IN Advanced Computer Architecture
program partitioning and scheduling  IN Advanced Computer Architectureprogram partitioning and scheduling  IN Advanced Computer Architecture
program partitioning and scheduling IN Advanced Computer Architecture
Pankaj Kumar Jain
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
Dr Sandeep Kumar Poonia
 
File replication
File replicationFile replication
File replication
Klawal13
 
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit ProtocolsDistributed Transactions(flat and nested) and Atomic Commit Protocols
Distributed Transactions(flat and nested) and Atomic Commit Protocols
Sachin Chauhan
 
Chapter 14 replication
Chapter 14 replicationChapter 14 replication
Chapter 14 replication
AbDul ThaYyal
 
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...
SDN( Software Defined Network) and NFV(Network Function Virtualization) for I...
Sagar Rai
 
Chapter 6-Consistency and Replication.ppt
Chapter 6-Consistency and Replication.pptChapter 6-Consistency and Replication.ppt
Chapter 6-Consistency and Replication.ppt
sirajmohammed35
 
Transport services
Transport servicesTransport services
Transport services
Navin Kumar
 
Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)Mutual Exclusion Election (Distributed computing)
Mutual Exclusion Election (Distributed computing)
Sri Prasanna
 
Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)
Sri Prasanna
 
Case Study - SUN NFS
Case Study - SUN NFSCase Study - SUN NFS
Case Study - SUN NFS
Ashish KC
 
Lamport’s algorithm for mutual exclusion
Lamport’s algorithm for mutual exclusionLamport’s algorithm for mutual exclusion
Lamport’s algorithm for mutual exclusion
Neelamani Samal
 

Similar to Vector clock algorithm (20)

Clocks
ClocksClocks
Clocks
guesta013ed8
 
Time in distributed systmes
Time in distributed systmesTime in distributed systmes
Time in distributed systmes
mohammad amid abbasi
 
Chap 5
Chap 5Chap 5
Chap 5
suks_87
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.ppt
MeymunaMohammed1
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.ppt
sirajmohammed35
 
Clock.pdf
Clock.pdfClock.pdf
Clock.pdf
MohdAbdulHaque
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System
Harshita Ved
 
Ds practical file
Ds practical fileDs practical file
Ds practical file
Khushboo Pal
 
dokumen.tips_synchronization-in-distributed-systems-chapter-6.ppt
dokumen.tips_synchronization-in-distributed-systems-chapter-6.pptdokumen.tips_synchronization-in-distributed-systems-chapter-6.ppt
dokumen.tips_synchronization-in-distributed-systems-chapter-6.ppt
samaghorab
 
slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
balewayalew
 
Chapter 6 synchronization
Chapter 6 synchronizationChapter 6 synchronization
Chapter 6 synchronization
Alagappa Government Arts College, Karaikudi
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework Help
Statistics Assignment Help
 
6.Distributed Operating Systems
6.Distributed Operating Systems6.Distributed Operating Systems
6.Distributed Operating Systems
Dr Sandeep Kumar Poonia
 
3. syncro. in distributed system
3. syncro. in distributed system3. syncro. in distributed system
3. syncro. in distributed system
Gd Goenka University
 
clock (1) .ppt
clock (1)                                   .pptclock (1)                                   .ppt
clock (1) .ppt
farantouqeer8
 
clock. ppt
clock.                               pptclock.                               ppt
clock. ppt
farantouqeer8
 
time-clocks.pdf
time-clocks.pdftime-clocks.pdf
time-clocks.pdf
BlankSpace23
 
Rate.docx
Rate.docxRate.docx
Rate.docx
kradha5
 
osama-quantum-computing and its uses and applications
osama-quantum-computing and its uses and applicationsosama-quantum-computing and its uses and applications
osama-quantum-computing and its uses and applications
Rachitdas2
 
A brief introduction of Quantum-computing
A brief introduction of Quantum-computingA brief introduction of Quantum-computing
A brief introduction of Quantum-computing
eugenecom
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.ppt
MeymunaMohammed1
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.ppt
sirajmohammed35
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System
Harshita Ved
 
dokumen.tips_synchronization-in-distributed-systems-chapter-6.ppt
dokumen.tips_synchronization-in-distributed-systems-chapter-6.pptdokumen.tips_synchronization-in-distributed-systems-chapter-6.ppt
dokumen.tips_synchronization-in-distributed-systems-chapter-6.ppt
samaghorab
 
Rate.docx
Rate.docxRate.docx
Rate.docx
kradha5
 
osama-quantum-computing and its uses and applications
osama-quantum-computing and its uses and applicationsosama-quantum-computing and its uses and applications
osama-quantum-computing and its uses and applications
Rachitdas2
 
A brief introduction of Quantum-computing
A brief introduction of Quantum-computingA brief introduction of Quantum-computing
A brief introduction of Quantum-computing
eugenecom
 
Ad

Recently uploaded (20)

Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Ad

Vector clock algorithm

  • 1. Subject: Distributed systems Department of computer science and Engineering Prof. S. Anbu Sep’10, 2021
  • 2.  This algorithm is used to determine the partial ordering of events in a distributed system and also to detect causality violations.
  • 3.  Assume the processes are running P0,P1 and P2.
  • 4.  At 1’o clock, The first process P0 send a message to P1. This message reaches P1 only at 6 pm in the evening.  At 2’0 clock, the first process P0 send an another message to the process p3. It reaches P3 at 3 pm.  The processPp3 also sends one message to process P2 at 4 ‘o clock. This message reaches P1 at 5 pm.
  • 5.  The important thing about this situation is that , the message from P2 arrives at P1, before the first message from P0 reaches p1 i.e the first message arrives only at 6 pm. ( late arrival)  This timing problem should be solved .
  • 7.  The process P0 gives one apple to P1.  Immediately P0 sends a message to P2 that P1 has one apple  So P2 sends a message to P1 to eat that apple.  But the real situation is, P1 not yet received that apple. So how does he eat it?
  • 8.  This example illustrates a causality violation.  A causality violation occurs when a message ordering problem results in one host taking an action based on information that another host should have received, but not yet received.  In this case , P2 is trying to invoke a method ( eat( ) ) on P1, because P2 wrongly assumes that P1 has an apple.
  • 9.  Each process in a system should have knowledge of other processes running in the system to find the causality violations. i.e An array of knowledge is needed by each process.  Lamport logical lock is not sufficient to solve this problem, because it tracks only the total number of events in the system  So a new communication mechanism is needed to solve this causality violation problem. What is that mechanism?  Vector clocks .
  • 10.  Vector Clocks are used in a distributed systems to determine whether pairs of events are causally related or not.  Using Vector Clocks, timestamps are generated for each event in the system, and their causal relationship is determined by comparing those timestamps.  Vector clock of a system of N processes is an array of N logical clocks, i.e one clock per process.   So for N given processes, there will be a vector/ array of size N. [ 1….N]
  • 11.  As with Lamport logical time, each process maintains its own view of the local time and updates it using the timestamps placed by the sender onto messages.  But with vector logical time, the time contains more information i.e it contains a vector representing the state of each process running in the distributed system.  In other words, this vector not only contains the event count for the process itself, it also contains the last-known event counts on each and every other process .
  • 12.  Initially, all the clocks are set to zero.  Every time, an Internal event occurs in a process, the value of the processes' logical clock in the vector is incremented by 1 Two rules  Rule 1: ( Local update rule) Every time a process sends a message, the value of the processes' logical clock in the vector is incremented by 1 and and then send a copy of its own vector.  Rule 2: (message rule) Every time, a process receives a message, the value of the processes' logical clock in the vector is incremented by 1. Moreover, each element is updated by taking the maximum of the value in its own vector clock and the value in the vector in the received message .
  • 13.  As a result, when a process receives a message, it merges its own time vector and the timestamp sent with the message -- it selects the higher of the values for each element.  This ensures that the sender has information that is at least as up-to- date as the receiver.
  • 15.  Assume, N = 3. i.e 3 processes are running p1, p2 and p3. Apply rule 1 ( Local update rule)  The event a occurs in p1. So it increments its own logical clock in the vector by 1. ( 1,0,0)  The event d occurs in p2. So it increments its own logical clock in the vector by 1. ( 0,1,0)  The event g occurs in p3. So it increments its own logical clock in the vector by 1. ( 0,0,1)
  • 16.  Now , event b occurs in process p1. So again apply rule 1 (local update rule). Process p1 increments its clock in the vector by 1. ( 2,0,0).
  • 17.  The event b of process p1 sends a message to the event e in process p2. Also sends a copy of its own vector to p2( By piggybacking. i.e sends vector elements on the shoulder of message).  Now what will be the status of the vector clocks ?.
  • 18.  Apply rule 2 ( Every time, a process receives a message, the value of the processes' logical clock in the vector is incremented by 1. Moreover, each element is updated by taking the maximum of the value in its own vector clock and the value in the vector in the received message (for every element) ) . First, Increment VC of p2 by 1 as per the rule. So ( 0,1,0) becomes ( 0,2,0) . Vector clock values in the received message are ( 2, 0, 0). ( Already sent by p1) Take maximum of these two vector clock values Time stamps ----------- 0, 2, 0 0 and 2 . maximum is 2 2, 0, 0 2 and 0 . maximum is 2 ----------- 2, 2, 0 ----------
  • 20.  Now, many events occur in all the processes  Event h occurs in process p3. So VCs become ( 0, 0, 2)  Event c occurs in process p1. Now, VCs become ( 3, 0, 0)  Event f occurs in process p2. Now, VCs become ( 2, 3, 0)  Event i occurs in process p3.
  • 23.  Now what will be the status of the vector clocks now ?.  Apply rule 2  first, Increment VC of p3 by 1 as per the rule  So ( 0, 0, 2) becomes ( 0, 0, 3 )  Vector clock values in the received message are ( Already sent by p2)  ( 2, 3, 0).  Take maximum of these two vector clock values  Time stamps  ------------  0, 0, 3 take maximum values  2, 3, 0  -----------  2, 3, 3  ---------- 
  • 25.  Vector clocks easily captures the causality between inter-process communications. Partial order (→) between a and i.
  • 26.  If two events are not comparable, we say these events are concurrent. But Lamport logical clock mechanism can not find whether the events are concurrent or not. This problem is solved by the vector clock mechanism  Using vector clock, timestamps are created for each event in the distributed system and their relationship is determined by comparing those timestamps. Whether they are concurrent or in a casual relationship.  Vector clock timestamps precisely capture happens-before relation  Vector Clocks guarantee strong clock consistency as they are an extension of Lamport Timestamps.  .
  翻译: