<p dir="ltr">Yes, we are talking about the same thing. I think the term 'optimistic locking' comes from what happens during the sql transaction. The sql engine converts a read (the WHERE clause) and update (the UPDATE clause) operations into an atomic operation. <br>

The atomic guarantee requires an internal lock in the database on the record after it is found by the WHERE clause but before the UPDATE is completed to prevent a simultaneous query with the same WHERE clause from updating the record at the same time. <br>

So the lock (or some serialization strategy) is still there, but it's just buried deep in the SQL engine internals where they belong. :-) </p>
<div class="gmail_quote">On Jul 30, 2014 2:00 PM, "Jay Pipes" <<a href="mailto:jaypipes@gmail.com">jaypipes@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 07/30/2014 12:21 PM, Kevin Benton wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Maybe I misunderstood your approach then.<br>
<br>
I though you were suggesting where a node performs an "UPDATE record<br>
WHERE record = last_state_node_saw" query and then checks the number of<br>
affected rows. That's optimistic locking by every definition I've heard<br>
of it. It matches the following statement from the wiki article you<br>
linked to as well:<br>
<br>
"The latter situation (optimistic locking) is only appropriate when<br>
there is less chance of someone needing to access the record while it is<br>
locked; otherwise it cannot be certain that the update will succeed<br>
because the attempt to update the record will fail if another user<br>
updates the record first."<br>
<br>
Did I misinterpret how your approach works?<br>
</blockquote>
<br>
The record is never "locked" in my approach, why is why I don't like to think of it as optimistic locking. It's more like "optimistic read and update with retry if certain conditions continue to be met..." :)<br>

<br>
To be very precise, the record is never locked explicitly -- either through the use of SELECT FOR UPDATE or some explicit file or distributed lock. InnoDB won't even hold a lock on anything, as it will simply add a new version to the row using its MGCC (sometimes called MVCC) methods.<br>

<br>
The technique I am showing in the patch relies on the behaviour of the SQL UPDATE statement with a WHERE clause that contains certain columns and values from the original view of the record. The behaviour of the UPDATE statement will be a NOOP when some other thread has updated the record in between the time that the first thread read the record, and the time the first thread attempted to update the record. The caller of UPDATE can detect this NOOP by checking the number of affected rows, and retry the UPDATE if certain conditions remain kosher...<br>

<br>
So, there's actually no locks taken in the entire process, which is why I object to the term optimistic locking :) I think where the confusion has been is that the initial SELECT and the following UPDATE statements are *not* done in the context of a single SQL transaction...<br>

<br>
Best,<br>
-jay<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wed, Jul 30, 2014 at 11:07 AM, Jay Pipes <<a href="mailto:jaypipes@gmail.com" target="_blank">jaypipes@gmail.com</a><br>
<mailto:<a href="mailto:jaypipes@gmail.com" target="_blank">jaypipes@gmail.com</a>>> wrote:<br>
<br>
    On 07/30/2014 10:53 AM, Kevin Benton wrote:<br>
<br>
        Using the UPDATE WHERE statement you described is referred to as<br>
        optimistic locking. [1]<br>
<br>
        <a href="https://docs.jboss.org/__jbossas/docs/Server___Configuration_Guide/4/html/__The_CMP_Engine-Optimistic___Locking.html" target="_blank">https://docs.jboss.org/__<u></u>jbossas/docs/Server___<u></u>Configuration_Guide/4/html/__<u></u>The_CMP_Engine-Optimistic___<u></u>Locking.html</a><br>

        <<a href="https://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/The_CMP_Engine-Optimistic_Locking.html" target="_blank">https://docs.jboss.org/<u></u>jbossas/docs/Server_<u></u>Configuration_Guide/4/html/<u></u>The_CMP_Engine-Optimistic_<u></u>Locking.html</a>><br>

<br>
<br>
    SQL != JBoss.<br>
<br>
    It's not optimistic locking in the database world. In the database<br>
    world, optimistic locking is an entirely separate animal:<br>
<br>
    <a href="http://en.wikipedia.org/wiki/__Lock_(database)" target="_blank">http://en.wikipedia.org/wiki/_<u></u>_Lock_(database)</a><br>
    <<a href="http://en.wikipedia.org/wiki/Lock_(database)" target="_blank">http://en.wikipedia.org/wiki/<u></u>Lock_(database)</a>><br>
<br>
    And what I am describing is not optimistic lock concurrency in<br>
    databases.<br>
<br>
    -jay<br>
<br>
<br>
<br>
    ______________________________<u></u>___________________<br>
    OpenStack-dev mailing list<br>
    OpenStack-dev@lists.openstack.<u></u>__org<br>
    <mailto:<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.<u></u>openstack.org</a>><br>
    <a href="http://lists.openstack.org/__cgi-bin/mailman/listinfo/__openstack-dev" target="_blank">http://lists.openstack.org/__<u></u>cgi-bin/mailman/listinfo/__<u></u>openstack-dev</a> <<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a>><br>

<br>
<br>
<br>
<br>
--<br>
Kevin Benton<br>
<br>
<br>
______________________________<u></u>_________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.<u></u>org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a><br>
<br>
</blockquote>
<br>
<br>
______________________________<u></u>_________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.<u></u>org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a><br>
</blockquote></div>