In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces what the CAS optimistic lock problem of couchbase is like, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.
Scenario: synchronous playback recording OPS: 30wcas problem CAS:Compare and Swap, translated into comparison and exchange. With the help of CAS, an optimistic lock different from synchronized synchronous lock is implemented in java.util.concurrent package. The principle is that CAS has three operands, the memory value V, the old expected value A, and the new value B to be modified. If and only if the expected value An is the same as the memory value V, change the memory value V to B, otherwise do nothing. / * * Atomically sets the value to the given updated value * if the current value {@ code =} the expected value. * * @ param expect the expected value * @ param update the new value * @ return {@ code true} if successful. False return indicates that * the actual value was not equal to the expected value. * / public final boolean compareAndSet (int expect, int update) {return unsafe.compareAndSwapInt (this, valueOffset, expect, update);} in high concurrency scenarios, writing couchbase will cause cas problems. That is, if cas is not used, then the data written later will overwrite the data written earlier. If cas is enabled, only the first one will be written successfully because one data is read at the same time, and the rest will not be written because compare and swap failed. It should be noted here that although the upsert method of the couchbase client supports cas, it will not throw an exception if there is an cas error when writing. Use the replace method as shown in the following two figures
When we use the correct cas, we need to deal with the data consistency problems caused by cas. At this time, we can use our own solutions to solve the problem. I use the drainTo method of redisson's getBlockingQueue, which cooperates with the scheduled task to realize batch processing. Extension: the cas problem is on the server side. If the design is unreasonable, it will cause aba problem. To put it simply, first X and Y deal with data X at the same time, change A to B, then change B to A, and then Y changes A to other values, which is also successful. But at this point the data has changed A-> B-> A, so a separate value is referenced at this time to uniquely distinguish between the two values. Such as uuid and so on. On the couchbase CAS optimistic lock is what kind of sharing here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.