<!-- 
RSS generated by JIRA (8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d) at Wed Feb 07 19:53:14 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>OpenDaylight JIRA</title>
    <link>https://jira.opendaylight.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>8.20.10</version>
        <build-number>820010</build-number>
        <build-date>22-06-2022</build-date>
    </build-info>


<item>
            <title>[CONTROLLER-524] Introduce example which shows read/write/retry cycle with OptimisticLockFailedException</title>
                <link>https://jira.opendaylight.org/browse/CONTROLLER-524</link>
                <project id="10113" key="CONTROLLER">controller</project>
                    <description>&lt;p&gt;Introduce an example which will showcase proper handling&lt;br/&gt;
of failure of Data Broker commit, which failed because of OptimisticLockFailedException.&lt;/p&gt;</description>
                <environment>&lt;p&gt;Operating System: Windows&lt;br/&gt;
Platform: PC&lt;/p&gt;</environment>
        <key id="25078">CONTROLLER-524</key>
            <summary>Introduce example which shows read/write/retry cycle with OptimisticLockFailedException</summary>
                <type id="10100" iconUrl="https://jira.opendaylight.org/secure/viewavatar?size=xsmall&amp;avatarId=10310&amp;avatarType=issuetype">Improvement</type>
                                                <status id="5" iconUrl="https://jira.opendaylight.org/images/icons/statuses/resolved.png" description="A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.">Resolved</status>
                    <statusCategory id="3" key="done" colorName="green"/>
                                    <resolution id="10000">Done</resolution>
                                        <assignee username="tony.tkacik@gmail.com">Tony Tkacik</assignee>
                                    <reporter username="tony.tkacik@gmail.com">Tony Tkacik</reporter>
                        <labels>
                    </labels>
                <created>Fri, 30 May 2014 12:14:39 +0000</created>
                <updated>Thu, 3 Jul 2014 08:37:39 +0000</updated>
                            <resolved>Thu, 3 Jul 2014 08:37:39 +0000</resolved>
                                    <version>Helium</version>
                                                    <component>mdsal</component>
                        <due>Mon, 30 Jun 2014 00:00:00 +0000</due>
                            <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="48439" author="tony.tkacik@gmail.com" created="Mon, 30 Jun 2014 13:16:04 +0000"  >&lt;p&gt;&lt;a href=&quot;https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Migration:Data_Broker#New_API_-_Write.2FCommit.2FRetry_Example&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Migration:Data_Broker#New_API_-_Write.2FCommit.2FRetry_Example&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="48440" author="readams@readams.net" created="Mon, 30 Jun 2014 16:11:07 +0000"  >&lt;p&gt;The example isn&apos;t quite right.  The logic needs to exhibit a read/modify/write loop and (in a synchronous pseudocode to make it easy to follow) it would look roughly like:&lt;/p&gt;


&lt;p&gt;while (true) {&lt;br/&gt;
   try &lt;/p&gt;
{
      Transaction t = newTransaction();
      ChunkOData d = t.read(chunkodatapath);
      ChunkOData newChunk = modify(d, relevantEvent);
      t.write(chunkodatapath, newChunk);

      break;
   }
&lt;p&gt; catch (ConcurrentModificationException) &lt;/p&gt;
{
      // nothing to do here
   }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;The read/modify part here is important for correctness, since if you get this exception if you just keep retrying your write you&apos;ll lose the data that was written by the other process or thread.&lt;/p&gt;</comment>
                            <comment id="48441" author="tony.tkacik@gmail.com" created="Tue, 1 Jul 2014 08:03:21 +0000"  >&lt;p&gt;Updated to:&lt;/p&gt;

&lt;p&gt;private void readWriteRetry() {&lt;br/&gt;
        ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction();&lt;/p&gt;

&lt;p&gt;        Optional&amp;lt;DataObject&amp;gt; readed = writeTx.read(LogicalDatastoreType.OPERATIONAL,PATH).get();&lt;br/&gt;
        DataObject modified = modifyData(readed);&lt;br/&gt;
        writeTx.put(LogicalDatastoreType.OPERATIONAL, PATH, data);&lt;br/&gt;
        ListenableFuture&amp;lt;RpcResult&amp;lt;TransactionStatus&amp;gt;&amp;gt; future = writeTx.commit();&lt;/p&gt;

&lt;p&gt;        Futures.addCallback(future, new FutureCallback&amp;lt;RpcResult&amp;lt;TransactionStatus&amp;gt;&amp;gt;() {&lt;/p&gt;

&lt;p&gt;            @Override&lt;br/&gt;
            public void onSuccess(final RpcResult&amp;lt;TransactionStatus&amp;gt; result) &lt;/p&gt;
{
                // Commited successfully
                // Nothing to do
            }

&lt;p&gt;            @Override&lt;br/&gt;
            public void onFailure(final Throwable t) {&lt;br/&gt;
                // Transaction failed&lt;/p&gt;

&lt;p&gt;                if(t instanceof OptimisticLockFailedException) &lt;/p&gt;
{
                    LOG.error(&quot;Concurrent modification of data&quot;,e);
                    readWriteRetry();
                }

&lt;p&gt;            }&lt;br/&gt;
        });&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;This example is bit harder to read than your pseudocode, but illustrates read/write/retry using ListenableFutures&lt;br/&gt;
to get transaction status.&lt;/p&gt;</comment>
                            <comment id="48442" author="readams@readams.net" created="Tue, 1 Jul 2014 15:54:01 +0000"  >&lt;p&gt;Looks much better, though this documentation really shouldn&apos;t be on this hidden page.  I might change to:&lt;/p&gt;

&lt;p&gt;private void readWriteRetry(RelevantEvent event) &lt;/p&gt;
{
   // ... 

   DataObject modified = modifyData(readed, event);

   // ... 

}

&lt;p&gt;but this is not critical.&lt;/p&gt;</comment>
                            <comment id="48443" author="readams@readams.net" created="Tue, 1 Jul 2014 17:42:53 +0000"  >&lt;p&gt;By the way, do we recommend calling get() on the read operation future?  Or are you supposed to write the double chain of async events?&lt;/p&gt;

&lt;p&gt;Is each module supposed to allocate its own executor or is there a global shared one to use?&lt;/p&gt;</comment>
                            <comment id="48444" author="tony.tkacik@gmail.com" created="Wed, 2 Jul 2014 08:32:40 +0000"  >&lt;p&gt;Futures.addCallback(Future,FutureCallback) for callback uses thread in which future completed (e.g. MD-SAL thread in this use cases). Futures.addCallback(Future,FutureCallback,Executor) uses executor of your choice.&lt;/p&gt;

&lt;p&gt;We do not have global shared executor.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10000">
                    <name>Blocks</name>
                                                                <inwardlinks description="is blocked by">
                                        <issuelink>
            <issuekey id="25076">CONTROLLER-522</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                            <customfield id="customfield_11400" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10208" key="com.atlassian.jira.plugin.system.customfieldtypes:textfield">
                        <customfieldname>External issue ID</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1111</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10201" key="com.atlassian.jira.plugin.system.customfieldtypes:url">
                        <customfieldname>External issue URL</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[https://bugs.opendaylight.org/show_bug.cgi?id=1111]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10000" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0|i02kxj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                </customfields>
    </item>
</channel>
</rss>