Distributed systems use logical clocks . In some distributed storage systems, a version number is added to the back of the data item , and the value of the version number is added when updating, which should be regarded as a kind of logical clock . [For example, the causal relationship of events is a kind of logic. 】
Common logical clocks (description methods): Lamport timestamps (event sequence relationship), Vector clock (no causal relationship, simultaneous events, vector is used for concurrency, did you think of the container in java? Yes! Haha ).
The former is used to describe the sequential relationship of an event (single thread). Vector clock is used to describe the simultaneous relationship (concurrent concurrency, multi-threading has concurrency, multi-threading and the number of CPU cores and hyper-threading technology ) . The method of Vector clock is used to find data version conflict (distributed storage system) , namely Version vector .
http://www.doc88.com/p-7903104995524.html
Or (recommended): https://www.cnblogs.com/bangerlee/p/5448766.html
Summary:
In some scenarios of distributed systems, it is also necessary to record and compare the order of events between different nodes , but different from the use of physical clocks to record time in daily life, distributed systems use logical clocks to record the sequence of events.
Why don't distributed systems use physical clocks to record events? Each event corresponds to a timestamp. When it is necessary to compare the order, it is better to compare the corresponding timestamps?
Reason: The time recorded by each node in the distributed system is not the same. Even if the NTP time synchronization node is set, there is still a millisecond-level deviation , which will also cause the sequence of events to be incomparable. [ Note : For physical clocks, milliseconds are very short in human eyes, but for high-speed CPUs , milliseconds are very long time intervals. During this error time interval, it is entirely possible that many events have occurred on different nodes, so when it is necessary to distinguish the sequence of events, it is impossible to distinguish the sequence of events! 】