3: Based on optimistic locking (two kinds) concurrency control: version, external lock

ES is based on optimistic concurrency control locks.
If there is concurrent business scenarios can be directly used ES built optimistic locking mechanism .
When used, the Java program you need to Get specified record, to get the version number, then Put the time, with the version number, the update request.
ES is determined to be in the recorded  version = version value request , the update order. If not equal, then discarded.
 
The following demonstrates how to use optimistic locking:
 
1, first create a record, this time there will return information ES logo: version = 1
PUT  /test_index/test_type/1
{
    "f1":"test f1"
}
2, with the update version = 1 Put executed, can be updated successfully
PUT /test_index/test_type/1?version=1
{
    "f1":"test Client 2"
}
3, another client at the same time also made a Get query to obtain version = 1, this time it took to perform version = 1 put, being given: version inconsistent. Even greater than nor
PUT /test_index/test_type/1?version=1
{
    "f1":"test Client 3"
}
4. After this happens, java program should Get once again, to get the new version number
GET  /test_index/test_type/1
5, once again initiate the request, with a version number just obtained. At this point you can successfully updated
PUT /test_index/test_type/1?version=2
{
    "f1":"test Client 3"
}
 
-------------------------------------------------- --- External lock --------------------------------------------- ---------------------------------------------
 
1. When external lock, ES is determined, the value of version version value> If the request is actually recorded, to update. Equal, then the update fails
PUT /test_index/test_type/2
{
    "f1":"test f1"
}
PUT /test_index/test_type/2?version=2&version_type=external
{
    "f1":"test f2"
}

Guess you like

Origin www.cnblogs.com/cc299/p/11032799.html