You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Andrus Adamchik (JIRA)" <ji...@apache.org> on 2010/08/23 13:39:16 UTC

[jira] Closed: (CAY-1473) Ensure DataRow version increment is atomic

     [ https://issues.apache.org/jira/browse/CAY-1473?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrus Adamchik closed CAY-1473.
--------------------------------

    Resolution: Fixed

> Ensure DataRow version increment is atomic
> ------------------------------------------
>
>                 Key: CAY-1473
>                 URL: https://issues.apache.org/jira/browse/CAY-1473
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0
>            Reporter: Andrus Adamchik
>            Assignee: Andrus Adamchik
>            Priority: Trivial
>             Fix For: 3.0.1, 3.1M1
>
>
> The following patch explains the issue... There seems to be a slight chance of 2 DataRows grabbng the same version. Nobody ever complained about this causing a real issue in an app (since two conflicting rows with the same version must belong to the same object, which is rather unlikely), still need to keep our algorithms tight and clean.
> diff --git a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java b/framework/cayenne-jdk1.5-unpublished/
> index 6a5fd74..8f1854b 100644
> --- a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java
> +++ b/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java
> @@ -21,6 +21,7 @@ package org.apache.cayenne;
>  
>  import java.util.HashMap;
>  import java.util.Map;
> +import java.util.concurrent.atomic.AtomicLong;
>  
>  import org.apache.cayenne.map.DbRelationship;
>  import org.apache.cayenne.util.ToStringBuilder;
> @@ -35,13 +36,11 @@ import org.apache.cayenne.util.Util;
>   */
>  public class DataRow extends HashMap<String, Object> {
>  
> -    // "volatile" is supposed to ensure consistency in read and increment operations;
> -    // is this universally true?
> -
>      // make sure the starting value is different from DataObject default version value
> -    private static volatile long currentVersion = DataObject.DEFAULT_VERSION + 1;
> +    private static volatile AtomicLong currentVersion = new AtomicLong(
> +            DataObject.DEFAULT_VERSION + 1);
>  
> -    protected long version = currentVersion++;
> +    protected long version = currentVersion.getAndIncrement();
>      protected long replacesVersion = DataObject.DEFAULT_VERSION;
>  
>      /**

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.