usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [47/50] git commit: Fixed incorrect UUID comparisons
Date Wed, 12 Feb 2014 13:21:55 GMT
Fixed incorrect UUID comparisons


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/499834a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/499834a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/499834a6

Branch: refs/heads/optimistic-tx-semantics
Commit: 499834a6bdd606e60252228b930b9234f1f7ea8a
Parents: e24f3d2
Author: Todd Nine <tnine@apigee.com>
Authored: Mon Feb 10 10:01:20 2014 -0700
Committer: Todd Nine <tnine@apigee.com>
Committed: Mon Feb 10 10:01:48 2014 -0700

----------------------------------------------------------------------
 .../mvcc/changelog/ChangeLogEntry.java          |  5 ++++-
 .../mvcc/changelog/ChangeLogGeneratorImpl.java  |  8 ++++++--
 .../persistence/graph/impl/EdgeManagerImpl.java | 21 +++++++++++++++++++-
 .../serialization/EdgeSerializationTest.java    |  4 +++-
 4 files changed, 33 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/499834a6/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogEntry.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogEntry.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogEntry.java
index 56ffc89..e4b2c2b 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogEntry.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogEntry.java
@@ -25,6 +25,9 @@ import java.util.UUID;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.field.Field;
 
+import com.fasterxml.uuid.UUIDComparator;
+
+
 /**
  * Records one change to an entry field: entry ID, version, change type and the changed field.
  */
@@ -54,7 +57,7 @@ public class ChangeLogEntry implements Comparable {
 
     public int compareTo( Object o ) {
         ChangeLogEntry other = (ChangeLogEntry)o;
-        return entityId.getUuid().compareTo( other.entityId.getUuid() );
+        return UUIDComparator.staticCompare(entityId.getUuid(), other.entityId.getUuid());
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/499834a6/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
index 4ede822..51d175a 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/changelog/ChangeLogGeneratorImpl.java
@@ -28,6 +28,9 @@ import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.field.Field;
 
+import com.fasterxml.uuid.UUIDComparator;
+
+
 /**
  * A default implementation of {@link ChangeLogGenerator}.
  */
@@ -49,7 +52,8 @@ public class ChangeLogGeneratorImpl implements ChangeLogGenerator {
         for ( MvccEntity mvccEntity : mvccEntities ) {
 
             Entity entity = mvccEntity.getEntity().get();
-            int compare = mvccEntity.getVersion().compareTo( minVersion );
+
+            int compare = UUIDComparator.staticCompare( mvccEntity.getVersion(), minVersion
);
 
             if ( compare == 0 ) {
                 keeper = entity;
@@ -59,7 +63,7 @@ public class ChangeLogGeneratorImpl implements ChangeLogGenerator {
         for ( MvccEntity mvccEntity : mvccEntities ) {
 
             Entity entity = mvccEntity.getEntity().get();
-            int compare = mvccEntity.getVersion().compareTo( minVersion );
+            int compare = UUIDComparator.staticCompare( mvccEntity.getVersion(), minVersion
);
 
             if ( compare == -1 ) { // less than minVersion
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/499834a6/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
index 5100119..67cd8e8 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/EdgeManagerImpl.java
@@ -21,6 +21,7 @@ package org.apache.usergrid.persistence.graph.impl;
 
 
 import java.util.Iterator;
+import java.util.UUID;
 
 import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.collection.mvcc.entity.ValidationUtils;
@@ -36,11 +37,13 @@ import org.apache.usergrid.persistence.graph.serialization.impl.parse.Observable
 import org.apache.usergrid.persistence.graph.serialization.stage.GraphIoEvent;
 import org.apache.usergrid.persistence.graph.serialization.stage.write.EdgeWriteStage;
 
+import com.fasterxml.uuid.UUIDComparator;
 import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
 
 import rx.Observable;
 import rx.Scheduler;
+import rx.util.functions.Func1;
 
 
 /**
@@ -93,12 +96,14 @@ public class EdgeManagerImpl implements EdgeManager {
 
     @Override
     public Observable<Edge> loadEdgesFromSource( final SearchByEdgeType search ) {
-        return Observable.create( new ObservableIterator<Edge>() {
+        Observable<Edge> iterator =  Observable.create( new ObservableIterator<Edge>()
{
             @Override
             protected Iterator<Edge> getIterator() {
                 return edgeSerialization.getEdgesFromSource( scope, search );
             }
         } );
+
+        return filter(iterator, search.getMaxVersion());
     }
 
 
@@ -167,4 +172,18 @@ public class EdgeManagerImpl implements EdgeManager {
             }
         } );
     }
+
+    private  Observable<Edge> filter(final Observable<Edge> observable, final
UUID maxVersion){
+        if(maxVersion == null){
+            return observable;
+        }
+
+        return observable.filter( new Func1<Edge, Boolean>() {
+            @Override
+            public Boolean call( final Edge edge ) {
+                //our edge version needs to be <= max Version
+                return UUIDComparator.staticCompare( edge.getVersion(), maxVersion ) <
1;
+            }
+        } );
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/499834a6/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
index a51b2b6..160ee27 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
@@ -22,6 +22,7 @@ import org.apache.usergrid.persistence.graph.guice.TestGraphModule;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 
+import com.fasterxml.uuid.UUIDComparator;
 import com.google.inject.Inject;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
@@ -180,7 +181,8 @@ public class EdgeSerializationTest {
 
         final Edge edgev2 = createEdge( sourceId, "edge1", targetId );
 
-        assertTrue( "Edge version 1 has lower time uuid", edgev1.getVersion().compareTo(
edgev2.getVersion() ) < 0 );
+        assertTrue( "Edge version 1 has lower time uuid", UUIDComparator
+                        .staticCompare( edgev1.getVersion(),  edgev2.getVersion() ) <
0 );
 
         //create edge type 2 to ensure we don't get it in results
         final Edge edgeType2V1 = createEdge( sourceId, "edge2", targetId );


Mime
View raw message