cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrus Adamchik (JIRA)" <j...@apache.org>
Subject [jira] Created: (CAY-1473) Ensure DataRow version increment is atomic
Date Mon, 23 Aug 2010 11:31:17 GMT
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.


Mime
View raw message