Logical Clocks refer to implementing a protocol on all machines within your distributed system, so that the machines are able to maintain consistent ordering of events within some virtual timespan. A logical clock is a mechanism for capturing chronological and causal relationships in a distributed system. Distributed systems may have no physically synchronous global clock, so a logical clock allows global ordering on events from different processes in such systems.
If we go outside then we have made a full plan that at which place we have to go first, second and so on. We don’t go to second place at first and then the first place. We always maintain the procedure or an organization that is planned before. In a similar way, we should do the operations on our PCs one by one in an organized way.
Suppose, we have more than 10 PCs in a distributed system and every PC is doing it’s own work but then how we make them work together. There comes a solution to this i.e. LOGICAL CLOCK.
To order events across process, try to sync clocks in one approach.
This means that if one PC has a time 2:00 pm then every PC should have the same time which is quite not possible. Not every clock can sync at one time. Then we can’t follow this method.
Another approach is to assign Timestamps to events.
Taking the example into consideration, this means if we assign the first place as 1, second place as 2, third place as 3 and so on. Then we always know that the first place will always come first and then so on. Similarly, If we give each PC their individual number than it will be organized in a way that 1st PC will complete its process first and then second and so on.
BUT, Timestamps will only work as long as they obey causality.
What is causality ?
Causality is fully based on HAPPEN BEFORE RELATIONSHIP.
- Taking single PC only if 2 events A and B are occurring one by one then TS(A) < TS(B). If A has timestamp of 1, then B should have timestamp more than 1, then only happen before relationship occurs.
- Taking 2 PCs and event A in P1 (PC.1) and event B in P2 (PC.2) then also the condition will be TS(A) < TS(B). Taking example- suppose you are sending message to someone at 2:00:00 pm, and the other person is receiving it at 2:00:02 pm.Then it’s obvious that TS(sender) < TS(receiver).
Properties Derived from Happen Before Relationship –
- Transitive Relation –
If, TS(A) <TS(B) and TS(B) <TS(C), then TS(A) < TS(C)
- Causally Ordered Relation –
a->b, this means that a is occurring before b and if there is any changes in a it will surely reflect on b.
- Concurrent Event –
This means that not every process occurs one by one, some processes are made to happen simultaneously i.e., A || B.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Various Failures in Distributed System
- Limitation of Distributed System
- Mutual exclusion in distributed system
- Features of Distributed Operating System
- Hierarchical Deadlock Detection in Distributed System
- Difference between Local File System (LFS) and Distributed File System (DFS)
- Maekawa’s Algorithm for Mutual Exclusion in Distributed System
- Lamport's Algorithm for Mutual Exclusion in Distributed System
- Suzuki–Kasami Algorithm for Mutual Exclusion in Distributed System
- Ricart–Agrawala Algorithm in Mutual Exclusion in Distributed System
- Logical and Physical Address in Operating System
- Difference between Token based and Non-Token based Algorithms in Distributed System
- Centralized Clock Synchronization
- Second Chance (or Clock) Page Replacement Policy
- Advantages of Distributed database
- Disadvantages of Distributed DBMS
- Distributed Application Paradigms
- Hashing in Distributed Systems
- Synchronization in Distributed Systems
- Concepts of Distributed databases