Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the concurrent operation and consistency of database

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to understand the concurrent operation and consistency of the database". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. let's study and learn how to understand the concurrent operation and consistency of the database.

As a developer of a distributed strongly consistent database, he was asked many times:

If I modify a record in both Singapore and Europe, such as set axiom 1 in Singapore and set aura 2 in Europe, what is the result a?

My answer is:

It could be averse 1, or it could be adept 2.

Then the questioner will be very confused and dissatisfied:

Didn't you say that the database is strongly consistent? Why is the result uncertain?

I fully understand his confusion, but the concurrency and consistency he mentioned are not necessarily related.

Concurrence

Martin Kleppmann mentions the definition of Concurrency:

For defining concurrency, exact time doesn't matter: we simply call two operations concurrent if they are both unaware of each other, regardless of the physical time at which they occurred.

To define concurrency, time is not a factor: if two operations do not know each other (the beginning and end of the operation and the result), no matter when they occur in physical time, we say the two operations are concurrent.

There are examples like this:

At 00:00:00, a request was made to the server, but the server did not return the result. Then, at 00:00:03 (obviously after the previous request was initiated), make a request to the server for B.

So, can we say that B comes after A? The conclusion is no, these two operations are concurrent operations! Although we clearly know that B is initiated after A, but when B initiates, (B) does not know the result of A. according to the definition of Martin Kleppman, the two operations are concurrent.

It may be better to understand concurrency from above the time range. An operation consists of a start time point and an end time point, which forms a time interval. If the time intervals of the two operations overlap, the two operations can not be distinguished.

Another way to define concurrency is:

Martin Kleppmann: An operation A happens before another operation B if B knows about A, or depends on A, or builds upon An in some way.

If this is not the case, it is concurrency.

Consistency

Consistency is closely related to three factors:

order

time

Space

As far as I understand, consistency is the only expectation. That is, given the input condition, the only result can be deduced. For an operation scenario, no matter how many times we repeat verification, how many times we observe (time), and where we observe (space), the result is constant.

If the read operation (observation) is after the write operation, then the observation is the definite result we expect.

If reads and writes are concurrent, old or new values may be observed. However, once a new value is observed, it is impossible to observe the old value (that is, Linearizable).

Thank you for your reading. the above is the content of "how to understand the concurrent operation and consistency of the database". After the study of this article, I believe you have a deeper understanding of how to understand the concurrent operation and consistency of the database. The specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report