<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Counter action giving duplicate numbers in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211606#M164736</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The code is usually called from an asynchronously executed action, which then wraps the actual code like so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;serviceRegistry.getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback&amp;lt;Boolean&amp;gt;() { &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Boolean execute() throws Throwable { &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // code called here &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR /&gt;}, false, true); &lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Separate calls to the code above are in turn queued. The duplicate counter values ended up being committed to the repository (i.e. visible via the Alfresco web UI). Essentially this is part of a drop folder logic where an incoming ZIP file is extracted to a newly created space. The counter's value does not affect the destination space's name, since a GUID is used for that – it's just stored in a property field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 Apr 2010 08:14:15 GMT</pubDate>
    <dc:creator>ovirtanen</dc:creator>
    <dc:date>2010-04-22T08:14:15Z</dc:date>
    <item>
      <title>Counter action giving duplicate numbers</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211604#M164734</link>
      <description>I have a piece of code that uses a central space as the location of a counter aspect, then injects the next value to a given object as a sequence number, like so:synchronized public void injectIdentifier(NodeRef nodeRef) {&amp;nbsp;&amp;nbsp;&amp;nbsp;NodeRef rootSpace = locateRootSpace();&amp;nbsp;&amp;nbsp;&amp;nbsp;Action countAction = serviceRegist</description>
      <pubDate>Tue, 20 Apr 2010 11:32:36 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211604#M164734</guid>
      <dc:creator>ovirtanen</dc:creator>
      <dc:date>2010-04-20T11:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Counter action giving duplicate numbers</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211605#M164735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Even though the code is synchronized, it still cannot see data written by uncommitted transactions and might even not see data by committed transactions due to its caches.&amp;nbsp; In theory, the setProperty should fall out with ConcurrentModificationException (and trigger transaction retrying) if there are concurrent count transactions taking place.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What are your transaction boundaries w.r.t. this method?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Who is reading the counter value (how did you detect the behaviour)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What does the action do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 20:46:44 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211605#M164735</guid>
      <dc:creator>derek</dc:creator>
      <dc:date>2010-04-21T20:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Counter action giving duplicate numbers</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211606#M164736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The code is usually called from an asynchronously executed action, which then wraps the actual code like so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;serviceRegistry.getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback&amp;lt;Boolean&amp;gt;() { &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Boolean execute() throws Throwable { &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // code called here &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR /&gt;}, false, true); &lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Separate calls to the code above are in turn queued. The duplicate counter values ended up being committed to the repository (i.e. visible via the Alfresco web UI). Essentially this is part of a drop folder logic where an incoming ZIP file is extracted to a newly created space. The counter's value does not affect the destination space's name, since a GUID is used for that – it's just stored in a property field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Apr 2010 08:14:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211606#M164736</guid>
      <dc:creator>ovirtanen</dc:creator>
      <dc:date>2010-04-22T08:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Counter action giving duplicate numbers</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211607#M164737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want your counter value to be consistent (i.e. behave predictably) then you need to get the &lt;/SPAN&gt;&lt;EM&gt;next&lt;/EM&gt;&lt;SPAN&gt; value using either the same transaction or a nested transaction.&amp;nbsp; Depending on how the "counter" action has been coded and configured, inconsistency could very well occur.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could just stick your counter logic in a regular bean so that you get this pseudo code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;start new transaction (as you did in your last post)&lt;BR /&gt;call injectIdentifier(NodeRef nodeRef);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Integer nextCount = call counterBean.nextCount();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start new, non-propagating transaction IFF you don't mind holes in the counter sequence (I'd suggest this for better concurrency)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get the value from the root space, increment it, set it and return the new value&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Set the property on your nodeRef (the folder that you're unzipping to, I presume)&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also use a new node (perhaps the folder or any node that has changed during the import) and call NodeService.getNodeStatus().getDbTxnId() to get a sequential number that will be unique for your import.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Apr 2010 09:35:35 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/counter-action-giving-duplicate-numbers/m-p/211607#M164737</guid>
      <dc:creator>derek</dc:creator>
      <dc:date>2010-04-22T09:35:35Z</dc:date>
    </item>
  </channel>
</rss>

