Elasticsearch-Analysis of two concurrency control schemes of pessimistic lock and optimistic lock (study notes)

  1. Pessimistic lock concurrency control schemes are
  common in relational databases, such as MySQL. The pessimistic lock concurrency control scheme is to lock the data in various situations. After the lock is locked, only one thread can manipulate this data. Of course, the locks on different scenarios are different, including row-level locks, table-level locks, read locks, and write locks.
  
 2. The optimistic locking concurrency control scheme
 es uses optimistic locking. Optimistic locking is that each thread without locking can operate at will. This control scheme will determine whether the version number of the current data is the same as that in es when writing data. The version numbers are consistent. If the version numbers are consistent, data is written. If the version numbers are inconsistent, the data has been modified. At this time, the thread will find the latest data and modify the data on this basis.  Advantages
 
 and disadvantages:
1. The advantages of pessimistic locking are: convenience, direct locking is transparent to the application, and no additional operations are required; the disadvantage is that the concurrency is low, and only one thread can operate data at the same time.
 2. The advantages of optimistic locking are: high concurrency, no data locks, a large number of concurrent operations of threads; the disadvantage is that it is troublesome, the version number must be compared each time the update is performed, and then the data needs to be reloaded and modified again. Write; this process may be repeated several times.
 
 

Guess you like

Origin blog.csdn.net/Micheal_yang0319/article/details/105739326
Recommended