高并发下membase的数据能否加锁
怎么锁定membase中的数据啊
在高并发情况下.....
急啊.....................................
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
怎么锁定membase中的数据啊
在高并发情况下.....
急啊.....................................
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
Here is an example for .net application. You can use it for java in similar way:
A CAS (Check And Set) operation is the correct way to ensure that operations happen without data loss without requiring distributed locking protocols or transactions to be handled. The way it works is you get the value of something with its cas. This is a monotonically increasing number that can be thought of as the version number of the object in the database. You mutate the object (change it in some way) and use a
Cas
operation to write it back to the database. This will fail (acasResult
whose Result property is set to false) if some other client had modified the value in the database in the meantime. Notice the use of the'??'
operator. This says assign to the list variableresult.Result
if it is not null; otherwise create an empty list具体用JAVA怎么操作啊
You can refer to this wiki article:
http://www.couchbase.org/wiki/display/membase/Locking
Locking
Advisory locks can be useful to control access to scarce resources. For example, retrieving information from backend or remote systems might be slow and consume a lot of resources. Instead of letting any client access the backend system and potentially overwhelm the backend system with high concurrent client requests, you could create an advisory lock to allow only one client at a time access the backend.
Advisory locks in Membase or Memcached can be created by setting expiration times on a named data item and by using the 'add' and 'delete' commands to access that named item. The 'add' or 'delete' commands are atomic, so you can be know that only one client will become the advisory lock owner.
The first client that tries to ADD a named lock item (with an expiration timeout) will succeed. Other clients will see error responses to an ADD command on that named lock item, so they can know that some other client is owning the named lock item. When the current lock owner is finished owning the lock, it can send an explicit DELETE command on the named lock item to free the lock.
If the lock owning client crashes, the lock will automatically become available to the next client that polls for the lock (using 'add') after the expiration timeout.